MOved VertexProgram and FragmentProgram::Extensions into GL2Extensions.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14580 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2014-12-08 16:08:44 +00:00
parent 35cfbfdb8c
commit a8804e2366
7 changed files with 33 additions and 362 deletions

View File

@ -404,10 +404,10 @@ int main(int argc, char *argv[])
++itr) ++itr)
{ {
unsigned int contextID = (*itr)->getState()->getContextID(); unsigned int contextID = (*itr)->getState()->getContextID();
osg::VertexProgram::Extensions* vpExt = osg::VertexProgram::getExtensions(contextID,false); osg::GL2Extensions* vpExt = osg::GL2Extensions::Get(contextID,false);
if (vpExt) if (vpExt)
{ {
if (!vpExt->isVertexProgramSupported()) if (!vpExt->isVertexProgramSupported)
{ {
std::cout<<"Warning: ARB_vertex_program not supported by OpenGL drivers, unable to run application."<<std::endl; std::cout<<"Warning: ARB_vertex_program not supported by OpenGL drivers, unable to run application."<<std::endl;
return 1; return 1;

View File

@ -234,62 +234,6 @@ class OSG_EXPORT FragmentProgram : public StateAttribute
State object pointer == NULL.*/ State object pointer == NULL.*/
virtual void releaseGLObjects(State* state=0) const; virtual void releaseGLObjects(State* state=0) const;
/** Extensions class which encapsulates the querying of extensions and
* associated function pointers, and provide convenience wrappers to
* check for the extensions or use the associated functions.*/
class OSG_EXPORT Extensions : public osg::Referenced
{
public:
Extensions(unsigned int contextID);
Extensions(const Extensions& rhs);
void lowestCommonDenominator(const Extensions& rhs);
void setupGLExtensions(unsigned int contextID);
void setFragmentProgramSupported(bool flag) { _isFragmentProgramSupported=flag; }
bool isFragmentProgramSupported() const { return _isFragmentProgramSupported; }
void glBindProgram(GLenum target, GLuint id) const;
void glGenPrograms(GLsizei n, GLuint *programs) const;
void glDeletePrograms(GLsizei n, GLuint *programs) const;
void glProgramString(GLenum target, GLenum format, GLsizei len, const void *string) const;
void glProgramLocalParameter4fv(GLenum target, GLuint index, const GLfloat *params) const;
protected:
~Extensions() {}
bool _isFragmentProgramSupported;
typedef void (GL_APIENTRY * BindProgramProc) (GLenum target, GLuint id);
typedef void (GL_APIENTRY * GenProgramsProc) (GLsizei n, GLuint *programs);
typedef void (GL_APIENTRY * DeleteProgramsProc) (GLsizei n, GLuint *programs);
typedef void (GL_APIENTRY * ProgramStringProc) (GLenum target, GLenum format, GLsizei len, const void *string);
typedef void (GL_APIENTRY * ProgramLocalParameter4fvProc) (GLenum target, GLuint index, const GLfloat *params);
BindProgramProc _glBindProgram;
GenProgramsProc _glGenPrograms;
DeleteProgramsProc _glDeletePrograms;
ProgramStringProc _glProgramString;
ProgramLocalParameter4fvProc _glProgramLocalParameter4fv;
};
/** Function to call to get the extension of a specified context.
* If the Extension object for that context has not yet been created and the
* 'createIfNotInitalized' flag has been set to false then returns NULL.
* If 'createIfNotInitalized' is true then the Extensions object is
* automatically created. However, in this case the extension object will
* only be created with the graphics context associated with ContextID..*/
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
/** setExtensions allows users to override the extensions across graphics contexts.
* typically used when you have different extensions supported across graphics pipes
* but need to ensure that they all use the same low common denominator extensions.*/
static void setExtensions(unsigned int contextID,Extensions* extensions);
protected: protected:
@ -304,8 +248,6 @@ class OSG_EXPORT FragmentProgram : public StateAttribute
MatrixList _matrixList; MatrixList _matrixList;
}; };
} }
#endif #endif

View File

@ -780,7 +780,6 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
// Vertex Array extensions // Vertex Array extensions
bool isVertexProgramSupported;
bool isSecondaryColorSupported; bool isSecondaryColorSupported;
bool isFogCoordSupported; bool isFogCoordSupported;
bool isMultiTexSupported; bool isMultiTexSupported;
@ -835,6 +834,17 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
void (GL_APIENTRY * glSampleMaski) (GLuint maskNumber, GLbitfield mask); void (GL_APIENTRY * glSampleMaski) (GLuint maskNumber, GLbitfield mask);
// Vertex/Fragment Programs
bool isVertexProgramSupported;
bool isFragmentProgramSupported;
void (GL_APIENTRY * glBindProgram) (GLenum target, GLuint id);
void (GL_APIENTRY * glGenPrograms) (GLsizei n, GLuint *programs);
void (GL_APIENTRY * glDeletePrograms) (GLsizei n, GLuint *programs);
void (GL_APIENTRY * glProgramString) (GLenum target, GLenum format, GLsizei len, const void *string);
void (GL_APIENTRY * glProgramLocalParameter4fv) (GLenum target, GLuint index, const GLfloat *params);
}; };
} }

