Commit ec8f03d7 authored by hybrid's avatar hybrid

Added another material flag to enable front face culling. Can be useful for special effects.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1308 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 1a45ab5d
...@@ -32,9 +32,12 @@ namespace video ...@@ -32,9 +32,12 @@ namespace video
//! This flag is ignored, if the material type is a transparent type. //! This flag is ignored, if the material type is a transparent type.
EMF_ZWRITE_ENABLE, EMF_ZWRITE_ENABLE,
//! Is backfaceculling enabled? Default: true //! Is backface culling enabled? Default: true
EMF_BACK_FACE_CULLING, EMF_BACK_FACE_CULLING,
//! Is frontface culling enabled? Default: false
EMF_FRONT_FACE_CULLING,
//! Is bilinear filtering enabled? Default: true //! Is bilinear filtering enabled? Default: true
EMF_BILINEAR_FILTER, EMF_BILINEAR_FILTER,
......
...@@ -71,7 +71,7 @@ namespace video ...@@ -71,7 +71,7 @@ namespace video
EmissiveColor(0,0,0,0), SpecularColor(255,255,255,255), EmissiveColor(0,0,0,0), SpecularColor(255,255,255,255),
Shininess(0.0f), MaterialTypeParam(0.0f), MaterialTypeParam2(0.0f), Thickness(1.0f), Shininess(0.0f), MaterialTypeParam(0.0f), MaterialTypeParam2(0.0f), Thickness(1.0f),
Wireframe(false), PointCloud(false), GouraudShading(true), Lighting(true), Wireframe(false), PointCloud(false), GouraudShading(true), Lighting(true),
ZWriteEnable(true), BackfaceCulling(true), ZWriteEnable(true), BackfaceCulling(true), FrontfaceCulling(false),
FogEnable(false), NormalizeNormals(false), ZBuffer(1) FogEnable(false), NormalizeNormals(false), ZBuffer(1)
{ } { }
...@@ -108,6 +108,7 @@ namespace video ...@@ -108,6 +108,7 @@ namespace video
Lighting = other.Lighting; Lighting = other.Lighting;
ZWriteEnable = other.ZWriteEnable; ZWriteEnable = other.ZWriteEnable;
BackfaceCulling = other.BackfaceCulling; BackfaceCulling = other.BackfaceCulling;
FrontfaceCulling = other.FrontfaceCulling;
FogEnable = other.FogEnable; FogEnable = other.FogEnable;
NormalizeNormals = other.NormalizeNormals; NormalizeNormals = other.NormalizeNormals;
ZBuffer = other.ZBuffer; ZBuffer = other.ZBuffer;
...@@ -204,6 +205,9 @@ namespace video ...@@ -204,6 +205,9 @@ namespace video
//! Is backface culling enabled? Default: true //! Is backface culling enabled? Default: true
bool BackfaceCulling; bool BackfaceCulling;
//! Is frontface culling enabled? Default: false
bool FrontfaceCulling;
//! Is fog enabled? Default: false //! Is fog enabled? Default: false
bool FogEnable; bool FogEnable;
...@@ -271,6 +275,8 @@ namespace video ...@@ -271,6 +275,8 @@ namespace video
ZWriteEnable = value; break; ZWriteEnable = value; break;
case EMF_BACK_FACE_CULLING: case EMF_BACK_FACE_CULLING:
BackfaceCulling = value; break; BackfaceCulling = value; break;
case EMF_FRONT_FACE_CULLING:
FrontfaceCulling = value; break;
case EMF_BILINEAR_FILTER: case EMF_BILINEAR_FILTER:
{ {
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
...@@ -323,6 +329,8 @@ namespace video ...@@ -323,6 +329,8 @@ namespace video
return ZWriteEnable; return ZWriteEnable;
case EMF_BACK_FACE_CULLING: case EMF_BACK_FACE_CULLING:
return BackfaceCulling; return BackfaceCulling;
case EMF_FRONT_FACE_CULLING:
return FrontfaceCulling;
case EMF_BILINEAR_FILTER: case EMF_BILINEAR_FILTER:
return TextureLayer[0].BilinearFilter; return TextureLayer[0].BilinearFilter;
case EMF_TRILINEAR_FILTER: case EMF_TRILINEAR_FILTER:
...@@ -362,6 +370,7 @@ namespace video ...@@ -362,6 +370,7 @@ namespace video
ZBuffer != b.ZBuffer || ZBuffer != b.ZBuffer ||
ZWriteEnable != b.ZWriteEnable || ZWriteEnable != b.ZWriteEnable ||
BackfaceCulling != b.BackfaceCulling || BackfaceCulling != b.BackfaceCulling ||
FrontfaceCulling != b.FrontfaceCulling ||
FogEnable != b.FogEnable || FogEnable != b.FogEnable ||
NormalizeNormals != b.NormalizeNormals; NormalizeNormals != b.NormalizeNormals;
for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i) for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i)
......
...@@ -1305,12 +1305,18 @@ void CD3D8Driver::setBasicRenderStates(const SMaterial& material, const SMateria ...@@ -1305,12 +1305,18 @@ void CD3D8Driver::setBasicRenderStates(const SMaterial& material, const SMateria
// back face culling // back face culling
if (resetAllRenderstates || lastmaterial.BackfaceCulling != material.BackfaceCulling) if (resetAllRenderstates || (lastmaterial.FrontfaceCulling != material.FrontfaceCulling) || (lastmaterial.BackfaceCulling != material.BackfaceCulling))
{ {
if (material.FrontfaceCulling && material.BackfaceCulling)
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW|D3DCULL_CCW);
else
if (material.FrontfaceCulling)
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
else
if (material.BackfaceCulling) if (material.BackfaceCulling)
pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
else else
pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
} }
// fog // fog
......
...@@ -1318,12 +1318,18 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria ...@@ -1318,12 +1318,18 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria
// back face culling // back face culling
if (resetAllRenderstates || lastmaterial.BackfaceCulling != material.BackfaceCulling) if (resetAllRenderstates || (lastmaterial.FrontfaceCulling != material.FrontfaceCulling) || (lastmaterial.BackfaceCulling != material.BackfaceCulling))
{ {
if (material.FrontfaceCulling && material.BackfaceCulling)
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW|D3DCULL_CCW);
else
if (material.FrontfaceCulling)
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
else
if (material.BackfaceCulling) if (material.BackfaceCulling)
pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
else else
pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE); pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
} }
// fog // fog
......
...@@ -1399,6 +1399,7 @@ io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMateria ...@@ -1399,6 +1399,7 @@ io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMateria
attr->addBool("ZWriteEnable", material.ZWriteEnable); attr->addBool("ZWriteEnable", material.ZWriteEnable);
attr->addInt("ZBuffer", material.ZBuffer); attr->addInt("ZBuffer", material.ZBuffer);
attr->addBool("BackfaceCulling", material.BackfaceCulling); attr->addBool("BackfaceCulling", material.BackfaceCulling);
attr->addBool("FrontfaceCulling", material.FrontfaceCulling);
attr->addBool("FogEnable", material.FogEnable); attr->addBool("FogEnable", material.FogEnable);
attr->addBool("NormalizeNormals", material.NormalizeNormals); attr->addBool("NormalizeNormals", material.NormalizeNormals);
...@@ -1454,6 +1455,7 @@ void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMater ...@@ -1454,6 +1455,7 @@ void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMater
outMaterial.ZWriteEnable = attr->getAttributeAsBool("ZWriteEnable"); outMaterial.ZWriteEnable = attr->getAttributeAsBool("ZWriteEnable");
outMaterial.ZBuffer = attr->getAttributeAsInt("ZBuffer"); outMaterial.ZBuffer = attr->getAttributeAsInt("ZBuffer");
outMaterial.BackfaceCulling = attr->getAttributeAsBool("BackfaceCulling"); outMaterial.BackfaceCulling = attr->getAttributeAsBool("BackfaceCulling");
outMaterial.FrontfaceCulling = attr->getAttributeAsBool("FrontfaceCulling");
outMaterial.FogEnable = attr->getAttributeAsBool("FogEnable"); outMaterial.FogEnable = attr->getAttributeAsBool("FogEnable");
outMaterial.NormalizeNormals = attr->getAttributeAsBool("NormalizeNormals"); outMaterial.NormalizeNormals = attr->getAttributeAsBool("NormalizeNormals");
prefix = "BilinearFilter"; prefix = "BilinearFilter";
......
...@@ -1685,8 +1685,23 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater ...@@ -1685,8 +1685,23 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
// back face culling // back face culling
if (resetAllRenderStates || lastmaterial.BackfaceCulling != material.BackfaceCulling) if (resetAllRenderStates || lastmaterial.BackfaceCulling != material.BackfaceCulling)
{ {
if ((material.FrontfaceCulling) && (material.BackfaceCulling))
{
glCullFace(GL_FRONT_AND_BACK);
glEnable(GL_CULL_FACE);
}
else
if (material.BackfaceCulling) if (material.BackfaceCulling)
{
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
}
else
if (material.FrontfaceCulling)
{
glCullFace(GL_FRONT);
glEnable(GL_CULL_FACE);
}
else else
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment