// INTERNAL INCLUDES
#include <dali/internal/common/buffer-index.h>
-#include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/gl-resources/gpu-buffer.h>
#include <dali/internal/render/renderers/render-vertex-buffer.h>
#include <dali/internal/render/shaders/program.h>
Geometry::~Geometry() = default;
-void Geometry::GlContextCreated(Context& context)
-{
-}
-
-void Geometry::GlContextDestroyed()
-{
-}
-
void Geometry::AddVertexBuffer(Render::VertexBuffer* vertexBuffer)
{
mVertexBuffers.PushBack(vertexBuffer);
mAttributesChanged = true;
}
+const Vector<Render::VertexBuffer*>& Geometry::GetVertexBuffers() const
+{
+ return mVertexBuffers;
+}
+
void Geometry::SetIndexBuffer(Dali::Vector<uint16_t>& indices)
{
mIndices.Swap(indices);
}
}
-void Geometry::GetAttributeLocationFromProgram(Vector<GLint>& attributeLocation, Program& program, BufferIndex bufferIndex) const
-{
- attributeLocation.Clear();
-
- for(auto&& vertexBuffer : mVertexBuffers)
- {
- const uint32_t attributeCount = vertexBuffer->GetAttributeCount();
- for(uint32_t j = 0; j < attributeCount; ++j)
- {
- auto attributeName = vertexBuffer->GetAttributeName(j);
- uint32_t index = program.RegisterCustomAttribute(attributeName);
- GLint location = program.GetCustomAttributeLocation(index);
-
- if(-1 == location)
- {
- DALI_LOG_WARNING("Attribute not found in the shader: %s\n", attributeName.GetCString());
- }
-
- attributeLocation.PushBack(location);
- }
- }
-}
-
void Geometry::OnRenderFinished()
{
mHasBeenUpdated = false;
}
}
-void Geometry::Draw(
- Context& context,
+bool Geometry::Draw(
Graphics::Controller& graphicsController,
Graphics::CommandBuffer& commandBuffer,
- BufferIndex bufferIndex,
- Vector<GLint>& attributeLocation,
uint32_t elementBufferOffset,
uint32_t elementBufferCount)
{
//Bind buffers to attribute locations
- uint32_t base = 0u;
- const uint32_t vertexBufferCount = static_cast<uint32_t>(mVertexBuffers.Count());
+ const auto vertexBufferCount = static_cast<uint32_t>(mVertexBuffers.Count());
std::vector<const Graphics::Buffer*> buffers;
std::vector<uint32_t> offsets;
for(uint32_t i = 0; i < vertexBufferCount; ++i)
{
- Graphics::Buffer* buffer = mVertexBuffers[i]->GetGpuBuffer().GetGraphicsObject();
-
- if(buffer)
+ const GpuBuffer* gpuBuffer = mVertexBuffers[i]->GetGpuBuffer();
+ if(gpuBuffer)
{
- buffers.push_back(buffer);
- offsets.push_back(0u);
+ const Graphics::Buffer* buffer = gpuBuffer->GetGraphicsObject();
+
+ if(buffer)
+ {
+ buffers.push_back(buffer);
+ offsets.push_back(0u);
+ }
}
+ //@todo Figure out why this is being drawn without geometry having been uploaded
}
+ if(buffers.empty())
+ {
+ return false;
+ }
+
commandBuffer.BindVertexBuffers(0, buffers, offsets);
uint32_t numIndices(0u);
if(elementBufferOffset != 0u)
{
elementBufferOffset = (elementBufferOffset >= numIndices) ? numIndices - 1 : elementBufferOffset;
- firstIndexOffset = elementBufferOffset * sizeof(GLushort);
+ firstIndexOffset = intptr_t(elementBufferOffset * sizeof(uint16_t));
numIndices -= elementBufferOffset;
}
}
}
- GLenum geometryGLType(GL_NONE);
+ //Draw call
+ if(mIndexBuffer && mGeometryType != Dali::Geometry::POINTS)
+ {
+ //Indexed draw call
+ const Graphics::Buffer* ibo = mIndexBuffer->GetGraphicsObject();
+ if(ibo)
+ {
+ commandBuffer.BindIndexBuffer(*ibo, 0, Graphics::Format::R16_UINT);
+ }
+
+ commandBuffer.DrawIndexed(numIndices, 1, firstIndexOffset, 0, 0);
+ }
+ else
+ {
+ // Un-indexed draw call
+ uint32_t numVertices(0u);
+ if(vertexBufferCount > 0)
+ {
+ // truncated, no value loss happening in practice
+ numVertices = static_cast<uint32_t>(mVertexBuffers[0]->GetElementCount());
+ }
+
+ commandBuffer.Draw(numVertices, 1, 0, 0);
+ }
+ return true;
+}
+
+Graphics::PrimitiveTopology Geometry::GetTopology() const
+{
+ Graphics::PrimitiveTopology topology = Graphics::PrimitiveTopology::TRIANGLE_LIST;
+
switch(mGeometryType)
{
case Dali::Geometry::TRIANGLES:
{
- geometryGLType = GL_TRIANGLES;
+ topology = Graphics::PrimitiveTopology::TRIANGLE_LIST;
break;
}
case Dali::Geometry::LINES:
{
- geometryGLType = GL_LINES;
+ topology = Graphics::PrimitiveTopology::LINE_LIST;
break;
}
case Dali::Geometry::POINTS:
{
- geometryGLType = GL_POINTS;
+ topology = Graphics::PrimitiveTopology::POINT_LIST;
break;
}
case Dali::Geometry::TRIANGLE_STRIP:
{
- geometryGLType = GL_TRIANGLE_STRIP;
+ topology = Graphics::PrimitiveTopology::TRIANGLE_STRIP;
break;
}
case Dali::Geometry::TRIANGLE_FAN:
{
- geometryGLType = GL_TRIANGLE_FAN;
+ topology = Graphics::PrimitiveTopology::TRIANGLE_FAN;
break;
}
case Dali::Geometry::LINE_LOOP:
{
- geometryGLType = GL_LINE_LOOP;
+ topology = Graphics::PrimitiveTopology::LINE_LOOP;
break;
}
case Dali::Geometry::LINE_STRIP:
{
- geometryGLType = GL_LINE_STRIP;
+ topology = Graphics::PrimitiveTopology::LINE_STRIP;
break;
}
}
-
- //Draw call
- if(mIndexBuffer && geometryGLType != GL_POINTS)
- {
- //Indexed draw call
- Graphics::Buffer* ibo = mIndexBuffer->GetGraphicsObject();
- if(ibo)
- {
- commandBuffer.BindIndexBuffer(*ibo, 0, Graphics::Format::R16_UINT);
- }
-
- // Command buffer contains Texture bindings, vertex bindings and index buffer binding.
- Graphics::SubmitInfo submitInfo{{}, 0 | Graphics::SubmitFlagBits::FLUSH};
- submitInfo.cmdBuffer.push_back(&commandBuffer);
- graphicsController.SubmitCommandBuffers(submitInfo);
-
- //@todo This should all be done from inside Pipeline implementation.
- //If there is only 1 vertex buffer, it should have been bound by SubmitCommandBuffers,
- //and the single GL call from this will work on that bound buffer.
- for(uint32_t i = 0; i < vertexBufferCount; ++i)
- {
- base += mVertexBuffers[i]->EnableVertexAttributes(context, attributeLocation, base);
- }
-
- // numIndices truncated, no value loss happening in practice
- context.DrawElements(geometryGLType, static_cast<GLsizei>(numIndices), GL_UNSIGNED_SHORT, reinterpret_cast<void*>(firstIndexOffset));
- }
- else
- {
- //Unindex draw call
- GLsizei numVertices(0u);
- if(vertexBufferCount > 0)
- {
- // truncated, no value loss happening in practice
- numVertices = static_cast<GLsizei>(mVertexBuffers[0]->GetElementCount());
- }
-
- // Command buffer contains Texture bindings & vertex bindings
- Graphics::SubmitInfo submitInfo{{}, 0 | Graphics::SubmitFlagBits::FLUSH};
- submitInfo.cmdBuffer.push_back(&commandBuffer);
- graphicsController.SubmitCommandBuffers(submitInfo);
-
- //@todo This should all be done from inside Pipeline implementation.
- //If there is only 1 vertex buffer, it should have been bound by SubmitCommandBuffers,
- //and the single GL call from this will work on that bound buffer.
- for(uint32_t i = 0; i < vertexBufferCount; ++i)
- {
- base += mVertexBuffers[i]->EnableVertexAttributes(context, attributeLocation, base);
- }
-
- context.DrawArrays(geometryGLType, 0, numVertices);
- }
-
- //Disable attributes
- for(auto&& attribute : attributeLocation)
- {
- if(attribute != -1)
- {
- context.DisableVertexAttributeArray(static_cast<GLuint>(attribute));
- }
- }
+ return topology;
}
} // namespace Render