View File

@ -237,66 +237,6 @@ class OSG_EXPORT VertexProgram : public StateAttribute
*/ */
virtual void releaseGLObjects(State* state=0) const; virtual void releaseGLObjects(State* state=0) const;
/** Extensions class which encapsulates the querying of extensions and
* associated function pointers, and provide convenience wrappers to
* check for the extensions or use the associated functions.
*/
class OSG_EXPORT Extensions : public osg::Referenced
{
public:
Extensions(unsigned int contextID);
Extensions(const Extensions& rhs);
void lowestCommonDenominator(const Extensions& rhs);
void setupGLExtensions(unsigned int contextID);
void setVertexProgramSupported(bool flag) { _isVertexProgramSupported=flag; }
bool isVertexProgramSupported() const { return _isVertexProgramSupported; }
void glBindProgram(GLenum target, GLuint id) const;
void glGenPrograms(GLsizei n, GLuint *programs) const;
void glDeletePrograms(GLsizei n, GLuint *programs) const;
void glProgramString(GLenum target, GLenum format, GLsizei len, const void *string) const;
void glProgramLocalParameter4fv(GLenum target, GLuint index, const GLfloat *params) const;
protected:
~Extensions() {}
bool _isVertexProgramSupported;
typedef void (GL_APIENTRY * BindProgramProc) (GLenum target, GLuint id);
typedef void (GL_APIENTRY * GenProgramsProc) (GLsizei n, GLuint *programs);
typedef void (GL_APIENTRY * DeleteProgramsProc) (GLsizei n, GLuint *programs);
typedef void (GL_APIENTRY * ProgramStringProc) (GLenum target, GLenum format, GLsizei len, const void *string);
typedef void (GL_APIENTRY * ProgramLocalParameter4fvProc) (GLenum target, GLuint index, const GLfloat *params);
BindProgramProc _glBindProgram;
GenProgramsProc _glGenPrograms;
DeleteProgramsProc _glDeletePrograms;
ProgramStringProc _glProgramString;
ProgramLocalParameter4fvProc _glProgramLocalParameter4fv;
};
/** Function to call to get the extension of a specified context.
* If the Extension object for that context has not yet been created
* and the 'createIfNotInitalized' flag been set to false then returns NULL.
* If 'createIfNotInitalized' is true then the Extensions object is
* automatically created. However, in this case the extension object
* will only be created with the graphics context associated with ContextID.
*/
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
/** The setExtensions method allows users to override the extensions across graphics contexts.
* Typically used when you have different extensions supported across graphics pipes
* but need to ensure that they all use the same low common denominator extensions.
*/
static void setExtensions(unsigned int contextID,Extensions* extensions);
protected: protected:
@ -312,8 +252,6 @@ class OSG_EXPORT VertexProgram : public StateAttribute
MatrixList _matrixList; MatrixList _matrixList;
}; };
} }
#endif #endif

View File

@ -56,7 +56,7 @@ void FragmentProgram::flushDeletedFragmentProgramObjects(unsigned int contextID,
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedFragmentProgramObjectCache); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedFragmentProgramObjectCache);
const Extensions* extensions = getExtensions(contextID,true); const GL2Extensions* extensions = GL2Extensions::Get(contextID,true);
FragmentProgramObjectList& vpol = s_deletedFragmentProgramObjectCache[contextID]; FragmentProgramObjectList& vpol = s_deletedFragmentProgramObjectCache[contextID];
@ -127,10 +127,9 @@ void FragmentProgram::apply(State& state) const
{ {
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE #ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
const unsigned int contextID = state.getContextID(); const GL2Extensions* extensions = state.get<GL2Extensions>();
const Extensions* extensions = getExtensions(contextID,true);
if (!extensions->isFragmentProgramSupported()) if (!extensions->isFragmentProgramSupported)
return; return;
@ -213,118 +212,3 @@ void FragmentProgram::releaseGLObjects(State* state) const
} }
} }
} }
typedef buffered_value< ref_ptr<FragmentProgram::Extensions> > BufferedExtensions;
static BufferedExtensions s_extensions;
FragmentProgram::Extensions* FragmentProgram::getExtensions(unsigned int contextID,bool createIfNotInitalized)
{
if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID);
return s_extensions[contextID].get();
}
void FragmentProgram::setExtensions(unsigned int contextID,Extensions* extensions)
{
s_extensions[contextID] = extensions;
}
FragmentProgram::Extensions::Extensions(unsigned int contextID)
{
setupGLExtensions(contextID);
}
FragmentProgram::Extensions::Extensions(const Extensions& rhs):
Referenced()
{
_isFragmentProgramSupported = rhs._isFragmentProgramSupported;
_glBindProgram = rhs._glBindProgram;
_glGenPrograms = rhs._glGenPrograms;
_glDeletePrograms = rhs._glDeletePrograms;
_glProgramString = rhs._glProgramString;
_glProgramLocalParameter4fv = rhs._glProgramLocalParameter4fv;
}
void FragmentProgram::Extensions::lowestCommonDenominator(const Extensions& rhs)
{
if (!rhs._isFragmentProgramSupported) _isFragmentProgramSupported = false;
if (!rhs._glBindProgram) _glBindProgram = 0;
if (!rhs._glGenPrograms) _glGenPrograms = 0;
if (!rhs._glDeletePrograms) _glDeletePrograms = 0;
if (!rhs._glProgramString) _glProgramString = 0;
if (!rhs._glProgramLocalParameter4fv) _glProgramLocalParameter4fv = 0;
}
void FragmentProgram::Extensions::setupGLExtensions(unsigned int contextID)
{
_isFragmentProgramSupported = isGLExtensionSupported(contextID,"GL_ARB_fragment_program");
setGLExtensionFuncPtr(_glBindProgram, "glBindProgramARB");
setGLExtensionFuncPtr(_glGenPrograms, "glGenProgramsARB");
setGLExtensionFuncPtr(_glDeletePrograms, "glDeleteProgramsARB");
setGLExtensionFuncPtr(_glProgramString, "glProgramStringARB");
setGLExtensionFuncPtr(_glProgramLocalParameter4fv, "glProgramLocalParameter4fvARB");
}
void FragmentProgram::Extensions::glBindProgram(GLenum target, GLuint id) const
{
if (_glBindProgram)
{
_glBindProgram(target,id);
}
else
{
OSG_WARN<<"Error: glBindProgram not supported by OpenGL driver"<<std::endl;
}
}
void FragmentProgram::Extensions::glGenPrograms(GLsizei n, GLuint *programs) const
{
if (_glGenPrograms)
{
_glGenPrograms(n,programs);
}
else
{
OSG_WARN<<"Error: glGenPrograms not supported by OpenGL driver"<<std::endl;
}
}
void FragmentProgram::Extensions::glDeletePrograms(GLsizei n, GLuint *programs) const
{
if (_glDeletePrograms)
{
_glDeletePrograms(n,programs);
}
else
{
OSG_WARN<<"Error: glDeletePrograms not supported by OpenGL driver"<<std::endl;
}
}
void FragmentProgram::Extensions::glProgramString(GLenum target, GLenum format, GLsizei len, const void *string) const
{
if (_glProgramString)
{
_glProgramString(target,format, len, string);
}
else
{
OSG_WARN<<"Error: glProgramString not supported by OpenGL driver"<<std::endl;
}
}
void FragmentProgram::Extensions::glProgramLocalParameter4fv(GLenum target, GLuint index, const GLfloat *params) const
{
if (_glProgramLocalParameter4fv)
{
_glProgramLocalParameter4fv(target, index, params);
}
else
{
OSG_WARN<<"Error: glProgramLocalParameter4fv not supported by OpenGL driver"<<std::endl;
}
}

View File

@ -320,7 +320,6 @@ GL2Extensions::GL2Extensions(unsigned int contextID)
// Vertex Array extensions // Vertex Array extensions
isVertexProgramSupported = isGLExtensionSupported(contextID,"GL_ARB_vertex_program");
isSecondaryColorSupported = isGLExtensionSupported(contextID,"GL_EXT_secondary_color"); isSecondaryColorSupported = isGLExtensionSupported(contextID,"GL_EXT_secondary_color");
isFogCoordSupported = isGLExtensionSupported(contextID,"GL_EXT_fog_coord"); isFogCoordSupported = isGLExtensionSupported(contextID,"GL_EXT_fog_coord");
isMultiTexSupported = isGLExtensionSupported(contextID,"GL_ARB_multitexture"); isMultiTexSupported = isGLExtensionSupported(contextID,"GL_ARB_multitexture");
@ -397,6 +396,20 @@ GL2Extensions::GL2Extensions(unsigned int contextID)
setGLExtensionFuncPtr(glSampleMaski, "glSampleMaski"); setGLExtensionFuncPtr(glSampleMaski, "glSampleMaski");
// protect against buggy drivers (maybe not necessary) // protect against buggy drivers (maybe not necessary)
isSampleMaskiSupported = glSampleMaski!=0; isSampleMaskiSupported = glSampleMaski!=0;
// old styple Vertex/Fragment Programs
isVertexProgramSupported = isGLExtensionSupported(contextID,"GL_ARB_vertex_program");
isFragmentProgramSupported = isGLExtensionSupported(contextID,"GL_ARB_fragment_program");
setGLExtensionFuncPtr(glBindProgram,"glBindProgramARB");
setGLExtensionFuncPtr(glGenPrograms, "glGenProgramsARB");
setGLExtensionFuncPtr(glDeletePrograms, "glDeleteProgramsARB");
setGLExtensionFuncPtr(glProgramString, "glProgramStringARB");
setGLExtensionFuncPtr(glProgramLocalParameter4fv, "glProgramLocalParameter4fvARB");
} }

View File

@ -56,7 +56,7 @@ void VertexProgram::flushDeletedVertexProgramObjects(unsigned int contextID,doub
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedVertexProgramObjectCache); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedVertexProgramObjectCache);
const Extensions* extensions = getExtensions(contextID,true); const GL2Extensions* extensions = GL2Extensions::Get(contextID,true);
VertexProgramObjectList& vpol = s_deletedVertexProgramObjectCache[contextID]; VertexProgramObjectList& vpol = s_deletedVertexProgramObjectCache[contextID];
@ -127,10 +127,9 @@ void VertexProgram::apply(State& state) const
{ {
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE #ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
const unsigned int contextID = state.getContextID(); const GL2Extensions* extensions = state.get<GL2Extensions>();
const Extensions* extensions = getExtensions(contextID,true);
if (!extensions->isVertexProgramSupported()) if (!extensions->isVertexProgramSupported)
return; return;
@ -213,118 +212,3 @@ void VertexProgram::releaseGLObjects(State* state) const
} }
} }
} }
typedef buffered_value< ref_ptr<VertexProgram::Extensions> > BufferedExtensions;
static BufferedExtensions s_extensions;
VertexProgram::Extensions* VertexProgram::getExtensions(unsigned int contextID,bool createIfNotInitalized)
{
if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID);
return s_extensions[contextID].get();
}
void VertexProgram::setExtensions(unsigned int contextID,Extensions* extensions)
{
s_extensions[contextID] = extensions;
}
VertexProgram::Extensions::Extensions(unsigned int contextID)
{
setupGLExtensions(contextID);
}
VertexProgram::Extensions::Extensions(const Extensions& rhs):
Referenced()
{
_isVertexProgramSupported = rhs._isVertexProgramSupported;
_glBindProgram = rhs._glBindProgram;
_glGenPrograms = rhs._glGenPrograms;
_glDeletePrograms = rhs._glDeletePrograms;
_glProgramString = rhs._glProgramString;
_glProgramLocalParameter4fv = rhs._glProgramLocalParameter4fv;
}
void VertexProgram::Extensions::lowestCommonDenominator(const Extensions& rhs)
{
if (!rhs._isVertexProgramSupported) _isVertexProgramSupported = false;
if (!rhs._glBindProgram) _glBindProgram = 0;
if (!rhs._glGenPrograms) _glGenPrograms = 0;
if (!rhs._glDeletePrograms) _glDeletePrograms = 0;
if (!rhs._glProgramString) _glProgramString = 0;
if (!rhs._glProgramLocalParameter4fv) _glProgramLocalParameter4fv = 0;
}
void VertexProgram::Extensions::setupGLExtensions(unsigned int contextID)
{
_isVertexProgramSupported = isGLExtensionSupported(contextID,"GL_ARB_vertex_program");
setGLExtensionFuncPtr(_glBindProgram,"glBindProgramARB");
setGLExtensionFuncPtr(_glGenPrograms, "glGenProgramsARB");
setGLExtensionFuncPtr(_glDeletePrograms, "glDeleteProgramsARB");
setGLExtensionFuncPtr(_glProgramString, "glProgramStringARB");
setGLExtensionFuncPtr(_glProgramLocalParameter4fv, "glProgramLocalParameter4fvARB");
}
void VertexProgram::Extensions::glBindProgram(GLenum target, GLuint id) const
{
if (_glBindProgram)
{
_glBindProgram(target,id);
}
else
{
OSG_WARN<<"Error: glBindProgram not supported by OpenGL driver"<<std::endl;
}
}
void VertexProgram::Extensions::glGenPrograms(GLsizei n, GLuint *programs) const
{
if (_glGenPrograms)
{
_glGenPrograms(n,programs);
}
else
{
OSG_WARN<<"Error: glGenPrograms not supported by OpenGL driver"<<std::endl;
}
}
void VertexProgram::Extensions::glDeletePrograms(GLsizei n, GLuint *programs) const
{
if (_glDeletePrograms)
{
_glDeletePrograms(n,programs);
}
else
{
OSG_WARN<<"Error: glDeletePrograms not supported by OpenGL driver"<<std::endl;
}
}
void VertexProgram::Extensions::glProgramString(GLenum target, GLenum format, GLsizei len, const void *string) const
{
if (_glProgramString)
{
_glProgramString(target,format, len, string);
}
else
{
OSG_WARN<<"Error: glProgramString not supported by OpenGL driver"<<std::endl;
}
}
void VertexProgram::Extensions::glProgramLocalParameter4fv(GLenum target, GLuint index, const GLfloat *params) const
{
if (_glProgramLocalParameter4fv)
{
_glProgramLocalParameter4fv(target, index, params);
}
else
{
OSG_WARN<<"Error: glProgramLocalParameter4fv not supported by OpenGL driver"<<std::endl;
}
}