Add proper support for IndexType and uint32 indices
This commit is contained in:
parent
66ff6cfa81
commit
9d526741b9
|
|
@ -875,7 +875,7 @@ int main()
|
|||
builder.SetViewport(env.renderRect);
|
||||
|
||||
//builder.BindVertexBuffer(0, vertexBuffer.get());
|
||||
builder.BindIndexBuffer(*coneMeshGfx->GetIndexBuffer(0).get());
|
||||
builder.BindIndexBuffer(*coneMeshGfx->GetIndexBuffer(0).get(), Nz::IndexType::U16);
|
||||
builder.BindVertexBuffer(0, *coneMeshGfx->GetVertexBuffer(0).get());
|
||||
|
||||
builder.BindShaderBinding(0, *gbufferShaderBinding);
|
||||
|
|
@ -907,7 +907,7 @@ int main()
|
|||
|
||||
builder.BindShaderBinding(0, *skyboxShaderBinding);
|
||||
|
||||
builder.BindIndexBuffer(*cubeMeshGfx->GetIndexBuffer(0));
|
||||
builder.BindIndexBuffer(*cubeMeshGfx->GetIndexBuffer(0), Nz::IndexType::U16);
|
||||
builder.BindVertexBuffer(0, *cubeMeshGfx->GetVertexBuffer(0));
|
||||
builder.BindPipeline(*skyboxPipeline);
|
||||
|
||||
|
|
|
|||
|
|
@ -404,7 +404,7 @@ int main()
|
|||
{
|
||||
builder.BeginRenderPass(windowRT->GetFramebuffer(frame.GetFramebufferIndex()), windowRT->GetRenderPass(), renderRect, { clearValues[0], clearValues[1] });
|
||||
{
|
||||
builder.BindIndexBuffer(renderBufferIB);
|
||||
builder.BindIndexBuffer(renderBufferIB, Nz::IndexType::U16);
|
||||
builder.BindPipeline(*pipeline);
|
||||
builder.BindVertexBuffer(0, renderBufferVB);
|
||||
builder.BindShaderBinding(0, *viewerShaderBinding);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ namespace Nz
|
|||
|
||||
inline const std::shared_ptr<RenderBuffer>& GetIndexBuffer(std::size_t subMesh) const;
|
||||
inline std::size_t GetIndexCount(std::size_t subMesh) const;
|
||||
inline IndexType GetIndexType(std::size_t subMesh) const;
|
||||
inline const std::shared_ptr<RenderBuffer>& GetVertexBuffer(std::size_t subMesh) const;
|
||||
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration(std::size_t subMesh) const;
|
||||
inline std::size_t GetSubMeshCount() const;
|
||||
|
|
@ -40,6 +41,7 @@ namespace Nz
|
|||
std::shared_ptr<RenderBuffer> vertexBuffer;
|
||||
std::size_t indexCount;
|
||||
std::shared_ptr<const VertexDeclaration> vertexDeclaration;
|
||||
IndexType indexType;
|
||||
};
|
||||
|
||||
std::vector<GraphicalSubMesh> m_subMeshes;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,12 @@ namespace Nz
|
|||
return m_subMeshes[subMesh].indexCount;
|
||||
}
|
||||
|
||||
inline IndexType GraphicalMesh::GetIndexType(std::size_t subMesh) const
|
||||
{
|
||||
assert(subMesh < m_subMeshes.size());
|
||||
return m_subMeshes[subMesh].indexType;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<RenderBuffer>& GraphicalMesh::GetVertexBuffer(std::size_t subMesh) const
|
||||
{
|
||||
assert(subMesh < m_subMeshes.size());
|
||||
|
|
|
|||
|
|
@ -23,13 +23,14 @@ namespace Nz
|
|||
class RenderSubmesh : public RenderElement
|
||||
{
|
||||
public:
|
||||
inline RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<RenderBuffer> indexBuffer, std::shared_ptr<RenderBuffer> vertexBuffer, const Recti& scissorBox);
|
||||
inline RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, IndexType indexType, std::shared_ptr<RenderBuffer> indexBuffer, std::shared_ptr<RenderBuffer> vertexBuffer, const Recti& scissorBox);
|
||||
~RenderSubmesh() = default;
|
||||
|
||||
inline UInt64 ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const override;
|
||||
|
||||
inline const RenderBuffer* GetIndexBuffer() const;
|
||||
inline std::size_t GetIndexCount() const;
|
||||
inline IndexType GetIndexType() const;
|
||||
inline const MaterialPass& GetMaterialPass() const;
|
||||
inline const RenderPipeline* GetRenderPipeline() const;
|
||||
inline const Recti& GetScissorBox() const;
|
||||
|
|
@ -45,6 +46,7 @@ namespace Nz
|
|||
std::shared_ptr<RenderPipeline> m_renderPipeline;
|
||||
std::size_t m_indexCount;
|
||||
const WorldInstance& m_worldInstance;
|
||||
IndexType m_indexType;
|
||||
Recti m_scissorBox;
|
||||
int m_renderLayer;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<RenderBuffer> indexBuffer, std::shared_ptr<RenderBuffer> vertexBuffer, const Recti& scissorBox) :
|
||||
inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, IndexType indexType, std::shared_ptr<RenderBuffer> indexBuffer, std::shared_ptr<RenderBuffer> vertexBuffer, const Recti& scissorBox) :
|
||||
RenderElement(BasicRenderElement::Submesh),
|
||||
m_indexBuffer(std::move(indexBuffer)),
|
||||
m_vertexBuffer(std::move(vertexBuffer)),
|
||||
|
|
@ -17,6 +17,7 @@ namespace Nz
|
|||
m_renderPipeline(std::move(renderPipeline)),
|
||||
m_indexCount(indexCount),
|
||||
m_worldInstance(worldInstance),
|
||||
m_indexType(indexType),
|
||||
m_scissorBox(scissorBox),
|
||||
m_renderLayer(renderLayer)
|
||||
{
|
||||
|
|
@ -80,6 +81,11 @@ namespace Nz
|
|||
return m_indexCount;
|
||||
}
|
||||
|
||||
inline IndexType RenderSubmesh::GetIndexType() const
|
||||
{
|
||||
return m_indexType;
|
||||
}
|
||||
|
||||
inline const MaterialPass& RenderSubmesh::GetMaterialPass() const
|
||||
{
|
||||
return *m_materialPass;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ namespace Nz
|
|||
const ShaderBinding* shaderBinding;
|
||||
std::size_t firstIndex;
|
||||
std::size_t indexCount;
|
||||
IndexType indexType;
|
||||
Recti scissorBox;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace Nz
|
|||
|
||||
inline void BeginDebugRegion(const std::string_view& regionName, const Color& color);
|
||||
|
||||
inline void BindIndexBuffer(GLuint indexBuffer, UInt64 offset = 0);
|
||||
inline void BindIndexBuffer(GLuint indexBuffer, IndexType indexType, UInt64 offset = 0);
|
||||
inline void BindPipeline(const OpenGLRenderPipeline* pipeline);
|
||||
inline void BindShaderBinding(const OpenGLRenderPipelineLayout& pipelineLayout, UInt32 set, const OpenGLShaderBinding* binding);
|
||||
inline void BindVertexBuffer(UInt32 binding, GLuint vertexBuffer, UInt64 offset = 0);
|
||||
|
|
@ -122,6 +122,7 @@ namespace Nz
|
|||
GLuint indexBuffer = 0;
|
||||
const OpenGLRenderPipeline* pipeline = nullptr;
|
||||
UInt64 indexBufferOffset;
|
||||
IndexType indexBufferType;
|
||||
std::optional<Recti> scissorRegion;
|
||||
std::optional<Recti> viewportRegion;
|
||||
std::vector<std::pair<const OpenGLRenderPipelineLayout*, const OpenGLShaderBinding*>> shaderBindings;
|
||||
|
|
|
|||
|
|
@ -33,10 +33,11 @@ namespace Nz
|
|||
m_commands.emplace_back(std::move(beginDebugRegion));
|
||||
}
|
||||
|
||||
inline void OpenGLCommandBuffer::BindIndexBuffer(GLuint indexBuffer, UInt64 offset)
|
||||
inline void OpenGLCommandBuffer::BindIndexBuffer(GLuint indexBuffer, IndexType indexType, UInt64 offset)
|
||||
{
|
||||
m_currentStates.indexBuffer = indexBuffer;
|
||||
m_currentStates.indexBufferOffset = offset;
|
||||
m_currentStates.indexBufferType = indexType;
|
||||
}
|
||||
|
||||
inline void OpenGLCommandBuffer::BindPipeline(const OpenGLRenderPipeline* pipeline)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Nz
|
|||
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
|
||||
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
|
||||
|
||||
void BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset = 0) override;
|
||||
void BindIndexBuffer(const RenderBuffer& indexBuffer, IndexType indexType, UInt64 offset = 0) override;
|
||||
void BindPipeline(const RenderPipeline& pipeline) override;
|
||||
void BindShaderBinding(UInt32 set, const ShaderBinding& binding) override;
|
||||
void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) override;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ namespace Nz
|
|||
inline GLenum ToOpenGL(FaceFilling filling);
|
||||
inline GLenum ToOpenGL(FaceSide side);
|
||||
inline GLenum ToOpenGL(FrontFace face);
|
||||
inline GLenum ToOpenGL(IndexType indexType);
|
||||
inline GLenum ToOpenGL(PrimitiveMode primitiveMode);
|
||||
inline GLenum ToOpenGL(SamplerFilter filter);
|
||||
inline GLenum ToOpenGL(SamplerFilter minFilter, SamplerMipmapMode mipmapFilter);
|
||||
|
|
|
|||
|
|
@ -120,6 +120,19 @@ namespace Nz
|
|||
return {};
|
||||
}
|
||||
|
||||
inline GLenum ToOpenGL(IndexType indexType)
|
||||
{
|
||||
switch (indexType)
|
||||
{
|
||||
case IndexType::U8: return GL_UNSIGNED_BYTE;
|
||||
case IndexType::U16: return GL_UNSIGNED_SHORT;
|
||||
case IndexType::U32: return GL_UNSIGNED_INT;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled IndexType 0x" + NumberToString(UnderlyingCast(indexType), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
inline GLenum ToOpenGL(PrimitiveMode primitiveMode)
|
||||
{
|
||||
switch (primitiveMode)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Nz
|
|||
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect);
|
||||
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, std::initializer_list<ClearValues> clearValues);
|
||||
|
||||
virtual void BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset = 0) = 0;
|
||||
virtual void BindIndexBuffer(const RenderBuffer& indexBuffer, IndexType indexType, UInt64 offset = 0) = 0;
|
||||
virtual void BindPipeline(const RenderPipeline& pipeline) = 0;
|
||||
virtual void BindShaderBinding(UInt32 set, const ShaderBinding& binding) = 0;
|
||||
virtual void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) = 0;
|
||||
|
|
|
|||
|
|
@ -180,6 +180,15 @@ namespace Nz
|
|||
|
||||
constexpr std::size_t ImageTypeCount = static_cast<std::size_t>(ImageType::Max) + 1;
|
||||
|
||||
enum class IndexType
|
||||
{
|
||||
U8,
|
||||
U16,
|
||||
U32,
|
||||
|
||||
Max = U32
|
||||
};
|
||||
|
||||
enum class NodeType
|
||||
{
|
||||
Default, // Node
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ namespace Nz
|
|||
{
|
||||
public:
|
||||
IndexBuffer() = default;
|
||||
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer);
|
||||
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
|
||||
IndexBuffer(bool largeIndices, UInt64 indexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
|
||||
IndexBuffer(IndexType indexType, std::shared_ptr<Buffer> buffer);
|
||||
IndexBuffer(IndexType indexType, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
|
||||
IndexBuffer(IndexType indexType, UInt64 indexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
|
||||
IndexBuffer(const IndexBuffer&) = default;
|
||||
IndexBuffer(IndexBuffer&&) noexcept = default;
|
||||
~IndexBuffer() = default;
|
||||
|
|
@ -31,11 +31,10 @@ namespace Nz
|
|||
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
||||
inline UInt64 GetEndOffset() const;
|
||||
inline UInt64 GetIndexCount() const;
|
||||
inline IndexType GetIndexType() const;
|
||||
inline UInt64 GetStride() const;
|
||||
inline UInt64 GetStartOffset() const;
|
||||
|
||||
inline bool HasLargeIndices() const;
|
||||
|
||||
inline bool IsValid() const;
|
||||
|
||||
inline void* Map(UInt64 startIndex, UInt64 length);
|
||||
|
|
@ -52,10 +51,10 @@ namespace Nz
|
|||
|
||||
private:
|
||||
std::shared_ptr<Buffer> m_buffer;
|
||||
IndexType m_indexType;
|
||||
UInt32 m_indexCount;
|
||||
UInt64 m_endOffset;
|
||||
UInt64 m_startOffset;
|
||||
bool m_largeIndices;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,27 @@ namespace Nz
|
|||
return m_indexCount;
|
||||
}
|
||||
|
||||
inline IndexType IndexBuffer::GetIndexType() const
|
||||
{
|
||||
return m_indexType;
|
||||
}
|
||||
|
||||
inline UInt64 IndexBuffer::GetStride() const
|
||||
{
|
||||
return (m_largeIndices) ? sizeof(UInt32) : sizeof(UInt16);
|
||||
switch (m_indexType)
|
||||
{
|
||||
case IndexType::U8:
|
||||
return sizeof(UInt8);
|
||||
|
||||
case IndexType::U16:
|
||||
return sizeof(UInt16);
|
||||
|
||||
case IndexType::U32:
|
||||
return sizeof(UInt32);
|
||||
}
|
||||
|
||||
NazaraError("invalid index size");
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline UInt64 IndexBuffer::GetStartOffset() const
|
||||
|
|
@ -33,11 +51,6 @@ namespace Nz
|
|||
return m_startOffset;
|
||||
}
|
||||
|
||||
inline bool IndexBuffer::HasLargeIndices() const
|
||||
{
|
||||
return m_largeIndices;
|
||||
}
|
||||
|
||||
inline bool IndexBuffer::IsValid() const
|
||||
{
|
||||
return m_buffer != nullptr;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace Nz
|
|||
inline VkCullModeFlagBits ToVulkan(FaceSide faceSide);
|
||||
inline VkPolygonMode ToVulkan(FaceFilling faceFilling);
|
||||
inline VkFrontFace ToVulkan(FrontFace frontFace);
|
||||
inline VkIndexType ToVulkan(IndexType indexType);
|
||||
inline VkAccessFlagBits ToVulkan(MemoryAccess memoryAccess);
|
||||
inline VkAccessFlags ToVulkan(MemoryAccessFlags memoryAccessFlags);
|
||||
inline VkPipelineStageFlagBits ToVulkan(PipelineStage pipelineStage);
|
||||
|
|
|
|||
|
|
@ -169,6 +169,19 @@ namespace Nz
|
|||
return {};
|
||||
}
|
||||
|
||||
inline VkIndexType ToVulkan(IndexType indexType)
|
||||
{
|
||||
switch (indexType)
|
||||
{
|
||||
case IndexType::U8: return VK_INDEX_TYPE_UINT8_EXT;
|
||||
case IndexType::U16: return VK_INDEX_TYPE_UINT16;
|
||||
case IndexType::U32: return VK_INDEX_TYPE_UINT32;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled IndexType 0x" + NumberToString(UnderlyingCast(indexType), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
inline VkAccessFlagBits ToVulkan(MemoryAccess memoryAccess)
|
||||
{
|
||||
switch (memoryAccess)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
|||
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
|
||||
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
|
||||
|
||||
void BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset = 0) override;
|
||||
void BindIndexBuffer(const RenderBuffer& indexBuffer, IndexType indexType, UInt64 offset = 0) override;
|
||||
void BindPipeline(const RenderPipeline& pipeline) override;
|
||||
void BindShaderBinding(UInt32 set, const ShaderBinding& binding) override;
|
||||
void BindShaderBinding(const RenderPipelineLayout& pipelineLayout, UInt32 set, const ShaderBinding& binding) override;
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||
// Index buffer
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
|
||||
IndexMapper indexMapper(*indexBuffer);
|
||||
IndexIterator index = indexMapper.begin();
|
||||
|
|
@ -465,7 +465,7 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||
// Index buffer
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
|
||||
IndexMapper indexMapper(*indexBuffer);
|
||||
IndexIterator index = indexMapper.begin();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ namespace Nz
|
|||
throw std::runtime_error("failed to fill index buffer");
|
||||
|
||||
submeshData.indexCount = indexBuffer->GetIndexCount();
|
||||
submeshData.indexType = indexBuffer->GetIndexType();
|
||||
|
||||
submeshData.vertexBuffer = renderDevice->InstantiateBuffer(BufferType::Vertex, vertexBuffer->GetStride() * vertexBuffer->GetVertexCount(), BufferUsage::DeviceLocal | BufferUsage::Write);
|
||||
if (!submeshData.vertexBuffer->Fill(vertexBufferContent->GetData() + vertexBuffer->GetStartOffset(), 0, vertexBuffer->GetEndOffset() - vertexBuffer->GetStartOffset()))
|
||||
|
|
|
|||
|
|
@ -46,7 +46,10 @@ namespace Nz
|
|||
const auto& vertexBuffer = m_graphicalMesh->GetVertexBuffer(i);
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(submeshData.vertexBufferData);
|
||||
|
||||
elements.emplace_back(std::make_unique<RenderSubmesh>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, m_graphicalMesh->GetIndexCount(i), indexBuffer, vertexBuffer, scissorBox));
|
||||
std::size_t indexCount = m_graphicalMesh->GetIndexCount(i);
|
||||
IndexType indexType = m_graphicalMesh->GetIndexType(i);
|
||||
|
||||
elements.emplace_back(std::make_unique<RenderSubmesh>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, indexCount, indexType, indexBuffer, vertexBuffer, scissorBox));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ namespace Nz
|
|||
{
|
||||
auto& data = static_cast<SpriteChainRendererData&>(rendererData);
|
||||
|
||||
commandBuffer.BindIndexBuffer(*m_indexBuffer);
|
||||
commandBuffer.BindIndexBuffer(*m_indexBuffer, Nz::IndexType::U16);
|
||||
|
||||
Vector2f targetSize = viewerInstance.GetTargetSize();
|
||||
Recti fullscreenScissorBox(0, 0, SafeCast<int>(std::floor(targetSize.x)), SafeCast<int>(std::floor(targetSize.y)));
|
||||
|
|
|
|||
|
|
@ -169,6 +169,7 @@ namespace Nz
|
|||
drawCall.firstIndex = 0;
|
||||
drawCall.indexBuffer = currentIndexBuffer;
|
||||
drawCall.indexCount = submesh.GetIndexCount();
|
||||
drawCall.indexType = submesh.GetIndexType();
|
||||
drawCall.renderPipeline = currentPipeline;
|
||||
drawCall.scissorBox = currentScissorBox;
|
||||
drawCall.shaderBinding = currentShaderBinding;
|
||||
|
|
@ -217,7 +218,7 @@ namespace Nz
|
|||
|
||||
if (currentIndexBuffer != drawData.indexBuffer)
|
||||
{
|
||||
commandBuffer.BindIndexBuffer(*drawData.indexBuffer);
|
||||
commandBuffer.BindIndexBuffer(*drawData.indexBuffer, drawData.indexType);
|
||||
currentIndexBuffer = drawData.indexBuffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,9 +105,17 @@ 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
|
||||
origin += command.states.indexBufferOffset;
|
||||
|
||||
switch (command.states.indexBufferType)
|
||||
{
|
||||
case IndexType::U8: origin += command.firstIndex * sizeof(UInt8); break;
|
||||
case IndexType::U16: origin += command.firstIndex * sizeof(UInt16); break;
|
||||
case IndexType::U32: origin += command.firstIndex * sizeof(UInt32); break;
|
||||
}
|
||||
|
||||
ApplyStates(*context, command.states);
|
||||
context->glDrawElementsInstanced(ToOpenGL(command.states.pipeline->GetPipelineInfo().primitiveMode), command.indexCount, GL_UNSIGNED_SHORT, origin + command.firstIndex * sizeof(UInt16), command.instanceCount);
|
||||
context->glDrawElementsInstanced(ToOpenGL(command.states.pipeline->GetPipelineInfo().primitiveMode), command.indexCount, ToOpenGL(command.states.indexBufferType), origin, command.instanceCount);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, EndDebugRegionData>)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ namespace Nz
|
|||
m_commandBuffer.SetFramebuffer(static_cast<const OpenGLFramebuffer&>(framebuffer), static_cast<const OpenGLRenderPass&>(renderPass), clearValues, clearValueCount);
|
||||
}
|
||||
|
||||
void OpenGLCommandBufferBuilder::BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset)
|
||||
void OpenGLCommandBufferBuilder::BindIndexBuffer(const RenderBuffer& indexBuffer, IndexType indexType, UInt64 offset)
|
||||
{
|
||||
const OpenGLBuffer& glBuffer = static_cast<const OpenGLBuffer&>(indexBuffer);
|
||||
|
||||
m_commandBuffer.BindIndexBuffer(glBuffer.GetBuffer().GetObjectId(), offset);
|
||||
m_commandBuffer.BindIndexBuffer(glBuffer.GetBuffer().GetObjectId(), indexType, offset);
|
||||
}
|
||||
|
||||
void OpenGLCommandBufferBuilder::BindPipeline(const RenderPipeline& pipeline)
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ namespace Nz
|
|||
});
|
||||
|
||||
std::shared_ptr<VertexBuffer> colliderVB = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ), colliderVertices.size(), BufferUsage::Write, SoftwareBufferFactory, colliderVertices.data());
|
||||
std::shared_ptr<IndexBuffer> colliderIB = std::make_shared<IndexBuffer>(false, colliderIndices.size(), BufferUsage::Write, SoftwareBufferFactory, colliderIndices.data());
|
||||
std::shared_ptr<IndexBuffer> colliderIB = std::make_shared<IndexBuffer>(IndexType::U16, colliderIndices.size(), BufferUsage::Write, SoftwareBufferFactory, colliderIndices.data());
|
||||
|
||||
std::shared_ptr<StaticMesh> colliderSubMesh = std::make_shared<StaticMesh>(std::move(colliderVB), std::move(colliderIB));
|
||||
colliderSubMesh->GenerateAABB();
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(false, 3 * header.num_tris, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(IndexType::U16, 3 * header.num_tris, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
|
||||
// Extract triangles data
|
||||
std::vector<MD2_Triangle> triangles(header.num_tris);
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ namespace Nz
|
|||
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ_Normal_UV_Tangent_Skinning), UInt32(vertexCount), parameters.vertexBufferFlags, parameters.bufferFactory);
|
||||
|
||||
// Index buffer
|
||||
|
|
@ -241,7 +241,7 @@ namespace Nz
|
|||
// Index buffer
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
|
||||
IndexMapper indexMapper(*indexBuffer);
|
||||
IndexIterator index = indexMapper.begin();
|
||||
|
|
@ -293,7 +293,7 @@ namespace Nz
|
|||
// Vertex colors (.md5mesh files have no vertex color)
|
||||
if (auto colorPtr = vertexMapper.GetComponentPtr<Color>(VertexComponent::Color))
|
||||
{
|
||||
for (std::size_t i = 0; i < md5Mesh.vertices.size(); ++i)
|
||||
for (std::size_t j = 0; j < md5Mesh.vertices.size(); ++j)
|
||||
*colorPtr++ = Color::White;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -254,7 +254,9 @@ namespace Nz
|
|||
}
|
||||
|
||||
// Création des buffers
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indices.size(), parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indices.size(), parameters.indexBufferFlags, parameters.bufferFactory);
|
||||
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, vertexCount, parameters.vertexBufferFlags, parameters.bufferFactory);
|
||||
|
||||
// Remplissage des indices
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer) :
|
||||
IndexBuffer::IndexBuffer(IndexType indexType, std::shared_ptr<Buffer> buffer) :
|
||||
m_buffer(std::move(buffer)),
|
||||
m_indexType(indexType),
|
||||
m_endOffset(m_buffer->GetSize()),
|
||||
m_startOffset(0),
|
||||
m_largeIndices(largeIndices)
|
||||
m_startOffset(0)
|
||||
{
|
||||
NazaraAssert(m_buffer, "invalid buffer");
|
||||
NazaraAssert(m_buffer->GetType() == BufferType::Index, "buffer must be an index buffer");
|
||||
|
|
@ -26,23 +26,23 @@ namespace Nz
|
|||
m_indexCount = m_endOffset / GetStride();
|
||||
}
|
||||
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size) :
|
||||
IndexBuffer::IndexBuffer(IndexType indexType, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size) :
|
||||
m_buffer(std::move(buffer)),
|
||||
m_indexType(indexType),
|
||||
m_endOffset(offset + size),
|
||||
m_startOffset(offset),
|
||||
m_largeIndices(largeIndices)
|
||||
m_startOffset(offset)
|
||||
{
|
||||
NazaraAssert(m_buffer, "invalid buffer");
|
||||
NazaraAssert(m_buffer->GetType() == BufferType::Index, "buffer must be an index buffer");
|
||||
NazaraAssert(size > 0, "invalid size");
|
||||
NazaraAssert(size > 0, "invalid buffer size");
|
||||
|
||||
m_indexCount = size / GetStride();
|
||||
}
|
||||
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, UInt64 indexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData) :
|
||||
IndexBuffer::IndexBuffer(IndexType indexType, UInt64 indexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData) :
|
||||
m_indexType(indexType),
|
||||
m_indexCount(indexCount),
|
||||
m_startOffset(0),
|
||||
m_largeIndices(largeIndices)
|
||||
m_startOffset(0)
|
||||
{
|
||||
NazaraAssert(indexCount > 0, "invalid index count");
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@ namespace Nz
|
|||
return static_cast<UInt32>(i);
|
||||
}
|
||||
|
||||
UInt32 Getter8(const void* buffer, std::size_t i)
|
||||
{
|
||||
const UInt8* ptr = static_cast<const UInt8*>(buffer);
|
||||
return ptr[i];
|
||||
}
|
||||
|
||||
UInt32 Getter16(const void* buffer, std::size_t i)
|
||||
{
|
||||
const UInt16* ptr = static_cast<const UInt16*>(buffer);
|
||||
|
|
@ -37,10 +43,16 @@ namespace Nz
|
|||
return 0;
|
||||
}
|
||||
|
||||
void Setter8(void* buffer, std::size_t i, UInt32 value)
|
||||
{
|
||||
UInt8* ptr = static_cast<UInt8*>(buffer);
|
||||
ptr[i] = SafeCast<UInt8>(value);
|
||||
}
|
||||
|
||||
void Setter16(void* buffer, std::size_t i, UInt32 value)
|
||||
{
|
||||
UInt16* ptr = static_cast<UInt16*>(buffer);
|
||||
ptr[i] = static_cast<UInt16>(value);
|
||||
ptr[i] = SafeCast<UInt16>(value);
|
||||
}
|
||||
|
||||
void Setter32(void* buffer, std::size_t i, UInt32 value)
|
||||
|
|
@ -63,13 +75,37 @@ namespace Nz
|
|||
if (!m_mapper.Map(indexBuffer, 0, m_indexCount))
|
||||
NazaraError("Failed to map buffer"); ///TODO: Unexcepted
|
||||
|
||||
Getter rightGetter = nullptr;
|
||||
Setter rightSetter = nullptr;
|
||||
|
||||
switch (indexBuffer.GetIndexType())
|
||||
{
|
||||
case IndexType::U8:
|
||||
rightGetter = Getter8;
|
||||
rightSetter = Setter8;
|
||||
break;
|
||||
|
||||
case IndexType::U16:
|
||||
rightGetter = Getter16;
|
||||
rightSetter = Setter16;
|
||||
break;
|
||||
|
||||
case IndexType::U32:
|
||||
rightGetter = Getter32;
|
||||
rightSetter = Setter32;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rightGetter)
|
||||
NazaraError("unexpected index size"); ///TODO: Unexcepted
|
||||
|
||||
if (indexBuffer.GetBuffer()->GetUsageFlags().Test(BufferUsage::Read))
|
||||
m_getter = (indexBuffer.HasLargeIndices()) ? Getter32 : Getter16;
|
||||
m_getter = rightGetter;
|
||||
else
|
||||
m_getter = GetterError;
|
||||
|
||||
if (indexBuffer.GetBuffer()->GetUsageFlags().Test(BufferUsage::Write))
|
||||
m_setter = (indexBuffer.HasLargeIndices()) ? Setter32 : Setter16;
|
||||
m_setter = rightSetter;
|
||||
else
|
||||
m_setter = SetterError;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,9 @@ namespace Nz
|
|||
std::size_t vertexCount;
|
||||
ComputeBoxIndexVertexCount(primitive.box.subdivision, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.vertexBufferFlags, params.bufferFactory);
|
||||
|
||||
VertexMapper vertexMapper(*vertexBuffer);
|
||||
|
|
@ -122,7 +124,9 @@ namespace Nz
|
|||
std::size_t vertexCount;
|
||||
ComputeConeIndexVertexCount(primitive.cone.subdivision, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.vertexBufferFlags, params.bufferFactory);
|
||||
|
||||
VertexMapper vertexMapper(*vertexBuffer);
|
||||
|
|
@ -144,7 +148,9 @@ namespace Nz
|
|||
std::size_t vertexCount;
|
||||
ComputePlaneIndexVertexCount(primitive.plane.subdivision, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.vertexBufferFlags, params.bufferFactory);
|
||||
|
||||
VertexMapper vertexMapper(*vertexBuffer);
|
||||
|
|
@ -170,7 +176,9 @@ namespace Nz
|
|||
std::size_t vertexCount;
|
||||
ComputeCubicSphereIndexVertexCount(primitive.sphere.cubic.subdivision, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.vertexBufferFlags, params.bufferFactory);
|
||||
|
||||
VertexMapper vertexMapper(*vertexBuffer);
|
||||
|
|
@ -192,7 +200,9 @@ namespace Nz
|
|||
std::size_t vertexCount;
|
||||
ComputeIcoSphereIndexVertexCount(primitive.sphere.ico.recursionLevel, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.vertexBufferFlags, params.bufferFactory);
|
||||
|
||||
VertexMapper vertexMapper(*vertexBuffer);
|
||||
|
|
@ -214,7 +224,9 @@ namespace Nz
|
|||
std::size_t vertexCount;
|
||||
ComputeUvSphereIndexVertexCount(primitive.sphere.uv.sliceCount, primitive.sphere.uv.stackCount, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
indexBuffer = std::make_shared<IndexBuffer>((largeIndices) ? IndexType::U32 : IndexType::U16, indexCount, params.indexBufferFlags, params.bufferFactory);
|
||||
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.vertexBufferFlags, params.bufferFactory);
|
||||
|
||||
VertexMapper vertexMapper(*vertexBuffer);
|
||||
|
|
|
|||
|
|
@ -72,11 +72,11 @@ namespace Nz
|
|||
m_currentSubpassIndex = 0;
|
||||
}
|
||||
|
||||
void VulkanCommandBufferBuilder::BindIndexBuffer(const RenderBuffer& indexBuffer, UInt64 offset)
|
||||
void VulkanCommandBufferBuilder::BindIndexBuffer(const RenderBuffer& indexBuffer, IndexType indexType, UInt64 offset)
|
||||
{
|
||||
const VulkanBuffer& vkBuffer = static_cast<const VulkanBuffer&>(indexBuffer);
|
||||
|
||||
m_commandBuffer.BindIndexBuffer(vkBuffer.GetBuffer(), offset, VK_INDEX_TYPE_UINT16); //< Fuck me right?
|
||||
m_commandBuffer.BindIndexBuffer(vkBuffer.GetBuffer(), offset, ToVulkan(indexType));
|
||||
}
|
||||
|
||||
void VulkanCommandBufferBuilder::BindPipeline(const RenderPipeline& pipeline)
|
||||
|
|
|
|||
Loading…
Reference in New Issue