From Mike Weiblen, updates to osgGL2 to support Uniform values
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/* file: include/osgGL2/Extensions
|
||||
* author: Mike Weiblen 2003-07-14
|
||||
* author: Mike Weiblen 2003-09-12
|
||||
*
|
||||
* See http://www.3dlabs.com/opengl2/ for more information regarding
|
||||
* the OpenGL Shading Language.
|
||||
@@ -152,17 +152,17 @@ class OSGGL2_EXPORT Extensions : public osg::Referenced
|
||||
void glUniform2i(GLint location, GLint v0, GLint v1) const;
|
||||
void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2) const;
|
||||
void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) const;
|
||||
void glUniform1fv(GLint location, GLsizei count, GLfloat *value) const;
|
||||
void glUniform2fv(GLint location, GLsizei count, GLfloat *value) const;
|
||||
void glUniform3fv(GLint location, GLsizei count, GLfloat *value) const;
|
||||
void glUniform4fv(GLint location, GLsizei count, GLfloat *value) const;
|
||||
void glUniform1iv(GLint location, GLsizei count, GLint *value) const;
|
||||
void glUniform2iv(GLint location, GLsizei count, GLint *value) const;
|
||||
void glUniform3iv(GLint location, GLsizei count, GLint *value) const;
|
||||
void glUniform4iv(GLint location, GLsizei count, GLint *value) const;
|
||||
void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const;
|
||||
void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const;
|
||||
void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) const;
|
||||
void glUniform1fv(GLint location, GLsizei count, const GLfloat *value) const;
|
||||
void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) const;
|
||||
void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) const;
|
||||
void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) const;
|
||||
void glUniform1iv(GLint location, GLsizei count, const GLint *value) const;
|
||||
void glUniform2iv(GLint location, GLsizei count, const GLint *value) const;
|
||||
void glUniform3iv(GLint location, GLsizei count, const GLint *value) const;
|
||||
void glUniform4iv(GLint location, GLsizei count, const GLint *value) const;
|
||||
void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const;
|
||||
void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const;
|
||||
void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) const;
|
||||
GLint glGetUniformLocation(GLhandleARB programObject, const GLcharARB *name) const;
|
||||
GLint glGetAttribLocation(GLhandleARB programObj, const GLcharARB *name) const;
|
||||
void glGetActiveUniform(GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLint *type, GLcharARB *name) const;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
/* file: include/osgGL2/ProgramObject
|
||||
* author: Mike Weiblen 2003-07-14
|
||||
* author: Mike Weiblen 2003-09-18
|
||||
*
|
||||
* See http://www.3dlabs.com/opengl2/ for more information regarding
|
||||
* the OpenGL Shading Language.
|
||||
@@ -25,26 +25,32 @@
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/buffered_value>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
|
||||
#include <osgGL2/Export>
|
||||
#include <osgGL2/Extensions>
|
||||
#include <osgGL2/UniformValue>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace osgGL2 {
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class ProgramObject;
|
||||
typedef osg::ref_ptr<ProgramObject> ProgramObjectPtr;
|
||||
|
||||
class ShaderObject;
|
||||
typedef osg::ref_ptr<ShaderObject> ShaderObjectPtr;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Encapsulates the OpenGL Shading Language ProgramObject */
|
||||
class OSGGL2_EXPORT ProgramObject : public osg::StateAttribute
|
||||
{
|
||||
public:
|
||||
|
||||
ProgramObject();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
@@ -74,10 +80,29 @@ class OSGGL2_EXPORT ProgramObject : public osg::StateAttribute
|
||||
|
||||
// data access methods.
|
||||
|
||||
/** Force a relink on next apply() of associated glProgramObject. */
|
||||
void dirtyProgramObject();
|
||||
/** Force a relink on next apply() of associated glProgramObject. */
|
||||
void dirtyProgramObject();
|
||||
|
||||
void addShader( ShaderObject* shader );
|
||||
/** Force a recompile of all ShaderObjects on next apply(). */
|
||||
void dirtyShaderObjects();
|
||||
|
||||
/** Set whether rendering of ProgramObject is enabled or disabled */
|
||||
void enable( bool enabled ) { _enabled = enabled; }
|
||||
|
||||
/** Attach a ShaderObject to this ProgramObject */
|
||||
void addShader( ShaderObject* shadObj );
|
||||
|
||||
void setUniform( const char* uniformName, int value );
|
||||
void setUniform( const char* uniformName, float value );
|
||||
void setUniform( const char* uniformName, osg::Vec2 value );
|
||||
void setUniform( const char* uniformName, osg::Vec3 value );
|
||||
void setUniform( const char* uniformName, osg::Vec4 value );
|
||||
|
||||
inline void setSampler( const char* uniformName, int value )
|
||||
{
|
||||
// emphatic alias for setUniform(int)
|
||||
setUniform( uniformName, static_cast<int>(value) );
|
||||
}
|
||||
|
||||
/** use deleteObject instead of glDeleteObject to allow
|
||||
* GL2 Objects to cached until they can be deleted
|
||||
@@ -89,50 +114,52 @@ class OSGGL2_EXPORT ProgramObject : public osg::StateAttribute
|
||||
* in the OpenGL context related to contextID.*/
|
||||
static void flushDeletedGL2Objects(unsigned int contextID,double currentTime, double& availableTime);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ProgramObject();
|
||||
|
||||
typedef std::vector< osg::ref_ptr<ShaderObject> > ShaderObjectList;
|
||||
ShaderObjectList _shaderObjectList;
|
||||
|
||||
|
||||
class OSGGL2_EXPORT PerContextProgObj : public osg::Referenced
|
||||
class PerContextProgObj : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
PerContextProgObj(const ProgramObject* parent, Extensions* extensions);
|
||||
PerContextProgObj(const ProgramObject* progObj, unsigned int contextID);
|
||||
PerContextProgObj(const PerContextProgObj& rhs);
|
||||
|
||||
GLhandleARB& getHandle() {return _handle;}
|
||||
GLhandleARB& getHandle() {return _glProgObjHandle;}
|
||||
|
||||
bool isDirty() const {return _dirty;}
|
||||
void markAsDirty() {_dirty = true; }
|
||||
void markAsClean() {_dirty = false;}
|
||||
bool build() const;
|
||||
void build();
|
||||
void use() const;
|
||||
|
||||
void markAsAttached() {_unattached = false;}
|
||||
bool isUnattached() const {return _unattached;}
|
||||
void updateUniforms( const UniformValueList& univalList );
|
||||
void applyUniformValues();
|
||||
|
||||
protected:
|
||||
PerContextProgObj() {};
|
||||
void printInfoLog(osg::NotifySeverity severity) const;
|
||||
|
||||
protected: /*methods*/
|
||||
PerContextProgObj();
|
||||
~PerContextProgObj();
|
||||
|
||||
const ProgramObject* _parent;
|
||||
protected: /*data*/
|
||||
const ProgramObject* _progObj;
|
||||
osg::ref_ptr<Extensions> _extensions;
|
||||
GLhandleARB _handle;
|
||||
GLhandleARB _glProgObjHandle;
|
||||
bool _dirty;
|
||||
bool _unattached;
|
||||
UniformValueList _univalList;
|
||||
const unsigned int _contextID;
|
||||
};
|
||||
|
||||
typedef osg::buffered_value< osg::ref_ptr<PerContextProgObj> > PCPOList;
|
||||
mutable PCPOList _pcpoList;
|
||||
|
||||
protected: /*methods*/
|
||||
virtual ~ProgramObject();
|
||||
PerContextProgObj* getPCPO(unsigned int contextID) const;
|
||||
void updateUniforms( int frameNumber ) const;
|
||||
|
||||
protected: /*data*/
|
||||
bool _enabled;
|
||||
std::vector< ShaderObjectPtr > _shaderObjectList;
|
||||
mutable osg::buffered_value< osg::ref_ptr<PerContextProgObj> > _pcpoList;
|
||||
mutable int _frameNumberOfLastPCPOUpdate;
|
||||
mutable UniformValueList _univalList;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Encapsulates the OpenGL Shading Language ShaderObject */
|
||||
@@ -159,51 +186,57 @@ class OSGGL2_EXPORT ShaderObject : public osg::Object
|
||||
void setShaderSource( const char* sourceText );
|
||||
inline const std::string& getShaderSource() const {return _shaderSource; }
|
||||
bool loadShaderSourceFromFile( const char* fileName );
|
||||
Type getType() const { return _type; }
|
||||
inline Type getType() const { return _type; }
|
||||
const char* getTypename() const;
|
||||
|
||||
/** Force a recompile on next apply() of associated glShaderObject. */
|
||||
void dirtyShaderObject();
|
||||
|
||||
bool build(unsigned int contextID) const;
|
||||
void build(unsigned int contextID) const;
|
||||
void attach(unsigned int contextID, GLhandleARB progObj) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ShaderObject();
|
||||
|
||||
std::string _shaderSource;
|
||||
Type _type;
|
||||
|
||||
class OSGGL2_EXPORT PerContextShaderObj : public osg::Referenced
|
||||
class PerContextShaderObj : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
PerContextShaderObj(const ShaderObject* parent, Extensions* extensions);
|
||||
PerContextShaderObj(const ShaderObject* shadObj, unsigned int contextID);
|
||||
PerContextShaderObj(const PerContextShaderObj& rhs);
|
||||
|
||||
GLhandleARB& getHandle() {return _handle;}
|
||||
GLhandleARB& getHandle() {return _glShaderObjHandle;}
|
||||
|
||||
bool isDirty() const {return _dirty;}
|
||||
void markAsDirty() {_dirty = true; }
|
||||
void markAsClean() {_dirty = false;}
|
||||
bool build();
|
||||
void build();
|
||||
|
||||
void attach(GLhandleARB progObj);
|
||||
void attach(GLhandleARB progObj) const;
|
||||
|
||||
protected:
|
||||
PerContextShaderObj() {};
|
||||
void printInfoLog(osg::NotifySeverity severity) const;
|
||||
|
||||
protected: /*methods*/
|
||||
PerContextShaderObj();
|
||||
~PerContextShaderObj();
|
||||
|
||||
const ShaderObject* _parent;
|
||||
protected: /*data*/
|
||||
const ShaderObject* _shadObj;
|
||||
osg::ref_ptr<Extensions> _extensions;
|
||||
GLhandleARB _handle;
|
||||
GLhandleARB _glShaderObjHandle;
|
||||
bool _dirty;
|
||||
const unsigned int _contextID;
|
||||
};
|
||||
|
||||
typedef osg::buffered_value< osg::ref_ptr<PerContextShaderObj> > PCSOList;
|
||||
mutable PCSOList _pcsoList;
|
||||
|
||||
protected: /*methods*/
|
||||
virtual ~ShaderObject();
|
||||
PerContextShaderObj* getPCSO(unsigned int contextID) const;
|
||||
|
||||
friend void ProgramObject::addShader( ShaderObject* shadObj ); // to access addProgObjRef()
|
||||
void addProgObjRef( ProgramObject* progObj );
|
||||
|
||||
protected: /*data*/
|
||||
Type _type;
|
||||
std::string _shaderSource;
|
||||
std::vector< ProgramObjectPtr > _programObjectList;
|
||||
mutable osg::buffered_value< osg::ref_ptr<PerContextShaderObj> > _pcsoList;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
88
include/osgGL2/UniformValue
Normal file
88
include/osgGL2/UniformValue
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
* Copyright (C) 2003 3Dlabs Inc. Ltd.
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commericial and non commericial
|
||||
* applications, as long as this copyright notice is maintained.
|
||||
*
|
||||
* This application 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.
|
||||
*/
|
||||
|
||||
/* file: include/osgGL2/UniformValue
|
||||
* author: Mike Weiblen 2003-09-18
|
||||
*
|
||||
* See http://www.3dlabs.com/opengl2/ for more information regarding
|
||||
* the OpenGL Shading Language.
|
||||
*/
|
||||
|
||||
#ifndef OSGGL2_UNIFORMVALUE
|
||||
#define OSGGL2_UNIFORMVALUE 1
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Referenced>
|
||||
|
||||
#include <osgGL2/Extensions>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace osgGL2 {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** An abstract class to encapsulate a new value for a glUniform.
|
||||
* osgGL2::ProgramObject.setUniform() constructs and sends a UniformValue
|
||||
* to all its PCPOs (per-context glProgramObjects) to set the value of a
|
||||
* glUniform; that value is propogated to the glProgramObjects during the
|
||||
* next osgGL2::ProgramObject.apply().
|
||||
* This class is for internal use by osgGL2::ProgramObject.
|
||||
*/
|
||||
|
||||
class UniformValue : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
virtual void apply( Extensions *ext, const GLhandleARB progObj ) const = 0;
|
||||
|
||||
protected:
|
||||
UniformValue( const char* uniformName ) : _name( uniformName ) {};
|
||||
virtual ~UniformValue() {};
|
||||
|
||||
int getLocation( Extensions *ext, const GLhandleARB progObj ) const;
|
||||
|
||||
std::string _name;
|
||||
};
|
||||
|
||||
typedef std::vector< osg::ref_ptr<UniformValue> > UniformValueList;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define META_UniformValue( typeName ) \
|
||||
class UniformValue_##typeName : public UniformValue \
|
||||
{ \
|
||||
public: \
|
||||
UniformValue_##typeName( const char* uniformName, typeName value ); \
|
||||
virtual void apply( Extensions *ext, const GLhandleARB progObj ) const; \
|
||||
protected: \
|
||||
typeName _value; \
|
||||
}
|
||||
|
||||
META_UniformValue( int );
|
||||
META_UniformValue( float );
|
||||
|
||||
using namespace osg;
|
||||
META_UniformValue( Vec2 );
|
||||
META_UniformValue( Vec3 );
|
||||
META_UniformValue( Vec4 );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*EOF*/
|
||||
|
||||
Reference in New Issue
Block a user