From 43049ebcf11c4ca38a525711c0b7806430d95102 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 9 Dec 2014 18:30:28 +0000 Subject: [PATCH] Moved FBO Extensions into GL2Extensions. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14586 16af8721-9629-0410-8352-f15c8da7e697 --- examples/osgfpdepth/osgfpdepth.cpp | 60 +++++---- examples/osgoit/DepthPeeling.cpp | 12 +- include/osg/FrameBufferObject | 95 +++------------ include/osg/GL2Extensions | 62 +++++++++- include/osg/GraphicsContext | 37 ------ src/osg/BufferObject.cpp | 187 ----------------------------- src/osg/FrameBufferObject.cpp | 118 +++--------------- src/osg/GL2Extensions.cpp | 55 ++++++++- src/osg/GraphicsContext.cpp | 36 ++---- src/osg/OcclusionQueryNode.cpp | 6 +- src/osg/Texture.cpp | 163 ++----------------------- src/osg/Texture3D.cpp | 70 ----------- src/osg/TextureRectangle.cpp | 35 ------ src/osgUtil/RenderStage.cpp | 30 ++--- 14 files changed, 217 insertions(+), 749 deletions(-) diff --git a/examples/osgfpdepth/osgfpdepth.cpp b/examples/osgfpdepth/osgfpdepth.cpp index 40c1a2e3d..eadf6fa94 100644 --- a/examples/osgfpdepth/osgfpdepth.cpp +++ b/examples/osgfpdepth/osgfpdepth.cpp @@ -132,10 +132,10 @@ void getPossibleConfigs(GraphicsContext* gc, BufferConfigList& colorConfigs, unsigned contextID = gc->getState()->getContextID(); colorConfigs.push_back(BufferConfig("RGBA8", GL_RGBA8, 8)); depthConfigs.push_back(BufferConfig("D24", GL_DEPTH_COMPONENT24, 24)); - FBOExtensions* fboe = FBOExtensions::instance(contextID, true); - if (!fboe->isSupported()) + osg::GL2Extensions* ext = gc->getState()->get(); + if (!ext->isRenderbufferMultisampleSupported()) return; - if (fboe->isMultisampleSupported()) + if (ext->isMultisampleSupported) glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples); // isMultisampleCoverageSupported if (isGLExtensionSupported(contextID, @@ -156,9 +156,8 @@ void getPossibleConfigs(GraphicsContext* gc, BufferConfigList& colorConfigs, bool checkFramebufferStatus(GraphicsContext* gc, bool silent = false) { State& state = *gc->getState(); - unsigned contextID = state.getContextID(); - FBOExtensions* fboe = FBOExtensions::instance(contextID, true); - switch(fboe->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT)) { + osg::GL2Extensions* ext = gc->getState()->get(); + switch(ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT)) { case GL_FRAMEBUFFER_COMPLETE_EXT: break; case GL_FRAMEBUFFER_UNSUPPORTED_EXT: @@ -242,30 +241,30 @@ bool createFBO(GraphicsContext* gc, FboConfig &config, FboData &data) } State& state = *gc->getState(); unsigned int contextID = state.getContextID(); - FBOExtensions* fboe = FBOExtensions::instance(contextID, true); + osg::GL2Extensions* ext = gc->getState()->get(); data.fb->apply(state); result = checkFramebufferStatus(gc, true); if (!result) { - fboe->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); return false; } int query; if (multisample) { - GLuint colorRBID = colorRB->getObjectID(contextID, fboe); - fboe->glBindRenderbuffer(GL_RENDERBUFFER_EXT, colorRBID); + GLuint colorRBID = colorRB->getObjectID(contextID, ext); + ext->glBindRenderbuffer(GL_RENDERBUFFER_EXT, colorRBID); if (csaa) { - fboe->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, + ext->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_COVERAGE_SAMPLES_NV, &query); if (query < config.coverageSamples) result = false; else config.coverageSamples = query; - fboe->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, + ext->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_COLOR_SAMPLES_NV, &query); @@ -277,7 +276,7 @@ bool createFBO(GraphicsContext* gc, FboConfig &config, FboData &data) } else { - fboe->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, + ext->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_SAMPLES_EXT, &query); if (query < config.depthSamples) @@ -303,7 +302,7 @@ bool createFBO(GraphicsContext* gc, FboConfig &config, FboData &data) result = false; } } - fboe->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); return result; } @@ -696,15 +695,15 @@ GraphicsContext* setupGC(osgViewer::Viewer& viewer, ArgumentParser& arguments) DisplaySettings* ds = viewer.getDisplaySettings() ? viewer.getDisplaySettings() : DisplaySettings::instance().get(); GraphicsContext::ScreenIdentifier si; si.readDISPLAY(); - - // displayNum has not been set so reset it to 0. - if (si.displayNum<0) si.displayNum = 0; + si.setUndefinedScreenDetailsToDefaultScreen(); bool decoration = true; if (x < 0) { unsigned int w, h; wsi->getScreenResolution(si, w, h); + OSG_NOTICE<<"Screen resolution is "< traits - = new GraphicsContext::Traits(ds); + OSG_NOTICE<<"x = "<realize(); - gc->makeCurrent(); + if (!gc->makeCurrent()) + { + OSG_NOTIFY(NOTICE) << "Unable to create GraphicsWindow"<releaseContext(); + gc->close(true); + return 0; + } + unsigned int contextID = gc->getState()->getContextID(); - FBOExtensions* fboe = FBOExtensions::instance(contextID, true); - if (!fboe->isSupported()) + osg::GL2Extensions* ext = gc->getState()->get(); + if (!ext->isFrameBufferObjectSupported) { OSG_NOTIFY(NOTICE) << "Frame buffer objects are not supported\n"; gc->releaseContext(); gc->close(true); return 0; } + if (isGLExtensionSupported(contextID, "GL_ARB_depth_buffer_float")) depthTextureEnum = GL_DEPTH_COMPONENT32F; else if (isGLExtensionSupported(contextID, "GL_NV_depth_buffer_float")) depthTextureEnum = GL_DEPTH_COMPONENT32F_NV; + BufferConfigList colorConfigs; BufferConfigList depthConfigs; vector coverageConfigs; diff --git a/examples/osgoit/DepthPeeling.cpp b/examples/osgoit/DepthPeeling.cpp index f9249b8e9..e1c8df5ff 100644 --- a/examples/osgoit/DepthPeeling.cpp +++ b/examples/osgoit/DepthPeeling.cpp @@ -86,9 +86,9 @@ public: // check if we need to do some depth buffer copying from a source FBO into the current FBO if (_source_fbo.get() != NULL) { - osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(renderInfo.getContextID(),true); - bool fbo_supported = fbo_ext && fbo_ext->isSupported(); - if (fbo_supported && fbo_ext->glBlitFramebuffer) + osg::GL2Extensions* ext = renderInfo.getState()->get(); + bool fbo_supported = ext && ext->isFrameBufferObjectSupported; + if (fbo_supported && ext->glBlitFramebuffer) { // blit the depth buffer from the solid geometry fbo into the current transparency fbo (_fbo.get())->apply(*renderInfo.getState(), osg::FrameBufferObject::DRAW_FRAMEBUFFER); @@ -96,7 +96,7 @@ public: // glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); // only needed to blit the color buffer // glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // only needed to blit the color buffer - fbo_ext->glBlitFramebuffer( + ext->glBlitFramebuffer( 0, 0, static_cast(_width), static_cast(_height), 0, 0, static_cast(_width), static_cast(_height), #ifdef USE_PACKED_DEPTH_STENCIL @@ -130,7 +130,9 @@ public: { // only unbind the fbo if this is the last transparency pass if (_restore) - osg::FBOExtensions::instance( renderInfo.getState()->getContextID(), false )->glBindFramebuffer( GL_FRAMEBUFFER_EXT, 0 ); + { + renderInfo.getState()->get()->glBindFramebuffer( GL_FRAMEBUFFER_EXT, 0 ); + } } protected: bool _restore; diff --git a/include/osg/FrameBufferObject b/include/osg/FrameBufferObject index 344e7ad26..41f16ed2b 100644 --- a/include/osg/FrameBufferObject +++ b/include/osg/FrameBufferObject @@ -119,73 +119,12 @@ namespace osg { -/************************************************************************** - * FBOExtensions - **************************************************************************/ - - class OSG_EXPORT FBOExtensions : public osg::Referenced - { - public: - typedef void GL_APIENTRY TglBindRenderbuffer(GLenum, GLuint); - typedef void GL_APIENTRY TglDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers); - typedef void GL_APIENTRY TglGenRenderbuffers(GLsizei, GLuint *); - typedef void GL_APIENTRY TglRenderbufferStorage(GLenum, GLenum, GLsizei, GLsizei); - typedef void GL_APIENTRY TglRenderbufferStorageMultisample(GLenum, GLsizei, GLenum, GLsizei, GLsizei); - typedef void GL_APIENTRY TglRenderbufferStorageMultisampleCoverageNV(GLenum, GLsizei, GLsizei, GLenum, GLsizei, GLsizei); - typedef void GL_APIENTRY TglBindFramebuffer(GLenum, GLuint); - typedef void GL_APIENTRY TglDeleteFramebuffers(GLsizei n, const GLuint *framebuffers); - typedef void GL_APIENTRY TglGenFramebuffers(GLsizei, GLuint *); - typedef GLenum GL_APIENTRY TglCheckFramebufferStatus(GLenum); - typedef void GL_APIENTRY TglFramebufferTexture1D(GLenum, GLenum, GLenum, GLuint, GLint); - typedef void GL_APIENTRY TglFramebufferTexture2D(GLenum, GLenum, GLenum, GLuint, GLint); - typedef void GL_APIENTRY TglFramebufferTexture3D(GLenum, GLenum, GLenum, GLuint, GLint, GLint); - typedef void GL_APIENTRY TglFramebufferTexture(GLenum, GLenum, GLint, GLint); - typedef void GL_APIENTRY TglFramebufferTextureLayer(GLenum, GLenum, GLuint, GLint, GLint); - typedef void GL_APIENTRY TglFramebufferRenderbuffer(GLenum, GLenum, GLenum, GLuint); - typedef void GL_APIENTRY TglGenerateMipmap(GLenum); - typedef void GL_APIENTRY TglBlitFramebuffer(GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum); - typedef void GL_APIENTRY TglGetRenderbufferParameteriv(GLenum, GLenum, GLint*); - - TglBindRenderbuffer* glBindRenderbuffer; - TglGenRenderbuffers* glGenRenderbuffers; - TglDeleteRenderbuffers* glDeleteRenderbuffers; - TglRenderbufferStorage* glRenderbufferStorage; - TglRenderbufferStorageMultisample* glRenderbufferStorageMultisample; - TglRenderbufferStorageMultisampleCoverageNV* glRenderbufferStorageMultisampleCoverageNV; - TglBindFramebuffer* glBindFramebuffer; - TglDeleteFramebuffers* glDeleteFramebuffers; - TglGenFramebuffers* glGenFramebuffers; - TglCheckFramebufferStatus* glCheckFramebufferStatus; - TglFramebufferTexture1D* glFramebufferTexture1D; - TglFramebufferTexture2D* glFramebufferTexture2D; - TglFramebufferTexture3D* glFramebufferTexture3D; - TglFramebufferTexture* glFramebufferTexture; - TglFramebufferTextureLayer* glFramebufferTextureLayer; - TglFramebufferRenderbuffer* glFramebufferRenderbuffer; - TglGenerateMipmap* glGenerateMipmap; - TglBlitFramebuffer* glBlitFramebuffer; - TglGetRenderbufferParameteriv* glGetRenderbufferParameteriv; - - static FBOExtensions* instance(unsigned contextID, bool createIfNotInitalized); - - bool isSupported() const { return _supported; } - bool isMultisampleSupported() const { return glRenderbufferStorageMultisample != 0; } - bool isMultisampleCoverageSupported() const { return glRenderbufferStorageMultisampleCoverageNV != 0; } - bool isPackedDepthStencilSupported() const { return _packed_depth_stencil_supported; } - - protected: - FBOExtensions(unsigned int contextID); - - bool _supported; - bool _packed_depth_stencil_supported; - }; - /************************************************************************** * RenderBuffer **************************************************************************/ - class OSG_EXPORT RenderBuffer: public Object - { +class OSG_EXPORT RenderBuffer: public Object +{ public: RenderBuffer(); RenderBuffer(int width, int height, GLenum internalFormat, int samples=0, int colorSamples=0); @@ -205,7 +144,7 @@ namespace osg inline void setSamples(int samples); inline void setColorSamples(int colorSamples); - GLuint getObjectID(unsigned int contextID, const FBOExtensions *ext) const; + GLuint getObjectID(unsigned int contextID, const GL2Extensions *ext) const; inline int compare(const RenderBuffer &rb) const; /** Mark internal RenderBuffer for deletion. @@ -222,7 +161,7 @@ namespace osg * this call is useful for when an OpenGL context has been destroyed. */ static void discardDeletedRenderBuffers(unsigned int contextID); - static int getMaxSamples(unsigned int contextID, const FBOExtensions *ext); + static int getMaxSamples(unsigned int contextID, const GL2Extensions* ext); /** Resize any per context GLObject buffers to specified size. */ virtual void resizeGLObjectBuffers(unsigned int maxSize); @@ -335,16 +274,16 @@ namespace osg /************************************************************************** * FrameBufferAttachement **************************************************************************/ - class Texture1D; - class Texture2D; - class Texture2DMultisample; - class Texture3D; - class Texture2DArray; - class TextureCubeMap; - class TextureRectangle; +class Texture1D; +class Texture2D; +class Texture2DMultisample; +class Texture3D; +class Texture2DArray; +class TextureCubeMap; +class TextureRectangle; - class OSG_EXPORT FrameBufferAttachment - { +class OSG_EXPORT FrameBufferAttachment +{ public: FrameBufferAttachment(); FrameBufferAttachment(const FrameBufferAttachment& copy); @@ -364,8 +303,8 @@ namespace osg FrameBufferAttachment&operator = (const FrameBufferAttachment& copy); bool isMultisample() const; - void createRequiredTexturesAndApplyGenerateMipMap(State& state, const FBOExtensions* ext) const; - void attach(State &state, GLenum target, GLenum attachment_point, const FBOExtensions* ext) const; + void createRequiredTexturesAndApplyGenerateMipMap(State& state, const GL2Extensions* ext) const; + void attach(State &state, GLenum target, GLenum attachment_point, const GL2Extensions* ext) const; int compare(const FrameBufferAttachment &fa) const; RenderBuffer* getRenderBuffer(); @@ -389,8 +328,8 @@ namespace osg /************************************************************************** * FrameBufferObject **************************************************************************/ - class OSG_EXPORT FrameBufferObject: public StateAttribute - { +class OSG_EXPORT FrameBufferObject: public StateAttribute +{ public: typedef std::map AttachmentMap; typedef std::vector MultipleRenderingTargets; diff --git a/include/osg/GL2Extensions b/include/osg/GL2Extensions index 5267570fa..d051a30e3 100644 --- a/include/osg/GL2Extensions +++ b/include/osg/GL2Extensions @@ -534,6 +534,24 @@ typedef char GLchar; #define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 #endif +#ifndef GL_ARB_sync +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#endif + // for compatibility with gl.h headers that don't support VBO, //GL_VERSION_1_5 and GL_ARB_vertex_buffer_object provide these types for OpenGL //all ES versions except GL_OES_VERSION_1_0 provide these types for OpenGL ES @@ -698,9 +716,6 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced void (GL_APIENTRY * glUniformMatrix3x4fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ); void (GL_APIENTRY * glUniformMatrix4x3fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ); void (GL_APIENTRY * glProgramParameteri)( GLuint program, GLenum pname, GLint value ); - void (GL_APIENTRY * glFramebufferTexture)( GLenum target, GLenum attachment, GLuint texture, GLint level ); - void (GL_APIENTRY * glFramebufferTextureLayer)( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer ); - void (GL_APIENTRY * glFramebufferTextureFace)( GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face ); void (GL_APIENTRY * glPatchParameteri)( GLenum pname, GLint value ); void (GL_APIENTRY * glPatchParameterfv)( GLenum pname, const GLfloat* values ); void (GL_APIENTRY * glGetUniformuiv)( GLuint program, GLint location, GLuint* params ); @@ -960,6 +975,7 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced void (GL_APIENTRY * glSampleCoverage) (GLclampf value, GLboolean invert); + // Point bool isPointParametersSupported; bool isPointSpriteSupported; @@ -969,6 +985,46 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced void (GL_APIENTRY * glPointParameterf) (GLenum pname, GLfloat param); void (GL_APIENTRY * glPointParameterfv) (GLenum pname, const GLfloat *params); + + // FrameBuferObject + bool isFrameBufferObjectSupported; + bool isPackedDepthStencilSupported; + bool isRenderbufferMultisampleSupported() const { return glRenderbufferStorageMultisample != 0; } + bool isRenderbufferMultisampleCoverageSupported() const { return glRenderbufferStorageMultisampleCoverageNV != 0; } + + void (GL_APIENTRY * glBindRenderbuffer) (GLenum, GLuint); + void (GL_APIENTRY * glDeleteRenderbuffers) (GLsizei n, const GLuint *renderbuffers); + void (GL_APIENTRY * glGenRenderbuffers) (GLsizei, GLuint *); + void (GL_APIENTRY * glRenderbufferStorage) (GLenum, GLenum, GLsizei, GLsizei); + void (GL_APIENTRY * glRenderbufferStorageMultisample) (GLenum, GLsizei, GLenum, GLsizei, GLsizei); + void (GL_APIENTRY * glRenderbufferStorageMultisampleCoverageNV) (GLenum, GLsizei, GLsizei, GLenum, GLsizei, GLsizei); + void (GL_APIENTRY * glBindFramebuffer) (GLenum, GLuint); + void (GL_APIENTRY * glDeleteFramebuffers) (GLsizei n, const GLuint *framebuffers); + void (GL_APIENTRY * glGenFramebuffers) (GLsizei, GLuint *); + GLenum (GL_APIENTRY * glCheckFramebufferStatus) (GLenum); + + void (GL_APIENTRY * glFramebufferTexture1D) (GLenum, GLenum, GLenum, GLuint, GLint); + void (GL_APIENTRY * glFramebufferTexture2D) (GLenum, GLenum, GLenum, GLuint, GLint); + void (GL_APIENTRY * glFramebufferTexture3D) (GLenum, GLenum, GLenum, GLuint, GLint, GLint); + void (GL_APIENTRY * glFramebufferTexture) (GLenum, GLenum, GLint, GLint); + void (GL_APIENTRY * glFramebufferTextureLayer) (GLenum, GLenum, GLuint, GLint, GLint); + void (GL_APIENTRY * glFramebufferTextureFace)( GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face ); + void (GL_APIENTRY * glFramebufferRenderbuffer) (GLenum, GLenum, GLenum, GLuint); + + void (GL_APIENTRY * glGenerateMipmap) (GLenum); + void (GL_APIENTRY * glBlitFramebuffer) (GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum); + void (GL_APIENTRY * glGetRenderbufferParameteriv) (GLenum, GLenum, GLint*); + + + // Sync + GLsync (GL_APIENTRY * glFenceSync) (GLenum condition, GLbitfield flags); + GLboolean (GL_APIENTRY * glIsSync) (GLsync sync); + void (GL_APIENTRY * glDeleteSync) (GLsync sync); + GLenum (GL_APIENTRY * glClientWaitSync) (GLsync sync, GLbitfield flags, GLuint64 timeout); + void (GL_APIENTRY * glWaitSync) (GLsync sync, GLbitfield flags, GLuint64 timeout); + void (GL_APIENTRY * glGetSynciv) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); + + }; } diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index 89b3aa815..65ea3eae4 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -533,53 +533,16 @@ class OSG_EXPORT GraphicsContext : public Object //#include -#ifndef GL_ARB_sync -#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 -#define GL_OBJECT_TYPE 0x9112 -#define GL_SYNC_CONDITION 0x9113 -#define GL_SYNC_STATUS 0x9114 -#define GL_SYNC_FLAGS 0x9115 -#define GL_SYNC_FENCE 0x9116 -#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 -#define GL_UNSIGNALED 0x9118 -#define GL_SIGNALED 0x9119 -#define GL_ALREADY_SIGNALED 0x911A -#define GL_TIMEOUT_EXPIRED 0x911B -#define GL_CONDITION_SATISFIED 0x911C -#define GL_WAIT_FAILED 0x911D -#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 -#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull -#endif class OSG_EXPORT SyncSwapBuffersCallback : public GraphicsContext::SwapCallback { public: SyncSwapBuffersCallback(); - void setUpExtensions(); - virtual void swapBuffersImplementation(GraphicsContext* gc); typedef struct __GLsync *GLsync; - typedef GLsync (GL_APIENTRY * PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); - typedef GLboolean (GL_APIENTRY * PFNGLISSYNCPROC) (GLsync sync); - typedef void (GL_APIENTRY * PFNGLDELETESYNCPROC) (GLsync sync); - typedef GLenum (GL_APIENTRY * PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); - typedef void (GL_APIENTRY * PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); - typedef void (GL_APIENTRY * PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); - typedef void (GL_APIENTRY * PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); - - bool _extensionInitialized; - - PFNGLFENCESYNCPROC _glFenceSync; - PFNGLISSYNCPROC _glIsSync; - PFNGLDELETESYNCPROC _glDeleteSync; - PFNGLCLIENTWAITSYNCPROC _glClientWaitSync; - PFNGLWAITSYNCPROC _glWaitSync; - PFNGLGETINTEGER64VPROC _glGetInteger64v; - PFNGLGETSYNCIVPROC _glGetSynciv; - GLsync _previousSync; }; diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index b4bdc918c..6dc51ec4d 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -264,193 +264,6 @@ void GLBufferObject::setBufferDataHasBeenRead(const osg::BufferData* bd) ++entry.numRead; } -#if 0 -////////////////////////////////////////////////////////////////////////////// -// -// Extension support -// - -typedef buffered_value< ref_ptr > BufferedExtensions; -static BufferedExtensions s_extensions; - -GLBufferObject::Extensions* GLBufferObject::getExtensions(unsigned int contextID,bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new GLBufferObject::Extensions(contextID); - return s_extensions[contextID].get(); -} - -void GLBufferObject::setExtensions(unsigned int contextID,Extensions* extensions) -{ - s_extensions[contextID] = extensions; -} - -GLBufferObject::Extensions::Extensions(unsigned int contextID) -{ - setupGLExtensions(contextID); -} - -GLBufferObject::Extensions::Extensions(const Extensions& rhs): - Referenced() -{ - _glGenBuffers = rhs._glGenBuffers; - _glBindBuffer = rhs._glBindBuffer; - _glBufferData = rhs._glBufferData; - _glBufferSubData = rhs._glBufferSubData; - _glDeleteBuffers = rhs._glDeleteBuffers; - _glIsBuffer = rhs._glIsBuffer; - _glGetBufferSubData = rhs._glGetBufferSubData; - _glMapBuffer = rhs._glMapBuffer; - _glUnmapBuffer = rhs._glUnmapBuffer; - _glGetBufferParameteriv = rhs._glGetBufferParameteriv; - _glGetBufferPointerv = rhs._glGetBufferPointerv; - _glBindBufferRange = rhs._glBindBufferRange; - _glBindBufferBase = rhs._glBindBufferBase; - _glTexBuffer = rhs._glTexBuffer; - -} - - -void GLBufferObject::Extensions::lowestCommonDenominator(const Extensions& rhs) -{ - if (!rhs._glGenBuffers) _glGenBuffers = rhs._glGenBuffers; - if (!rhs._glBindBuffer) _glBindBuffer = rhs._glBindBuffer; - if (!rhs._glBufferData) _glBufferData = rhs._glBufferData; - if (!rhs._glBufferSubData) _glBufferSubData = rhs._glBufferSubData; - if (!rhs._glDeleteBuffers) _glDeleteBuffers = rhs._glDeleteBuffers; - if (!rhs._glIsBuffer) _glIsBuffer = rhs._glIsBuffer; - if (!rhs._glGetBufferSubData) _glGetBufferSubData = rhs._glGetBufferSubData; - if (!rhs._glMapBuffer) _glMapBuffer = rhs._glMapBuffer; - if (!rhs._glUnmapBuffer) _glUnmapBuffer = rhs._glUnmapBuffer; - if (!rhs._glGetBufferParameteriv) _glGetBufferParameteriv = rhs._glGetBufferParameteriv; - if (!rhs._glGetBufferParameteriv) _glGetBufferPointerv = rhs._glGetBufferPointerv; - if (!rhs._glBindBufferRange) _glBindBufferRange = rhs._glBindBufferRange; - if (!rhs._glBindBufferBase) _glBindBufferBase = rhs._glBindBufferBase; - if (!rhs._glTexBuffer) _glTexBuffer = rhs._glTexBuffer; - - _isPBOSupported = rhs._isPBOSupported; - _isUniformBufferObjectSupported = rhs._isUniformBufferObjectSupported; - _isTBOSupported = rhs._isTBOSupported; -} - -void GLBufferObject::Extensions::setupGLExtensions(unsigned int contextID) -{ - setGLExtensionFuncPtr(_glGenBuffers, "glGenBuffers","glGenBuffersARB"); - setGLExtensionFuncPtr(_glBindBuffer, "glBindBuffer","glBindBufferARB"); - setGLExtensionFuncPtr(_glBufferData, "glBufferData","glBufferDataARB"); - setGLExtensionFuncPtr(_glBufferSubData, "glBufferSubData","glBufferSubDataARB"); - setGLExtensionFuncPtr(_glDeleteBuffers, "glDeleteBuffers","glDeleteBuffersARB"); - setGLExtensionFuncPtr(_glIsBuffer, "glIsBuffer","glIsBufferARB"); - setGLExtensionFuncPtr(_glGetBufferSubData, "glGetBufferSubData","glGetBufferSubDataARB"); - setGLExtensionFuncPtr(_glMapBuffer, "glMapBuffer","glMapBufferARB"); - setGLExtensionFuncPtr(_glUnmapBuffer, "glUnmapBuffer","glUnmapBufferARB"); - setGLExtensionFuncPtr(_glGetBufferParameteriv, "glGetBufferParameteriv","glGetBufferParameterivARB"); - setGLExtensionFuncPtr(_glGetBufferPointerv, "glGetBufferPointerv","glGetBufferPointervARB"); - setGLExtensionFuncPtr(_glBindBufferRange, "glBindBufferRange"); - setGLExtensionFuncPtr(_glBindBufferBase, "glBindBufferBase"); - setGLExtensionFuncPtr(_glTexBuffer, "glTexBuffer","glTexBufferARB" ); - - _isPBOSupported = OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID,"GL_ARB_pixel_buffer_object"); - _isUniformBufferObjectSupported = osg::isGLExtensionSupported(contextID, "GL_ARB_uniform_buffer_object"); - _isTBOSupported = osg::isGLExtensionSupported(contextID,"GL_ARB_texture_buffer_object"); -} - -void GLBufferObject::Extensions::glGenBuffers(GLsizei n, GLuint *buffers) const -{ - if (_glGenBuffers) _glGenBuffers(n, buffers); - else OSG_WARN<<"Error: glGenBuffers not supported by OpenGL driver"< > s_extensions; - -FBOExtensions* FBOExtensions::instance(unsigned contextID, bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new FBOExtensions(contextID); - return s_extensions[contextID].get(); -} - -/************************************************************************** - * FBOExtensions - **************************************************************************/ -#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) - #if defined(OSG_GLES1_AVAILABLE) - #define LOAD_FBO_EXT(name) setGLExtensionFuncPtr(name, (#name), (std::string(#name)+std::string("OES") ).c_str() ) - #else - #define LOAD_FBO_EXT(name) setGLExtensionFuncPtr(name, (#name), std::string(#name).c_str() ) - #endif -#else - #define LOAD_FBO_EXT(name) setGLExtensionFuncPtr(name, (#name), (std::string(#name)+std::string("EXT") ).c_str() ) -#endif - -FBOExtensions::FBOExtensions(unsigned int contextID) -: glBindRenderbuffer(0), - glGenRenderbuffers(0), - glDeleteRenderbuffers(0), - glRenderbufferStorage(0), - glRenderbufferStorageMultisample(0), - glRenderbufferStorageMultisampleCoverageNV(0), - glBindFramebuffer(0), - glDeleteFramebuffers(0), - glGenFramebuffers(0), - glCheckFramebufferStatus(0), - glFramebufferTexture1D(0), - glFramebufferTexture2D(0), - glFramebufferTexture3D(0), - glFramebufferTexture(0), - glFramebufferTextureLayer(0), - glFramebufferRenderbuffer(0), - glGenerateMipmap(0), - glBlitFramebuffer(0), - _supported(false), - _packed_depth_stencil_supported(false) -{ - LOAD_FBO_EXT(glBindRenderbuffer); - LOAD_FBO_EXT(glGenRenderbuffers); - LOAD_FBO_EXT(glDeleteRenderbuffers); - LOAD_FBO_EXT(glRenderbufferStorage); - LOAD_FBO_EXT(glBindFramebuffer); - LOAD_FBO_EXT(glDeleteFramebuffers); - LOAD_FBO_EXT(glGenFramebuffers); - LOAD_FBO_EXT(glCheckFramebufferStatus); - LOAD_FBO_EXT(glFramebufferTexture1D); - LOAD_FBO_EXT(glFramebufferTexture2D); - LOAD_FBO_EXT(glFramebufferTexture3D); - LOAD_FBO_EXT(glFramebufferTexture); - LOAD_FBO_EXT(glFramebufferTextureLayer); - LOAD_FBO_EXT(glFramebufferRenderbuffer); - LOAD_FBO_EXT(glGenerateMipmap); - LOAD_FBO_EXT(glGetRenderbufferParameteriv); - - _supported = - glBindRenderbuffer != 0 && - glDeleteRenderbuffers != 0 && - glGenRenderbuffers != 0 && - glRenderbufferStorage != 0 && - glBindFramebuffer != 0 && - glDeleteFramebuffers != 0 && - glGenFramebuffers != 0 && - glCheckFramebufferStatus != 0 && - glFramebufferTexture2D != 0 && - glFramebufferRenderbuffer != 0 && - glGenerateMipmap != 0 && - glGetRenderbufferParameteriv != 0; - -#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) - _supported = _supported && - glFramebufferTexture1D != 0 && - glFramebufferTexture3D != 0 && - isGLExtensionOrVersionSupported(contextID, "GL_EXT_framebuffer_object",3.0f); -#endif - - LOAD_FBO_EXT(glBlitFramebuffer); - LOAD_FBO_EXT(glRenderbufferStorageMultisample); - LOAD_FBO_EXT(glRenderbufferStorageMultisampleCoverageNV); - - _packed_depth_stencil_supported = OSG_GL3_FEATURES || - (isGLExtensionSupported(contextID, "GL_EXT_packed_depth_stencil")) || - (isGLExtensionSupported(contextID, "GL_OES_packed_depth_stencil")); -} - /************************************************************************** * RenderBuffer @@ -149,8 +59,8 @@ void RenderBuffer::flushDeletedRenderBuffers(unsigned int contextID,double /*cur // if no time available don't try to flush objects. if (availableTime<=0.0) return; - const FBOExtensions* extensions = FBOExtensions::instance(contextID,true); - if(!extensions || !extensions->isSupported() ) return; + const GL2Extensions* extensions = GL2Extensions::Get(contextID,true); + if(!extensions || !extensions->isFrameBufferObjectSupported ) return; const osg::Timer& timer = *osg::Timer::instance(); osg::Timer_t start_tick = timer.tick(); @@ -219,13 +129,13 @@ RenderBuffer::~RenderBuffer() } } -int RenderBuffer::getMaxSamples(unsigned int contextID, const FBOExtensions *ext) +int RenderBuffer::getMaxSamples(unsigned int contextID, const GL2Extensions* ext) { static osg::buffered_value maxSamplesList; GLint& maxSamples = maxSamplesList[contextID]; - if (!maxSamples && ext->isMultisampleSupported()) + if (!maxSamples && ext->isMultisampleSupported) { glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples); } @@ -233,7 +143,7 @@ int RenderBuffer::getMaxSamples(unsigned int contextID, const FBOExtensions *ext return maxSamples; } -GLuint RenderBuffer::getObjectID(unsigned int contextID, const FBOExtensions *ext) const +GLuint RenderBuffer::getObjectID(unsigned int contextID, const GL2Extensions* ext) const { GLuint &objectID = _objectID[contextID]; @@ -261,7 +171,7 @@ GLuint RenderBuffer::getObjectID(unsigned int contextID, const FBOExtensions *ex const_cast(this)->setSamples(_colorSamples); } - if (_samples > 0 && ext->isMultisampleCoverageSupported()) + if (_samples > 0 && ext->isRenderbufferMultisampleCoverageSupported()) { int samples = minimum(_samples, getMaxSamples(contextID, ext)); int colorSamples = minimum(_colorSamples, samples); @@ -269,7 +179,7 @@ GLuint RenderBuffer::getObjectID(unsigned int contextID, const FBOExtensions *ex ext->glRenderbufferStorageMultisampleCoverageNV(GL_RENDERBUFFER_EXT, samples, colorSamples, _internalFormat, _width, _height); } - else if (_samples > 0 && ext->isMultisampleSupported()) + else if (_samples > 0 && ext->isRenderbufferMultisampleSupported()) { int samples = minimum(_samples, getMaxSamples(contextID, ext)); @@ -540,7 +450,7 @@ bool FrameBufferAttachment::isMultisample() const return false; } -void FrameBufferAttachment::createRequiredTexturesAndApplyGenerateMipMap(State &state, const FBOExtensions* ext) const +void FrameBufferAttachment::createRequiredTexturesAndApplyGenerateMipMap(State &state, const GL2Extensions* ext) const { unsigned int contextID = state.getContextID(); @@ -571,7 +481,7 @@ void FrameBufferAttachment::createRequiredTexturesAndApplyGenerateMipMap(State & } } -void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachment_point, const FBOExtensions* ext) const +void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachment_point, const GL2Extensions* ext) const { unsigned int contextID = state.getContextID(); @@ -731,8 +641,8 @@ void FrameBufferObject::flushDeletedFrameBufferObjects(unsigned int contextID,do // if no time available don't try to flush objects. if (availableTime<=0.0) return; - const FBOExtensions* extensions = FBOExtensions::instance(contextID,true); - if(!extensions || !extensions->isSupported() ) return; + const GL2Extensions* extensions = GL2Extensions::Get(contextID,true); + if(!extensions || !extensions->isFrameBufferObjectSupported ) return; const osg::Timer& timer = *osg::Timer::instance(); osg::Timer_t start_tick = timer.tick(); @@ -862,8 +772,8 @@ void FrameBufferObject::apply(State &state, BindTarget target) const return; - FBOExtensions* ext = FBOExtensions::instance(contextID,true); - if (!ext->isSupported()) + GL2Extensions* ext = state.get(); + if (!ext->isFrameBufferObjectSupported) { _unsupported[contextID] = 1; OSG_WARN << "Warning: EXT_framebuffer_object is not supported" << std::endl; @@ -938,7 +848,7 @@ void FrameBufferObject::apply(State &state, BindTarget target) const switch(i->first) { case(Camera::PACKED_DEPTH_STENCIL_BUFFER): - if (ext->isPackedDepthStencilSupported()) + if (ext->isPackedDepthStencilSupported) { fa.attach(state, target, GL_DEPTH_ATTACHMENT_EXT, ext); fa.attach(state, target, GL_STENCIL_ATTACHMENT_EXT, ext); diff --git a/src/osg/GL2Extensions.cpp b/src/osg/GL2Extensions.cpp index a2bb9e0ce..d2b6bd445 100644 --- a/src/osg/GL2Extensions.cpp +++ b/src/osg/GL2Extensions.cpp @@ -222,9 +222,6 @@ GL2Extensions::GL2Extensions(unsigned int contextID) // EXT_geometry_shader4 setGLExtensionFuncPtr(glProgramParameteri, "glProgramParameteri", "glProgramParameteriEXT" ); - setGLExtensionFuncPtr(glFramebufferTexture, "glFramebufferTexture", "glFramebufferTextureEXT" ); - setGLExtensionFuncPtr(glFramebufferTextureLayer, "glFramebufferTextureLayer", "glFramebufferTextureLayerEXT" ); - setGLExtensionFuncPtr(glFramebufferTextureFace, "glFramebufferTextureFace", "glFramebufferTextureFaceEXT" ); // ARB_tesselation_shader setGLExtensionFuncPtr(glPatchParameteri, "glPatchParameteri" ); @@ -612,6 +609,58 @@ GL2Extensions::GL2Extensions(unsigned int contextID) setGLExtensionFuncPtr(glSampleCoverage, "glSampleCoverageARB"); + + // FrameBufferObject + setGLExtensionFuncPtr(glBindRenderbuffer, "glBindRenderbuffer", "glBindRenderbufferEXT", "glBindRenderbufferOES"); + setGLExtensionFuncPtr(glDeleteRenderbuffers, "glDeleteRenderbuffers", "glDeleteRenderbuffersEXT", "glDeleteRenderbuffersOES"); + setGLExtensionFuncPtr(glGenRenderbuffers, "glGenRenderbuffers", "glGenRenderbuffersEXT", "glGenRenderbuffersOES"); + setGLExtensionFuncPtr(glRenderbufferStorage, "glRenderbufferStorage", "glRenderbufferStorageEXT", "glRenderbufferStorageOES"); + setGLExtensionFuncPtr(glRenderbufferStorageMultisample, "glRenderbufferStorageMultisample", "glRenderbufferStorageMultisampleEXT", "glRenderbufferStorageMultisampleOES"); + setGLExtensionFuncPtr(glRenderbufferStorageMultisampleCoverageNV, "glRenderbufferStorageMultisampleCoverageNV"); + setGLExtensionFuncPtr(glBindFramebuffer, "glBindFramebuffer", "glBindFramebufferEXT", "glBindFramebufferOES"); + setGLExtensionFuncPtr(glDeleteFramebuffers, "glDeleteFramebuffers", "glDeleteFramebuffersEXT", "glDeleteFramebuffersOES"); + setGLExtensionFuncPtr(glGenFramebuffers, "glGenFramebuffers", "glGenFramebuffersEXT", "glGenFramebuffersOES"); + setGLExtensionFuncPtr(glCheckFramebufferStatus, "glCheckFramebufferStatus", "glCheckFramebufferStatusEXT", "glCheckFramebufferStatusOES"); + + setGLExtensionFuncPtr(glFramebufferTexture1D, "glFramebufferTexture1D", "glFramebufferTexture1DEXT", "glFramebufferTexture1DOES"); + setGLExtensionFuncPtr(glFramebufferTexture2D, "glFramebufferTexture2D", "glFramebufferTexture2DEXT", "glFramebufferTexture2DOES"); + setGLExtensionFuncPtr(glFramebufferTexture3D, "glFramebufferTexture3D", "glFramebufferTexture3DEXT", "glFramebufferTexture3DOES"); + setGLExtensionFuncPtr(glFramebufferTexture, "glFramebufferTexture", "glFramebufferTextureEXT", "glFramebufferTextureOES"); + setGLExtensionFuncPtr(glFramebufferTextureLayer, "glFramebufferTextureLayer", "glFramebufferTextureLayerEXT", "glFramebufferTextureLayerOES"); + setGLExtensionFuncPtr(glFramebufferTextureFace, "glFramebufferTextureFace", "glFramebufferTextureFaceEXT", "glFramebufferTextureFaceOES" ); + setGLExtensionFuncPtr(glFramebufferRenderbuffer, "glFramebufferRenderbuffer", "glFramebufferRenderbufferEXT", "glFramebufferRenderbufferOES"); + + setGLExtensionFuncPtr(glGenerateMipmap, "glGenerateMipmap", "glGenerateMipmapEXT", "glGenerateMipmapOES"); + setGLExtensionFuncPtr(glBlitFramebuffer, "glBlitFramebuffer", "glBlitFramebufferEXT", "glBlitFramebufferOES"); + setGLExtensionFuncPtr(glGetRenderbufferParameteriv, "glGetRenderbufferParameteriv", "glGetRenderbufferParameterivEXT", "glGetRenderbufferParameterivOES"); + + isFrameBufferObjectSupported = + glBindRenderbuffer != 0 && + glDeleteRenderbuffers != 0 && + glGenRenderbuffers != 0 && + glRenderbufferStorage != 0 && + glBindFramebuffer != 0 && + glDeleteFramebuffers != 0 && + glGenFramebuffers != 0 && + glCheckFramebufferStatus != 0 && + glFramebufferTexture2D != 0 && + glFramebufferRenderbuffer != 0 && + glGenerateMipmap != 0 && + glGetRenderbufferParameteriv != 0; + + isPackedDepthStencilSupported = OSG_GL3_FEATURES || + (isGLExtensionSupported(contextID, "GL_EXT_packed_depth_stencil")) || + (isGLExtensionSupported(contextID, "GL_OES_packed_depth_stencil")); + + + // Sync + osg::setGLExtensionFuncPtr(glFenceSync, "glFenceSync"); + osg::setGLExtensionFuncPtr(glIsSync, "glIsSync"); + osg::setGLExtensionFuncPtr(glDeleteSync, "glDeleteSync"); + osg::setGLExtensionFuncPtr(glClientWaitSync, "glClientWaitSync"); + osg::setGLExtensionFuncPtr(glWaitSync, "glWaitSync"); + osg::setGLExtensionFuncPtr(glGetSynciv, "glGetSynciv"); + } diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index df8e75512..b1dbd7eff 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -982,30 +982,9 @@ void GraphicsContext::resizedImplementation(int x, int y, int width, int height) // // SyncSwapBuffersCallback // -SyncSwapBuffersCallback::SyncSwapBuffersCallback(): - _extensionInitialized(false), - _glFenceSync(0), - _glIsSync(0), - _glDeleteSync(0), - _glClientWaitSync(0), - _glWaitSync(0), - _glGetInteger64v(0), - _glGetSynciv(0), - _previousSync(0) +SyncSwapBuffersCallback::SyncSwapBuffersCallback() { - OSG_NOTICE<<"Created Swap callback."<swapBuffersImplementation(); //glFinish(); - if (!_extensionInitialized) setUpExtensions(); + GL2Extensions* ext = gc->getState()->get(); - if (_glClientWaitSync) + if (ext->glClientWaitSync) { if (_previousSync) { unsigned int num_seconds = 1; GLuint64 timeout = num_seconds * ((GLuint64)1000 * 1000 * 1000); - _glClientWaitSync(_previousSync, 0, timeout); - - _glDeleteSync(_previousSync); + ext->glClientWaitSync(_previousSync, 0, timeout); + ext->glDeleteSync(_previousSync); } - _previousSync = _glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + _previousSync = ext->glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } //gc->getState()->checkGLErrors("after glWaitSync"); diff --git a/src/osg/OcclusionQueryNode.cpp b/src/osg/OcclusionQueryNode.cpp index 7a94aa180..180795cd3 100644 --- a/src/osg/OcclusionQueryNode.cpp +++ b/src/osg/OcclusionQueryNode.cpp @@ -129,13 +129,13 @@ struct RetrieveQueriesCallback : public osg::Camera::DrawCallback { // No valid GraphicsContext in the Camera. This might happen in // SceneView-based apps. Rely on the creating code to have passed - // in a valid Extensions pointer, and hope it's valid for any + // in a valid GL2Extensions pointer, and hope it's valid for any // context that might be current. - OSG_DEBUG << "osgOQ: RQCB: Using fallback path to obtain Extensions pointer." << std::endl; + OSG_DEBUG << "osgOQ: RQCB: Using fallback path to obtain GL2Extensions pointer." << std::endl; ext = _extensionsFallback; if (!ext) { - OSG_FATAL << "osgOQ: RQCB: Extensions pointer fallback is NULL." << std::endl; + OSG_FATAL << "osgOQ: RQCB: GL2Extensions pointer fallback is NULL." << std::endl; return; } } diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index c876daf06..b759c35cf 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -2671,17 +2671,13 @@ bool Texture::isHardwareMipmapGenerationEnabled(const State& state) const { if (_useHardwareMipMapGeneration) { - unsigned int contextID = state.getContextID(); const GL2Extensions* extensions = state.get(); - if (extensions->isGenerateMipMapSupported) { return true; } - const FBOExtensions* fbo_ext = FBOExtensions::instance(contextID,true); - - if (fbo_ext->isSupported() && fbo_ext->glGenerateMipmap) + if (extensions->glGenerateMipmap) { return true; } @@ -2698,13 +2694,12 @@ Texture::GenerateMipmapMode Texture::mipmapBeforeTexImage(const State& state, bo return GENERATE_MIPMAP; #else - FBOExtensions* fbo_ext = FBOExtensions::instance(state.getContextID(),true); - const GL2Extensions* tex_ext = state.get(); - bool useGenerateMipMap = fbo_ext->isSupported() && fbo_ext->glGenerateMipmap; + const GL2Extensions* extensions = state.get(); + bool useGenerateMipMap = extensions->glGenerateMipmap; if (useGenerateMipMap) { - if (tex_ext->preferGenerateMipmapSGISForPowerOfTwo) + if (extensions->preferGenerateMipmapSGISForPowerOfTwo) { int width = getTextureWidth(); int height = getTextureHeight(); @@ -2736,8 +2731,8 @@ void Texture::mipmapAfterTexImage(State& state, GenerateMipmapMode beforeResult) TextureObject* textureObject = getTextureObject(contextID); if (textureObject) { - osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(contextID, true); - fbo_ext->glGenerateMipmap(textureObject->target()); + osg::GL2Extensions* ext = state.get(); + ext->glGenerateMipmap(textureObject->target()); } break; } @@ -2769,13 +2764,13 @@ void Texture::generateMipmap(State& state) const } // get fbo extension which provides us with the glGenerateMipmapEXT function - osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(state.getContextID(), true); + osg::GL2Extensions* ext = state.get(); // check if the function is supported - if (fbo_ext->isSupported() && fbo_ext->glGenerateMipmap) + if (ext->glGenerateMipmap) { textureObject->bind(); - fbo_ext->glGenerateMipmap(textureObject->target()); + ext->glGenerateMipmap(textureObject->target()); // inform state that this texture is the current one bound. state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); @@ -2818,144 +2813,4 @@ void Texture::releaseGLObjects(State* state) const } } -#if 0 -Texture::Extensions* Texture::getExtensions(unsigned int contextID,bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); - return s_extensions[contextID].get(); -} - -void Texture::setExtensions(unsigned int contextID,Extensions* extensions) -{ - s_extensions[contextID] = extensions; -} - -Texture::Extensions::Extensions(unsigned int contextID) -{ - const char* version = (const char*) glGetString( GL_VERSION ); - if (!version) - { - OSG_FATAL<<"Error: In Texture::Extensions::setupGLExtensions(..) OpenGL version test failed, requires valid graphics context."<= 1.2f ); - - _isTextureStorageEnabled = isTexStorage2DSupported(); - if ( (ptr = getenv("OSG_GL_TEXTURE_STORAGE")) != 0 && isTexStorage2DSupported()) - { - if (strcmp(ptr,"OFF")==0 || strcmp(ptr,"DISABLE")==0 ) _isTextureStorageEnabled = false; - else _isTextureStorageEnabled = true; - } - - OSG_DEBUG<<"Texture::Extensions::Extensionts() _isTextureStorageEnabled = "<<_isTextureStorageEnabled< > BufferedExtensions; -static BufferedExtensions s_extensions; - -Texture3D::Extensions* Texture3D::getExtensions(unsigned int contextID,bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); - return s_extensions[contextID].get(); -} - -void Texture3D::setExtensions(unsigned int contextID,Extensions* extensions) -{ - s_extensions[contextID] = extensions; -} - -#ifndef GL_MAX_3D_TEXTURE_SIZE -#define GL_MAX_3D_TEXTURE_SIZE 0x8073 -#endif - -Texture3D::Extensions::Extensions(unsigned int contextID) -{ - setupGLExtensions(contextID); -} - -Texture3D::Extensions::Extensions(const Extensions& rhs): - Referenced() -{ - _isTexture3DSupported = rhs._isTexture3DSupported; - _isTexture3DFast = rhs._isTexture3DFast; - _maxTexture3DSize = rhs._maxTexture3DSize; - - glTexImage3D = rhs.glTexImage3D; - glTexSubImage3D = rhs.glTexSubImage3D; - glCompressedTexImage3D = rhs.glCompressedTexImage3D; - glCompressedTexSubImage3D = rhs.glCompressedTexSubImage3D; - glCopyTexSubImage3D = rhs.glCopyTexSubImage3D; -} - -void Texture3D::Extensions::lowestCommonDenominator(const Extensions& rhs) -{ - if (!rhs._isTexture3DSupported) _isTexture3DSupported = false; - if (!rhs._isTexture3DFast) _isTexture3DFast = false; - if (rhs._maxTexture3DSize<_maxTexture3DSize) _maxTexture3DSize = rhs._maxTexture3DSize; - - if (!rhs.glTexImage3D) glTexImage3D = 0; - if (!rhs.glTexSubImage3D) glTexSubImage3D = 0; - if (!rhs.glCompressedTexImage3D) glCompressedTexImage3D = 0; - if (!rhs.glCompressedTexSubImage3D) glCompressedTexSubImage3D = 0; - if (!rhs.glCopyTexSubImage3D) glCopyTexSubImage3D = 0; -} - -void Texture3D::Extensions::setupGLExtensions(unsigned int contextID) -{ - _isTexture3DFast = OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture3D"); - - if (_isTexture3DFast) _isTexture3DSupported = true; - else _isTexture3DSupported = strncmp((const char*)glGetString(GL_VERSION),"1.2",3)>=0; - - _maxTexture3DSize = 0; - glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &_maxTexture3DSize); - - setGLExtensionFuncPtr(glTexImage3D,"glTexImage3D","glTexImage3DEXT"); - setGLExtensionFuncPtr(glTexSubImage3D,"glTexSubImage3D","glTexSubImage3DEXT"); - setGLExtensionFuncPtr(glCompressedTexImage3D,"glCompressedTexImage3D","glCompressedTexImage3DARB"); - setGLExtensionFuncPtr(glCompressedTexSubImage3D,"glCompressedTexSubImage3D","glCompressedTexSubImage3DARB"); - setGLExtensionFuncPtr(glCopyTexSubImage3D,"glCopyTexSubImage3D","glCopyTexSubImage3DEXT"); - -} -#endif diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index f2f57f091..405dde7ff 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -499,24 +499,6 @@ void TextureRectangle::copyTexImage2D(State& state, int x, int y, int width, int applyTexParameters(GL_TEXTURE_RECTANGLE,state); - -/* bool needHardwareMipMap = (_min_filter != LINEAR && _min_filter != NEAREST); - bool hardwareMipMapOn = false; - if (needHardwareMipMap) - { - const Extensions* extensions = getExtensions(contextID,true); - bool generateMipMapSupported = extensions->isGenerateMipMapSupported(); - - hardwareMipMapOn = _useHardwareMipMapGeneration && generateMipMapSupported; - - if (!hardwareMipMapOn) - { - // have to swtich off mip mapping - OSG_NOTICE<<"Warning: Texture2D::copyTexImage2D(,,,,) switch of mip mapping as hardware support not available."<isGenerateMipMapSupported(); - - hardwareMipMapOn = _useHardwareMipMapGeneration && generateMipMapSupported; - - if (!hardwareMipMapOn) - { - // have to swtich off mip mapping - OSG_NOTICE<<"Warning: Texture2D::copyTexImage2D(,,,,) switch of mip mapping as hardware support not available."<isSupported(); + osg::GL2Extensions* ext = state.get(); + bool fbo_supported = ext->isFrameBufferObjectSupported; if (fbo_supported) { @@ -362,7 +362,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) unsigned int renderBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true); unsigned int resolveBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true); - if (fbo_ext->isMultisampleSupported()) + if (ext->isRenderbufferMultisampleSupported()) { for(osg::Camera::BufferAttachmentMap::iterator itr = bufferAttachments.begin(); itr != bufferAttachments.end(); @@ -518,7 +518,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) #endif } - GLenum status = fbo_ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); + GLenum status = ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -526,7 +526,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) fbo_supported = false; GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0; - fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); + ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); fbo = 0; // clean up. @@ -548,7 +548,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) { fbo_multisample->apply(state); - GLenum status = fbo_ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); + GLenum status = ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -903,8 +903,8 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b osg::State& state = *renderInfo.getState(); - osg::FBOExtensions* fbo_ext = _fbo.valid() ? osg::FBOExtensions::instance(state.getContextID(),true) : 0; - bool fbo_supported = fbo_ext && fbo_ext->isSupported(); + osg::GL2Extensions* ext = _fbo.valid() ? state.get() : 0; + bool fbo_supported = ext && ext->isFrameBufferObjectSupported; bool using_multiple_render_targets = fbo_supported && _fbo->hasMultipleRenderingTargets(); @@ -934,9 +934,9 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b { if (state.checkGLErrors("after RenderBin::draw(..)")) { - if ( fbo_ext ) + if ( ext ) { - GLenum fbstatus = fbo_ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); + GLenum fbstatus = ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); if ( fbstatus != GL_FRAMEBUFFER_COMPLETE_EXT ) { OSG_NOTICE<<"RenderStage::drawInner(,) FBO status = 0x"<glBlitFramebuffer) + if (fbo_supported && _resolveFbo.valid() && ext->glBlitFramebuffer) { GLbitfield blitMask = 0; bool needToBlitColorBuffers = false; @@ -988,7 +988,7 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b // Note that (with nvidia 175.16 windows drivers at least) if the read // framebuffer is multisampled then the dimension arguments are ignored // and the whole framebuffer is always copied. - fbo_ext->glBlitFramebuffer( + ext->glBlitFramebuffer( static_cast(_viewport->x()), static_cast(_viewport->y()), static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), static_cast(_viewport->x()), static_cast(_viewport->y()), @@ -1009,7 +1009,7 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); - fbo_ext->glBlitFramebuffer( + ext->glBlitFramebuffer( static_cast(_viewport->x()), static_cast(_viewport->y()), static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), static_cast(_viewport->x()), static_cast(_viewport->y()), @@ -1088,7 +1088,7 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b { // switch off the frame buffer object GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0; - fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); + ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); } doCopyTexture = true; @@ -1106,7 +1106,7 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b { state.setActiveTextureUnit(0); state.applyTextureAttribute(0, itr->second._texture.get()); - fbo_ext->glGenerateMipmap(itr->second._texture->getTextureTarget()); + ext->glGenerateMipmap(itr->second._texture->getTextureTarget()); } } }