Graphics/Material: Rework UBO handling
This commit is contained in:
@@ -67,13 +67,13 @@ namespace Nz
|
||||
inline BlendFunc GetSrcBlend() const;
|
||||
inline const std::shared_ptr<Texture>& GetTexture(std::size_t textureIndex) const;
|
||||
inline const std::shared_ptr<TextureSampler>& GetTextureSampler(std::size_t textureIndex) const;
|
||||
inline UniformBufferRef& GetUniformBuffer(std::size_t bufferIndex);
|
||||
inline const UniformBufferRef& GetUniformBuffer(std::size_t bufferIndex) const;
|
||||
inline const std::shared_ptr<AbstractBuffer>& GetUniformBuffer(std::size_t bufferIndex) const;
|
||||
inline std::vector<UInt8>& GetUniformBufferData(std::size_t bufferIndex);
|
||||
inline const std::vector<UInt8>& GetUniformBufferConstData(std::size_t bufferIndex);
|
||||
|
||||
inline bool HasTexture(std::size_t textureIndex) const;
|
||||
inline bool HasVertexColor() const;
|
||||
|
||||
inline bool IsAlphaTestEnabled() const;
|
||||
inline bool IsBlendingEnabled() const;
|
||||
inline bool IsColorWriteEnabled() const;
|
||||
inline bool IsConditionEnabled(std::size_t conditionIndex) const;
|
||||
@@ -93,16 +93,19 @@ namespace Nz
|
||||
inline void SetFaceFilling(FaceFilling filling);
|
||||
inline void SetLineWidth(float lineWidth);
|
||||
inline void SetPointSize(float pointSize);
|
||||
inline void SetUniformBuffer(std::size_t bufferIndex, UniformBufferRef uniformBuffer);
|
||||
inline void SetUniformBuffer(std::size_t bufferIndex, std::shared_ptr<AbstractBuffer> uniformBuffer);
|
||||
inline void SetSrcBlend(BlendFunc func);
|
||||
inline void SetTexture(std::size_t textureIndex, std::shared_ptr<Texture> texture);
|
||||
inline void SetTextureSampler(std::size_t textureIndex, std::shared_ptr<TextureSampler> sampler);
|
||||
|
||||
void UpdateShaderBinding(ShaderBinding& shaderBinding) const;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnMaterialRelease, const Material* /*material*/);
|
||||
|
||||
private:
|
||||
inline void InvalidatePipeline();
|
||||
inline void InvalidateShaderBinding();
|
||||
inline void UpdatePipeline() const;
|
||||
|
||||
struct MaterialTexture
|
||||
@@ -111,9 +114,16 @@ namespace Nz
|
||||
std::shared_ptr<Texture> texture;
|
||||
};
|
||||
|
||||
struct UniformBuffer
|
||||
{
|
||||
std::shared_ptr<AbstractBuffer> buffer;
|
||||
std::vector<UInt8> data;
|
||||
bool dataInvalidated = true;
|
||||
};
|
||||
|
||||
std::shared_ptr<const MaterialSettings> m_settings;
|
||||
std::vector<MaterialTexture> m_textures;
|
||||
std::vector<UniformBufferRef> m_uniformBuffers;
|
||||
std::vector<UniformBuffer> m_uniformBuffers;
|
||||
mutable std::shared_ptr<MaterialPipeline> m_pipeline;
|
||||
UInt64 m_enabledConditions;
|
||||
mutable MaterialPipelineInfo m_pipelineInfo;
|
||||
|
||||
@@ -442,16 +442,24 @@ namespace Nz
|
||||
return m_textures[textureIndex].sampler;
|
||||
}
|
||||
|
||||
inline UniformBufferRef& Material::GetUniformBuffer(std::size_t bufferIndex)
|
||||
inline const std::shared_ptr<AbstractBuffer>& Material::GetUniformBuffer(std::size_t bufferIndex) const
|
||||
{
|
||||
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
|
||||
return m_uniformBuffers[bufferIndex];
|
||||
return m_uniformBuffers[bufferIndex].buffer;
|
||||
}
|
||||
|
||||
inline const UniformBufferRef& Material::GetUniformBuffer(std::size_t bufferIndex) const
|
||||
inline std::vector<UInt8>& Material::GetUniformBufferData(std::size_t bufferIndex)
|
||||
{
|
||||
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
|
||||
return m_uniformBuffers[bufferIndex];
|
||||
UniformBuffer& uboEntry = m_uniformBuffers[bufferIndex];
|
||||
uboEntry.dataInvalidated = true;
|
||||
return uboEntry.data;
|
||||
}
|
||||
|
||||
inline const std::vector<UInt8>& Material::GetUniformBufferConstData(std::size_t bufferIndex)
|
||||
{
|
||||
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
|
||||
return m_uniformBuffers[bufferIndex].data;
|
||||
}
|
||||
|
||||
inline bool Material::HasTexture(std::size_t textureIndex) const
|
||||
@@ -666,22 +674,35 @@ namespace Nz
|
||||
InvalidatePipeline();
|
||||
}
|
||||
|
||||
inline void Material::SetUniformBuffer(std::size_t bufferIndex, UniformBufferRef uniformBuffer)
|
||||
inline void Material::SetUniformBuffer(std::size_t bufferIndex, std::shared_ptr<AbstractBuffer> uniformBuffer)
|
||||
{
|
||||
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid shared uniform buffer index");
|
||||
m_uniformBuffers[bufferIndex] = std::move(uniformBuffer);
|
||||
if (m_uniformBuffers[bufferIndex].buffer != uniformBuffer)
|
||||
{
|
||||
m_uniformBuffers[bufferIndex].buffer = std::move(uniformBuffer);
|
||||
m_uniformBuffers[bufferIndex].dataInvalidated = true;
|
||||
InvalidateShaderBinding();
|
||||
}
|
||||
}
|
||||
|
||||
inline void Material::SetTexture(std::size_t textureIndex, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
NazaraAssert(textureIndex < m_textures.size(), "Invalid texture index");
|
||||
m_textures[textureIndex].texture = std::move(texture);
|
||||
if (m_textures[textureIndex].texture != texture)
|
||||
{
|
||||
m_textures[textureIndex].texture = std::move(texture);
|
||||
InvalidateShaderBinding();
|
||||
}
|
||||
}
|
||||
|
||||
inline void Material::SetTextureSampler(std::size_t textureIndex, std::shared_ptr<TextureSampler> sampler)
|
||||
{
|
||||
NazaraAssert(textureIndex < m_textures.size(), "Invalid texture index");
|
||||
m_textures[textureIndex].sampler = std::move(sampler);
|
||||
if (m_textures[textureIndex].sampler != sampler)
|
||||
{
|
||||
m_textures[textureIndex].sampler = std::move(sampler);
|
||||
InvalidateShaderBinding();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -705,6 +726,11 @@ namespace Nz
|
||||
m_pipelineUpdated = false;
|
||||
}
|
||||
|
||||
inline void Material::InvalidateShaderBinding()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
inline void Material::UpdatePipeline() const
|
||||
{
|
||||
for (auto& shader : m_pipelineInfo.shaders)
|
||||
|
||||
Reference in New Issue
Block a user