/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
namespace Render
{
+namespace
+{
+inline constexpr size_t GetSizeOfIndexFromIndexType(Dali::Graphics::Format graphicsFormat)
+{
+ switch(graphicsFormat)
+ {
+ case Dali::Graphics::Format::R16_UINT:
+ {
+ return sizeof(uint16_t);
+ }
+ case Dali::Graphics::Format::R32_UINT:
+ {
+ return sizeof(uint32_t);
+ }
+ default:
+ {
+ // TODO : Not implmeneted.
+ return sizeof(uint16_t);
+ }
+ }
+}
+} // unnamed namespace
Geometry::Geometry()
: mIndices(),
mIndexBuffer(nullptr),
+ mIndexType(Dali::Graphics::Format::R16_UINT),
mGeometryType(Dali::Geometry::TRIANGLES),
mIndicesChanged(false),
mHasBeenUpdated(false),
return mVertexBuffers;
}
-void Geometry::SetIndexBuffer(Dali::Vector<uint16_t>& indices)
+void Geometry::SetIndexBuffer(Uint16ContainerType& indices)
{
mIndices.Swap(indices);
mIndicesChanged = true;
+ mIndexType = Graphics::Format::R16_UINT;
+}
+
+void Geometry::SetIndexBuffer(Uint32ContainerType& indices)
+{
+ // mIndices type is not matched with indices. Copy memory hardly.
+ mIndices.ResizeUninitialized(indices.Count() * 2);
+ memcpy(mIndices.Begin(), indices.Begin(), indices.Count() * sizeof(uint32_t));
+ mIndicesChanged = true;
+ mIndexType = Graphics::Format::R32_UINT;
}
void Geometry::RemoveVertexBuffer(const Render::VertexBuffer* vertexBuffer)
}
}
-bool Geometry::Draw(
- Graphics::Controller& graphicsController,
- Graphics::CommandBuffer& commandBuffer,
- uint32_t elementBufferOffset,
- uint32_t elementBufferCount)
+bool Geometry::BindVertexAttributes(Graphics::CommandBuffer& commandBuffer)
{
//Bind buffers to attribute locations
const auto vertexBufferCount = static_cast<uint32_t>(mVertexBuffers.Count());
commandBuffer.BindVertexBuffers(0, buffers, offsets);
+ return true;
+}
+
+bool Geometry::Draw(
+ Graphics::Controller& graphicsController,
+ Graphics::CommandBuffer& commandBuffer,
+ uint32_t elementBufferOffset,
+ uint32_t elementBufferCount)
+{
uint32_t numIndices(0u);
intptr_t firstIndexOffset(0u);
if(mIndexBuffer)
{
- numIndices = static_cast<uint32_t>(mIndices.Size());
+ std::size_t sizeOfIndex = GetSizeOfIndexFromIndexType(mIndexType);
+
+ numIndices = static_cast<uint32_t>(mIndices.Size() * sizeof(uint16_t) / sizeOfIndex);
if(elementBufferOffset != 0u)
{
elementBufferOffset = (elementBufferOffset >= numIndices) ? numIndices - 1 : elementBufferOffset;
- firstIndexOffset = elementBufferOffset * sizeof(GLushort);
+ firstIndexOffset = intptr_t(elementBufferOffset * sizeOfIndex);
numIndices -= elementBufferOffset;
}
const Graphics::Buffer* ibo = mIndexBuffer->GetGraphicsObject();
if(ibo)
{
- commandBuffer.BindIndexBuffer(*ibo, 0, Graphics::Format::R16_UINT);
+ commandBuffer.BindIndexBuffer(*ibo, 0, mIndexType);
}
commandBuffer.DrawIndexed(numIndices, 1, firstIndexOffset, 0, 0);
else
{
// Un-indexed draw call
- GLsizei numVertices(0u);
- if(vertexBufferCount > 0)
+ uint32_t numVertices(0u);
+
+ if(mVertexBuffers.Count() > 0)
{
// truncated, no value loss happening in practice
- numVertices = static_cast<GLsizei>(mVertexBuffers[0]->GetElementCount());
+ numVertices = static_cast<uint32_t>(mVertexBuffers[0]->GetElementCount());
}
commandBuffer.Draw(numVertices, 1, 0, 0);