depth function can be set in a material

This commit is contained in:
Mikulas Florek 2014-07-19 20:48:21 +02:00
parent fda0fbf529
commit c9ec6d45d2
2 changed files with 35 additions and 0 deletions

View file

@ -27,6 +27,15 @@ void Material::apply(Renderer& renderer, PipelineInstance& pipeline)
if(getState() == State::READY)
{
m_shader->apply();
switch (m_depth_func)
{
case DepthFunc::LEQUAL:
glDepthFunc(GL_LEQUAL);
break;
default:
glDepthFunc(GL_LESS);
break;
}
if (m_is_backface_culling)
{
glEnable(GL_CULL_FACE);
@ -259,6 +268,23 @@ void Material::loaded(FS::IFile* file, bool success, FS::FileSystem& fs)
{
serializer.deserialize(m_is_backface_culling);
}
else if (strcmp(label, "depth_func") == 0)
{
char tmp[30];
serializer.deserialize(tmp, 30);
if (strcmp(tmp, "lequal") == 0)
{
m_depth_func = DepthFunc::LEQUAL;
}
else if (strcmp(tmp, "less") == 0)
{
m_depth_func = DepthFunc::LESS;
}
else
{
g_log_warning.log("Renderer") << "Unknown depth function " << tmp << " in material " << m_path.c_str();
}
}
else
{
g_log_warning.log("renderer") << "Unknown parameter " << label << " in material " << m_path.c_str();

View file

@ -24,6 +24,13 @@ class Texture;
class LUMIX_ENGINE_API Material : public Resource
{
friend class MaterialManager;
public:
enum class DepthFunc
{
LEQUAL,
LESS
};
public:
void apply(Renderer& renderer, PipelineInstance& pipeline);
bool isZTest() const { return m_is_z_test; }
@ -46,6 +53,7 @@ private:
, m_shader(NULL)
, m_is_z_test(true)
, m_is_backface_culling(true)
, m_depth_func(DepthFunc::LESS)
{ }
~Material();
@ -86,6 +94,7 @@ private:
Array<Uniform> m_uniforms;
bool m_is_z_test;
bool m_is_backface_culling;
DepthFunc m_depth_func;
};
} // ~namespace Lumix