Renderer: Implement firstIndex on DrawIndexed command for OpenGL

This commit is contained in:
Jérôme Leclercq 2021-09-05 15:46:00 +02:00
parent 02a12d9328
commit b6c3988bbe
9 changed files with 16 additions and 14 deletions

View File

@ -46,7 +46,7 @@ namespace Nz
inline void CopyBuffer(const UploadPool::Allocation& allocation, GLuint target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0);
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstIndex = 0, UInt32 firstInstance = 0);
inline void EndDebugRegion();
@ -122,8 +122,8 @@ namespace Nz
struct DrawIndexedData
{
DrawStates states;
UInt32 firstIndex;
UInt32 firstInstance;
UInt32 firstVertex;
UInt32 indexCount;
UInt32 instanceCount;
};

View File

@ -102,15 +102,15 @@ namespace Nz
m_commands.emplace_back(std::move(draw));
}
inline void OpenGLCommandBuffer::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
inline void OpenGLCommandBuffer::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstIndex, UInt32 firstInstance)
{
if (!m_currentStates.pipeline)
throw std::runtime_error("no pipeline bound");
DrawIndexedData draw;
draw.states = m_currentStates;
draw.firstIndex = firstIndex;
draw.firstInstance = firstInstance;
draw.firstVertex = firstVertex;
draw.indexCount = indexCount;
draw.instanceCount = instanceCount;

View File

@ -36,7 +36,7 @@ namespace Nz
void CopyBuffer(const UploadPool::Allocation& allocation, const RenderBufferView& target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0) override;
void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) override;
void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) override;
void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstIndex = 0, UInt32 firstInstance = 0) override;
void EndDebugRegion() override;
void EndRenderPass() override;

View File

@ -52,7 +52,7 @@ namespace Nz
virtual void CopyBuffer(const UploadPool::Allocation& allocation, const RenderBufferView& target, UInt64 size, UInt64 fromOffset = 0, UInt64 toOffset = 0) = 0;
virtual void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) = 0;
virtual void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) = 0;
virtual void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstIndex = 0, UInt32 firstInstance = 0) = 0;
virtual void EndDebugRegion() = 0;
virtual void EndRenderPass() = 0;

View File

@ -37,7 +37,7 @@ namespace Nz
void CopyBuffer(const UploadPool::Allocation& allocation, const RenderBufferView& target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0) override;
void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) override;
void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) override;
void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstIndex = 0, UInt32 firstInstance = 0) override;
void EndDebugRegion() override;
void EndRenderPass() override;

View File

@ -259,9 +259,9 @@ namespace Nz
return m_pool->GetDevice()->vkCmdDraw(m_handle, vertexCount, instanceCount, firstVertex, firstInstance);
}
inline void CommandBuffer::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstVertex, Int32 vertexOffset, UInt32 firstInstance)
inline void CommandBuffer::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstIndex, Int32 vertexOffset, UInt32 firstInstance)
{
return m_pool->GetDevice()->vkCmdDrawIndexed(m_handle, indexCount, instanceCount, firstVertex, vertexOffset, firstInstance);
return m_pool->GetDevice()->vkCmdDrawIndexed(m_handle, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
}
inline bool CommandBuffer::End()

View File

@ -96,8 +96,10 @@ namespace Nz
}
else if constexpr (std::is_same_v<T, DrawIndexedData>)
{
const UInt8* origin = 0; //< For an easy way to cast an integer to a pointer
ApplyStates(*context, command.states);
context->glDrawElementsInstanced(ToOpenGL(command.states.pipeline->GetPipelineInfo().primitiveMode), command.indexCount, GL_UNSIGNED_SHORT, nullptr, command.instanceCount);
context->glDrawElementsInstanced(ToOpenGL(command.states.pipeline->GetPipelineInfo().primitiveMode), command.indexCount, GL_UNSIGNED_SHORT, origin + command.firstIndex * sizeof(UInt16), command.instanceCount);
}
else if constexpr (std::is_same_v<T, EndDebugRegionData>)
{

View File

@ -80,9 +80,9 @@ namespace Nz
m_commandBuffer.Draw(vertexCount, instanceCount, firstVertex, firstInstance);
}
void OpenGLCommandBufferBuilder::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
void OpenGLCommandBufferBuilder::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstIndex, UInt32 firstInstance)
{
m_commandBuffer.DrawIndexed(indexCount, instanceCount, firstVertex, firstInstance);
m_commandBuffer.DrawIndexed(indexCount, instanceCount, firstIndex, firstInstance);
}
void OpenGLCommandBufferBuilder::EndDebugRegion()

View File

@ -131,9 +131,9 @@ namespace Nz
m_commandBuffer.Draw(vertexCount, instanceCount, firstVertex, firstInstance);
}
void VulkanCommandBufferBuilder::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
void VulkanCommandBufferBuilder::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstIndex, UInt32 firstInstance)
{
m_commandBuffer.DrawIndexed(indexCount, instanceCount, firstVertex, 0, firstInstance);
m_commandBuffer.DrawIndexed(indexCount, instanceCount, firstIndex, 0, firstInstance);
}
void VulkanCommandBufferBuilder::EndDebugRegion()