121 lines
4.7 KiB
Plaintext
121 lines
4.7 KiB
Plaintext
#ifndef OSG_MATERIAL
|
|
#define OSG_MATERIAL 1
|
|
|
|
#include <osg/Vec4>
|
|
#include <osg/StateAttribute>
|
|
#include <osg/StateSet>
|
|
|
|
namespace osg {
|
|
/** Material - encapsulates OpenGL glMaterial state.*/
|
|
class SG_EXPORT Material : public StateAttribute
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
Material();
|
|
virtual Object* clone() const { return new Material(); }
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Material*>(obj)!=NULL; }
|
|
const char* className() const { return "Material"; }
|
|
|
|
virtual const Type getType() const { return MATERIAL; }
|
|
|
|
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
|
{
|
|
// Have to think about the role of _colorMode
|
|
// in setting the colormaterial... also need to take the
|
|
// color material enable/disable out of the the apply()...
|
|
ds.setMode(GL_COLOR_MATERIAL,value);
|
|
}
|
|
|
|
virtual void apply(State& state) const;
|
|
|
|
enum Face {
|
|
FRONT = GL_FRONT,
|
|
BACK = GL_BACK,
|
|
FRONT_AND_BACK = GL_FRONT_AND_BACK
|
|
};
|
|
|
|
enum ColorMode {
|
|
AMBIENT = GL_AMBIENT,
|
|
DIFFUSE = GL_DIFFUSE,
|
|
SPECULAR = GL_SPECULAR,
|
|
EMISSION = GL_EMISSION,
|
|
AMBIENT_AND_DIFFUSE = GL_AMBIENT_AND_DIFFUSE,
|
|
OFF
|
|
};
|
|
|
|
inline void setColorMode(const ColorMode mode) { _colorMode = mode; }
|
|
inline const ColorMode getColorMode() const { return _colorMode; }
|
|
|
|
void setAmbient( const Face face, const Vec4& ambient );
|
|
const Vec4& getAmbient(const Face face) const;
|
|
inline const bool getAmbientFrontAndBack() const { return _ambientFrontAndBack; }
|
|
|
|
void setDiffuse( const Face face, const Vec4& diffuse );
|
|
const Vec4& getDiffuse(const Face face) const;
|
|
inline const bool getDiffuseFrontAndBack() const { return _diffuseFrontAndBack; }
|
|
|
|
/** Set specular value of specified face(s) of the material,
|
|
* valid specular[0..3] range is 0.0 to 1.0.*/
|
|
void setSpecular( const Face face, const Vec4& specular );
|
|
/** Get the specular value for specified face.*/
|
|
const Vec4& getSpecular(const Face face) const;
|
|
/** Get the whether specular values are equal for front and back faces.*/
|
|
inline const bool getSpecularFrontAndBack() const { return _specularFrontAndBack; }
|
|
|
|
/** Set emmision value of specified face(s) of the material,
|
|
* valid emmison[0..3] range is 0.0 to 1.0.*/
|
|
void setEmission( const Face face, const Vec4& emission );
|
|
/** Get the emmsion value for specified face.*/
|
|
const Vec4& getEmission(const Face face) const;
|
|
/** Get the whether emmision values are equal for front and back faces.*/
|
|
inline const bool getEmissionFrontAndBack() const { return _emissionFrontAndBack; }
|
|
|
|
/** Set shininess of specified face(s) of the material, valid shininess range is 0.0 to 1.0.*/
|
|
void setShininess( const Face face, float shininess );
|
|
/** Get the shininess value for specified face.*/
|
|
const float getShininess(const Face face) const;
|
|
/** Get the whether shininess values are equal for front and back faces.*/
|
|
inline const bool getShininessFrontAndBack() const { return _shininessFrontAndBack; }
|
|
|
|
/** Set the alpha value of ambient,diffuse,specular and emmission colors,
|
|
* of specified face, to 1-transparancy. Valid transparancy range is 0.0 to 1.0.*/
|
|
void setTransparency(const Face face,float trans);
|
|
|
|
/** Set the alpha value of ambient,diffuse,specular and emmission colors.
|
|
* Valid transparancy range is 0.0 to 1.0.*/
|
|
void setAlpha(const Face face,float alpha);
|
|
|
|
protected :
|
|
|
|
virtual ~Material();
|
|
|
|
ColorMode _colorMode;
|
|
|
|
bool _ambientFrontAndBack;
|
|
Vec4 _ambientFront; // r, g, b, w
|
|
Vec4 _ambientBack; // r, g, b, w
|
|
|
|
bool _diffuseFrontAndBack;
|
|
Vec4 _diffuseFront; // r, g, b, w
|
|
Vec4 _diffuseBack; // r, g, b, w
|
|
|
|
bool _specularFrontAndBack;
|
|
Vec4 _specularFront; // r, g, b, w
|
|
Vec4 _specularBack; // r, g, b, w
|
|
|
|
bool _emissionFrontAndBack;
|
|
Vec4 _emissionFront; // r, g, b, w
|
|
Vec4 _emissionBack; // r, g, b, w
|
|
|
|
bool _shininessFrontAndBack;
|
|
float _shininessFront; // values 0 - 1.0
|
|
float _shininessBack; // values 0 - 1.0
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|