DALI_ASSERT_DEBUG(size > 0);
mSize = size;
- if(!mGraphicsObject)
+ if(!mGraphicsObject || size > mCapacity)
{
Graphics::BufferCreateInfo createInfo{};
createInfo.SetUsage(mUsage).SetSize(size);
- mGraphicsObject = graphicsController.CreateBuffer(createInfo, nullptr);
+ mGraphicsObject = graphicsController.CreateBuffer(createInfo, std::move(mGraphicsObject));
mCapacity = size;
}
return mSize;
}
- inline Graphics::Buffer* GetGraphicsObject()
+ inline const Graphics::Buffer* GetGraphicsObject() const
{
return mGraphicsObject.get();
}
}
}
-void Geometry::Draw(
+bool Geometry::Draw(
Graphics::Controller& graphicsController,
Graphics::CommandBuffer& commandBuffer,
uint32_t elementBufferOffset,
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.size() == 0)
+ {
+ return false;
+ }
+
commandBuffer.BindVertexBuffers(0, buffers, offsets);
uint32_t numIndices(0u);
if(mIndexBuffer && mGeometryType != Dali::Geometry::POINTS)
{
//Indexed draw call
- Graphics::Buffer* ibo = mIndexBuffer->GetGraphicsObject();
+ const Graphics::Buffer* ibo = mIndexBuffer->GetGraphicsObject();
if(ibo)
{
commandBuffer.BindIndexBuffer(*ibo, 0, Graphics::Format::R16_UINT);
commandBuffer.Draw(numVertices, 1, 0, 0);
}
+ return true;
}
Graphics::PrimitiveTopology Geometry::GetTopology() const
void Upload(Graphics::Controller& graphicsController);
/**
- * Set up the attributes and perform the Draw call corresponding to the geometry type
+ * Set up the attributes and perform the Draw call corresponding to the geometry type.
+ *
* @param[in] context The GL context @todo remove
* @param[in] graphicsController The graphics controller
* @param[in] bufferIndex The current buffer index
* @param[in] attributeLocation The location for the attributes in the shader
* @param[in] elementBufferOffset The index of first element to draw if index buffer bound
* @param[in] elementBufferCount Number of elements to draw if index buffer bound, uses whole buffer when 0
+ * @return true if the draw command was issued, false otherwise
*/
- void Draw(Graphics::Controller& graphicsController,
+ bool Draw(Graphics::Controller& graphicsController,
Graphics::CommandBuffer& commandBuffer,
uint32_t elementBufferOffset,
uint32_t elementBufferCount);
context.BlendBarrier();
}
+ bool drawn = false; // Draw can fail if there are no vertex buffers or they haven't been uploaded yet
+ // @todo We should detect this case much earlier to prevent unnecessary work
+
//@todo manage mDrawCommands in the same way as above command buffer?!
if(mDrawCommands.empty())
{
SetBlending(context, blend);
- mGeometry->Draw(*mGraphicsController, *commandBuffer.get(), mIndexedDrawFirstElement, mIndexedDrawElementsCount);
+ drawn = mGeometry->Draw(*mGraphicsController, *commandBuffer.get(), mIndexedDrawFirstElement, mIndexedDrawElementsCount);
}
else
{
}
// Command buffer contains Texture bindings, vertex bindings, index buffer binding, pipeline(vertex format)
- Graphics::SubmitInfo submitInfo{{}, 0 | Graphics::SubmitFlagBits::FLUSH};
- submitInfo.cmdBuffer.push_back(commandBuffer.get());
- mGraphicsController->SubmitCommandBuffers(submitInfo);
+ // @todo We should return the command buffer(s) and let the calling method submit
+ // If not drawn, then don't add command buffer to submit info, and if empty, don't
+ // submit.
+ if(drawn)
+ {
+ Graphics::SubmitInfo submitInfo{{}, 0 | Graphics::SubmitFlagBits::FLUSH};
+ submitInfo.cmdBuffer.push_back(commandBuffer.get());
+ mGraphicsController->SubmitCommandBuffers(submitInfo);
+ }
mUpdated = false;
}
return mFormat.Get();
}
- inline GpuBuffer& GetGpuBuffer()
+ inline const GpuBuffer* GetGpuBuffer() const
{
- return *(const_cast<GpuBuffer*>(mGpuBuffer.Get())); // @todo change to unique_ptr to avoid const cast?
+ return mGpuBuffer.Get();
}
private: