Material.ZWriteEnable is now of type E_ZWRITE instead of bool and ZWriteFineControl get removed (or merged into ZWriteEnable).

This breaks compiling. To have old values replace false with EZW_OFF and true with EWZ_AUTO.

There's a bit history to this change. ZWriteFineControl got introduced after 1.8 so it was never in a released version.
Basically it was needed after some changes had been made to allow shaders to have zwrite enabled independent
of the material-type (which worked badly for shaders). This had caused other problems as it was then enabled too often instead. 
So to quickly fix those bugs and avoid breaking compatibility I had introduced a new enum ZWriteFineControl in SMaterial.
This worked and didn't break compiling - but I noticed by now that introducing a second flag for this made maintainance for an already 
very hard to understand problem (figuring out the implementation of transparency and zwriting) even more complicated. 
So to keep maintance somewhat sane I decided to break compiling now and merge those two flags. 
The behavior should not be affected by this commit - except for users which set this flag already in their code and have to switch to the enum now.

Serialization is switched on loading old files (so SMaterial has enum already and writes that out).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6026 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2020-01-02 15:34:52 +00:00
parent fc37b383ed
commit 2928a632a4
22 changed files with 85 additions and 69 deletions

View File

@ -962,7 +962,7 @@ bool CB3DMeshFileLoader::readChunkBRUS()
else
{
B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
B3dMaterial.Material.ZWriteEnable = false;
B3dMaterial.Material.ZWriteEnable = video::EZW_OFF;
}
}
else if (B3dMaterial.Textures[0]) //One texture:
@ -971,7 +971,7 @@ bool CB3DMeshFileLoader::readChunkBRUS()
if (B3dMaterial.Textures[0]->Flags & 0x2) //(Alpha mapped)
{
B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
B3dMaterial.Material.ZWriteEnable = false;
B3dMaterial.Material.ZWriteEnable = video::EZW_OFF;
}
else if (B3dMaterial.Textures[0]->Flags & 0x4) //(Masked)
B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; // TODO: create color key texture
@ -984,7 +984,7 @@ bool CB3DMeshFileLoader::readChunkBRUS()
else
{
B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
B3dMaterial.Material.ZWriteEnable = false;
B3dMaterial.Material.ZWriteEnable = video::EZW_OFF;
}
}
else //No texture:
@ -994,7 +994,7 @@ bool CB3DMeshFileLoader::readChunkBRUS()
else
{
B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
B3dMaterial.Material.ZWriteEnable = false;
B3dMaterial.Material.ZWriteEnable = video::EZW_OFF;
}
}
@ -1023,7 +1023,7 @@ bool CB3DMeshFileLoader::readChunkBRUS()
if (B3dMaterial.fx & 32) //force vertex alpha-blending
{
B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
B3dMaterial.Material.ZWriteEnable = false;
B3dMaterial.Material.ZWriteEnable = video::EZW_OFF;
}
B3dMaterial.Material.Shininess = B3dMaterial.shininess;

View File

