TexGen
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_TEXGEN
#define OSG_TEXGEN 1
#include <osg/Plane>
#include <osg/StateAttribute>
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) || defined(OSG_GL3_AVAILABLE)
#define GL_OBJECT_LINEAR 0x2401
#define GL_EYE_LINEAR 0x2400
#define GL_SPHERE_MAP 0x2402
#define GL_TEXTURE_GEN_S 0x0C60
#define GL_TEXTURE_GEN_T 0x0C61
#define GL_TEXTURE_GEN_R 0x0C62
#define GL_TEXTURE_GEN_Q 0x0C63
#endif
#ifndef GL_NORMAL_MAP_ARB
#define GL_NORMAL_MAP_ARB 0x8511
#endif
#ifndef GL_REFLECTION_MAP_ARB
#define GL_REFLECTION_MAP_ARB 0x8512
#endif
namespace osg {
class OSG_EXPORT TexGen : public StateAttribute
{
public :
TexGen();
TexGen(const TexGen& texgen,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(texgen,copyop),
_mode(texgen._mode),
_plane_s(texgen._plane_s),
_plane_t(texgen._plane_t),
_plane_r(texgen._plane_r),
_plane_q(texgen._plane_q) {}
META_StateAttribute(osg, TexGen, TEXGEN);
virtual bool isTextureAttribute() const { return true; }
virtual int compare(const StateAttribute& sa) const
{
// Check for equal types, then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(TexGen,sa)
// Compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_mode)
COMPARE_StateAttribute_Parameter(_plane_s)
COMPARE_StateAttribute_Parameter(_plane_t)
COMPARE_StateAttribute_Parameter(_plane_r)
COMPARE_StateAttribute_Parameter(_plane_q)
return 0; // Passed all the above comparison macros, so must be equal.
}
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesTextureMode(GL_TEXTURE_GEN_S);
usage.usesTextureMode(GL_TEXTURE_GEN_T);
// Not happy with turning all tex gen parameters on
// as the OSG currently only supports 2D textures and therefore
// only S and T will be required, R&Q would be redundant...
// So commenting out the following until OSG supports 3D textures.
// I plan to revamp the OpenGL state management later so will
// tidy up then. Robert Osfield. Jan 2001.
// The tidy up is now happening, but will have a think before
// resolving the below parameters.
usage.usesTextureMode(GL_TEXTURE_GEN_R);
usage.usesTextureMode(GL_TEXTURE_GEN_Q);
return true;
}
virtual void apply(State& state) const;
enum Mode {
OBJECT_LINEAR = GL_OBJECT_LINEAR,
EYE_LINEAR = GL_EYE_LINEAR,
SPHERE_MAP = GL_SPHERE_MAP,
NORMAL_MAP = GL_NORMAL_MAP_ARB,
REFLECTION_MAP = GL_REFLECTION_MAP_ARB
};
inline void setMode( Mode mode ) { _mode = mode; }
Mode getMode() const { return _mode; }
enum Coord {
S, T, R, Q
};
void setPlane(Coord which, const Plane& plane);
Plane& getPlane(Coord which);
const Plane& getPlane(Coord which) const;
void setPlanesFromMatrix(const Matrixd& matrix);
protected :
virtual ~TexGen( void );
Mode _mode;
Plane _plane_s, _plane_t, _plane_r, _plane_q;
};
}
#endif
Plane
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
GL_NORMAL_MAP_ARB
#define GL_NORMAL_MAP_ARB
Definition TexGen:31
GL_REFLECTION_MAP_ARB
#define GL_REFLECTION_MAP_ARB
Definition TexGen:35
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Matrixd
Definition Matrixd:27
osg::Plane
A plane class. It can be used to represent an infinite plane.
Definition Plane:34
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::TEXGEN
@ TEXGEN
Definition StateAttribute:146
osg::State
Definition State:80
osg::TexGen::~TexGen
virtual ~TexGen(void)
osg::TexGen::getPlane
Plane & getPlane(Coord which)
osg::TexGen::compare
virtual int compare(const StateAttribute &sa) const
Definition TexGen:62
osg::TexGen::setMode
void setMode(Mode mode)
Definition TexGen:108
osg::TexGen::_plane_q
Plane _plane_q
Definition TexGen:136
osg::TexGen::Coord
Coord
Definition TexGen:112
osg::TexGen::S
@ S
Definition TexGen:113
osg::TexGen::T
@ T
Definition TexGen:113
osg::TexGen::Q
@ Q
Definition TexGen:113
osg::TexGen::R
@ R
Definition TexGen:113
osg::TexGen::_plane_s
Plane _plane_s
Definition TexGen:136
osg::TexGen::_mode
Mode _mode
Definition TexGen:132
osg::TexGen::Mode
Mode
Definition TexGen:100
osg::TexGen::NORMAL_MAP
@ NORMAL_MAP
Definition TexGen:104
osg::TexGen::EYE_LINEAR
@ EYE_LINEAR
Definition TexGen:102
osg::TexGen::REFLECTION_MAP
@ REFLECTION_MAP
Definition TexGen:105
osg::TexGen::SPHERE_MAP
@ SPHERE_MAP
Definition TexGen:103
osg::TexGen::OBJECT_LINEAR
@ OBJECT_LINEAR
Definition TexGen:101
osg::TexGen::TexGen
TexGen()
osg::TexGen::META_StateAttribute
META_StateAttribute(osg, TexGen, TEXGEN)
osg::TexGen::getModeUsage
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition TexGen:78
osg::TexGen::TexGen
TexGen(const TexGen &texgen, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition TexGen:49
osg::TexGen::isTextureAttribute
virtual bool isTextureAttribute() const
Definition TexGen:59
osg::TexGen::setPlanesFromMatrix
void setPlanesFromMatrix(const Matrixd &matrix)
osg::TexGen::getMode
Mode getMode() const
Definition TexGen:110
osg::TexGen::getPlane
const Plane & getPlane(Coord which) const
osg::TexGen::_plane_r
Plane _plane_r
Definition TexGen:136
osg::TexGen::_plane_t
Plane _plane_t
Definition TexGen:136
osg::TexGen::apply
virtual void apply(State &state) const
osg::TexGen::setPlane
void setPlane(Coord which, const Plane &plane)
osg
Definition AlphaFunc:19
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
osg::StateAttribute::ModeUsage
Definition StateAttribute:308
osg::StateAttribute::ModeUsage::usesTextureMode
virtual void usesTextureMode(GLMode mode)=0