OpenSceneGraph 3.6.5
osg::Program::PerContextProgram Class Reference

PerContextProgram (PCP) is an OSG-internal encapsulation of glPrograms per-GL context. More...

#include <Program>

Inheritance diagram for osg::Program::PerContextProgram:

Public Member Functions

 PerContextProgram (const Program *program, unsigned int contextID, GLuint programHandle=0)
 Use "0" as programHandle to let the PeContextProgram execute "glCreateProgram"and "glDeleteProgram".
GLuint getHandle () const
const osg::ProgramgetProgram () const
void setDefineString (const std::string &defStr)
const std::string & getDefineString () const
void requestLink ()
virtual void linkProgram (osg::State &state)
virtual bool validateProgram ()
bool needsLink () const
bool isLinked () const
virtual bool getInfoLog (std::string &infoLog) const
bool loadedBinary () const
 Was glProgramBinary called successfully?
virtual ProgramBinarycompileProgramBinary (osg::State &state)
 Compile a program binary.
virtual void useProgram () const
void resetAppliedUniforms () const
void apply (const Uniform &uniform) const
const ActiveUniformMapgetActiveUniforms () const
const ActiveVarInfoMapgetActiveAttribs () const
const UniformBlockMapgetUniformBlocks () const
GLint getUniformLocation (unsigned int uniformNameID) const
GLint getUniformLocation (const std::string &uniformName) const
 Alternative version of getUniformLocation( unsigned int uniformNameID ) retrofited into OSG for backward compatibility with osgCal, after uniform ids were refactored from std::strings to GLints in OSG version 2.9.10.
GLint getAttribLocation (const std::string &name) const
void addShaderToAttach (Shader *shader)
void addShaderToDetach (Shader *shader)
Public Member Functions inherited from osg::Referenced
 Referenced ()
 Referenced (bool threadSafeRefUnref)
 Deprecated, Referenced is now always uses thread safe ref/unref, use default Referenced() constructor instead.
 Referenced (const Referenced &)
Referencedoperator= (const Referenced &)
virtual void setThreadSafeRefUnref (bool)
 Deprecated, Referenced is always theadsafe so there method now has no effect and does not need to be called.
bool getThreadSafeRefUnref () const
 Get whether a mutex is used to ensure ref() and unref() are thread safe.
OpenThreads::Mutex * getRefMutex () const
 Get the mutex used to ensure thread safety of ref()/unref().
int ref () const
 Increment the reference count by one, indicating that this object has another pointer which is referencing it.
int unref () const
 Decrement the reference count by one, indicating that a pointer to this object is no longer referencing it.
int unref_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is no longer referencing it.
int referenceCount () const
 Return the number of pointers currently referencing this object.
ObserverSetgetObserverSet () const
 Get the ObserverSet if one is attached, otherwise return NULL.
ObserverSetgetOrCreateObserverSet () const
 Get the ObserverSet if one is attached, otherwise create an ObserverSet, attach it, then return this newly created ObserverSet.
void addObserver (Observer *observer) const
 Add a Observer that is observing this object, notify the Observer when this object gets deleted.
void removeObserver (Observer *observer) const
 Remove Observer that is observing this object.

Protected Types

typedef std::pair< osg::ref_ptr< const osg::Uniform >, unsigned int > UniformModifiedCountPair
typedef std::map< unsigned int, UniformModifiedCountPairLastAppliedUniformList
typedef std::vector< ref_ptr< Shader > > ShaderList

Protected Member Functions

virtual ~PerContextProgram ()
Protected Member Functions inherited from osg::Referenced
virtual ~Referenced ()
void signalObserversAndDelete (bool signalDelete, bool doDelete) const
void deleteUsingDeleteHandler () const

Protected Attributes

const Program_program
 Pointer to our parent Program.
osg::ref_ptr< GLExtensions_extensions
 Pointer to this context's extension functions.
GLuint _glProgramHandle
 Handle to the actual OpenGL glProgram.
std::string _defineStr
 Define string passed on to Shaders to help configure them.
bool _needsLink
 Does our glProgram need to be linked?
bool _isLinked
 Is our glProgram successfully linked?
bool _loadedBinary
 Was glProgramBinary called successfully?
const unsigned int _contextID
bool _ownsProgramHandle
 Does the glProgram handle belongs to this class?
ActiveUniformMap _uniformInfoMap
ActiveVarInfoMap _attribInfoMap
UniformBlockMap _uniformBlockMap
LastAppliedUniformList _lastAppliedUniformList
ShaderList _shadersToDetach
ShaderList _shadersToAttach
Protected Attributes inherited from osg::Referenced
OpenThreads::AtomicPtr _observerSet
OpenThreads::Atomic _refCount

Additional Inherited Members

Static Public Member Functions inherited from osg::Referenced
static OpenThreads::Mutex * getGlobalReferencedMutex ()
 Get the optional global Referenced mutex, this can be shared between all osg::Referenced.
static void setDeleteHandler (DeleteHandler *handler)
 Set a DeleteHandler to which deletion of all referenced counted objects will be delegated.
static DeleteHandlergetDeleteHandler ()
 Get a DeleteHandler.

Detailed Description

PerContextProgram (PCP) is an OSG-internal encapsulation of glPrograms per-GL context.

Member Typedef Documentation

◆ LastAppliedUniformList

◆ ShaderList

typedef std::vector< ref_ptr<Shader> > osg::Program::PerContextProgram::ShaderList
protected

◆ UniformModifiedCountPair

typedef std::pair<osg::ref_ptr<const osg::Uniform>, unsigned int> osg::Program::PerContextProgram::UniformModifiedCountPair
protected

Constructor & Destructor Documentation

◆ PerContextProgram()

osg::Program::PerContextProgram::PerContextProgram ( const Program * program,
unsigned int contextID,
GLuint programHandle = 0 )

Use "0" as programHandle to let the PeContextProgram execute "glCreateProgram"and "glDeleteProgram".

References osg::Program::Program().

◆ ~PerContextProgram()

virtual osg::Program::PerContextProgram::~PerContextProgram ( )
protectedvirtual

Member Function Documentation

◆ addShaderToAttach()

void osg::Program::PerContextProgram::addShaderToAttach ( Shader * shader)
inline

References _shadersToAttach.

◆ addShaderToDetach()

void osg::Program::PerContextProgram::addShaderToDetach ( Shader * shader)
inline

References _shadersToDetach.

◆ apply()

void osg::Program::PerContextProgram::apply ( const Uniform & uniform) const
inline

◆ compileProgramBinary()

virtual ProgramBinary * osg::Program::PerContextProgram::compileProgramBinary ( osg::State & state)
virtual

Compile a program binary.

For this to work setProgramBinary must have been called on the osg::Program with an empty ProgramBinary prior to compileGLObjects being called. 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.

◆ getActiveAttribs()

const ActiveVarInfoMap & osg::Program::PerContextProgram::getActiveAttribs ( ) const
inline

References _attribInfoMap.

◆ getActiveUniforms()

const ActiveUniformMap & osg::Program::PerContextProgram::getActiveUniforms ( ) const
inline

References _uniformInfoMap.

◆ getAttribLocation()

GLint osg::Program::PerContextProgram::getAttribLocation ( const std::string & name) const
inline

References _attribInfoMap.

◆ getDefineString()

const std::string & osg::Program::PerContextProgram::getDefineString ( ) const
inline

References _defineStr.

◆ getHandle()

GLuint osg::Program::PerContextProgram::getHandle ( ) const
inline

References _glProgramHandle.

◆ getInfoLog()

virtual bool osg::Program::PerContextProgram::getInfoLog ( std::string & infoLog) const
virtual

◆ getProgram()

const osg::Program * osg::Program::PerContextProgram::getProgram ( ) const
inline

References _program.

◆ getUniformBlocks()

const UniformBlockMap & osg::Program::PerContextProgram::getUniformBlocks ( ) const
inline

References _uniformBlockMap.

◆ getUniformLocation() [1/2]

GLint osg::Program::PerContextProgram::getUniformLocation ( const std::string & uniformName) const
inline

Alternative version of getUniformLocation( unsigned int uniformNameID ) retrofited into OSG for backward compatibility with osgCal, after uniform ids were refactored from std::strings to GLints in OSG version 2.9.10.

Drawbacks: This method is not particularly fast. It has to access mutexed static map of uniform ids. So don't overuse it or your app performance will suffer.

References osg::Uniform::getNameID(), and getUniformLocation().

Referenced by getUniformLocation().

◆ getUniformLocation() [2/2]

GLint osg::Program::PerContextProgram::getUniformLocation ( unsigned int uniformNameID) const
inline

References _uniformInfoMap.

Referenced by apply().

◆ isLinked()

bool osg::Program::PerContextProgram::isLinked ( ) const
inline

References _isLinked.

◆ linkProgram()

virtual void osg::Program::PerContextProgram::linkProgram ( osg::State & state)
virtual

◆ loadedBinary()

bool osg::Program::PerContextProgram::loadedBinary ( ) const
inline

Was glProgramBinary called successfully?

References _loadedBinary.

◆ needsLink()

bool osg::Program::PerContextProgram::needsLink ( ) const
inline

References _needsLink.

◆ requestLink()

void osg::Program::PerContextProgram::requestLink ( )

◆ resetAppliedUniforms()

void osg::Program::PerContextProgram::resetAppliedUniforms ( ) const
inline

◆ setDefineString()

void osg::Program::PerContextProgram::setDefineString ( const std::string & defStr)
inline

References _defineStr.

◆ useProgram()

virtual void osg::Program::PerContextProgram::useProgram ( ) const
virtual

◆ validateProgram()

virtual bool osg::Program::PerContextProgram::validateProgram ( )
virtual

Member Data Documentation

◆ _attribInfoMap

ActiveVarInfoMap osg::Program::PerContextProgram::_attribInfoMap
protected

◆ _contextID

const unsigned int osg::Program::PerContextProgram::_contextID
protected

◆ _defineStr

std::string osg::Program::PerContextProgram::_defineStr
protected

Define string passed on to Shaders to help configure them.

Referenced by getDefineString(), and setDefineString().

◆ _extensions

osg::ref_ptr<GLExtensions> osg::Program::PerContextProgram::_extensions
protected

Pointer to this context's extension functions.

Referenced by apply().

◆ _glProgramHandle

GLuint osg::Program::PerContextProgram::_glProgramHandle
protected

Handle to the actual OpenGL glProgram.

Referenced by getHandle().

◆ _isLinked

bool osg::Program::PerContextProgram::_isLinked
protected

Is our glProgram successfully linked?

Referenced by isLinked().

◆ _lastAppliedUniformList

LastAppliedUniformList osg::Program::PerContextProgram::_lastAppliedUniformList
mutableprotected

Referenced by apply(), and resetAppliedUniforms().

◆ _loadedBinary

bool osg::Program::PerContextProgram::_loadedBinary
protected

Was glProgramBinary called successfully?

Referenced by loadedBinary().

◆ _needsLink

bool osg::Program::PerContextProgram::_needsLink
protected

Does our glProgram need to be linked?

Referenced by needsLink().

◆ _ownsProgramHandle

bool osg::Program::PerContextProgram::_ownsProgramHandle
protected

Does the glProgram handle belongs to this class?

◆ _program

const Program* osg::Program::PerContextProgram::_program
protected

Pointer to our parent Program.

Referenced by getProgram().

◆ _shadersToAttach

ShaderList osg::Program::PerContextProgram::_shadersToAttach
protected

Referenced by addShaderToAttach().

◆ _shadersToDetach

ShaderList osg::Program::PerContextProgram::_shadersToDetach
protected

Referenced by addShaderToDetach().

◆ _uniformBlockMap

UniformBlockMap osg::Program::PerContextProgram::_uniformBlockMap
protected

Referenced by getUniformBlocks().

◆ _uniformInfoMap

ActiveUniformMap osg::Program::PerContextProgram::_uniformInfoMap
protected

The documentation for this class was generated from the following file:

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.