OpenSceneGraph/src/osg/TexGen.cpp

93 lines
2.7 KiB
C++
Raw Normal View History

#include <osg/TexGen>
#include <osg/Notify>
2001-01-11 00:32:10 +08:00
using namespace osg;
TexGen::TexGen()
2001-01-11 00:32:10 +08:00
{
_mode = OBJECT_LINEAR;
_plane_s.set(1.0f, 0.0f, 0.0f, 0.0f);
_plane_t.set(0.0f, 1.0f, 0.0f, 0.0f);
_plane_r.set(0.0f, 0.0f, 1.0f, 0.0f);
_plane_q.set(0.0f, 0.0f, 0.0f, 1.0f);
2001-01-11 00:32:10 +08:00
}
TexGen::~TexGen()
2001-01-11 00:32:10 +08:00
{
}
void TexGen::setPlane(const Coord which, const Vec4& plane)
2001-01-11 00:32:10 +08:00
{
switch( which )
{
case S : _plane_s = plane; break;
case T : _plane_t = plane; break;
case R : _plane_r = plane; break;
case Q : _plane_q = plane; break;
default : notify(WARN)<<"Error: invalid 'which' passed TexGen::setPlane("<<(unsigned int)which<<","<<plane<<")"<<endl; break;
}
2001-01-11 00:32:10 +08:00
}
const Vec4& TexGen::getPlane(const Coord which) const
2001-01-11 00:32:10 +08:00
{
switch( which )
2001-01-11 00:32:10 +08:00
{
case S : return _plane_s;
case T : return _plane_t;
case R : return _plane_r;
case Q : return _plane_q;
default : notify(WARN)<<"Error: invalid 'which' passed TexGen::getPlane(which)"<<endl; return _plane_r;
2001-01-11 00:32:10 +08:00
}
}
void TexGen::apply(State&) const
2001-01-11 00:32:10 +08:00
{
if (_mode == OBJECT_LINEAR)
2001-01-11 00:32:10 +08:00
{
glTexGenfv(GL_S, GL_OBJECT_PLANE, _plane_s.ptr());
glTexGenfv(GL_T, GL_OBJECT_PLANE, _plane_t.ptr());
glTexGenfv(GL_R, GL_OBJECT_PLANE, _plane_r.ptr());
glTexGenfv(GL_Q, GL_OBJECT_PLANE, _plane_q.ptr());
2001-01-11 00:32:10 +08:00
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, _mode );
2001-01-11 00:32:10 +08:00
// note, R & Q will be disabled so R&Q settings won't
// have an effect, see above comment in enable(). RO.
2001-01-11 00:32:10 +08:00
}
else if (_mode == EYE_LINEAR)
{
glTexGenfv(GL_S, GL_EYE_PLANE, _plane_s.ptr());
glTexGenfv(GL_T, GL_EYE_PLANE, _plane_t.ptr());
glTexGenfv(GL_R, GL_EYE_PLANE, _plane_r.ptr());
glTexGenfv(GL_Q, GL_EYE_PLANE, _plane_q.ptr());
2001-01-11 00:32:10 +08:00
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, _mode );
2001-01-11 00:32:10 +08:00
// note, R & Q will be disabled so R&Q settings won't
// have an effect, see above comment in enable(). RO.
2001-01-11 00:32:10 +08:00
}
else // SPHERE_MAP
{
// We ignore the planes if we are not in OBJECT_ or EYE_LINEAR mode.
2001-01-11 00:32:10 +08:00
// Also don't set the mode of GL_R & GL_Q as these will generate
// GL_INVALID_ENUM (See OpenGL Refrence Guide, glTexGEn.)
2001-01-11 00:32:10 +08:00
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, _mode );
}
2001-01-11 00:32:10 +08:00
}