}
}
+inline void HashString(const char* string, std::size_t& hash, char terminator)
+{
+ char c;
+ while((c = *string++) && c != terminator)
+ {
+ hash = hash * 33 + c;
+ }
+}
+
} // unnamed namespace
std::size_t CalculateHash(const std::string& toHash)
return hash;
}
+std::size_t CalculateHash(const std::string& toHash, char terminator)
+{
+ std::size_t hash(INITIAL_HASH_VALUE);
+
+ HashString(toHash.c_str(), hash, terminator);
+
+ return hash;
+}
+
std::size_t CalculateHash(const std::string& string1, const std::string& string2)
{
std::size_t hash(INITIAL_HASH_VALUE);
*/
DALI_CORE_API std::size_t CalculateHash(const std::string& string1, const std::string& string2);
+/**
+ * @brief Create a hash code for a string
+ * @param toHash string to hash
+ * @param terminator character terminating the hashing
+ * @return hash code
+ */
+DALI_CORE_API std::size_t CalculateHash(const std::string& toHash, char terminator);
+
} // namespace Dali
#endif // DALI_HASH
}
/**
+ * @brief Sets properties flags
+ *
+ * Properties flag bits can alter behaviour of the implementation
+ *
+ * @param[in] value Flags
+ * @return reference to this structure
+ */
+ auto& SetBufferPropertiesFlags( BufferPropertiesFlags value )
+ {
+ propertiesFlags = value;
+ return *this;
+ }
+
+ /**
* @brief Sets allocation callbacks which will be used when object is created
* and destroyed.
*
ExtensionCreateInfo* nextExtension{nullptr};
BufferUsageFlags usage{};
uint32_t size{0u};
-
+ BufferPropertiesFlags propertiesFlags{};
const AllocationCallbacks* allocationCallbacks{nullptr};
};
* It is useful if the command buffer has to be re-recorded frequently, for example,
* every frame.
*/
- virtual void Reset(CommandBuffer& commandBuffer) = 0;
+ virtual void Reset() = 0;
/**
* @brief Changes scissor rect
}
/**
+ * @brief Buffer property bits
+ *
+ * Use these bits to set BufferPropertiesFlags.
+ */
+enum class BufferPropertiesFlagBit : uint32_t
+{
+ CPU_ALLOCATED = 1 << 0, ///< Buffer is allocated on the CPU side
+ TRANSIENT_MEMORY = 1 << 1, ///< Buffer memory will be short-lived
+};
+
+/**
+ * @brief BufferPropetiesFlags alters behaviour of implementation
+ */
+using BufferPropertiesFlags = uint32_t;
+
+inline BufferPropertiesFlags operator|(BufferPropertiesFlags flags, BufferPropertiesFlagBit usage)
+{
+ flags |= static_cast<uint32_t>(usage);
+ return flags;
+}
+
+/**
* @brief The structure describes memory requirements of GPU resource (texture, buffer)
*/
struct MemoryRequirements
{
return;
}
+ if(!mGraphicsCommandBuffer)
+ {
+ mGraphicsCommandBuffer = mGraphicsController->CreateCommandBuffer(
+ Graphics::CommandBufferCreateInfo()
+ .SetLevel(Graphics::CommandBufferLevel::SECONDARY),
+ nullptr);
+ }
+ else
+ {
+ mGraphicsCommandBuffer->Reset();
+ }
- Graphics::UniquePtr<Graphics::CommandBuffer> commandBuffer = mGraphicsController->CreateCommandBuffer(
- Graphics::CommandBufferCreateInfo()
- .SetLevel(Graphics::CommandBufferLevel::SECONDARY),
- nullptr);
+ auto& commandBuffer = mGraphicsCommandBuffer;
//Set blending mode
if(!mDrawCommands.empty())
template<class T>
bool Renderer::WriteDefaultUniform(const Graphics::UniformInfo* uniformInfo, Render::UniformBuffer& ubo, const std::vector<Graphics::UniformBufferBinding>& bindings, const T& data)
{
- if(uniformInfo)
+ if(uniformInfo && !uniformInfo->name.empty())
{
WriteUniform(ubo, bindings, *uniformInfo, data);
return true;
switch((*iter).propertyValue->GetType())
{
- case Property::Type::FLOAT:
- case Property::Type::INTEGER:
case Property::Type::BOOLEAN:
{
+ ubo.Write(&(*iter).propertyValue->GetBoolean(updateBufferIndex),
+ sizeof(bool),
+ dst + static_cast<uint32_t>(sizeof(bool)) * arrayIndex);
+ break;
+ }
+ case Property::Type::INTEGER:
+ {
+ ubo.Write(&(*iter).propertyValue->GetInteger(updateBufferIndex),
+ sizeof(int32_t),
+ dst + static_cast<int32_t>(sizeof(int32_t)) * arrayIndex);
+ break;
+ }
+ case Property::Type::FLOAT:
+ {
ubo.Write(&(*iter).propertyValue->GetFloat(updateBufferIndex),
sizeof(float),
- dst + static_cast<uint32_t>(sizeof(Vector4)) * arrayIndex);
+ dst + static_cast<uint32_t>(sizeof(float)) * arrayIndex);
break;
}
case Property::Type::VECTOR2:
{
ubo.Write(&(*iter).propertyValue->GetVector2(updateBufferIndex),
sizeof(Vector2),
- dst + static_cast<uint32_t>(sizeof(Vector4)) * arrayIndex);
+ dst + static_cast<uint32_t>(sizeof(Vector2)) * arrayIndex);
break;
}
case Property::Type::VECTOR3:
{
ubo.Write(&(*iter).propertyValue->GetVector3(updateBufferIndex),
sizeof(Vector3),
- dst + static_cast<uint32_t>(sizeof(Vector4)) * arrayIndex);
+ dst + static_cast<uint32_t>(sizeof(Vector3)) * arrayIndex);
break;
}
case Property::Type::VECTOR4:
}
case Property::Type::MATRIX3:
{
- const auto& matrix = &(*iter).propertyValue->GetMatrix3(updateBufferIndex);
- for(int i = 0; i < 3; ++i)
- {
- ubo.Write(&matrix->AsFloat()[i * 3],
- sizeof(float) * 3,
- dst + (i * static_cast<uint32_t>(sizeof(Vector4))));
- }
+ // todo: handle data padding properly
+ // Vulkan:
+ //
+ //const auto& matrix = &(*iter).propertyValue->GetMatrix3(updateBufferIndex);
+ //for(int i = 0; i < 3; ++i)
+ //{
+ //ubo.Write(&matrix->AsFloat()[i * 3],
+ // sizeof(float) * 3,
+ // dst + (i * static_cast<uint32_t>(sizeof(Vector4))));
+ //}
+ // GL:
+ ubo.Write(&(*iter).propertyValue->GetMatrix3(updateBufferIndex),
+ sizeof(Matrix3),
+ dst + static_cast<uint32_t>(sizeof(Matrix3)) * arrayIndex);
break;
}
default:
Context* mContext;
Render::Geometry* mGeometry;
+ Graphics::UniquePtr<Graphics::CommandBuffer> mGraphicsCommandBuffer{};
+
ProgramCache* mProgramCache{};
Render::ShaderCache* mShaderCache{};
mSize = size;
- Graphics::BufferCreateInfo createInfo;
- createInfo.SetSize(mSize);
- createInfo.SetUsage(mUsageFlags);
- mBuffer = std::move(mController->CreateBuffer(createInfo, std::move(mBuffer)));
+ auto createInfo = Graphics::BufferCreateInfo()
+ .SetSize(mSize)
+ .SetBufferPropertiesFlags( 0 | Graphics::BufferPropertiesFlagBit::CPU_ALLOCATED )
+ .SetUsage(mUsageFlags);
+
+ mBuffer = mController->CreateBuffer(createInfo, std::move(mBuffer));
mMapBufferInfo.buffer = mBuffer.get();
mMapBufferInfo.usage = 0 | Graphics::MemoryUsageFlagBits::WRITE;
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/common/dali-vector.h>
-namespace
-{
-void LogWithLineNumbers(const char* source)
-{
- uint32_t lineNumber = 0u;
- const char* prev = source;
- const char* ptr = prev;
-
- while(true)
- {
- if(lineNumber > 200u)
- {
- break;
- }
- // seek the next end of line or end of text
- while(*ptr != '\n' && *ptr != '\0')
- {
- ++ptr;
- }
-
- std::string line(prev, ptr - prev);
- Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugError, "%4d %s\n", lineNumber, line.c_str());
-
- if(*ptr == '\0')
- {
- break;
- }
- prev = ++ptr;
- ++lineNumber;
- }
-}
-
-} //namespace
-
namespace Dali
{
namespace Internal
return false;
}
- hashedName = !hashedName ? CalculateHash(name) : hashedName;
+ hashedName = !hashedName ? CalculateHash(name, '[') : hashedName;
for(const ReflectionUniformInfo& item : mReflection)
{
auto pos0 = theUniformName.GetStringView().rfind("[", pos);
arrayIndex = atoi(theUniformName.GetCString() + pos0 + 1);
// Calculate hash from name without array index
- uniformNameHashNoArray = Dali::CalculateHash(theUniformName.GetStringView().substr(0, pos0).data());
+ uniformNameHashNoArray = Dali::CalculateHash(theUniformName.GetStringView().substr(0, pos0).data(), '[');
}
uniformName = theUniformName;
uniformNameHash = Dali::CalculateHash(theUniformName.GetCString());