From e31f6824516a3f10623caa5c7fb64d3e0181f550 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 9 Dec 2014 14:57:25 +0000 Subject: [PATCH] Moved local Extensions structs into GL2Extensions git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14584 16af8721-9629-0410-8352-f15c8da7e697 --- include/osg/ClampColor | 42 ------------- include/osg/ColorMaski | 8 --- include/osg/GL2Extensions | 28 +++++++++ include/osg/Multisample | 49 --------------- include/osg/Point | 53 ---------------- include/osg/PointSprite | 2 - include/osg/PrimitiveRestartIndex | 13 ++-- include/osg/Stencil | 4 +- src/osg/ClampColor.cpp | 64 +------------------ src/osg/ColorMaski.cpp | 9 +-- src/osg/GL2Extensions.cpp | 46 ++++++++++++++ src/osg/Multisample.cpp | 73 ++-------------------- src/osg/Point.cpp | 100 +----------------------------- src/osg/PointSprite.cpp | 52 ++++------------ src/osg/PrimitiveRestartIndex.cpp | 85 ++----------------------- 15 files changed, 110 insertions(+), 518 deletions(-) diff --git a/include/osg/ClampColor b/include/osg/ClampColor index e1882ebc1..35edb413c 100644 --- a/include/osg/ClampColor +++ b/include/osg/ClampColor @@ -80,49 +80,7 @@ class OSG_EXPORT ClampColor : public StateAttribute void setClampReadColor(GLenum mode) { _clampReadColor = mode; } GLenum getClampReadColor() const { return _clampReadColor; } - virtual void apply(State& state) const; - /** Encapsulates queries of extension availability, obtains extension - * function pointers, and provides convenience wrappers for - * calling extension 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 setClampColorSupported(bool flag) { _isClampColorSupported=flag; } - bool isClampColorSupported() const { return _isClampColorSupported; } - - void glClampColor(GLenum target, GLenum mode) const; - - protected: - - ~Extensions() {} - - typedef void (GL_APIENTRY * GLClampColorProc) (GLenum target, GLenum mode); - bool _isClampColorSupported; - GLClampColorProc _glClampColor; - - }; - - /** Returns the Extensions object for the given context. - * If createIfNotInitalized is true and the Extensions object doesn't - * exist, getExtensions() creates it on the given context. - * Returns NULL if createIfNotInitalized is false and the Extensions - * object doesn't exist. */ - 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 : diff --git a/include/osg/ColorMaski b/include/osg/ColorMaski index 548f680e0..451330ce6 100644 --- a/include/osg/ColorMaski +++ b/include/osg/ColorMaski @@ -60,14 +60,6 @@ class OSG_EXPORT ColorMaski : public ColorMask virtual void apply(State& state) const; - /** Encapsulates queries of extension availability, obtains extension function pointers. */ - struct OSG_EXPORT Extensions : public osg::Referenced - { - Extensions(unsigned int contextID); - - void (GL_APIENTRY * glColorMaski)(GLuint buf, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); - }; - protected: virtual ~ColorMaski(); diff --git a/include/osg/GL2Extensions b/include/osg/GL2Extensions index 60407871d..5267570fa 100644 --- a/include/osg/GL2Extensions +++ b/include/osg/GL2Extensions @@ -941,6 +941,34 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced void (GL_APIENTRY * glStencilFuncSeparateATI) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); + // ColorMask + void (GL_APIENTRY * glColorMaski)(GLuint buf, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + + + // ClampColor + bool isClampColorSupported; + void (GL_APIENTRY * glClampColor) (GLenum target, GLenum mode); + + + // PrimitiveRestartIndex + void (GL_APIENTRY * glPrimitiveRestartIndex) ( GLuint index ); + + + // Mutlisample + bool isMultisampleSupported; + bool isMultisampleFilterHintSupported; + + void (GL_APIENTRY * glSampleCoverage) (GLclampf value, GLboolean invert); + + // Point + bool isPointParametersSupported; + bool isPointSpriteSupported; + bool isPointSpriteCoordOriginSupported; + + void (GL_APIENTRY * glPointParameteri) (GLenum pname, GLint param); + void (GL_APIENTRY * glPointParameterf) (GLenum pname, GLfloat param); + void (GL_APIENTRY * glPointParameterfv) (GLenum pname, const GLfloat *params); + }; } diff --git a/include/osg/Multisample b/include/osg/Multisample index 60477a932..d82f024c7 100644 --- a/include/osg/Multisample +++ b/include/osg/Multisample @@ -92,55 +92,6 @@ class OSG_EXPORT Multisample : 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 setMultisampleSupported(bool flag) { _isMultisampleSupported=flag; } - void setMultisampleFilterHintSupported(bool flag) { _isMultisampleFilterHintSupported=flag; } - bool isMultisampleSupported() const { return _isMultisampleSupported; } - bool isMultisampleFilterHintSupported() const { return _isMultisampleFilterHintSupported; } - - void glSampleCoverage(GLclampf value, GLboolean invert) const; - - protected: - - ~Extensions() {} - - bool _isMultisampleSupported; - bool _isMultisampleFilterHintSupported; - - typedef void (GL_APIENTRY * GLSampleCoverageProc) (GLclampf value, GLboolean invert); - GLSampleCoverageProc _glSampleCoverage; - - }; - - /** 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); - - /** 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 : virtual ~Multisample(); diff --git a/include/osg/Point b/include/osg/Point index 1c5f2592d..1cadc966e 100644 --- a/include/osg/Point +++ b/include/osg/Point @@ -87,59 +87,6 @@ class OSG_EXPORT Point : public StateAttribute virtual void apply(State& state) const; - /** Encapsulates queries of extension availability, obtains extension - * function pointers, and provides convenience wrappers for - * calling extension 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 setPointParametersSupported(bool flag) { _isPointParametersSupported=flag; } - bool isPointParametersSupported() const { return _isPointParametersSupported; } - - void setPointSpriteCoordOriginSupported(bool flag) { _isPointSpriteCoordOriginSupported=flag; } - bool isPointSpriteCoordOriginSupported() const { return _isPointSpriteCoordOriginSupported; } - - void glPointParameteri(GLenum pname, GLint param) const; - void glPointParameterf(GLenum pname, GLfloat param) const; - void glPointParameterfv(GLenum pname, const GLfloat *params) const; - - protected: - - ~Extensions() {} - - bool _isPointParametersSupported; - bool _isPointSpriteCoordOriginSupported; - - typedef void (GL_APIENTRY * GLPointParameteriProc) (GLenum pname, GLint param); - typedef void (GL_APIENTRY * GLPointParameterfProc) (GLenum pname, GLfloat param); - typedef void (GL_APIENTRY * GLPointParameterfvProc) (GLenum pname, const GLfloat *params); - - GLPointParameteriProc _glPointParameteri; - GLPointParameterfProc _glPointParameterf; - GLPointParameterfvProc _glPointParameterfv; - - }; - - /** Returns the Extensions object for the given context. - * If createIfNotInitalized is true and the Extensions object doesn't - * exist, getExtensions() creates it on the given context. - * Returns NULL if createIfNotInitalized is false and the Extensions - * object doesn't exist. */ - 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 : virtual ~Point(); diff --git a/include/osg/PointSprite b/include/osg/PointSprite index a127cea4b..c8a7408ee 100644 --- a/include/osg/PointSprite +++ b/include/osg/PointSprite @@ -59,8 +59,6 @@ public: virtual void apply(osg::State& state) const; - static bool isPointSpriteSupported(unsigned int context); - enum CoordOriginMode { UPPER_LEFT = GL_UPPER_LEFT, LOWER_LEFT = GL_LOWER_LEFT diff --git a/include/osg/PrimitiveRestartIndex b/include/osg/PrimitiveRestartIndex index 5872311ba..79811533b 100644 --- a/include/osg/PrimitiveRestartIndex +++ b/include/osg/PrimitiveRestartIndex @@ -18,7 +18,7 @@ namespace osg { -/** +/** * osg::PrimitiveRestartIndex does nothing if OpenGL 3.1 is not available. */ class OSG_EXPORT PrimitiveRestartIndex : public StateAttribute @@ -35,13 +35,14 @@ class OSG_EXPORT PrimitiveRestartIndex : public StateAttribute /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ virtual int compare(const StateAttribute& sa) const; - + inline void setRestartIndex(unsigned int restartIndex ) { _restartIndex = restartIndex; } - + inline unsigned int getRestartIndex() const { return _restartIndex; } virtual void apply(State& state) const; +#if 0 public: /** Extensions class which encapsulates the querying of extensions and @@ -67,19 +68,19 @@ class OSG_EXPORT PrimitiveRestartIndex : public StateAttribute protected: ~Extensions() {} - + bool _isOpenGL31Supported; bool _isPrimitiveRestartIndexNVSupported; typedef void (GL_APIENTRY * PrimitiveRestartIndex)( GLuint index ); - + PrimitiveRestartIndex _glPrimitiveRestartIndex; }; static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized); static void setExtensions(unsigned int contextID,Extensions* extensions); - +#endif protected: diff --git a/include/osg/Stencil b/include/osg/Stencil index 08728282d..1960c1797 100644 --- a/include/osg/Stencil +++ b/include/osg/Stencil @@ -31,9 +31,7 @@ namespace osg { * GL_EXT_stencil_wrap extension is present. * * If INCR_WRAP or DECR_WRAP values are used while they are detected to be not supported, -* the INCR or DECR values are sent to OpenGL instead. Note: do not use Stencil::getFunction() -* to detect whether WRAP operations is used as the object's value is kept intact. -* Use osg::Stencil::getExtensions() method instead. +* the INCR or DECR values are sent to OpenGL instead. * * OpenGL 2.0 introduced two side stenciling that is available through * osg::StencilTwoSided class. diff --git a/src/osg/ClampColor.cpp b/src/osg/ClampColor.cpp index 4b4783d83..f6f95815b 100644 --- a/src/osg/ClampColor.cpp +++ b/src/osg/ClampColor.cpp @@ -42,11 +42,8 @@ void ClampColor::apply(State& state) const // get the contextID (user defined ID of 0 upwards) for the // current OpenGL context. - const unsigned int contextID = state.getContextID(); - - const Extensions* extensions = getExtensions(contextID,true); - - if (!extensions->isClampColorSupported()) + const GL2Extensions* extensions = state.get(); + if (!extensions->isClampColorSupported) { OSG_WARN<<"Warning: ClampColor::apply(..) failed, ClampColor is not support by OpenGL driver."<glClampColor(GL_CLAMP_FRAGMENT_COLOR, _clampFragmentColor); extensions->glClampColor(GL_CLAMP_READ_COLOR, _clampReadColor); } - - -typedef buffered_value< ref_ptr > BufferedExtensions; -static BufferedExtensions s_extensions; - -ClampColor::Extensions* ClampColor::getExtensions(unsigned int contextID,bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); - return s_extensions[contextID].get(); -} - -void ClampColor::setExtensions(unsigned int contextID,Extensions* extensions) -{ - s_extensions[contextID] = extensions; -} - - -ClampColor::Extensions::Extensions(unsigned int contextID) -{ - setupGLExtensions(contextID); -} - -ClampColor::Extensions::Extensions(const Extensions& rhs): - Referenced() -{ - _isClampColorSupported = rhs._isClampColorSupported; - _glClampColor = rhs._glClampColor; -} - -void ClampColor::Extensions::lowestCommonDenominator(const Extensions& rhs) -{ - if (!rhs._isClampColorSupported) _isClampColorSupported = false; - if (!rhs._glClampColor) _glClampColor = 0; -} - -void ClampColor::Extensions::setupGLExtensions(unsigned int contextID) -{ - _isClampColorSupported = OSG_GL3_FEATURES || - isGLExtensionSupported(contextID,"GL_ARB_color_buffer_float") || - strncmp((const char*)glGetString(GL_VERSION),"2.0",3)>=0; - - setGLExtensionFuncPtr(_glClampColor, "glClampColor", "glClampColorARB"); -} - -void ClampColor::Extensions::glClampColor(GLenum target, GLenum mode) const -{ - if (_glClampColor) - { - _glClampColor(target,mode); - } - else - { - OSG_WARN<<"Error: glClampColor not supported by OpenGL driver"<(); + const GL2Extensions* extensions = state.get(); if (extensions->glColorMaski) { extensions->glColorMaski((GLboolean)_index, (GLboolean)_red,(GLboolean)_green,(GLboolean)_blue,(GLboolean)_alpha); diff --git a/src/osg/GL2Extensions.cpp b/src/osg/GL2Extensions.cpp index 2f1123c0b..a2bb9e0ce 100644 --- a/src/osg/GL2Extensions.cpp +++ b/src/osg/GL2Extensions.cpp @@ -566,6 +566,52 @@ GL2Extensions::GL2Extensions(unsigned int contextID) setGLExtensionFuncPtr(glStencilMaskSeparate, "glStencilMaskSeparate"); setGLExtensionFuncPtr(glStencilFuncSeparate, "glStencilFuncSeparate", "glStencilFuncSeparateATI"); setGLExtensionFuncPtr(glStencilFuncSeparateATI, "glStencilFuncSeparateATI"); + + + // Color Mask + setGLExtensionFuncPtr(glColorMaski, "glColorMaski", "glColorMaskiARB"); + + + // ClampColor + isClampColorSupported = OSG_GL3_FEATURES || + isGLExtensionSupported(contextID,"GL_ARB_color_buffer_float") || + strncmp((const char*)glGetString(GL_VERSION),"2.0",3)>=0; + + setGLExtensionFuncPtr(glClampColor, "glClampColor", "glClampColorARB"); + + + // PrimitiveRestartIndex + setGLExtensionFuncPtr(glPrimitiveRestartIndex, "glPrimitiveRestartIndex", "glPrimitiveRestartIndexNV"); + + + // Point + isPointParametersSupported = OSG_GL3_FEATURES || + strncmp((const char*)glGetString(GL_VERSION),"1.4",3)>=0 || + isGLExtensionSupported(contextID,"GL_ARB_point_parameters") || + isGLExtensionSupported(contextID,"GL_EXT_point_parameters") || + isGLExtensionSupported(contextID,"GL_SGIS_point_parameters"); + + + isPointSpriteSupported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID, "GL_ARB_point_sprite") || isGLExtensionSupported(contextID, "GL_OES_point_sprite") || isGLExtensionSupported(contextID, "GL_NV_point_sprite"); + isPointSpriteCoordOriginSupported = OSG_GL3_FEATURES || strncmp((const char*)glGetString(GL_VERSION),"2.0",3)>=0; + + + setGLExtensionFuncPtr(glPointParameteri, "glPointParameteri", "glPointParameteriARB"); + if (!glPointParameteri) setGLExtensionFuncPtr(glPointParameteri, "glPointParameteriEXT", "glPointParameteriSGIS"); + + setGLExtensionFuncPtr(glPointParameterf, "glPointParameterf", "glPointParameterfARB"); + if (!glPointParameterf) setGLExtensionFuncPtr(glPointParameterf, "glPointParameterfEXT", "glPointParameterfSGIS"); + + setGLExtensionFuncPtr(glPointParameterfv, "glPointParameterfv", "glPointParameterfvARB"); + if (!glPointParameterfv) setGLExtensionFuncPtr(glPointParameterfv, "glPointParameterfvEXT", "glPointParameterfvSGIS"); + + + // Multisample + isMultisampleSupported = OSG_GLES2_FEATURES || OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_ARB_multisample"); + isMultisampleFilterHintSupported = isGLExtensionSupported(contextID, "GL_NV_multisample_filter_hint"); + + setGLExtensionFuncPtr(glSampleCoverage, "glSampleCoverageARB"); + } diff --git a/src/osg/Multisample.cpp b/src/osg/Multisample.cpp index 799cff488..0fcd1b5b6 100644 --- a/src/osg/Multisample.cpp +++ b/src/osg/Multisample.cpp @@ -31,78 +31,17 @@ Multisample::~Multisample() void Multisample::apply(State& state) const { - // get the contextID (user defined ID of 0 upwards) for the - // current OpenGL context. - const unsigned int contextID = state.getContextID(); - - const Extensions* extensions = getExtensions(contextID,true); - - if (!extensions->isMultisampleSupported()) + const GL2Extensions* extensions = state.get(); + if (!extensions->isMultisampleSupported) { OSG_WARN<<"Warning: Multisample::apply(..) failed, Multisample is not support by OpenGL driver."<isMultisampleFilterHintSupported()) + if(extensions->isMultisampleFilterHintSupported) + { glHint(GL_MULTISAMPLE_FILTER_HINT_NV, _mode); + } + extensions->glSampleCoverage(_coverage, _invert); } - - - - - -typedef buffered_value< ref_ptr > BufferedExtensions; -static BufferedExtensions s_extensions; - -Multisample::Extensions* Multisample::getExtensions(unsigned int contextID,bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); - return s_extensions[contextID].get(); -} - -void Multisample::setExtensions(unsigned int contextID,Extensions* extensions) -{ - s_extensions[contextID] = extensions; -} - - -Multisample::Extensions::Extensions(unsigned int contextID) -{ - setupGLExtensions(contextID); -} - -Multisample::Extensions::Extensions(const Extensions& rhs): - Referenced() -{ - _isMultisampleSupported = rhs._isMultisampleSupported; - _isMultisampleFilterHintSupported = rhs._isMultisampleFilterHintSupported; -} - -void Multisample::Extensions::lowestCommonDenominator(const Extensions& rhs) -{ - if (!rhs._isMultisampleSupported) _isMultisampleSupported = false; - if (!rhs._isMultisampleFilterHintSupported) _isMultisampleFilterHintSupported = false; - if (!rhs._glSampleCoverage) _glSampleCoverage = 0; -} - -void Multisample::Extensions::setupGLExtensions(unsigned int contextID) -{ - _isMultisampleSupported = OSG_GLES2_FEATURES || OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_ARB_multisample"); - _isMultisampleFilterHintSupported = isGLExtensionSupported(contextID,"GL_NV_multisample_filter_hint"); - - setGLExtensionFuncPtr(_glSampleCoverage, "glSampleCoverageARB"); -} - -void Multisample::Extensions::glSampleCoverage(GLclampf value, GLboolean invert) const -{ - if (_glSampleCoverage) - { - _glSampleCoverage(value, invert); - } - else - { - OSG_WARN<<"Error: glSampleCoverage not supported by OpenGL driver"<(); - if (!extensions->isPointParametersSupported()) + if (!extensions->isPointParametersSupported) return; extensions->glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, (const GLfloat*)&_distanceAttenuation); @@ -98,98 +97,3 @@ void Point::apply(State& state) const OSG_NOTICE<<"Warning: Point::apply(State&) - not supported."< > BufferedExtensions; -static BufferedExtensions s_extensions; - -Point::Extensions* Point::getExtensions(unsigned int contextID,bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); - return s_extensions[contextID].get(); -} - -void Point::setExtensions(unsigned int contextID,Extensions* extensions) -{ - s_extensions[contextID] = extensions; -} - -Point::Extensions::Extensions(unsigned int contextID) -{ - setupGLExtensions(contextID); -} - -Point::Extensions::Extensions(const Extensions& rhs): - Referenced() -{ - _isPointParametersSupported = rhs._isPointParametersSupported; - _isPointSpriteCoordOriginSupported = rhs._isPointSpriteCoordOriginSupported; - _glPointParameteri = rhs._glPointParameteri; - _glPointParameterf = rhs._glPointParameterf; - _glPointParameterfv = rhs._glPointParameterfv; -} - -void Point::Extensions::lowestCommonDenominator(const Extensions& rhs) -{ - if (!rhs._isPointParametersSupported) _isPointParametersSupported = false; - if (!rhs._isPointSpriteCoordOriginSupported) _isPointSpriteCoordOriginSupported = false; - if (!rhs._glPointParameteri) _glPointParameteri = 0; - if (!rhs._glPointParameterf) _glPointParameterf = 0; - if (!rhs._glPointParameterfv) _glPointParameterfv = 0; -} - -void Point::Extensions::setupGLExtensions(unsigned int contextID) -{ - _isPointParametersSupported = OSG_GL3_FEATURES || - strncmp((const char*)glGetString(GL_VERSION),"1.4",3)>=0 || - isGLExtensionSupported(contextID,"GL_ARB_point_parameters") || - isGLExtensionSupported(contextID,"GL_EXT_point_parameters") || - isGLExtensionSupported(contextID,"GL_SGIS_point_parameters"); - - _isPointSpriteCoordOriginSupported = OSG_GL3_FEATURES || strncmp((const char*)glGetString(GL_VERSION),"2.0",3)>=0; - - setGLExtensionFuncPtr(_glPointParameteri, "glPointParameteri", "glPointParameteriARB"); - if (!_glPointParameteri) setGLExtensionFuncPtr(_glPointParameteri, "glPointParameteriEXT", "glPointParameteriSGIS"); - - setGLExtensionFuncPtr(_glPointParameterf, "glPointParameterf", "glPointParameterfARB"); - if (!_glPointParameterf) setGLExtensionFuncPtr(_glPointParameterf, "glPointParameterfEXT", "glPointParameterfSGIS"); - - setGLExtensionFuncPtr(_glPointParameterfv, "glPointParameterfv", "glPointParameterfvARB"); - if (!_glPointParameterfv) setGLExtensionFuncPtr(_glPointParameterfv, "glPointParameterfvEXT", "glPointParameterfvSGIS"); -} - -void Point::Extensions::glPointParameteri(GLenum pname, GLint param) const -{ - if (_glPointParameteri) - { - _glPointParameteri(pname, param); - } - else - { - OSG_WARN<<"Error: glPointParameteri not supported by OpenGL driver"<(); + bool modeValid = extensions->isPointSpriteSupported; #if defined( OSG_GLES1_AVAILABLE ) //point sprites don't exist on es 2.0 state.setModeValidity(GL_POINT_SPRITE_OES, modeValid); #else state.setModeValidity(GL_POINT_SPRITE_ARB, modeValid); #endif - + return modeValid; } void PointSprite::apply(osg::State& state) const { + const GL2Extensions* extensions = state.get(); #if defined( OSG_GL3_AVAILABLE ) - - const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true); - extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode); + + extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, _coordOriginMode); #elif defined( OSG_GLES1_AVAILABLE ) //point sprites don't exist on es 2.0 - - if(!isPointSpriteSupported(state.getContextID())) return; - + + if (!extensions->isPointSpriteSupported) return; + glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, 1); - + #elif defined( OSG_GL_FIXED_FUNCTION_AVAILABLE ) - if(!isPointSpriteSupported(state.getContextID())) return; + if (!extensions->isPointSpriteSupported) return; glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, 1); - const Point::Extensions* extensions = Point::getExtensions(state.getContextID(),true); - - if (extensions->isPointSpriteCoordOriginSupported()) - extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,_coordOriginMode); + if (extensions->isPointSpriteCoordOriginSupported) + extensions->glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, _coordOriginMode); #else OSG_NOTICE<<"Warning: PointSprite::apply(State&) - not supported."< BufferedExtensions; -static BufferedExtensions s_extensions; - -bool PointSprite::isPointSpriteSupported(unsigned int contextID) -{ - if (!s_extensions[contextID].initialized) - { - s_extensions[contextID].initialized = true; - s_extensions[contextID].supported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID, "GL_ARB_point_sprite") || isGLExtensionSupported(contextID, "GL_OES_point_sprite") || isGLExtensionSupported(contextID, "GL_NV_point_sprite"); - } - - return s_extensions[contextID].supported; -} diff --git a/src/osg/PrimitiveRestartIndex.cpp b/src/osg/PrimitiveRestartIndex.cpp index 6607c40c7..3240f073a 100644 --- a/src/osg/PrimitiveRestartIndex.cpp +++ b/src/osg/PrimitiveRestartIndex.cpp @@ -52,90 +52,13 @@ int PrimitiveRestartIndex::compare(const StateAttribute& sa) const void PrimitiveRestartIndex::apply(State& state) const { // get "per-context" extensions - const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); - - if ( (extensions->isOpenGL31Supported()) || (extensions->isPrimitiveRestartIndexNVSupported()) ) + const GL2Extensions* extensions = state.get(); + if (extensions->glPrimitiveRestartIndex) { extensions->glPrimitiveRestartIndex( _restartIndex ); return; } - OSG_WARN << "PrimitiveRestartIndex failed as the required graphics capabilities were\n" - " not found (contextID " << contextID << "). OpenGL 3.1 or \n" - " GL_NV_primitive_restart extension is required." << std::endl; + OSG_WARN << "PrimitiveRestartIndex failed as the required graphics capabilities were not found\n" + " OpenGL 3.1 or GL_NV_primitive_restart extension is required." << std::endl; } - - -typedef buffered_value< ref_ptr > BufferedExtensions; -static BufferedExtensions s_extensions; - -PrimitiveRestartIndex::Extensions* PrimitiveRestartIndex::getExtensions(unsigned int contextID,bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); - return s_extensions[contextID].get(); -} - -void PrimitiveRestartIndex::setExtensions(unsigned int contextID,Extensions* extensions) -{ - s_extensions[contextID] = extensions; -} - -PrimitiveRestartIndex::Extensions::Extensions(unsigned int contextID) -{ - setupGLExtensions(contextID); -} - -PrimitiveRestartIndex::Extensions::Extensions(const Extensions& rhs): - Referenced() -{ - _isOpenGL31Supported = rhs._isOpenGL31Supported; - _isPrimitiveRestartIndexNVSupported = rhs._isPrimitiveRestartIndexNVSupported; - _glPrimitiveRestartIndex = rhs._glPrimitiveRestartIndex; -} - -void PrimitiveRestartIndex::Extensions::lowestCommonDenominator(const Extensions& rhs) -{ - if (!rhs._isOpenGL31Supported) _isOpenGL31Supported = false; - if (!rhs._isPrimitiveRestartIndexNVSupported) _isPrimitiveRestartIndexNVSupported = false; - if (!rhs._glPrimitiveRestartIndex) _glPrimitiveRestartIndex = NULL; -} - -void PrimitiveRestartIndex::Extensions::setupGLExtensions(unsigned int contextID) -{ - // extension support - _isPrimitiveRestartIndexNVSupported = isGLExtensionSupported(contextID, "GL_NV_primitive_restart"); - _isOpenGL31Supported = getGLVersionNumber() >= 3.1; - _glPrimitiveRestartIndex = NULL; - - // function pointers - if (_isOpenGL31Supported) - setGLExtensionFuncPtr(_glPrimitiveRestartIndex, "glPrimitiveRestartIndex"); - else if (_isPrimitiveRestartIndexNVSupported) - setGLExtensionFuncPtr(_glPrimitiveRestartIndex, "glPrimitiveRestartIndexNV"); - - // protect against buggy drivers (maybe not necessary) - if (!_glPrimitiveRestartIndex) _isPrimitiveRestartIndexNVSupported = false; - - // notify - if( _isOpenGL31Supported ) - { - OSG_INFO << "PrimitiveRestartIndex is going to use OpenGL 3.1 API (contextID " << contextID << ")." << std::endl; - } - else if( _isPrimitiveRestartIndexNVSupported ) - { - OSG_INFO << "PrimitiveRestartIndex is going to use GL_NV_primitive_restart extension (contextID " << contextID << ")." << std::endl; - } - else - { - OSG_INFO << "PrimitiveRestartIndex did not found required graphics capabilities\n" - " (contextID " << contextID << "). OpenGL 3.1 or \n" - " GL_NV_primitive_restart extension is required." << std::endl; - } -} - -void PrimitiveRestartIndex::Extensions::glPrimitiveRestartIndex( GLuint index ) const -{ - _glPrimitiveRestartIndex( index ); -} -