Added user-friendly method for loading maps
Former-commit-id: 4990988256a37c55c6d07b273fd48430221235ae
This commit is contained in:
parent
8ff32e2376
commit
38a28c26d2
|
|
@ -12,6 +12,7 @@
|
|||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceRef.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
|
|
@ -86,17 +87,22 @@ class NAZARA_API NzMaterial : public NzResource
|
|||
|
||||
void SetAmbientColor(const NzColor& ambient);
|
||||
void SetDiffuseColor(const NzColor& diffuse);
|
||||
bool SetDiffuseMap(const NzString& texturePath);
|
||||
void SetDiffuseMap(NzTexture* map);
|
||||
void SetDiffuseSampler(const NzTextureSampler& sampler);
|
||||
void SetDstBlend(nzBlendFunc func);
|
||||
bool SetEmissiveMap(const NzString& texturePath);
|
||||
void SetEmissiveMap(NzTexture* map);
|
||||
void SetFaceCulling(nzFaceCulling culling);
|
||||
void SetFaceFilling(nzFaceFilling filling);
|
||||
bool SetHeightMap(const NzString& texturePath);
|
||||
void SetHeightMap(NzTexture* map);
|
||||
bool SetNormalMap(const NzString& texturePath);
|
||||
void SetNormalMap(NzTexture* map);
|
||||
void SetCustomShader(const NzShader* shader);
|
||||
void SetShininess(float shininess);
|
||||
void SetSpecularColor(const NzColor& specular);
|
||||
bool SetSpecularMap(const NzString& texturePath);
|
||||
void SetSpecularMap(NzTexture* map);
|
||||
void SetSpecularSampler(const NzTextureSampler& sampler);
|
||||
void SetSrcBlend(nzBlendFunc func);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
bool NzMaterialParams::IsValid() const
|
||||
|
|
@ -367,6 +368,23 @@ void NzMaterial::SetDiffuseColor(const NzColor& diffuse)
|
|||
m_diffuseColor = diffuse;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetDiffuseMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetDiffuseMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetDiffuseMap(NzTexture* map)
|
||||
{
|
||||
m_diffuseMap = map;
|
||||
|
|
@ -386,6 +404,23 @@ void NzMaterial::SetDstBlend(nzBlendFunc func)
|
|||
m_dstBlend = func;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetEmissiveMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetEmissiveMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetEmissiveMap(NzTexture* map)
|
||||
{
|
||||
m_emissiveMap = map;
|
||||
|
|
@ -405,11 +440,45 @@ void NzMaterial::SetFaceFilling(nzFaceFilling filling)
|
|||
m_faceFilling = filling;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetHeightMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetHeightMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetHeightMap(NzTexture* map)
|
||||
{
|
||||
m_heightMap = map;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetNormalMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetNormalMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetNormalMap(NzTexture* map)
|
||||
{
|
||||
m_normalMap = map;
|
||||
|
|
@ -429,6 +498,23 @@ void NzMaterial::SetSpecularColor(const NzColor& specular)
|
|||
m_specularColor = specular;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetSpecularMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetSpecularMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetSpecularMap(NzTexture* map)
|
||||
{
|
||||
m_specularMap = map;
|
||||
|
|
|
|||
Loading…
Reference in New Issue