X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali%2Finternal%2Frender%2Frenderers%2Frender-geometry.cpp;h=b407b6f9fac49a5ac8adcb4e9fef84c039259f9c;hb=a513234144a775134eff3a24144983a5e374d1d5;hp=cd6f8f64afb1c08fcda61874a83276d19a697448;hpb=3aa909145b7d672d0b966d3595b138ed1537b091;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/renderers/render-geometry.cpp b/dali/internal/render/renderers/render-geometry.cpp index cd6f8f6..b407b6f 100644 --- a/dali/internal/render/renderers/render-geometry.cpp +++ b/dali/internal/render/renderers/render-geometry.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -28,9 +28,32 @@ namespace Internal { 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), @@ -51,10 +74,20 @@ const Vector& Geometry::GetVertexBuffers() const return mVertexBuffers; } -void Geometry::SetIndexBuffer(Dali::Vector& 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) @@ -116,11 +149,7 @@ void Geometry::Upload(Graphics::Controller& graphicsController) } } -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(mVertexBuffers.Count()); @@ -150,16 +179,27 @@ bool Geometry::Draw( 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(mIndices.Size()); + std::size_t sizeOfIndex = GetSizeOfIndexFromIndexType(mIndexType); + + numIndices = static_cast(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; } @@ -176,7 +216,7 @@ bool Geometry::Draw( 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); @@ -184,11 +224,12 @@ bool Geometry::Draw( 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(mVertexBuffers[0]->GetElementCount()); + numVertices = static_cast(mVertexBuffers[0]->GetElementCount()); } commandBuffer.Draw(numVertices, 1, 0, 0);