Material
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_MATERIAL
#define OSG_MATERIAL 1
#include <osg/Vec4>
#include <osg/StateAttribute>
#ifndef OSG_GL_FIXED_FUNCTION_AVAILABLE
#define GL_AMBIENT 0x1200
#define GL_DIFFUSE 0x1201
#define GL_SPECULAR 0x1202
#define GL_EMISSION 0x1600
#define GL_AMBIENT_AND_DIFFUSE 0x1602
#define GL_COLOR_MATERIAL 0x0B57
#endif
namespace osg {
class OSG_EXPORT Material : public StateAttribute
{
public :
Material();
Material(const Material& mat,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(mat,copyop),
_colorMode(mat._colorMode),
_ambientFrontAndBack(mat._ambientFrontAndBack),
_ambientFront(mat._ambientFront),
_ambientBack(mat._ambientBack),
_diffuseFrontAndBack(mat._diffuseFrontAndBack),
_diffuseFront(mat._diffuseFront),
_diffuseBack(mat._diffuseBack),
_specularFrontAndBack(mat._specularFrontAndBack),
_specularFront(mat._specularFront),
_specularBack(mat._specularBack),
_emissionFrontAndBack(mat._emissionFrontAndBack),
_emissionFront(mat._emissionFront),
_emissionBack(mat._emissionBack),
_shininessFrontAndBack(mat._shininessFrontAndBack),
_shininessFront(mat._shininessFront),
_shininessBack(mat._shininessBack) {}
META_StateAttribute(osg, Material, MATERIAL);
virtual int compare(const StateAttribute& sa) const
{
// check the types are equal and then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(Material,sa)
// compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_colorMode)
COMPARE_StateAttribute_Parameter(_ambientFrontAndBack)
COMPARE_StateAttribute_Parameter(_ambientFront)
COMPARE_StateAttribute_Parameter(_ambientBack)
COMPARE_StateAttribute_Parameter(_diffuseFrontAndBack)
COMPARE_StateAttribute_Parameter(_diffuseFront)
COMPARE_StateAttribute_Parameter(_diffuseBack)
COMPARE_StateAttribute_Parameter(_specularFrontAndBack)
COMPARE_StateAttribute_Parameter(_specularFront)
COMPARE_StateAttribute_Parameter(_specularBack)
COMPARE_StateAttribute_Parameter(_emissionFrontAndBack)
COMPARE_StateAttribute_Parameter(_emissionFront)
COMPARE_StateAttribute_Parameter(_emissionBack)
COMPARE_StateAttribute_Parameter(_shininessFrontAndBack)
COMPARE_StateAttribute_Parameter(_shininessFront)
COMPARE_StateAttribute_Parameter(_shininessBack)
return 0; // passed all the above comparison macros, must be equal.
}
Material& operator = (const Material& rhs);
virtual bool getModeUsage(StateAttribute::ModeUsage& /*usage*/) const
{
// note, since Material does it's own glEnable/glDisable of GL_COLOR_MATERIAL
// we shouldn't declare usage of that mode, so commenting out the below usage.
// usage.usesMode(GL_COLOR_MATERIAL);
return true;
}
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(ColorMode mode) { _colorMode = mode; }
inline ColorMode getColorMode() const { return _colorMode; }
void setAmbient( Face face, const Vec4& ambient );
const Vec4& getAmbient(Face face) const;
inline bool getAmbientFrontAndBack() const { return _ambientFrontAndBack; }
void setDiffuse( Face face, const Vec4& diffuse );
const Vec4& getDiffuse(Face face) const;
inline bool getDiffuseFrontAndBack() const { return _diffuseFrontAndBack; }
void setSpecular( Face face, const Vec4& specular );
const Vec4& getSpecular(Face face) const;
inline bool getSpecularFrontAndBack() const { return _specularFrontAndBack; }
void setEmission( Face face, const Vec4& emission );
const Vec4& getEmission(Face face) const;
inline bool getEmissionFrontAndBack() const { return _emissionFrontAndBack; }
void setShininess(Face face, float shininess );
float getShininess(Face face) const;
inline bool getShininessFrontAndBack() const { return _shininessFrontAndBack; }
void setTransparency(Face face,float trans);
void setAlpha(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 - 128.0
float _shininessBack; // values 0 - 128.0
};
}
#endif
GL_DIFFUSE
#define GL_DIFFUSE
Definition Material:22
GL_AMBIENT_AND_DIFFUSE
#define GL_AMBIENT_AND_DIFFUSE
Definition Material:25
GL_SPECULAR
#define GL_SPECULAR
Definition Material:23
GL_AMBIENT
#define GL_AMBIENT
Definition Material:21
GL_EMISSION
#define GL_EMISSION
Definition Material:24
StateAttribute
COMPARE_StateAttribute_Parameter
#define COMPARE_StateAttribute_Parameter(parameter)
Definition StateAttribute:69
COMPARE_StateAttribute_Types
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
Definition StateAttribute:57
Vec4
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Material::_ambientBack
Vec4 _ambientBack
Definition Material:183
osg::Material::apply
virtual void apply(State &state) const
osg::Material::_diffuseFront
Vec4 _diffuseFront
Definition Material:186
osg::Material::_emissionFrontAndBack
bool _emissionFrontAndBack
Definition Material:193
osg::Material::getAmbientFrontAndBack
bool getAmbientFrontAndBack() const
Definition Material:119
osg::Material::getDiffuseFrontAndBack
bool getDiffuseFrontAndBack() const
Definition Material:123
osg::Material::getShininess
float getShininess(Face face) const
osg::Material::getDiffuse
const Vec4 & getDiffuse(Face face) const
osg::Material::setTransparency
void setTransparency(Face face, float trans)
osg::Material::~Material
virtual ~Material()
osg::Material::setAlpha
void setAlpha(Face face, float alpha)
osg::Material::_ambientFrontAndBack
bool _ambientFrontAndBack
Definition Material:181
osg::Material::getSpecularFrontAndBack
bool getSpecularFrontAndBack() const
Definition Material:136
osg::Material::_ambientFront
Vec4 _ambientFront
Definition Material:182
osg::Material::setSpecular
void setSpecular(Face face, const Vec4 &specular)
osg::Material::_shininessFrontAndBack
bool _shininessFrontAndBack
Definition Material:197
osg::Material::_emissionFront
Vec4 _emissionFront
Definition Material:194
osg::Material::_colorMode
ColorMode _colorMode
Definition Material:179
osg::Material::Face
Face
Definition Material:99
osg::Material::FRONT
@ FRONT
Definition Material:100
osg::Material::FRONT_AND_BACK
@ FRONT_AND_BACK
Definition Material:102
osg::Material::BACK
@ BACK
Definition Material:101
osg::Material::_diffuseBack
Vec4 _diffuseBack
Definition Material:187
osg::Material::getColorMode
ColorMode getColorMode() const
Definition Material:115
osg::Material::getAmbient
const Vec4 & getAmbient(Face face) const
osg::Material::setShininess
void setShininess(Face face, float shininess)
osg::Material::_specularFront
Vec4 _specularFront
Definition Material:190
osg::Material::getEmissionFrontAndBack
bool getEmissionFrontAndBack() const
Definition Material:149
osg::Material::getShininessFrontAndBack
bool getShininessFrontAndBack() const
Definition Material:162
osg::Material::_emissionBack
Vec4 _emissionBack
Definition Material:195
osg::Material::getModeUsage
virtual bool getModeUsage(StateAttribute::ModeUsage &) const
Definition Material:89
osg::Material::setEmission
void setEmission(Face face, const Vec4 &emission)
osg::Material::ColorMode
ColorMode
Definition Material:105
osg::Material::OFF
@ OFF
Definition Material:111
osg::Material::AMBIENT_AND_DIFFUSE
@ AMBIENT_AND_DIFFUSE
Definition Material:110
osg::Material::DIFFUSE
@ DIFFUSE
Definition Material:107
osg::Material::EMISSION
@ EMISSION
Definition Material:109
osg::Material::SPECULAR
@ SPECULAR
Definition Material:108
osg::Material::AMBIENT
@ AMBIENT
Definition Material:106
osg::Material::compare
virtual int compare(const StateAttribute &sa) const
Definition Material:60
osg::Material::getSpecular
const Vec4 & getSpecular(Face face) const
osg::Material::_diffuseFrontAndBack
bool _diffuseFrontAndBack
Definition Material:185
osg::Material::getEmission
const Vec4 & getEmission(Face face) const
osg::Material::_specularFrontAndBack
bool _specularFrontAndBack
Definition Material:189
osg::Material::setColorMode
void setColorMode(ColorMode mode)
Definition Material:114
osg::Material::Material
Material()
osg::Material::setDiffuse
void setDiffuse(Face face, const Vec4 &diffuse)
osg::Material::setAmbient
void setAmbient(Face face, const Vec4 &ambient)
osg::Material::Material
Material(const Material &mat, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition Material:38
osg::Material::_shininessFront
float _shininessFront
Definition Material:198
osg::Material::META_StateAttribute
META_StateAttribute(osg, Material, MATERIAL)
osg::Material::_shininessBack
float _shininessBack
Definition Material:199
osg::Material::_specularBack
Vec4 _specularBack
Definition Material:191
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::MATERIAL
@ MATERIAL
Definition StateAttribute:129
osg::State
Definition State:80
osg
Definition AlphaFunc:19
osg::Vec4
Vec4f Vec4
Definition Vec4:21
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
osg::StateAttribute::ModeUsage
Definition StateAttribute:308