Moveved Stencil/StencilTwoSided::Extensions into GL2Extensions

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14583 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2014-12-09 11:14:33 +00:00
parent ec4f898bce
commit 3f1e77d479
6 changed files with 39 additions and 303 deletions

View File

@ -599,9 +599,6 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
bool isCubeMapSupported;
void (GL_APIENTRY * glDrawBuffers)(GLsizei n, const GLenum *bufs);
void (GL_APIENTRY * glStencilOpSeparate)(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
void (GL_APIENTRY * glStencilFuncSeparate)(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
void (GL_APIENTRY * glStencilMaskSeparate)(GLenum face, GLuint mask);
void (GL_APIENTRY * glAttachShader)(GLuint program, GLuint shader);
void (GL_APIENTRY * glBindAttribLocation)(GLuint program, GLuint index, const GLchar *name);
void (GL_APIENTRY * glCompileShader)(GLuint shader);
@ -930,6 +927,20 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
void (GL_APIENTRY * glEnablei) (GLenum capability, GLuint buf);
void (GL_APIENTRY * glDisablei) (GLenum capability, GLuint buf);
// Stencil
bool isStencilWrapSupported;
bool isStencilTwoSidedSupported;
bool isOpenGL20Supported;
bool isSeparateStencilSupported;
void (GL_APIENTRY * glActiveStencilFace) (GLenum face);
void (GL_APIENTRY * glStencilOpSeparate) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
void (GL_APIENTRY * glStencilMaskSeparate) (GLenum face, GLuint mask);
void (GL_APIENTRY * glStencilFuncSeparate) (GLenum face, GLenum func, GLint ref, GLuint mask);
void (GL_APIENTRY * glStencilFuncSeparateATI) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
};
}

View File

@ -166,47 +166,6 @@ class OSG_EXPORT Stencil : public StateAttribute
virtual void apply(State& state) 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 setStencilWrapSupported(bool flag) { _isStencilWrapSupported = flag; }
bool isStencilWrapSupported() const { return _isStencilWrapSupported; }
protected:
~Extensions() {}
bool _isStencilWrapSupported;
};
/** 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:
virtual ~Stencil();

View File

@ -140,76 +140,9 @@ class OSG_EXPORT StencilTwoSided : public StateAttribute
inline unsigned int getWriteMask(Face face) const { return _writeMask[face]; }
virtual void apply(State& state) const;
public:
/** 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 setStencilTwoSidedSupported(bool flag) { _isStencilTwoSidedSupported=flag; }
bool isStencilTwoSidedSupported() const { return _isStencilTwoSidedSupported; }
void setOpenGL20Supported(bool flag) { _isOpenGL20Supported=flag; }
bool isOpenGL20Supported() const { return _isOpenGL20Supported; }
void setSeparateStencilSupported(bool flag) { _isSeparateStencilSupported=flag; }
bool isSeparateStencilSupported() const { return _isSeparateStencilSupported; }
void glActiveStencilFace(GLenum face) const;
void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) const;
void glStencilMaskSeparate(GLenum face, GLuint mask) const;
void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) const;
void glStencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask) const;
protected:
~Extensions() {}
bool _isStencilTwoSidedSupported;
bool _isOpenGL20Supported;
bool _isSeparateStencilSupported;
typedef void (GL_APIENTRY * ActiveStencilFaceProc) (GLenum);
typedef void (GL_APIENTRY * StencilOpSeparate) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
typedef void (GL_APIENTRY * StencilMaskSeparate) (GLenum face, GLuint mask);
typedef void (GL_APIENTRY * StencilFuncSeparate) (GLenum face, GLenum func, GLint ref, GLuint mask);
typedef void (GL_APIENTRY * StencilFuncSeparateATI) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
ActiveStencilFaceProc _glActiveStencilFace;
StencilOpSeparate _glStencilOpSeparate;
StencilMaskSeparate _glStencilMaskSeparate;
StencilFuncSeparate _glStencilFuncSeparate;
StencilFuncSeparate _glStencilFuncSeparateATI;
};
/** 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:
virtual ~StencilTwoSided();

View File

@ -116,9 +116,6 @@ GL2Extensions::GL2Extensions(unsigned int contextID)
setGLExtensionFuncPtr(glDrawBuffers, "glDrawBuffers", "glDrawBuffersARB");
setGLExtensionFuncPtr(glStencilOpSeparate, "glStencilOpSeparate");
setGLExtensionFuncPtr(glStencilFuncSeparate, "glStencilFuncSeparate");
setGLExtensionFuncPtr(glStencilMaskSeparate, "glStencilMaskSeparate");
setGLExtensionFuncPtr(glAttachShader, "glAttachShader", "glAttachObjectARB");
setGLExtensionFuncPtr(glBindAttribLocation, "glBindAttribLocation", "glBindAttribLocationARB");
setGLExtensionFuncPtr(glCompileShader, "glCompileShader", "glCompileShaderARB");
@ -551,10 +548,24 @@ GL2Extensions::GL2Extensions(unsigned int contextID)
setGLExtensionFuncPtr(glBlendEquationi, "glBlendEquationi", "glBlendEquationiARB");
setGLExtensionFuncPtr(glBlendEquationSeparatei, "glBlendEquationSeparatei", "glBlendEquationSeparateiARB");
// glEnablei/glDisabli
setGLExtensionFuncPtr(glEnablei, "glEnablei");
setGLExtensionFuncPtr(glDisablei, "glDisablei");
// Stencil`
isStencilWrapSupported = isGLExtensionOrVersionSupported(contextID, "GL_EXT_stencil_wrap", 1.4f);
isStencilTwoSidedSupported = isGLExtensionSupported(contextID, "GL_EXT_stencil_two_side");
isOpenGL20Supported = getGLVersionNumber() >= 2.0;
isSeparateStencilSupported = isGLExtensionSupported(contextID, "GL_ATI_separate_stencil");
// function pointers
setGLExtensionFuncPtr(glActiveStencilFace, "glActiveStencilFaceEXT");
setGLExtensionFuncPtr(glStencilOpSeparate, "glStencilOpSeparate", "glStencilOpSeparateATI");
setGLExtensionFuncPtr(glStencilMaskSeparate, "glStencilMaskSeparate");
setGLExtensionFuncPtr(glStencilFuncSeparate, "glStencilFuncSeparate", "glStencilFuncSeparateATI");
setGLExtensionFuncPtr(glStencilFuncSeparateATI, "glStencilFuncSeparateATI");
}

View File

@ -37,22 +37,14 @@ Stencil::~Stencil()
{
}
static Stencil::Operation validateOperation(State& state,
const Stencil::Extensions* extensions, Stencil::Operation op)
static Stencil::Operation validateOperation(const GL2Extensions* extensions, Stencil::Operation op)
{
// only wrap requires validation
if (op != Stencil::INCR_WRAP && op != Stencil::DECR_WRAP)
return op;
// get extension object
if (!extensions)
{
const unsigned int contextID = state.getContextID();
extensions = Stencil::getExtensions(contextID, true);
}
// wrap support
if (extensions->isStencilWrapSupported())
if (extensions->isStencilWrapSupported)
return op;
else
return op==Stencil::INCR_WRAP ? Stencil::INCR : Stencil::DECR;
@ -60,53 +52,12 @@ static Stencil::Operation validateOperation(State& state,
void Stencil::apply(State& state) const
{
const Extensions* extensions = NULL;
Operation sf = validateOperation(state, extensions, _sfail);
Operation zf = validateOperation(state, extensions, _zfail);
Operation zp = validateOperation(state, extensions, _zpass);
const GL2Extensions* extensions = state.get<GL2Extensions>();
Operation sf = validateOperation(extensions, _sfail);
Operation zf = validateOperation(extensions, _zfail);
Operation zp = validateOperation(extensions, _zpass);
glStencilFunc((GLenum)_func,_funcRef,_funcMask);
glStencilOp((GLenum)sf,(GLenum)zf,(GLenum)zp);
glStencilMask(_writeMask);
}
typedef buffered_value< ref_ptr<Stencil::Extensions> > BufferedExtensions;
static BufferedExtensions s_extensions;
Stencil::Extensions* Stencil::getExtensions(unsigned int contextID, bool createIfNotInitalized)
{
if (!s_extensions[contextID] && createIfNotInitalized)
s_extensions[contextID] = new Extensions(contextID);
return s_extensions[contextID].get();
}
void Stencil::setExtensions(unsigned int contextID, Extensions* extensions)
{
s_extensions[contextID] = extensions;
}
Stencil::Extensions::Extensions(unsigned int contextID)
{
setupGLExtensions(contextID);
}
Stencil::Extensions::Extensions(const Extensions& rhs) :
Referenced()
{
_isStencilWrapSupported = rhs._isStencilWrapSupported;
}
void Stencil::Extensions::lowestCommonDenominator(const Extensions& rhs)
{
if (!rhs._isStencilWrapSupported)
_isStencilWrapSupported = false;
}
void Stencil::Extensions::setupGLExtensions(unsigned int contextID)
{
_isStencilWrapSupported = isGLExtensionOrVersionSupported(contextID, "GL_EXT_stencil_wrap", 1.4f);
OSG_INFO << "Stencil wrap: " << (_isStencilWrapSupported ? "supported" : "not supported") << std::endl;
}

View File

@ -88,10 +88,10 @@ void StencilTwoSided::apply(State& state) const
{
// get "per-context" extensions
const unsigned int contextID = state.getContextID();
const Extensions* extensions = getExtensions(contextID,true);
const GL2Extensions* extensions = state.get<GL2Extensions>();
// use OpenGL 2.0 functions if available
if (extensions->isOpenGL20Supported())
if (extensions->isOpenGL20Supported)
{
// front face
extensions->glStencilOpSeparate(GL_FRONT, (GLenum)_sfail[FRONT],(GLenum)_zfail[FRONT],(GLenum)_zpass[FRONT]);
@ -107,7 +107,7 @@ void StencilTwoSided::apply(State& state) const
}
// try to use GL_EXT_stencil_two_side extension
if (extensions->isStencilTwoSidedSupported())
if (extensions->isStencilTwoSidedSupported)
{
// enable two sided stenciling
glEnable(GL_STENCIL_TEST_TWO_SIDE);
@ -128,7 +128,7 @@ void StencilTwoSided::apply(State& state) const
}
// try to use GL_ATI_separate_stencil extension
if (extensions->isSeparateStencilSupported())
if (extensions->isSeparateStencilSupported)
{
if( _writeMask[FRONT] != _writeMask[BACK] ||
_funcRef[FRONT] != _funcRef[BACK] ||
@ -156,132 +156,3 @@ void StencilTwoSided::apply(State& state) const
" not found (contextID " << contextID << "). OpenGL 2.0 or one of extensions\n"
" GL_EXT_stencil_two_side or GL_ATI_separate_stencil is required." << std::endl;
}
typedef buffered_value< ref_ptr<StencilTwoSided::Extensions> > BufferedExtensions;
static BufferedExtensions s_extensions;
StencilTwoSided::Extensions* StencilTwoSided::getExtensions(unsigned int contextID,bool createIfNotInitalized)
{
if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID);
return s_extensions[contextID].get();
}
void StencilTwoSided::setExtensions(unsigned int contextID,Extensions* extensions)
{
s_extensions[contextID] = extensions;
}
StencilTwoSided::Extensions::Extensions(unsigned int contextID)
{
setupGLExtensions(contextID);
}
StencilTwoSided::Extensions::Extensions(const Extensions& rhs):
Referenced()
{
_isStencilTwoSidedSupported = rhs._isStencilTwoSidedSupported;
_isOpenGL20Supported = rhs._isOpenGL20Supported;
_isSeparateStencilSupported = rhs._isSeparateStencilSupported;
_glActiveStencilFace = rhs._glActiveStencilFace;
_glStencilOpSeparate = rhs._glStencilOpSeparate;
_glStencilMaskSeparate = rhs._glStencilMaskSeparate;
_glStencilFuncSeparate = rhs._glStencilFuncSeparate;
_glStencilFuncSeparateATI = rhs._glStencilFuncSeparateATI;
}
void StencilTwoSided::Extensions::lowestCommonDenominator(const Extensions& rhs)
{
if (!rhs._isStencilTwoSidedSupported) _isStencilTwoSidedSupported = false;
if (!rhs._isOpenGL20Supported) _isOpenGL20Supported = false;
if (!rhs._isSeparateStencilSupported) _isSeparateStencilSupported = false;
if (!rhs._glActiveStencilFace) _glActiveStencilFace = NULL;
if (!rhs._glStencilOpSeparate) _glStencilOpSeparate = NULL;
if (!rhs._glStencilMaskSeparate) _glStencilMaskSeparate = NULL;
if (!rhs._glStencilFuncSeparate) _glStencilFuncSeparate = NULL;
if (!rhs._glStencilFuncSeparateATI) _glStencilFuncSeparateATI = NULL;
}
void StencilTwoSided::Extensions::setupGLExtensions(unsigned int contextID)
{
// extension support
_isStencilTwoSidedSupported = isGLExtensionSupported(contextID, "GL_EXT_stencil_two_side");
_isOpenGL20Supported = getGLVersionNumber() >= 2.0;
_isSeparateStencilSupported = isGLExtensionSupported(contextID, "GL_ATI_separate_stencil");
// function pointers
setGLExtensionFuncPtr(_glActiveStencilFace, "glActiveStencilFaceEXT");
setGLExtensionFuncPtr(_glStencilOpSeparate, "glStencilOpSeparate", "glStencilOpSeparateATI");
setGLExtensionFuncPtr(_glStencilMaskSeparate, "glStencilMaskSeparate");
setGLExtensionFuncPtr(_glStencilFuncSeparate, "glStencilFuncSeparate");
setGLExtensionFuncPtr(_glStencilFuncSeparateATI, "glStencilFuncSeparateATI");
// protect against buggy drivers (maybe not necessary)
if (!_glActiveStencilFace) _isStencilTwoSidedSupported = false;
if (!_glStencilOpSeparate) { _isOpenGL20Supported = false; _isSeparateStencilSupported = false; }
if (!_glStencilMaskSeparate) _isOpenGL20Supported = false;
if (!_glStencilFuncSeparate) _isOpenGL20Supported = false;
if (!_glStencilFuncSeparateATI) _isSeparateStencilSupported = false;
// notify
if( _isOpenGL20Supported )
{
OSG_INFO << "StencilTwoSided is going to use OpenGL 2.0 API (contextID " << contextID << ")." << std::endl;
}
else if( _isStencilTwoSidedSupported )
{
OSG_INFO << "StencilTwoSided is going to use GL_EXT_stencil_two_side extension (contextID " << contextID << ")." << std::endl;
}
else if( _isSeparateStencilSupported )
{
OSG_INFO << "StencilTwoSided is going to use GL_ATI_separate_stencil extension (contextID " << contextID << ")." << std::endl;
}
else
{
OSG_INFO << "StencilTwoSided did not found required graphics capabilities\n"
" (contextID " << contextID << "). OpenGL 2.0 or one of extensions\n"
" GL_EXT_stencil_two_side or GL_ATI_separate_stencil is required." << std::endl;
}
}
void StencilTwoSided::Extensions::glActiveStencilFace(GLenum face) const
{
if (_isStencilTwoSidedSupported)
{
_glActiveStencilFace(face);
}
}
void StencilTwoSided::Extensions::glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) const
{
if (_isOpenGL20Supported || _isSeparateStencilSupported)
{
_glStencilOpSeparate(face, sfail, dpfail, dppass);
}
}
void StencilTwoSided::Extensions::glStencilMaskSeparate(GLenum face, GLuint mask) const
{
if (_isOpenGL20Supported)
{
_glStencilMaskSeparate(face, mask);
}
}
void StencilTwoSided::Extensions::glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) const
{
if (_isOpenGL20Supported)
{
_glStencilFuncSeparate(face, func, ref, mask);
}
}
void StencilTwoSided::Extensions::glStencilFuncSeparateATI(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask) const
{
if (_isSeparateStencilSupported)
{
_glStencilFuncSeparateATI(frontfunc, backfunc, ref, mask);
}
}