END_TEST;
}
+int UtcDaliGeometrySetIndexBuffer32Bits(void)
+{
+ TestApplication application;
+ auto& bufferTrace = application.GetGlAbstraction().GetBufferTrace();
+ bufferTrace.Enable(true);
+ bufferTrace.EnableLogging(true);
+
+ tet_infoline("Test SetIndexBuffer 32Bits");
+
+ VertexBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord");
+
+ Geometry geometry = Geometry::New();
+ geometry.AddVertexBuffer(vertexBuffer);
+
+ Shader shader = CreateShader();
+ Renderer renderer = Renderer::New(geometry, shader);
+ Actor actor = Actor::New();
+ actor.SetProperty(Actor::Property::SIZE, Vector3::ONE * 100.f);
+ actor.AddRenderer(renderer);
+ application.GetScene().Add(actor);
+
+ application.SendNotification();
+ application.Render(0);
+ application.Render();
+ application.SendNotification();
+
+ {
+ const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
+ application.GetGlAbstraction().GetBufferDataCalls();
+
+ DALI_TEST_EQUALS(bufferDataCalls.size(), 3u, TEST_LOCATION);
+
+ DALI_TEST_EQUALS(bufferDataCalls[0], 4 * sizeof(TexturedQuadVertex), TEST_LOCATION);
+ }
+
+ // Set index buffer
+ application.GetGlAbstraction().ResetBufferDataCalls();
+
+ const uint32_t indexData32Bits[6] = {0, 3, 1, 0, 2, 3};
+ geometry.SetIndexBuffer(indexData32Bits, sizeof(indexData32Bits) / sizeof(indexData32Bits[0]));
+ application.SendNotification();
+ application.Render(0);
+ application.Render();
+ application.SendNotification();
+
+ {
+ const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
+ application.GetGlAbstraction().GetBufferDataCalls();
+
+ //Only the index buffer should be uploaded
+ DALI_TEST_EQUALS(bufferDataCalls.size(), 1u, TEST_LOCATION);
+
+ // should be unsigned int instead of unsigned short
+ DALI_TEST_EQUALS(bufferDataCalls[0], 6 * sizeof(uint32_t), TEST_LOCATION);
+ }
+
+ END_TEST;
+}
+
int UtcDaliGeometrySetGetGeometryType01(void)
{
TestApplication application;
/*
- * 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.
void Geometry::SetIndexBuffer(const uint16_t* indices, uint32_t count)
{
- Dali::Vector<uint16_t> indexData;
+ Render::Geometry::Uint16ContainerType indexData;
if(indices && count)
{
- indexData.Resize(count);
+ indexData.ResizeUninitialized(count);
+ std::copy(indices, indices + count, indexData.Begin());
+ }
+
+ SceneGraph::SetIndexBufferMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, indexData);
+}
+
+void Geometry::SetIndexBuffer(const uint32_t* indices, uint32_t count)
+{
+ Render::Geometry::Uint32ContainerType indexData;
+ if(indices && count)
+ {
+ indexData.ResizeUninitialized(count);
std::copy(indices, indices + count, indexData.Begin());
}
void SetIndexBuffer(const uint16_t* indices, uint32_t count);
/**
+ * @copydoc Dali::Geometry::SetIndexBuffer()
+ */
+ void SetIndexBuffer(const uint32_t* indices, uint32_t count);
+
+ /**
* @copydoc Dali::Geometry::SetType()
*/
void SetType(Dali::Geometry::Type geometryType);
// create a new DALi vector to store the buffer data
// the heap allocated vector will end up being owned by Render::VertexBuffer
OwnerPointer<Vector<uint8_t> > bufferCopy = new Dali::Vector<uint8_t>();
- bufferCopy->Resize(bufferSize);
+ bufferCopy->ResizeUninitialized(bufferSize);
// copy the data
const uint8_t* source = static_cast<const uint8_t*>(data);
vertexBuffer->SetData(data.Release(), size);
}
-void RenderManager::SetIndexBuffer(Render::Geometry* geometry, Dali::Vector<uint16_t>& indices)
+void RenderManager::SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint16ContainerType& indices)
+{
+ geometry->SetIndexBuffer(indices);
+}
+
+void RenderManager::SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint32ContainerType& indices)
{
geometry->SetIndexBuffer(indices);
}
* @param[in] geometry The geometry
* @param[in] data A vector containing the indices
*/
- void SetIndexBuffer(Render::Geometry* geometry, Dali::Vector<uint16_t>& data);
+ void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint16ContainerType& data);
+
+ /**
+ * Sets the data for the index buffer of an existing geometry
+ * @param[in] geometry The geometry
+ * @param[in] data A vector containing the indices
+ */
+ void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint32ContainerType& data);
/**
* Set the geometry type of an existing render geometry
/*
- * 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)
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 = intptr_t(elementBufferOffset * sizeof(uint16_t));
+ 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);
#define DALI_INTERNAL_RENDER_GEOMETRY_H
/*
- * 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.
// INTERNAL INCLUDES
#include <dali/devel-api/common/owner-container.h>
#include <dali/graphics-api/graphics-controller.h>
+#include <dali/graphics-api/graphics-types.h>
#include <dali/internal/common/buffer-index.h>
#include <dali/internal/common/owner-pointer.h>
#include <dali/public-api/common/dali-vector.h>
class Geometry
{
public:
- using Type = Dali::Geometry::Type;
+ using Type = Dali::Geometry::Type;
+ using IndexType = Dali::Graphics::Format;
+
+ using Uint16ContainerType = Dali::Vector<uint16_t>;
+ using Uint32ContainerType = Dali::Vector<uint32_t>;
Geometry();
* Set the data for the index buffer to be used by the geometry
* @param[in] indices A vector containing the indices
*/
- void SetIndexBuffer(Dali::Vector<uint16_t>& indices);
+ void SetIndexBuffer(Uint16ContainerType& indices);
+
+ /**
+ * Set the data for the index buffer to be used by the geometry
+ * @param[in] indices A vector containing the indices
+ */
+ void SetIndexBuffer(Uint32ContainerType& indices);
/**
* Removes a VertexBuffer from the geometry
// VertexBuffers
Vector<Render::VertexBuffer*> mVertexBuffers;
- Dali::Vector<uint16_t> mIndices;
+ Uint16ContainerType mIndices;
OwnerPointer<GpuBuffer> mIndexBuffer;
+ IndexType mIndexType;
Type mGeometryType;
// Booleans
new(slot) DerivedType(&mImpl->renderManager, &RenderManager::SetGeometryType, geometry, geometryType);
}
-void UpdateManager::SetIndexBuffer(Render::Geometry* geometry, Dali::Vector<uint16_t>& indices)
+void UpdateManager::SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint16ContainerType& indices)
{
- using DerivedType = IndexBufferMessage<RenderManager>;
+ using DerivedType = IndexBufferMessage<RenderManager, Render::Geometry::Uint16ContainerType>;
+
+ // Reserve some memory inside the render queue
+ uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
+
+ // Construct message in the render queue memory; note that delete should not be called on the return value
+ new(slot) DerivedType(&mImpl->renderManager, geometry, indices);
+}
+
+void UpdateManager::SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint32ContainerType& indices)
+{
+ using DerivedType = IndexBufferMessage<RenderManager, Render::Geometry::Uint32ContainerType>;
// Reserve some memory inside the render queue
uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType));
* @param[in] geometry The geometry
* @param[in] indices A vector containing the indices for the geometry
*/
- void SetIndexBuffer(Render::Geometry* geometry, Dali::Vector<uint16_t>& indices);
+ void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint16ContainerType& indices);
+
+ /**
+ * Sets the index buffer to be used by a geometry
+ * @param[in] geometry The geometry
+ * @param[in] indices A vector containing the indices for the geometry
+ */
+ void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint32ContainerType& indices);
/**
* Adds a vertex buffer to a geometry
}
// Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
-template<typename T>
+template<typename T, typename IndexContainerType>
class IndexBufferMessage : public MessageBase
{
public:
/**
* Constructor which does a Vector::Swap()
*/
- IndexBufferMessage(T* manager, Render::Geometry* geometry, Dali::Vector<uint16_t>& indices)
+ IndexBufferMessage(T* manager, Render::Geometry* geometry, IndexContainerType& indices)
: MessageBase(),
mManager(manager),
mRenderGeometry(geometry)
}
private:
- T* mManager;
- Render::Geometry* mRenderGeometry;
- Dali::Vector<uint16_t> mIndices;
+ T* mManager;
+ Render::Geometry* mRenderGeometry;
+ IndexContainerType mIndices;
};
-inline void SetIndexBufferMessage(UpdateManager& manager, Render::Geometry& geometry, Dali::Vector<uint16_t>& indices)
+inline void SetIndexBufferMessage(UpdateManager& manager, Render::Geometry& geometry, Render::Geometry::Uint16ContainerType& indices)
+{
+ using LocalType = IndexBufferMessage<UpdateManager, Render::Geometry::Uint16ContainerType>;
+
+ // Reserve some memory inside the message queue
+ uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new(slot) LocalType(&manager, &geometry, indices);
+}
+
+inline void SetIndexBufferMessage(UpdateManager& manager, Render::Geometry& geometry, Render::Geometry::Uint32ContainerType& indices)
{
- using LocalType = IndexBufferMessage<UpdateManager>;
+ using LocalType = IndexBufferMessage<UpdateManager, Render::Geometry::Uint32ContainerType>;
// Reserve some memory inside the message queue
uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
GetImplementation(*this).SetIndexBuffer(indices, static_cast<uint32_t>(count));
}
+void Geometry::SetIndexBuffer(const uint32_t* indices, size_t count)
+{
+ GetImplementation(*this).SetIndexBuffer(indices, static_cast<uint32_t>(count));
+}
+
void Geometry::SetType(Type geometryType)
{
GetImplementation(*this).SetType(geometryType);
#define DALI_GEOMETRY_H
/*
- * Copyright (c) 2020 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.
void RemoveVertexBuffer(std::size_t index);
/**
- * @brief Sets a the index data to be used as a source of indices for the geometry
+ * @brief Sets the index data to be used as a source of indices for the geometry
* Setting this buffer will cause the geometry to be rendered using indices.
* To unset call SetIndexBuffer with a null pointer or count 0.
*
void SetIndexBuffer(const uint16_t* indices, size_t count);
/**
+ * @brief Sets the 32bits index data to be used as a source of indices for the geometry
+ * Setting this buffer will cause the geometry to be rendered using indices.
+ * To unset call SetIndexBuffer with a null pointer or count 0.
+ *
+ * @SINCE_2_2.16
+ * @param[in] indices Array of indices with uint32_t elements.
+ * @param[in] count Number of indices in the array
+ */
+ void SetIndexBuffer(const uint32_t* indices, size_t count);
+
+ /**
* @brief Sets the type of primitives this geometry contains.
*
* @SINCE_1_1.43