Add proper support for IndexType and uint32 indices
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user