VertexProgram
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_VERTEXPROGRAM
#define OSG_VERTEXPROGRAM 1
#include <osg/StateAttribute>
#include <osg/Vec4>
#include <osg/Matrix>
#include <osg/buffered_value>
#include <map>
#include <string>
// if not defined by gl.h use the definition found in:
// http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_program.txt
#ifndef GL_ARB_vertex_program
#define GL_VERTEX_PROGRAM_ARB 0x8620
#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643
#define GL_COLOR_SUM_ARB 0x8458
#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622
#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624
#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A
#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626
#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645
#define GL_PROGRAM_LENGTH_ARB 0x8627
#define GL_PROGRAM_FORMAT_ARB 0x8876
#define GL_PROGRAM_BINDING_ARB 0x8677
#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0
#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1
#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2
#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3
#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4
#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5
#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6
#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7
#define GL_PROGRAM_PARAMETERS_ARB 0x88A8
#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9
#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA
#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB
#define GL_PROGRAM_ATTRIBS_ARB 0x88AC
#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD
#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE
#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF
#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0
#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1
#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2
#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3
#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4
#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5
#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6
#define GL_PROGRAM_STRING_ARB 0x8628
#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B
#define GL_CURRENT_MATRIX_ARB 0x8641
#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7
#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640
#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869
#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F
#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E
#define GL_PROGRAM_ERROR_STRING_ARB 0x8874
#define GL_MATRIX0_ARB 0x88C0
#define GL_MATRIX1_ARB 0x88C1
#define GL_MATRIX2_ARB 0x88C2
#define GL_MATRIX3_ARB 0x88C3
#define GL_MATRIX4_ARB 0x88C4
#define GL_MATRIX5_ARB 0x88C5
#define GL_MATRIX6_ARB 0x88C6
#define GL_MATRIX7_ARB 0x88C7
#define GL_MATRIX8_ARB 0x88C8
#define GL_MATRIX9_ARB 0x88C9
#define GL_MATRIX10_ARB 0x88CA
#define GL_MATRIX11_ARB 0x88CB
#define GL_MATRIX12_ARB 0x88CC
#define GL_MATRIX13_ARB 0x88CD
#define GL_MATRIX14_ARB 0x88CE
#define GL_MATRIX15_ARB 0x88CF
#define GL_MATRIX16_ARB 0x88D0
#define GL_MATRIX17_ARB 0x88D1
#define GL_MATRIX18_ARB 0x88D2
#define GL_MATRIX19_ARB 0x88D3
#define GL_MATRIX20_ARB 0x88D4
#define GL_MATRIX21_ARB 0x88D5
#define GL_MATRIX22_ARB 0x88D6
#define GL_MATRIX23_ARB 0x88D7
#define GL_MATRIX24_ARB 0x88D8
#define GL_MATRIX25_ARB 0x88D9
#define GL_MATRIX26_ARB 0x88DA
#define GL_MATRIX27_ARB 0x88DB
#define GL_MATRIX28_ARB 0x88DC
#define GL_MATRIX29_ARB 0x88DD
#define GL_MATRIX30_ARB 0x88DE
#define GL_MATRIX31_ARB 0x88DF
#endif
namespace osg {
class OSG_EXPORT VertexProgram : public StateAttribute
{
public:
VertexProgram();
VertexProgram(const VertexProgram& vp,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_StateAttribute(osg, VertexProgram, VERTEXPROGRAM);
virtual int compare(const osg::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(VertexProgram,sa)
// compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_vertexProgram)
return 0; // passed all the above comparison macros, must be equal.
}
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesMode(GL_VERTEX_PROGRAM_ARB);
return true;
}
// data access methods.
inline GLuint& getVertexProgramID(unsigned int contextID) const
{
return _vertexProgramIDList[contextID];
}
inline void setVertexProgram( const char* program )
{
_vertexProgram = program;
dirtyVertexProgramObject();
}
inline void setVertexProgram( const std::string& program )
{
_vertexProgram = program;
dirtyVertexProgramObject();
}
inline const std::string& getVertexProgram() const { return _vertexProgram; }
inline void setProgramLocalParameter(const GLuint index, const Vec4& p)
{
_programLocalParameters[index] = p;
}
typedef std::map<GLuint,Vec4> LocalParamList;
inline void setLocalParameters(const LocalParamList& lpl) { _programLocalParameters = lpl; }
inline LocalParamList& getLocalParameters() { return _programLocalParameters; }
inline const LocalParamList& getLocalParameters() const { return _programLocalParameters; }
inline void setMatrix(const GLenum mode, const Matrix& matrix)
{
_matrixList[mode] = matrix;
}
typedef std::map<GLenum,Matrix> MatrixList;
inline void setMatrices(const MatrixList& matrices) { _matrixList = matrices; }
inline MatrixList& getMatrices() { return _matrixList; }
inline const MatrixList& getMatrices() const { return _matrixList; }
void dirtyVertexProgramObject();
virtual void apply(State& state) const;
virtual void compileGLObjects(State& state) const { apply(state); }
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(State* state=0) const;
protected:
virtual ~VertexProgram();
typedef buffered_value<GLuint> VertexProgramIDList;
mutable VertexProgramIDList _vertexProgramIDList;
std::string _vertexProgram;
LocalParamList _programLocalParameters;
MatrixList _matrixList;
};
}
#endif
Matrix
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
GL_VERTEX_PROGRAM_ARB
#define GL_VERTEX_PROGRAM_ARB
Definition VertexProgram:28
buffered_value
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::StateAttribute
Definition StateAttribute:77
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::VERTEXPROGRAM
@ VERTEXPROGRAM
Definition StateAttribute:161
osg::State
Definition State:80
osg::VertexProgram::getVertexProgram
const std::string & getVertexProgram() const
Definition VertexProgram:169
osg::VertexProgram::getModeUsage
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition VertexProgram:139
osg::VertexProgram::getVertexProgramID
GLuint & getVertexProgramID(unsigned int contextID) const
Definition VertexProgram:148
osg::VertexProgram::LocalParamList
std::map< GLuint, Vec4 > LocalParamList
Definition VertexProgram:177
osg::VertexProgram::getLocalParameters
LocalParamList & getLocalParameters()
Definition VertexProgram:183
osg::VertexProgram::compileGLObjects
virtual void compileGLObjects(State &state) const
Definition VertexProgram:210
osg::VertexProgram::getMatrices
MatrixList & getMatrices()
Definition VertexProgram:200
osg::VertexProgram::releaseGLObjects
virtual void releaseGLObjects(State *state=0) const
osg::VertexProgram::setLocalParameters
void setLocalParameters(const LocalParamList &lpl)
Definition VertexProgram:180
osg::VertexProgram::dirtyVertexProgramObject
void dirtyVertexProgramObject()
osg::VertexProgram::~VertexProgram
virtual ~VertexProgram()
osg::VertexProgram::setVertexProgram
void setVertexProgram(const char *program)
Definition VertexProgram:155
osg::VertexProgram::getMatrices
const MatrixList & getMatrices() const
Definition VertexProgram:203
osg::VertexProgram::setMatrix
void setMatrix(const GLenum mode, const Matrix &matrix)
Definition VertexProgram:189
osg::VertexProgram::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osg::VertexProgram::_matrixList
MatrixList _matrixList
Definition VertexProgram:233
osg::VertexProgram::_programLocalParameters
LocalParamList _programLocalParameters
Definition VertexProgram:231
osg::VertexProgram::apply
virtual void apply(State &state) const
osg::VertexProgram::VertexProgram
VertexProgram(const VertexProgram &vp, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::VertexProgram::VertexProgramIDList
buffered_value< GLuint > VertexProgramIDList
Definition VertexProgram:226
osg::VertexProgram::_vertexProgram
std::string _vertexProgram
Definition VertexProgram:229
osg::VertexProgram::MatrixList
std::map< GLenum, Matrix > MatrixList
Definition VertexProgram:194
osg::VertexProgram::setVertexProgram
void setVertexProgram(const std::string &program)
Definition VertexProgram:162
osg::VertexProgram::META_StateAttribute
META_StateAttribute(osg, VertexProgram, VERTEXPROGRAM)
osg::VertexProgram::VertexProgram
VertexProgram()
osg::VertexProgram::compare
virtual int compare(const osg::StateAttribute &sa) const
Definition VertexProgram:127
osg::VertexProgram::setMatrices
void setMatrices(const MatrixList &matrices)
Definition VertexProgram:197
osg::VertexProgram::_vertexProgramIDList
VertexProgramIDList _vertexProgramIDList
Definition VertexProgram:227
osg::VertexProgram::setProgramLocalParameter
void setProgramLocalParameter(const GLuint index, const Vec4 &p)
Definition VertexProgram:172
osg::VertexProgram::getLocalParameters
const LocalParamList & getLocalParameters() const
Definition VertexProgram:186
osg::buffered_value
Definition buffered_value:27
osg
Definition AlphaFunc:19
osg::Matrix
Matrixd Matrix
Definition Matrix:27
osg::Vec4
Vec4f Vec4
Definition Vec4:21
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
osg::StateAttribute::ModeUsage
Definition StateAttribute:308
osg::StateAttribute::ModeUsage::usesMode
virtual void usesMode(GLMode mode)=0