Use BlendFactor only when MaterialType != EMT_ONETEXTURE_BLEND

The way this was implemented BlendFactor and MaterialTypeParam could conflict otherwise as they both send the blend functions.

We could probably rewrite all places which use EMT_ONETEXTURE_BLEND+MaterialTypeParam to additionally check for BlendFactor, but it would still set the blend-functions twice. 
I'm not sure if BlendFactor works with 2D materials currently? (but we can't set those to shaders yet anyway except in the gles branch...).

I've also started documenting a few things about how I suppose it's working, I hope I got it all right.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6034 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2020-01-03 14:58:46 +00:00
parent 473ab1ea58
commit 0b71328102
7 changed files with 26 additions and 11 deletions

@ -187,7 +187,9 @@ namespace video
EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA,
//! BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC )
/** Using only first texture. Generic blending method. */
/** Using only first texture. Generic blending method.
The blend function is set to SMaterial::MaterialTypeParam with
pack_textureBlendFunc (for 2D) or pack_textureBlendFuncSeparate (for 3D). */
EMT_ONETEXTURE_BLEND,
//! This value is not used. It only forces this enumeration to compile to 32 bit.

@ -19,7 +19,8 @@ namespace video
{
class ITexture;
//! Flag for EMT_ONETEXTURE_BLEND, ( BlendFactor ) BlendFunc = source * sourceFactor + dest * destFactor
//! Flag for MaterialTypeParam (in combination with EMT_ONETEXTURE_BLEND) or for BlendFactor
//! BlendFunc = source * sourceFactor + dest * destFactor
enum E_BLEND_FACTOR
{
EBF_ZERO = 0, //!< src & dest (0, 0, 0, 0)
@ -431,8 +432,8 @@ namespace video
f32 Shininess;
//! Free parameter, dependent on the material type.
/** Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID
and EMT_TRANSPARENT_ALPHA_CHANNEL. */
/** Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID,
EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND. */
f32 MaterialTypeParam;
//! Second free parameter, dependent on the material type.
@ -474,8 +475,14 @@ namespace video
//! Store the blend factors
/** textureBlendFunc/textureBlendFuncSeparate functions should be used to write
properly blending factors to this parameter. If you use EMT_ONETEXTURE_BLEND
type for this material, this field should be equal to MaterialTypeParams. */
properly blending factors to this parameter.
Due to historical reasons this parameter is not used for material type
EMT_ONETEXTURE_BLEND which uses MaterialTypeParam instead for the blend factor.
It's generally used only for materials without any blending otherwise (like EMT_SOLID).
It's main use is to allow having shader materials which can enable/disable
blending after they have been created.
When you set this you usually also have to set BlendOperation to a value != EBO_NONE
(setting it to EBO_ADD is probably the most common one value). */
f32 BlendFactor;
//! DEPRECATED. Will be removed after Irrlicht 1.9. Please use PolygonOffsetDepthBias instead.

@ -2219,7 +2219,9 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria
}
// Blend Factor
if (IR(material.BlendFactor) & 0xFFFFFFFF)
if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF?
&& material.MaterialType != EMT_ONETEXTURE_BLEND
)
{
E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
E_BLEND_FACTOR dstRGBFact = EBF_ZERO;

@ -2759,7 +2759,9 @@ bool CNullDriver::needsTransparentRenderPass(const irr::video::SMaterial& materi
// zwrite disabled and getWriteZBuffer calls this function.
video::IMaterialRenderer* rnd = getMaterialRenderer(material.MaterialType);
if (rnd && rnd->isTransparent())
// TODO: I suspect IMaterialRenderer::isTransparent also often could use SMaterial as parameter
// We could for example then get rid of IsTransparent function in SMaterial and move that to the software material renderer.
if (rnd && rnd->isTransparent())
return true;
return false;

@ -2585,7 +2585,9 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
}
// Blend Factor
if (IR(material.BlendFactor) & 0xFFFFFFFF)
if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF?
&& material.MaterialType != EMT_ONETEXTURE_BLEND
)
{
E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
E_BLEND_FACTOR dstRGBFact = EBF_ZERO;

@ -21,7 +21,7 @@ namespace video
class COpenGLDriver;
class IShaderConstantSetCallBack;
//! Class for using vertex and pixel shaders with OpenGL
//! Class for using vertex and pixel shaders with OpenGL (asm not glsl!)
class COpenGLShaderMaterialRenderer : public IMaterialRenderer
{
public:

@ -1,4 +1,4 @@
Tests finished. 72 tests of 72 passed.
Compiled as DEBUG
Test suite pass at GMT Fri Jan 03 10:49:15 2020
Test suite pass at GMT Fri Jan 03 14:40:24 2020