@ -655,7 +655,7 @@ void CBurningShader_Raster_Reference::setMaterial ( const SBurningShaderMaterial
}
// depth buffer write
ShaderParam.SetRenderState( BD3DRS_ZWRITEENABLE, m.ZWriteEnable );
ShaderParam.SetRenderState( BD3DRS_ZWRITEENABLE, m.ZWriteEnable != video::EZW_OFF );
}
/*!

View File

@ -1541,7 +1541,7 @@ void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect *
if ((effect->Transparency != 0.0f) && (effect->Transparency != 1.0f))
{
effect->Mat.MaterialType = irr::video::EMT_TRANSPARENT_VERTEX_ALPHA;
effect->Mat.ZWriteEnable = false;
effect->Mat.ZWriteEnable = video::EZW_OFF;
}
video::E_TEXTURE_CLAMP twu = video::ETC_REPEAT;
@ -1658,7 +1658,7 @@ void CColladaFileLoader::readBindMaterialSection(io::IXMLReaderUTF8* reader, con
if ((material->Transparency!=0.0f) && (material->Transparency!=1.0f))
{
toBind[i]->getMaterial().MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
toBind[i]->getMaterial().ZWriteEnable = false;
toBind[i]->getMaterial().ZWriteEnable = video::EZW_OFF;
}
}
SceneManager->getMeshManipulator()->setVertexColors(&tmpmesh,material->Mat.DiffuseColor);

View File

@ -1065,7 +1065,7 @@ IMesh* CGeometryCreator::createVolumeLightMesh(
Buffer->Material.MaterialTypeParam = pack_textureBlendFunc( video::EBF_SRC_COLOR, video::EBF_SRC_ALPHA, video::EMFN_MODULATE_1X );
Buffer->Material.Lighting = false;
Buffer->Material.ZWriteEnable = false;
Buffer->Material.ZWriteEnable = video::EZW_OFF;
Buffer->setDirty(EBT_VERTEX_AND_INDEX);

View File

@ -196,7 +196,7 @@ CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& scre
InitMaterial2D.AntiAliasing=video::EAAM_OFF;
InitMaterial2D.Lighting=false;
InitMaterial2D.ZWriteEnable=false;
InitMaterial2D.ZWriteEnable=video::EZW_OFF;
InitMaterial2D.ZBuffer=video::ECFN_DISABLED;
InitMaterial2D.UseMipMaps=false;
for (u32 i=0; i<video::MATERIAL_MAX_TEXTURES; ++i)
@ -1944,7 +1944,7 @@ void CNullDriver::runOcclusionQuery(scene::ISceneNode* node, bool visible)
mat.AntiAliasing=0;
mat.ColorMask=ECP_NONE;
mat.GouraudShading=false;
mat.ZWriteEnable=false;
mat.ZWriteEnable=EZW_OFF;
setMaterial(mat);
}
setTransform(video::ETS_WORLD, node->getAbsoluteTransformation());
@ -2149,7 +2149,7 @@ io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMateria
attr->addBool("PointCloud", material.PointCloud);
attr->addBool("GouraudShading", material.GouraudShading);
attr->addBool("Lighting", material.Lighting);
attr->addBool("ZWriteEnable", material.ZWriteEnable);
attr->addEnum("ZWriteEnable", (irr::s32)material.ZWriteEnable, video::ZWriteNames);
attr->addInt("ZBuffer", material.ZBuffer);
attr->addBool("BackfaceCulling", material.BackfaceCulling);
attr->addBool("FrontfaceCulling", material.FrontfaceCulling);
@ -2165,7 +2165,6 @@ io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMateria
attr->addEnum("PolygonOffsetDirection", material.PolygonOffsetDirection, video::PolygonOffsetDirectionNames);
attr->addFloat("PolygonOffsetDepthBias", material.PolygonOffsetDepthBias);
attr->addFloat("PolygonOffsetSlopeScale", material.PolygonOffsetSlopeScale);
attr->addInt("ZWriteFineControl", material.ZWriteFineControl);
// TODO: Would be nice to have a flag that only serializes rest of texture data when a texture pointer exists.
prefix = "BilinearFilter";
@ -2228,7 +2227,13 @@ void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMater
outMaterial.PointCloud = attr->getAttributeAsBool("PointCloud", outMaterial.PointCloud);
outMaterial.GouraudShading = attr->getAttributeAsBool("GouraudShading", outMaterial.GouraudShading);
outMaterial.Lighting = attr->getAttributeAsBool("Lighting", outMaterial.Lighting);
outMaterial.ZWriteEnable = attr->getAttributeAsBool("ZWriteEnable", outMaterial.ZWriteEnable);
io::E_ATTRIBUTE_TYPE attType = attr->getAttributeType("ZWriteEnable");
if (attType == io::EAT_BOOL ) // Before Irrlicht 1.9
outMaterial.ZWriteEnable = attr->getAttributeAsBool("ZWriteEnable", outMaterial.ZWriteEnable != video::EZW_OFF ) ? video::EZW_AUTO : video::EZW_OFF;
else if (attType == io::EAT_ENUM )
outMaterial.ZWriteEnable = (video::E_ZWRITE)attr->getAttributeAsEnumeration("ZWriteEnable", video::ZWriteNames, outMaterial.ZWriteEnable);
outMaterial.ZBuffer = (u8)attr->getAttributeAsInt("ZBuffer", outMaterial.ZBuffer);
outMaterial.BackfaceCulling = attr->getAttributeAsBool("BackfaceCulling", outMaterial.BackfaceCulling);
outMaterial.FrontfaceCulling = attr->getAttributeAsBool("FrontfaceCulling", outMaterial.FrontfaceCulling);
@ -2245,7 +2250,7 @@ void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMater
outMaterial.PolygonOffsetDirection = (video::E_POLYGON_OFFSET)attr->getAttributeAsEnumeration("PolygonOffsetDirection", video::PolygonOffsetDirectionNames, outMaterial.PolygonOffsetDirection);
outMaterial.PolygonOffsetDepthBias = attr->getAttributeAsFloat("PolygonOffsetDepthBias", outMaterial.PolygonOffsetDepthBias);
outMaterial.PolygonOffsetSlopeScale = attr->getAttributeAsFloat("PolygonOffsetSlopeScale", outMaterial.PolygonOffsetSlopeScale);
outMaterial.ZWriteFineControl = (video::E_ZWRITE_FINE_CONTROL)attr->getAttributeAsInt("ZWriteFineControl", outMaterial.ZWriteFineControl);
prefix = "BilinearFilter";
if (attr->existsAttribute(prefix.c_str())) // legacy
outMaterial.setFlag(EMF_BILINEAR_FILTER, attr->getAttributeAsBool(prefix.c_str()));

View File

@ -745,22 +745,16 @@ namespace video
inline bool getWriteZBuffer(const SMaterial&material) const
{
if (material.ZWriteEnable)
switch ( material.ZWriteEnable )
{
if (!AllowZWriteOnTransparent)
{
switch (material.ZWriteFineControl)
{
case EZI_ONLY_NON_TRANSPARENT:
return !material.isTransparent();
case EZI_ZBUFFER_FLAG:
return true;
}
}
else
case video::EZW_OFF:
return false;
case video::EZW_AUTO:
return AllowZWriteOnTransparent || !material.isTransparent();
case video::EZW_ON:
return true;
}
return false;
return true; // never should get here, but some compilers don't know and complain
}
struct SSurface

View File

@ -1013,7 +1013,7 @@ void COgreMeshFileLoader::readPass(io::IReadFile* file, OgreTechnique& technique
else if (token=="depth_write")
{
getMaterialToken(file, token);
pass.Material.ZWriteEnable=(token=="on");
pass.Material.ZWriteEnable=(token=="on") ? video::EZW_ON : video::EZW_OFF;
}
else if (token=="depth_func")
{

View File

@ -69,6 +69,13 @@ protected:
COpenGLDriver* Driver;
IShaderConstantSetCallBack* CallBack;
// I didn't write this, but here's my understanding:
// Those flags seem to be exclusive so far (so could be an enum).
// Maybe the idea was to make them non-exclusive in future (basically having a shader-material)
// Actually currently there's not even any need to cache them (probably even slower than not doing so).
// They seem to be mostly for downward compatibility.
// I suppose the idea is to use SMaterial.BlendOperation + SMaterial.BlendFactor and a simple non-transparent type as base for more flexibility in the future.
// Note that SMaterial.BlendOperation + SMaterial.BlendFactor are in some drivers already evaluated before OnSetMaterial.
bool Alpha;
bool Blending;
bool FixedBlending;

View File

@ -718,7 +718,7 @@ s32 CQ3LevelMesh::setShaderFogMaterial( video::SMaterial &material, const tBSPFa
material.setTexture(2, 0);
material.setTexture(3, 0);
material.ZBuffer = video::ECFN_LESSEQUAL;
material.ZWriteEnable = false;
material.ZWriteEnable = video::EZW_OFF;
material.MaterialTypeParam = 0.f;
s32 shaderState = -1;
@ -746,7 +746,7 @@ s32 CQ3LevelMesh::setShaderMaterial( video::SMaterial &material, const tBSPFace
material.setTexture(2, 0);
material.setTexture(3, 0);
material.ZBuffer = video::ECFN_LESSEQUAL;
material.ZWriteEnable = true;
material.ZWriteEnable = video::EZW_AUTO;
material.MaterialTypeParam = 0.f;
s32 shaderState = -1;
@ -804,7 +804,7 @@ s32 CQ3LevelMesh::setShaderMaterial( video::SMaterial &material, const tBSPFace
if ( group->isDefined( "depthwrite" ) )
{
material.ZWriteEnable = true;
material.ZWriteEnable = video::EZW_ON;
}
SBlendFunc blendfunc ( LoadParam.defaultModulate );

View File

@ -368,13 +368,14 @@ void CQuake3ShaderSceneNode::render()
material.setTexture(0, tex );
material.ZBuffer = getDepthFunction( group->get( "depthfunc" ) );
// TODO: maybe should be video::EZW_ON instead of EZW_AUTO now (we didn't have that before and I just kept old values here when introducing it to not break anything)
if ( group->isDefined( "depthwrite" ) )
{
material.ZWriteEnable = true;
material.ZWriteEnable = video::EZW_AUTO;
}
else
{
material.ZWriteEnable = drawCount == 0;
material.ZWriteEnable = drawCount == 0 ? video::EZW_AUTO : video::EZW_OFF;
}
//resolve quake3 blendfunction to irrlicht Material Type

View File

@ -39,7 +39,7 @@ CSkyBoxSceneNode::CSkyBoxSceneNode(video::ITexture* top, video::ITexture* bottom
video::SMaterial mat;
mat.Lighting = false;
mat.ZBuffer = video::ECFN_DISABLED;
mat.ZWriteEnable = false;
mat.ZWriteEnable = video::EZW_OFF;
mat.AntiAliasing=0;
mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;

View File

@ -49,7 +49,7 @@ CSkyDomeSceneNode::CSkyDomeSceneNode(video::ITexture* sky, u32 horiRes, u32 vert
Buffer = new SMeshBuffer();
Buffer->Material.Lighting = false;
Buffer->Material.ZBuffer = video::ECFN_DISABLED;
Buffer->Material.ZWriteEnable = false;
Buffer->Material.ZWriteEnable = video::EZW_OFF;
Buffer->Material.AntiAliasing = video::EAAM_OFF;
Buffer->Material.setTexture(0, sky);
Buffer->BoundingBox.MaxEdge.set(0,0,0);

View File

@ -139,7 +139,7 @@ void CSoftwareDriver::selectRightTriangleRenderer()
renderer = ETR_TEXTURE_GOURAUD_ADD;
}
else
if ((Material.ZBuffer==ECFN_DISABLED) && !Material.ZWriteEnable)
if ((Material.ZBuffer==ECFN_DISABLED) && Material.ZWriteEnable == video::EZW_OFF)
renderer = ETR_TEXTURE_GOURAUD_NOZ;
else
{

View File

@ -177,7 +177,7 @@ void CBurningVideoDriver::setCurrentShader()
ITexture *texture1 = Material.org.getTexture(1);
bool zMaterialTest = Material.org.ZBuffer != ECFN_DISABLED &&
Material.org.ZWriteEnable &&
Material.org.ZWriteEnable != video::EZW_OFF &&
getWriteZBuffer(Material.org);
EBurningFFShader shader = zMaterialTest ? ETR_TEXTURE_GOURAUD : ETR_TEXTURE_GOURAUD_NOZ;
@ -2291,7 +2291,7 @@ void CBurningVideoDriver::drawStencilShadowVolume(const core::array<core::vector
Material.org.MaterialType = video::EMT_SOLID;
Material.org.Lighting = false;
Material.org.ZWriteEnable = false;
Material.org.ZWriteEnable = video::EZW_OFF;
Material.org.ZBuffer = ECFN_LESSEQUAL;
LightSpace.Flags &= ~VERTEXTRANSFORM;

View File

@ -134,7 +134,7 @@ CBillboardTextSceneNode::CBillboardTextSceneNode(ISceneNode* parent, ISceneManag
Material.BackfaceCulling = false;
Material.Lighting = false;
Material.ZBuffer = video::ECFN_LESSEQUAL;
Material.ZWriteEnable = false;
Material.ZWriteEnable = video::EZW_OFF;
if (font)
{