From Aurelien Albert, "Recently I had to integrate a client OpenGL library with OSG. For textures and other StateAttribute I've done that by subclassing osg::StateAttribute and this works well.

But for glPrograms, in order to get all osg's uniform management system to work, I had to subclass osg::program::PerContextProgram.

Here is a modified version of this class, which add some "virtual" method to allow easy subclassing."
This commit is contained in:
Robert Osfield
2013-07-02 10:32:53 +00:00
parent 08f741bcd9
commit 095b64dc41
2 changed files with 30 additions and 16 deletions

View File

@@ -243,16 +243,17 @@ class OSG_EXPORT Program : public osg::StateAttribute
class OSG_EXPORT PerContextProgram : public osg::Referenced
{
public:
PerContextProgram(const Program* program, unsigned int contextID);
/** Use "0" as programHandle to let the PeContextProgram execute "glCreateProgram"and "glDeleteProgram" */
PerContextProgram(const Program* program, unsigned int contextID, GLuint programHandle=0);
GLuint getHandle() const {return _glProgramHandle;}
void requestLink();
void linkProgram(osg::State& state);
bool validateProgram();
virtual void linkProgram(osg::State& state);
virtual bool validateProgram();
bool needsLink() const {return _needsLink;}
bool isLinked() const {return _isLinked;}
bool getInfoLog( std::string& infoLog ) const;
virtual bool getInfoLog( std::string& infoLog ) const;
/** Was glProgramBinary called successfully? */
bool loadedBinary() const {return _loadedBinary;}
@@ -263,9 +264,9 @@ class OSG_EXPORT Program : public osg::StateAttribute
* compileProgramBinary should be called after the program has been
* "exercised" by rendering with it. The ProgramBinary can then be saved
* to disk for faster subsequent compiling. */
ProgramBinary* compileProgramBinary(osg::State& state);
virtual ProgramBinary* compileProgramBinary(osg::State& state);
void useProgram() const;
virtual void useProgram() const;
void resetAppliedUniforms() const
{
@@ -324,7 +325,7 @@ class OSG_EXPORT Program : public osg::StateAttribute
}
protected: /*methods*/
~PerContextProgram();
virtual ~PerContextProgram();
protected: /*data*/
/** Pointer to our parent Program */
@@ -339,7 +340,11 @@ class OSG_EXPORT Program : public osg::StateAttribute
bool _isLinked;
/** Was glProgramBinary called successfully? */
bool _loadedBinary;
const unsigned int _contextID;
/** Does the glProgram handle belongs to this class? */
bool _ownsProgramHandle;
ActiveUniformMap _uniformInfoMap;
ActiveVarInfoMap _attribInfoMap;
@@ -382,7 +387,7 @@ class OSG_EXPORT Program : public osg::StateAttribute
GLint _geometryInputType;
GLint _geometryOutputType;
/** Parameter maintained with glDispatchCompute */
GLint _numGroupsX;
GLint _numGroupsY;