2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_MATERIAL
|
|
|
|
#define OSG_MATERIAL 1
|
|
|
|
|
|
|
|
#include <osg/Vec4>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/StateAttribute>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Material - encapsulates OpenGL glMaterial state.*/
|
|
|
|
class SG_EXPORT Material : public StateAttribute
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public :
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
Material();
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
Material(const Material& mat,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
StateAttribute(mat,copyop),
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
_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) {}
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_StateAttribute(osg, Material, MATERIAL);
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
|
|
|
virtual int compare(const StateAttribute& sa) const
|
|
|
|
{
|
|
|
|
// check the types are equal and then create the rhs variable
|
|
|
|
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
|
|
|
COMPARE_StateAttribute_Types(Material,sa)
|
|
|
|
|
2004-01-04 20:37:18 +08:00
|
|
|
// compare each parameter in turn against the rhs.
|
2001-09-22 10:42:08 +08:00
|
|
|
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 macro's, must be equal.
|
|
|
|
}
|
|
|
|
|
2004-02-20 19:51:14 +08:00
|
|
|
Material& operator = (const Material& rhs);
|
|
|
|
|
2004-03-03 23:38:22 +08:00
|
|
|
virtual bool getModeUsage(ModeUsage& usage) const
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2004-03-03 23:38:22 +08:00
|
|
|
usage.usesMode(GL_COLOR_MATERIAL);
|
|
|
|
return true;
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(State& state) const;
|
|
|
|
|
|
|
|
enum Face {
|
|
|
|
FRONT = GL_FRONT,
|
|
|
|
BACK = GL_BACK,
|
|
|
|
FRONT_AND_BACK = GL_FRONT_AND_BACK
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ColorMode {
|
|
|
|
AMBIENT = GL_AMBIENT,
|
|
|
|
DIFFUSE = GL_DIFFUSE,
|
|
|
|
SPECULAR = GL_SPECULAR,
|
|
|
|
EMISSION = GL_EMISSION,
|
|
|
|
AMBIENT_AND_DIFFUSE = GL_AMBIENT_AND_DIFFUSE,
|
|
|
|
OFF
|
|
|
|
};
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setColorMode(ColorMode mode) { _colorMode = mode; }
|
|
|
|
inline ColorMode getColorMode() const { return _colorMode; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void setAmbient( Face face, const Vec4& ambient );
|
|
|
|
const Vec4& getAmbient(Face face) const;
|
|
|
|
inline bool getAmbientFrontAndBack() const { return _ambientFrontAndBack; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void setDiffuse( Face face, const Vec4& diffuse );
|
|
|
|
const Vec4& getDiffuse(Face face) const;
|
|
|
|
inline bool getDiffuseFrontAndBack() const { return _diffuseFrontAndBack; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
/** Set specular value of specified face(s) of the material,
|
|
|
|
* valid specular[0..3] range is 0.0 to 1.0.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setSpecular( Face face, const Vec4& specular );
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Get the specular value for specified face.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
const Vec4& getSpecular(Face face) const;
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Get the whether specular values are equal for front and back faces.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool getSpecularFrontAndBack() const { return _specularFrontAndBack; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-10-01 19:15:55 +08:00
|
|
|
/** Set emission value of specified face(s) of the material,
|
2001-09-20 05:08:56 +08:00
|
|
|
* valid emmison[0..3] range is 0.0 to 1.0.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setEmission( Face face, const Vec4& emission );
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Get the emmsion value for specified face.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
const Vec4& getEmission(Face face) const;
|
2001-10-01 19:15:55 +08:00
|
|
|
/** Get the whether emission values are equal for front and back faces.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool getEmissionFrontAndBack() const { return _emissionFrontAndBack; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-07-18 17:55:30 +08:00
|
|
|
/** Set shininess of specified face(s) of the material, valid shininess range is 0.0 to 128.0.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setShininess(Face face, float shininess );
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Get the shininess value for specified face.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
float getShininess(Face face) const;
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Get the whether shininess values are equal for front and back faces.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool getShininessFrontAndBack() const { return _shininessFrontAndBack; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-10-01 19:15:55 +08:00
|
|
|
/** Set the alpha value of ambient,diffuse,specular and emission colors,
|
|
|
|
* of specified face, to 1-transparency. Valid transparency range is 0.0 to 1.0.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setTransparency(Face face,float trans);
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-10-01 19:15:55 +08:00
|
|
|
/** Set the alpha value of ambient,diffuse,specular and emission colors.
|
|
|
|
* Valid transparency range is 0.0 to 1.0.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setAlpha(Face face,float alpha);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
protected :
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual ~Material();
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
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;
|
2002-07-18 17:55:30 +08:00
|
|
|
float _shininessFront; // values 0 - 128.0
|
|
|
|
float _shininessBack; // values 0 - 128.0
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|