ColorMask support. Allows for selective disabling of color planes upon rendering.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2130 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2009-01-23 00:35:46 +00:00
parent a8d090c43b
commit d51b2f8349
8 changed files with 93 additions and 6 deletions

View File

@ -1,5 +1,9 @@
Changes in version 1.6
- Added ColorMask support to selectively disable color planes on rendering.
- Added support for all available depth test functions.
- Add an outNode to getCollisionPoint() that returns the scene node that was hit, as well as the triangle.
- Initial support for Alpha To Coverage, needs some more fixing until it works on all supported platforms.

View File

@ -85,6 +85,12 @@ namespace video
//! Are vertex buffer objects supported?
EVDF_VERTEX_BUFFER_OBJECT,
//! Supports Alpha To Coverage
EVDF_ALPHA_TO_COVERAGE,
//! Supports Color masks (disabling color planes in output)
EVDF_COLOR_MASK,
//! Only used for counting the elements of this enum
EVDF_COUNT
};

View File

@ -71,6 +71,9 @@ namespace video
//! AntiAliasing mode
EMF_ANTI_ALIASING,
//! ColorMask bits, for enabling the color planes
EMF_COLOR_MASK,
//! This is not a flag, but a value indicating how much flags there are.
EMF_MATERIAL_FLAG_COUNT
};

View File

@ -63,6 +63,25 @@ namespace video
ECFN_ALWAYS
};
//! Enum values for enabling/disabling color planes for rendering
enum E_COLOR_PLANE
{
//! No color enabled
ECP_NONE=0,
//! Alpha enabled
ECP_ALPHA=1,
//! Red enabled
ECP_RED=2,
//! Green enabled
ECP_GREEN=4,
//! Blue enabled
ECP_BLUE=8,
//! All colors, no alpha
ECP_RGB=14,
//! All planes enabled
ECP_ALL=15
};
//! EMT_ONETEXTURE_BLEND: pack srcFact & dstFact and Modulo to MaterialTypeParam
inline f32 pack_texureBlendFunc ( const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact, const E_MODULATE_FUNC modulate )
{
@ -119,7 +138,7 @@ namespace video
Shininess(0.0f), MaterialTypeParam(0.0f), MaterialTypeParam2(0.0f), Thickness(1.0f),
Wireframe(false), PointCloud(false), GouraudShading(true), Lighting(true),
ZWriteEnable(true), BackfaceCulling(true), FrontfaceCulling(false),
FogEnable(false), NormalizeNormals(false), ZBuffer(ECFN_LESSEQUAL), AntiAliasing(EAAM_SIMPLE|EAAM_LINE_SMOOTH)
FogEnable(false), NormalizeNormals(false), ZBuffer(ECFN_LESSEQUAL), AntiAliasing(EAAM_SIMPLE|EAAM_LINE_SMOOTH), ColorMask(ECP_ALL)
{ }
//! Copy constructor
@ -166,6 +185,7 @@ namespace video
NormalizeNormals = other.NormalizeNormals;
ZBuffer = other.ZBuffer;
AntiAliasing = other.AntiAliasing;
ColorMask = other.ColorMask;
return *this;
}
@ -279,6 +299,13 @@ namespace video
//! Sets the antialiasing mode
u8 AntiAliasing;
//! Defines the enabled color planes
/** Values are defined as or'ed values of the E_COLOR_PLANE enum.
Only enabled color planes will be rendered to the current render
target. Typical use is to disable all colors when rendering only to
depth or stencil buffer, or using Red and Green for Stereo rendering. */
u8 ColorMask;
//! Gets the texture transformation matrix for level i
/** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES.
\return Texture matrix for texture level i. */
@ -383,7 +410,11 @@ namespace video
}
break;
case EMF_ANTI_ALIASING:
AntiAliasing = value?1:0;
AntiAliasing = value?EAAM_SIMPLE:EAAM_OFF;
break;
case EMF_COLOR_MASK:
ColorMask = value?ECP_ALL:ECP_NONE;
break;
default:
break;
}
@ -429,6 +460,8 @@ namespace video
TextureLayer[3].TextureWrap);
case EMF_ANTI_ALIASING:
return (AntiAliasing==1);
case EMF_COLOR_MASK:
return (ColorMask!=ECP_NONE);
case EMF_MATERIAL_FLAG_COUNT:
break;
}
@ -460,8 +493,9 @@ namespace video
BackfaceCulling != b.BackfaceCulling ||
FrontfaceCulling != b.FrontfaceCulling ||
FogEnable != b.FogEnable ||
NormalizeNormals != b.NormalizeNormals||
AntiAliasing != b.AntiAliasing;
NormalizeNormals != b.NormalizeNormals ||
AntiAliasing != b.AntiAliasing ||
ColorMask != b.ColorMask;
for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i)
{
different |= (TextureLayer[i] != b.TextureLayer[i]);

View File

@ -566,6 +566,8 @@ bool CD3D8Driver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
return (Caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) == 0;
case EVDF_TEXTURE_NPOT:
return (Caps.TextureCaps & D3DPTEXTURECAPS_POW2) == 0;
case EVDF_COLOR_MASK:
return (Caps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE) != 0;
default:
return false;
};
@ -1446,6 +1448,18 @@ void CD3D8Driver::setBasicRenderStates(const SMaterial& material, const SMateria
pID3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, material.NormalizeNormals);
}
// Color Mask
if (queryFeature(EVDF_COLOR_MASK) &&
(resetAllRenderstates || lastmaterial.ColorMask != material.ColorMask))
{
const DWORD flag =
((material.ColorMask & ECP_RED)?D3DCOLORWRITEENABLE_RED:0) |
((material.ColorMask & ECP_GREEN)?D3DCOLORWRITEENABLE_GREEN:0) |
((material.ColorMask & ECP_BLUE)?D3DCOLORWRITEENABLE_BLUE:0) |
((material.ColorMask & ECP_ALPHA)?D3DCOLORWRITEENABLE_ALPHA:0);
pID3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, flag);
}
// thickness
if (resetAllRenderstates || lastmaterial.Thickness != material.Thickness)
{

View File

@ -614,6 +614,8 @@ bool CD3D9Driver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
return (Caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) == 0;
case EVDF_TEXTURE_NPOT:
return (Caps.TextureCaps & D3DPTEXTURECAPS_POW2) == 0;
case EVDF_COLOR_MASK:
return (Caps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE) != 0;
default:
return false;
};
@ -1772,6 +1774,18 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria
pID3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, material.NormalizeNormals);
}
// Color Mask
if (queryFeature(EVDF_COLOR_MASK) &&
(resetAllRenderstates || lastmaterial.ColorMask != material.ColorMask))
{
const DWORD flag =
((material.ColorMask & ECP_RED)?D3DCOLORWRITEENABLE_RED:0) |
((material.ColorMask & ECP_GREEN)?D3DCOLORWRITEENABLE_GREEN:0) |
((material.ColorMask & ECP_BLUE)?D3DCOLORWRITEENABLE_BLUE:0) |
((material.ColorMask & ECP_ALPHA)?D3DCOLORWRITEENABLE_ALPHA:0);
pID3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, flag);
}
// Anti Aliasing
if (resetAllRenderstates || lastmaterial.AntiAliasing != material.AntiAliasing)
{

View File

@ -2146,6 +2146,16 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
glDisable(GL_NORMALIZE);
}
// Color Mask
if (resetAllRenderStates || lastmaterial.ColorMask != material.ColorMask)
{
glColorMask(
(material.ColorMask & ECP_RED)?GL_TRUE:GL_FALSE,
(material.ColorMask & ECP_GREEN)?GL_TRUE:GL_FALSE,
(material.ColorMask & ECP_BLUE)?GL_TRUE:GL_FALSE,
(material.ColorMask & ECP_ALPHA)?GL_TRUE:GL_FALSE);
}
// thickness
if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness)
{

View File

@ -485,6 +485,10 @@ bool COpenGLExtensionHandler::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
return FeatureAvailable[IRR_EXT_framebuffer_object];
case EVDF_VERTEX_BUFFER_OBJECT:
return FeatureAvailable[IRR_ARB_vertex_buffer_object];
case EVDF_COLOR_MASK:
return true;
case EVDF_ALPHA_TO_COVERAGE:
return FeatureAvailable[IRR_ARB_multisample];
default:
return false;
};
@ -495,5 +499,3 @@ bool COpenGLExtensionHandler::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
}
#endif