Refactored Material interface
Former-commit-id: 9a00be1b73b2c879fc77c9fdddc0192baa241fda
This commit is contained in:
parent
7a45ff4884
commit
88d3ec1ad1
|
|
@ -45,15 +45,13 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
|
|
||||||
void Apply(const NzShader* shader) const;
|
void Apply(const NzShader* shader) const;
|
||||||
|
|
||||||
void EnableAlphaBlending(bool blending);
|
void Enable(nzRendererParameter renderParameter, bool enable);
|
||||||
void EnableFaceCulling(bool faceCulling);
|
|
||||||
void EnableLighting(bool lighting);
|
void EnableLighting(bool lighting);
|
||||||
void EnableZBuffer(bool zBuffer);
|
|
||||||
void EnableZWrite(bool zWrite);
|
|
||||||
|
|
||||||
NzColor GetAmbientColor() const;
|
|
||||||
NzTexture* GetAlphaMap() const;
|
NzTexture* GetAlphaMap() const;
|
||||||
|
NzColor GetAmbientColor() const;
|
||||||
const NzShader* GetCustomShader() const;
|
const NzShader* GetCustomShader() const;
|
||||||
|
nzRendererComparison GetDepthFunc() const;
|
||||||
NzColor GetDiffuseColor() const;
|
NzColor GetDiffuseColor() const;
|
||||||
NzTexture* GetDiffuseMap() const;
|
NzTexture* GetDiffuseMap() const;
|
||||||
NzTextureSampler& GetDiffuseSampler();
|
NzTextureSampler& GetDiffuseSampler();
|
||||||
|
|
@ -64,6 +62,7 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
nzFaceFilling GetFaceFilling() const;
|
nzFaceFilling GetFaceFilling() const;
|
||||||
NzTexture* GetHeightMap() const;
|
NzTexture* GetHeightMap() const;
|
||||||
NzTexture* GetNormalMap() const;
|
NzTexture* GetNormalMap() const;
|
||||||
|
const NzRenderStates& GetRenderStates() const;
|
||||||
nzUInt32 GetShaderFlags() const;
|
nzUInt32 GetShaderFlags() const;
|
||||||
float GetShininess() const;
|
float GetShininess() const;
|
||||||
NzColor GetSpecularColor() const;
|
NzColor GetSpecularColor() const;
|
||||||
|
|
@ -71,15 +70,11 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
NzTextureSampler& GetSpecularSampler();
|
NzTextureSampler& GetSpecularSampler();
|
||||||
const NzTextureSampler& GetSpecularSampler() const;
|
const NzTextureSampler& GetSpecularSampler() const;
|
||||||
nzBlendFunc GetSrcBlend() const;
|
nzBlendFunc GetSrcBlend() const;
|
||||||
nzRendererComparison GetZTestCompare() const;
|
|
||||||
|
|
||||||
bool HasCustomShader() const;
|
bool HasCustomShader() const;
|
||||||
|
|
||||||
bool IsAlphaBlendingEnabled() const;
|
bool IsEnabled(nzRendererParameter renderParameter) const;
|
||||||
bool IsFaceCullingEnabled() const;
|
|
||||||
bool IsLightingEnabled() const;
|
bool IsLightingEnabled() const;
|
||||||
bool IsZBufferEnabled() const;
|
|
||||||
bool IsZWriteEnabled() const;
|
|
||||||
|
|
||||||
bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
|
bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
|
||||||
bool LoadFromMemory(const void* data, std::size_t size, const NzMaterialParams& params = NzMaterialParams());
|
bool LoadFromMemory(const void* data, std::size_t size, const NzMaterialParams& params = NzMaterialParams());
|
||||||
|
|
@ -90,6 +85,8 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
bool SetAlphaMap(const NzString& texturePath);
|
bool SetAlphaMap(const NzString& texturePath);
|
||||||
void SetAlphaMap(NzTexture* map);
|
void SetAlphaMap(NzTexture* map);
|
||||||
void SetAmbientColor(const NzColor& ambient);
|
void SetAmbientColor(const NzColor& ambient);
|
||||||
|
void SetCustomShader(const NzShader* shader);
|
||||||
|
void SetDepthFunc(nzRendererComparison depthFunc);
|
||||||
void SetDiffuseColor(const NzColor& diffuse);
|
void SetDiffuseColor(const NzColor& diffuse);
|
||||||
bool SetDiffuseMap(const NzString& texturePath);
|
bool SetDiffuseMap(const NzString& texturePath);
|
||||||
void SetDiffuseMap(NzTexture* map);
|
void SetDiffuseMap(NzTexture* map);
|
||||||
|
|
@ -103,14 +100,13 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
void SetHeightMap(NzTexture* map);
|
void SetHeightMap(NzTexture* map);
|
||||||
bool SetNormalMap(const NzString& texturePath);
|
bool SetNormalMap(const NzString& texturePath);
|
||||||
void SetNormalMap(NzTexture* map);
|
void SetNormalMap(NzTexture* map);
|
||||||
void SetCustomShader(const NzShader* shader);
|
void SetRenderStates(const NzRenderStates& states);
|
||||||
void SetShininess(float shininess);
|
void SetShininess(float shininess);
|
||||||
void SetSpecularColor(const NzColor& specular);
|
void SetSpecularColor(const NzColor& specular);
|
||||||
bool SetSpecularMap(const NzString& texturePath);
|
bool SetSpecularMap(const NzString& texturePath);
|
||||||
void SetSpecularMap(NzTexture* map);
|
void SetSpecularMap(NzTexture* map);
|
||||||
void SetSpecularSampler(const NzTextureSampler& sampler);
|
void SetSpecularSampler(const NzTextureSampler& sampler);
|
||||||
void SetSrcBlend(nzBlendFunc func);
|
void SetSrcBlend(nzBlendFunc func);
|
||||||
void SetZTestCompare(nzRendererComparison compareFunc);
|
|
||||||
|
|
||||||
NzMaterial& operator=(const NzMaterial& material);
|
NzMaterial& operator=(const NzMaterial& material);
|
||||||
NzMaterial& operator=(NzMaterial&& material);
|
NzMaterial& operator=(NzMaterial&& material);
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ void NzForwardRenderQueue::AddModel(const NzModel* model)
|
||||||
case nzAnimationType_Static:
|
case nzAnimationType_Static:
|
||||||
{
|
{
|
||||||
NzStaticMesh* staticMesh = static_cast<NzStaticMesh*>(subMesh);
|
NzStaticMesh* staticMesh = static_cast<NzStaticMesh*>(subMesh);
|
||||||
if (material->IsAlphaBlendingEnabled())
|
if (material->IsEnabled(nzRendererParameter_Blend))
|
||||||
{
|
{
|
||||||
unsigned int index = transparentStaticModels.size();
|
unsigned int index = transparentStaticModels.size();
|
||||||
transparentStaticModels.resize(index+1);
|
transparentStaticModels.resize(index+1);
|
||||||
|
|
|
||||||
|
|
@ -140,14 +140,17 @@ void NzMaterial::Apply(const NzShader* shader) const
|
||||||
NzRenderer::SetRenderStates(m_states);
|
NzRenderer::SetRenderStates(m_states);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::EnableAlphaBlending(bool blending)
|
void NzMaterial::Enable(nzRendererParameter renderParameter, bool enable)
|
||||||
{
|
{
|
||||||
m_states.parameters[nzRendererParameter_Blend] = blending;
|
#ifdef NAZARA_DEBUG
|
||||||
|
if (renderParameter > nzRendererParameter_Max)
|
||||||
|
{
|
||||||
|
NazaraError("Renderer parameter out of enum");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void NzMaterial::EnableFaceCulling(bool faceCulling)
|
m_states.parameters[renderParameter] = enable;
|
||||||
{
|
|
||||||
m_states.parameters[nzRendererParameter_FaceCulling] = faceCulling;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::EnableLighting(bool lighting)
|
void NzMaterial::EnableLighting(bool lighting)
|
||||||
|
|
@ -159,14 +162,9 @@ void NzMaterial::EnableLighting(bool lighting)
|
||||||
m_shaderFlags &= ~nzShaderFlags_Lighting;
|
m_shaderFlags &= ~nzShaderFlags_Lighting;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::EnableZBuffer(bool zBuffer)
|
NzTexture* NzMaterial::GetAlphaMap() const
|
||||||
{
|
{
|
||||||
m_states.parameters[nzRendererParameter_DepthBuffer] = zBuffer;
|
return m_alphaMap;
|
||||||
}
|
|
||||||
|
|
||||||
void NzMaterial::EnableZWrite(bool zWrite)
|
|
||||||
{
|
|
||||||
m_states.parameters[nzRendererParameter_DepthWrite] = zWrite;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NzColor NzMaterial::GetAmbientColor() const
|
NzColor NzMaterial::GetAmbientColor() const
|
||||||
|
|
@ -174,16 +172,16 @@ NzColor NzMaterial::GetAmbientColor() const
|
||||||
return m_ambientColor;
|
return m_ambientColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
NzTexture* NzMaterial::GetAlphaMap() const
|
|
||||||
{
|
|
||||||
return m_alphaMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NzShader* NzMaterial::GetCustomShader() const
|
const NzShader* NzMaterial::GetCustomShader() const
|
||||||
{
|
{
|
||||||
return m_customShader;
|
return m_customShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nzRendererComparison NzMaterial::GetDepthFunc() const
|
||||||
|
{
|
||||||
|
return m_states.depthFunc;
|
||||||
|
}
|
||||||
|
|
||||||
NzColor NzMaterial::GetDiffuseColor() const
|
NzColor NzMaterial::GetDiffuseColor() const
|
||||||
{
|
{
|
||||||
return m_diffuseColor;
|
return m_diffuseColor;
|
||||||
|
|
@ -234,6 +232,11 @@ NzTexture* NzMaterial::GetNormalMap() const
|
||||||
return m_normalMap;
|
return m_normalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NzRenderStates& NzMaterial::GetRenderStates() const
|
||||||
|
{
|
||||||
|
return m_states;
|
||||||
|
}
|
||||||
|
|
||||||
nzUInt32 NzMaterial::GetShaderFlags() const
|
nzUInt32 NzMaterial::GetShaderFlags() const
|
||||||
{
|
{
|
||||||
return m_shaderFlags;
|
return m_shaderFlags;
|
||||||
|
|
@ -269,24 +272,22 @@ nzBlendFunc NzMaterial::GetSrcBlend() const
|
||||||
return m_states.srcBlend;
|
return m_states.srcBlend;
|
||||||
}
|
}
|
||||||
|
|
||||||
nzRendererComparison NzMaterial::GetZTestCompare() const
|
|
||||||
{
|
|
||||||
return m_states.depthFunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzMaterial::HasCustomShader() const
|
bool NzMaterial::HasCustomShader() const
|
||||||
{
|
{
|
||||||
return m_customShader != nullptr;
|
return m_customShader != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzMaterial::IsAlphaBlendingEnabled() const
|
bool NzMaterial::IsEnabled(nzRendererParameter parameter) const
|
||||||
{
|
{
|
||||||
return m_states.parameters[nzRendererParameter_Blend];
|
#ifdef NAZARA_DEBUG
|
||||||
|
if (parameter > nzRendererParameter_Max)
|
||||||
|
{
|
||||||
|
NazaraError("Renderer parameter out of enum");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool NzMaterial::IsFaceCullingEnabled() const
|
return m_states.parameters[parameter];
|
||||||
{
|
|
||||||
return m_states.parameters[nzRendererParameter_FaceCulling];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzMaterial::IsLightingEnabled() const
|
bool NzMaterial::IsLightingEnabled() const
|
||||||
|
|
@ -294,16 +295,6 @@ bool NzMaterial::IsLightingEnabled() const
|
||||||
return m_lightingEnabled;
|
return m_lightingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzMaterial::IsZBufferEnabled() const
|
|
||||||
{
|
|
||||||
return m_states.parameters[nzRendererParameter_DepthBuffer];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzMaterial::IsZWriteEnabled() const
|
|
||||||
{
|
|
||||||
return m_states.parameters[nzRendererParameter_DepthWrite];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzMaterial::LoadFromFile(const NzString& filePath, const NzMaterialParams& params)
|
bool NzMaterial::LoadFromFile(const NzString& filePath, const NzMaterialParams& params)
|
||||||
{
|
{
|
||||||
return NzMaterialLoader::LoadFromFile(this, filePath, params);
|
return NzMaterialLoader::LoadFromFile(this, filePath, params);
|
||||||
|
|
@ -378,6 +369,11 @@ void NzMaterial::SetCustomShader(const NzShader* shader)
|
||||||
m_customShader = shader;
|
m_customShader = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzMaterial::SetDepthFunc(nzRendererComparison depthFunc)
|
||||||
|
{
|
||||||
|
m_states.depthFunc = depthFunc;
|
||||||
|
}
|
||||||
|
|
||||||
void NzMaterial::SetDiffuseColor(const NzColor& diffuse)
|
void NzMaterial::SetDiffuseColor(const NzColor& diffuse)
|
||||||
{
|
{
|
||||||
m_diffuseColor = diffuse;
|
m_diffuseColor = diffuse;
|
||||||
|
|
@ -503,6 +499,11 @@ void NzMaterial::SetNormalMap(NzTexture* map)
|
||||||
m_shaderFlags &= ~nzShaderFlags_NormalMapping;
|
m_shaderFlags &= ~nzShaderFlags_NormalMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzMaterial::SetRenderStates(const NzRenderStates& states)
|
||||||
|
{
|
||||||
|
m_states = states;
|
||||||
|
}
|
||||||
|
|
||||||
void NzMaterial::SetShininess(float shininess)
|
void NzMaterial::SetShininess(float shininess)
|
||||||
{
|
{
|
||||||
m_shininess = shininess;
|
m_shininess = shininess;
|
||||||
|
|
@ -549,11 +550,6 @@ void NzMaterial::SetSrcBlend(nzBlendFunc func)
|
||||||
m_states.srcBlend = func;
|
m_states.srcBlend = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::SetZTestCompare(nzRendererComparison compareFunc)
|
|
||||||
{
|
|
||||||
m_states.depthFunc = compareFunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
NzMaterial& NzMaterial::operator=(const NzMaterial& material)
|
NzMaterial& NzMaterial::operator=(const NzMaterial& material)
|
||||||
{
|
{
|
||||||
Copy(material);
|
Copy(material);
|
||||||
|
|
@ -584,10 +580,9 @@ NzMaterial* NzMaterial::GetDefault()
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
defaultMaterial.EnableFaceCulling(false);
|
|
||||||
defaultMaterial.EnableLighting(false);
|
defaultMaterial.EnableLighting(false);
|
||||||
defaultMaterial.SetFaceFilling(nzFaceFilling_Line);
|
|
||||||
defaultMaterial.SetDiffuseColor(NzColor::White);
|
defaultMaterial.SetDiffuseColor(NzColor::White);
|
||||||
|
defaultMaterial.SetFaceFilling(nzFaceFilling_Line);
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue