# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NL3D::CMaterial Class Reference

A material represent ALL the states relatives to the aspect of a primitive. More...

#include <material.h>

Inheritance diagram for NL3D::CMaterial

Inheritance graph
[legend]
Collaboration diagram for NL3D::CMaterial:

Collaboration graph
[legend]
List of all members.

Public Types

enum  ZFunc {
  always = 0,
  never,
  equal,
  notequal,
  less,
  lessequal,
  greater,
  greaterequal,
  zfuncCount
}
enum  TBlend {
  one = 0,
  zero,
  srcalpha,
  invsrcalpha,
  srccolor,
  invsrccolor,
  blendCount
}
enum  TShader {
  Normal = 0,
  Bump,
  UserColor,
  shaderCount
}
 Normal shader: use simple multitexturing. More...

enum  TTexOperator {
  Replace = 0,
  Modulate,
  Add,
  AddSigned,
  InterpolateTexture,
  InterpolatePrevious,
  InterpolateDiffuse,
  InterpolateConstant
}
 Environements operators: Replace: out= arg0 Modulate: out= arg0 * arg1 Add: out= arg0 + arg1 AddSigned: out= arg0 + arg1 -0.5 Interpolate*: out= arg0*As + arg1*(1-As), where As is taken from the SrcAlpha of Texture/Previous/Diffuse/Constant, respectively if operator is InterpolateTexture/InterpolatePrevious/InterpolateDiffuse/InterpolateConstant. More...

enum  TTexSource {
  Previous,
  Diffuse,
  Constant
}
 Source argument. More...

enum  TTexOperand {
  SrcColor = 0,
  InvSrcColor,
  SrcAlpha,
  InvSrcAlpha
}
 Operand for the argument. More...


Public Methods

 CMaterial ()
 ctor. More...

 CMaterial (const CMaterial &mat)
 see operator=. More...

 ~CMaterial ()
 dtor. More...

CMaterial& operator= (const CMaterial &mat)
 Do not copy DrvInfos, copy all infos and set IDRV_TOUCHED_ALL. More...

void setShader (TShader val)
 Set the shader for this material. More...

TShader getShader () const
 get the current material shadertype. More...

void setTexture (uint8 stage, ITexture* ptex)
 set a texture for a special stage. More...

ITexturegetTexture (uint8 stage) const
bool texturePresent (uint8 stage) const
void setBlend (bool active)
void setBlendFunc (TBlend src, TBlend dst)
void setSrcBlend (TBlend val)
void setDstBlend (TBlend val)
bool getBlend () const
TBlend getSrcBlend (void) const
TBlend getDstBlend (void) const
void setDoubleSided (bool active)
bool detDoubleSided () const
void setZFunc (ZFunc val)
void setZWrite (bool active)
void setZBias (float val)
ZFunc getZFunc (void) const
bool getZWrite (void) const
float getZBias (void) const
void setColor (CRGBA rgba)
 The Color is used only if lighting is disabled. Also, color is replaced by per vertex color (if any). More...

void setLighting ( bool active, bool DefMat=true, CRGBA emissive=CRGBA(0,0,0), CRGBA ambient=CRGBA(0,0,0), CRGBA diffuse=CRGBA(0,0,0), CRGBA specular=CRGBA(0,0,0), float shininess= 10)
 Batch setup lighting. Opacity is in diffuse.A. More...

void setEmissive ( CRGBA emissive=CRGBA(0,0,0) )
 Set the emissive part ot material. Usefull only if setLighting(true, false) has been done. More...

void setAmbient ( CRGBA ambient=CRGBA(0,0,0) )
 Set the Ambient part ot material. Usefull only if setLighting(true, false) has been done. More...

void setDiffuse ( CRGBA diffuse=CRGBA(0,0,0) )
 Set the Diffuse part ot material. Usefull only if setLighting(true, false) has been done. NB: opacity is NOT copied from diffuse.A. More...

void setOpacity ( uint8 opa )
 Set the Opacity part ot material. Usefull only if setLighting(true, false) has been done. More...

void setSpecular ( CRGBA specular=CRGBA(0,0,0) )
 Set the specular part ot material. Usefull only if setLighting(true, false) has been done. More...

void setShininess ( float shininess )
 Set the shininess part ot material. Usefull only if setLighting(true, false) has been done. More...

bool isLighted () const
CRGBA getColor (void) const
CRGBA getEmissive () const
CRGBA getAmbient () const
CRGBA getDiffuse () const
 return diffuse part. NB: A==opacity. More...

uint8 getOpacity () const
CRGBA getSpecular () const
float getShininess () const
void texEnvOpRGB (uint stage, TTexOperator ope)
 This part is valid for Normal shaders (nlassert). More...

void texEnvArg0RGB (uint stage, TTexSource src, TTexOperand oper)
void texEnvArg1RGB (uint stage, TTexSource src, TTexOperand oper)
void texEnvOpAlpha (uint stage, TTexOperator ope)
void texEnvArg0Alpha (uint stage, TTexSource src, TTexOperand oper)
void texEnvArg1Alpha (uint stage, TTexSource src, TTexOperand oper)
void texConstantColor (uint stage, CRGBA color)
 Setup the constant color for a stage. Used for the TTexSource:Constant. More...

uint32 getTexEnvMode (uint stage)
 For push/pop only, get the packed version of the environnment mode. More...

void setTexEnvMode (uint stage, uint32 packed)
 For push/pop only, set the packed version of the environnment mode. More...

CRGBA getTexConstantColor (uint stage)
void setUserColor (CRGBA userColor)
 This part is valid for Normal shaders (nlassert). More...

CRGBA getUserColor () const
void initUnlit ()
 Init the material as unlit. More...

void initLighted ()
 Init the material as default white lighted material. More...

void serial (NLMISC::IStream &f)
uint32 getFlags () const
uint32 getTouched (void) const
void clearTouched (uint32 flag)

Public Attributes

CTexEnv _TexEnvs [IDRV_MAT_MAXTEXTURES]
CRefPtr<IShaderpShader

Private Attributes

TShader _ShaderType
uint32 _Flags
TBlend _SrcBlend
TBlend _DstBlend
ZFunc _ZFunction
float _ZBias
CRGBA _Color
CRGBA _Emissive
CRGBA _Ambient
CRGBA _Diffuse
CRGBA _Specular
float _Shininess
uint32 _Touched
CSmartPtr<ITexture_Textures [IDRV_MAT_MAXTEXTURES]

Detailed Description

A material represent ALL the states relatives to the aspect of a primitive.

Definition at line 82 of file material.h.


Member Enumeration Documentation

enum NL3D::CMaterial::TBlend
 

Enumeration values:
one  
zero  
srcalpha  
invsrcalpha  
srccolor  
invsrccolor  
blendCount  

Definition at line 87 of file material.h.

enum NL3D::CMaterial::TShader
 

Normal shader: use simple multitexturing.

  • see texEnv*() methods. Bump:
    • not implemented yet. UserColor:
    • UserColor (see setUserColor()) is blended with precomputed texture/textureAlpha.
    • Alpha Blending ignore Alpha of texture (of course :) ), but use Alpha diffuse (vertex/material color).
Enumeration values:
Normal  
Bump  
UserColor  
shaderCount  

Definition at line 97 of file material.h.

enum NL3D::CMaterial::TTexOperand
 

Operand for the argument.

For Alpha arguments, only SrcAlpha and InvSrcAlpha are Valid!!
SrcColor: arg= ColorSource. InvSrcColor: arg= 1-ColorSource. SrcAlpha: arg= AlphaSource. InvSrcAlpha: arg= 1-AlphaSource.

Enumeration values:
SrcColor  
InvSrcColor  
SrcAlpha  
InvSrcAlpha  

Definition at line 128 of file material.h.

enum NL3D::CMaterial::TTexOperator
 

Environements operators: Replace: out= arg0 Modulate: out= arg0 * arg1 Add: out= arg0 + arg1 AddSigned: out= arg0 + arg1 -0.5 Interpolate*: out= arg0*As + arg1*(1-As), where As is taken from the SrcAlpha of Texture/Previous/Diffuse/Constant, respectively if operator is InterpolateTexture/InterpolatePrevious/InterpolateDiffuse/InterpolateConstant.

Enumeration values:
Replace  
Modulate  
Add  
AddSigned  
InterpolateTexture  
InterpolatePrevious  
InterpolateDiffuse  
InterpolateConstant  

Definition at line 110 of file material.h.

enum NL3D::CMaterial::TTexSource
 

Source argument.

Texture: the arg is taken from the current texture of the stage. Previous: the arg is taken from the previous enabled stage. If stage 0, Previous==Diffuse. Diffuse: the arg is taken from the primary color vertex. Constant: the arg is taken from the constant color setuped for this texture stage.

Enumeration values:
Previous  
Diffuse  
Constant  

Definition at line 119 of file material.h.

enum NL3D::CMaterial::ZFunc
 

Enumeration values:
always  
never  
equal  
notequal  
less  
lessequal  
greater  
greaterequal  
zfuncCount  

Definition at line 86 of file material.h.


Constructor & Destructor Documentation

NL3D::CMaterial::CMaterial ( )
 

ctor.

By default, shader is normal, SrcBlend is srcalpha, dstblend is invsrcalpha, ZFunction is lessequal, ZBias is 0, Color is White: (255,255,255,255), not double sided.

Definition at line 38 of file material.cpp.

NL3D::CMaterial::CMaterial ( const CMaterial & mat ) [inline]
 

see operator=.

Definition at line 141 of file material.h.

NL3D::CMaterial::~CMaterial ( )
 

dtor.

Definition at line 107 of file material.cpp.


Member Function Documentation

void NL3D::CMaterial::clearTouched ( uint32 flag ) [inline]
 

Definition at line 390 of file material.h.

bool NL3D::CMaterial::detDoubleSided ( ) const [inline]
 

Definition at line 186 of file material.h.

CRGBA NL3D::CMaterial::getAmbient ( ) const [inline]
 

Definition at line 233 of file material.h.

bool NL3D::CMaterial::getBlend ( ) const [inline]
 

Definition at line 176 of file material.h.

CRGBA NL3D::CMaterial::getColor ( void ) const [inline]
 

Definition at line 231 of file material.h.

CRGBA NL3D::CMaterial::getDiffuse ( ) const [inline]
 

return diffuse part. NB: A==opacity.

Definition at line 235 of file material.h.

TBlend NL3D::CMaterial::getDstBlend ( void ) const [inline]
 

Definition at line 178 of file material.h.

CRGBA NL3D::CMaterial::getEmissive ( ) const [inline]
 

Definition at line 232 of file material.h.

uint32 NL3D::CMaterial::getFlags ( ) const [inline]
 

Definition at line 388 of file material.h.

uint8 NL3D::CMaterial::getOpacity ( ) const [inline]
 

Definition at line 236 of file material.h.

TShader NL3D::CMaterial::getShader ( ) const [inline]
 

get the current material shadertype.

Definition at line 153 of file material.h.

float NL3D::CMaterial::getShininess ( ) const [inline]
 

Definition at line 238 of file material.h.

CRGBA NL3D::CMaterial::getSpecular ( ) const [inline]
 

Definition at line 237 of file material.h.

TBlend NL3D::CMaterial::getSrcBlend ( void ) const [inline]
 

Definition at line 177 of file material.h.

CRGBA NL3D::CMaterial::getTexConstantColor ( uint stage ) [inline]
 

Definition at line 268 of file driver_material_inline.h.

uint32 NL3D::CMaterial::getTexEnvMode ( uint stage ) [inline]
 

For push/pop only, get the packed version of the environnment mode.

Definition at line 254 of file driver_material_inline.h.

ITexture * NL3D::CMaterial::getTexture ( uint8 n ) const [inline]
 

Definition at line 46 of file driver_material_inline.h.

uint32 NL3D::CMaterial::getTouched ( void ) const [inline]
 

Definition at line 389 of file material.h.

CRGBA NL3D::CMaterial::getUserColor ( ) const [inline]
 

Definition at line 291 of file driver_material_inline.h.

float NL3D::CMaterial::getZBias ( void ) const [inline]
 

Definition at line 198 of file material.h.

ZFunc NL3D::CMaterial::getZFunc ( void ) const [inline]
 

Definition at line 196 of file material.h.

bool NL3D::CMaterial::getZWrite ( void ) const [inline]
 

Definition at line 197 of file material.h.

void NL3D::CMaterial::initLighted ( )
 

Init the material as default white lighted material.

normal shader, lighting .... Default to: normal shader, lighting to default material, no texture, ZBias=0, ZFunc= lessequal, ZWrite==true, no blend. All other states are undefined (such as blend function, since blend is disabled).

Definition at line 68 of file material.cpp.

void NL3D::CMaterial::initUnlit ( )
 

Init the material as unlit.

normal shader, no lighting .... Default to: normal shader, no lighting, color to White(1,1,1,1), no texture, ZBias=0, ZFunc= lessequal, ZWrite==true, no blend. All other states are undefined (such as blend function, since blend is disabled).

Definition at line 53 of file material.cpp.

bool NL3D::CMaterial::isLighted ( ) const [inline]
 

Definition at line 229 of file material.h.

CMaterial & NL3D::CMaterial::operator= ( const CMaterial & mat )
 

Do not copy DrvInfos, copy all infos and set IDRV_TOUCHED_ALL.

Definition at line 76 of file material.cpp.

void NL3D::CMaterial::serial ( NLMISC::IStream & f )
 

Definition at line 115 of file material.cpp.

void NL3D::CMaterial::setAmbient ( CRGBA ambient = CRGBA(0,0,0) ) [inline]
 

Set the Ambient part ot material. Usefull only if setLighting(true, false) has been done.

Definition at line 150 of file driver_material_inline.h.

void NL3D::CMaterial::setBlend ( bool active ) [inline]
 

Definition at line 64 of file driver_material_inline.h.

void NL3D::CMaterial::setBlendFunc ( TBlend src,
TBlend dst ) [inline]
 

Definition at line 78 of file driver_material_inline.h.

void NL3D::CMaterial::setColor ( NLMISC::CRGBA rgba ) [inline]
 

The Color is used only if lighting is disabled. Also, color is replaced by per vertex color (if any).

Definition at line 105 of file driver_material_inline.h.

void NL3D::CMaterial::setDiffuse ( CRGBA diffuse = CRGBA(0,0,0) ) [inline]
 

Set the Diffuse part ot material. Usefull only if setLighting(true, false) has been done. NB: opacity is NOT copied from diffuse.A.

Definition at line 156 of file driver_material_inline.h.

void NL3D::CMaterial::setDoubleSided ( bool active ) [inline]
 

Definition at line 71 of file driver_material_inline.h.

void NL3D::CMaterial::setDstBlend ( TBlend val ) [inline]
 

Definition at line 58 of file driver_material_inline.h.

void NL3D::CMaterial::setEmissive ( CRGBA emissive = CRGBA(0,0,0) ) [inline]
 

Set the emissive part ot material. Usefull only if setLighting(true, false) has been done.

Definition at line 144 of file driver_material_inline.h.

void NL3D::CMaterial::setLighting ( bool active,
bool DefMat = true,
NLMISC::CRGBA emissive = CRGBA(0,0,0),
NLMISC::CRGBA ambient = CRGBA(0,0,0),
NLMISC::CRGBA diffuse = CRGBA(0,0,0),
NLMISC::CRGBA specular = CRGBA(0,0,0),
float shininess = 10 ) [inline]
 

Batch setup lighting. Opacity is in diffuse.A.

Definition at line 111 of file driver_material_inline.h.

void NL3D::CMaterial::setOpacity ( uint8 opa ) [inline]
 

Set the Opacity part ot material. Usefull only if setLighting(true, false) has been done.

Definition at line 165 of file driver_material_inline.h.

void NL3D::CMaterial::setShader ( TShader val )
 

Set the shader for this material.

All textures are reseted!!

Definition at line 179 of file material.cpp.

void NL3D::CMaterial::setShininess ( float shininess ) [inline]
 

Set the shininess part ot material. Usefull only if setLighting(true, false) has been done.

Definition at line 177 of file driver_material_inline.h.

void NL3D::CMaterial::setSpecular ( CRGBA specular = CRGBA(0,0,0) ) [inline]
 

Set the specular part ot material. Usefull only if setLighting(true, false) has been done.

Definition at line 171 of file driver_material_inline.h.

void NL3D::CMaterial::setSrcBlend ( TBlend val ) [inline]
 

Definition at line 52 of file driver_material_inline.h.

void NL3D::CMaterial::setTexEnvMode ( uint stage,
uint32 packed ) [inline]
 

For push/pop only, set the packed version of the environnment mode.

Definition at line 261 of file driver_material_inline.h.

void NL3D::CMaterial::setTexture ( uint8 n,
ITexture * ptex )
 

set a texture for a special stage.

Different usage according to shader:

  • Normal shader do multitexturing (see texEnv*() methods).
  • UserColor assert if stage!=0. (NB: internal only: UserColor setup texture to stage 0 and 1).

Definition at line 214 of file material.cpp.

void NL3D::CMaterial::setUserColor ( CRGBA userColor ) [inline]
 

This part is valid for Normal shaders (nlassert).

See also:
TShader.

Definition at line 283 of file driver_material_inline.h.

void NL3D::CMaterial::setZBias ( float val ) [inline]
 

Definition at line 99 of file driver_material_inline.h.

void NL3D::CMaterial::setZFunc ( ZFunc val ) [inline]
 

Definition at line 86 of file driver_material_inline.h.

void NL3D::CMaterial::setZWrite ( bool active ) [inline]
 

Definition at line 92 of file driver_material_inline.h.

void NL3D::CMaterial::texConstantColor ( uint stage,
CRGBA color ) [inline]
 

Setup the constant color for a stage. Used for the TTexSource:Constant.

Definition at line 245 of file driver_material_inline.h.

void NL3D::CMaterial::texEnvArg0Alpha ( uint stage,
TTexSource src,
TTexOperand oper ) [inline]
 

Definition at line 224 of file driver_material_inline.h.

void NL3D::CMaterial::texEnvArg0RGB ( uint stage,
TTexSource src,
TTexOperand oper ) [inline]
 

Definition at line 198 of file driver_material_inline.h.

void NL3D::CMaterial::texEnvArg1Alpha ( uint stage,
TTexSource src,
TTexOperand oper ) [inline]
 

Definition at line 233 of file driver_material_inline.h.

void NL3D::CMaterial::texEnvArg1RGB ( uint stage,
TTexSource src,
TTexOperand oper ) [inline]
 

Definition at line 206 of file driver_material_inline.h.

void NL3D::CMaterial::texEnvOpAlpha ( uint stage,
TTexOperator ope ) [inline]
 

Definition at line 217 of file driver_material_inline.h.

void NL3D::CMaterial::texEnvOpRGB ( uint stage,
TTexOperator ope ) [inline]
 

This part is valid for Normal shaders (nlassert).

It maps the EXT_texture_env_combine opengl extension. A stage is enabled iff his texture is !=NULL. By default, all stages are setup to Modulate style: AlphaOp=RGBOp= Modulate, RGBArg0= TextureSrcColor, RGBArg1= PreviousSrcColor, AlphaArg0= TextureSrcAlpha, AlphaArg1= PreviousSrcAlpha. ConstantColor default to White(255,255,255,255).

For compatibility problems:

  • no scaling is allowed (some cards do not implement this well).
  • Texture can be the source only for Arg0 (DirectX restriction). nlassert...
NB: for Alpha Aguments, only operands SrcAlpha and InvSrcAlpha are valid (nlassert..).

Definition at line 191 of file driver_material_inline.h.

bool NL3D::CMaterial::texturePresent ( uint8 n ) const [inline]
 

Definition at line 36 of file driver_material_inline.h.


Member Data Documentation

CRGBA NL3D::CMaterial::_Ambient [private]
 

Definition at line 377 of file material.h.

CRGBA NL3D::CMaterial::_Color [private]
 

Definition at line 376 of file material.h.

CRGBA NL3D::CMaterial::_Diffuse [private]
 

Definition at line 377 of file material.h.

TBlend NL3D::CMaterial::_DstBlend [private]
 

Definition at line 373 of file material.h.

CRGBA NL3D::CMaterial::_Emissive [private]
 

Definition at line 377 of file material.h.

uint32 NL3D::CMaterial::_Flags [private]
 

Definition at line 372 of file material.h.

TShader NL3D::CMaterial::_ShaderType [private]
 

Definition at line 371 of file material.h.

float NL3D::CMaterial::_Shininess [private]
 

Definition at line 378 of file material.h.

CRGBA NL3D::CMaterial::_Specular [private]
 

Definition at line 377 of file material.h.

TBlend NL3D::CMaterial::_SrcBlend [private]
 

Definition at line 373 of file material.h.

CTexEnv NL3D::CMaterial::_TexEnvs[IDRV_MAT_MAXTEXTURES]
 

Definition at line 385 of file material.h.

CSmartPtr< ITexture > NL3D::CMaterial::_Textures[IDRV_MAT_MAXTEXTURES] [private]
 

Definition at line 381 of file material.h.

uint32 NL3D::CMaterial::_Touched [private]
 

Definition at line 379 of file material.h.

float NL3D::CMaterial::_ZBias [private]
 

Definition at line 375 of file material.h.

ZFunc NL3D::CMaterial::_ZFunction [private]
 

Definition at line 374 of file material.h.

CRefPtr< IShader > NL3D::CMaterial::pShader
 

Definition at line 386 of file material.h.


The documentation for this class was generated from the following files: