Moved FBO Extensions into GL2Extensions.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14586 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2014-12-09 18:30:28 +00:00
parent d5fcdabfa1
commit 43049ebcf1
14 changed files with 217 additions and 749 deletions

View File

@ -132,10 +132,10 @@ void getPossibleConfigs(GraphicsContext* gc, BufferConfigList& colorConfigs,
unsigned contextID = gc->getState()->getContextID(); unsigned contextID = gc->getState()->getContextID();
colorConfigs.push_back(BufferConfig("RGBA8", GL_RGBA8, 8)); colorConfigs.push_back(BufferConfig("RGBA8", GL_RGBA8, 8));
depthConfigs.push_back(BufferConfig("D24", GL_DEPTH_COMPONENT24, 24)); depthConfigs.push_back(BufferConfig("D24", GL_DEPTH_COMPONENT24, 24));
FBOExtensions* fboe = FBOExtensions::instance(contextID, true); osg::GL2Extensions* ext = gc->getState()->get<GL2Extensions>();
if (!fboe->isSupported()) if (!ext->isRenderbufferMultisampleSupported())
return; return;
if (fboe->isMultisampleSupported()) if (ext->isMultisampleSupported)
glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples); glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples);
// isMultisampleCoverageSupported // isMultisampleCoverageSupported
if (isGLExtensionSupported(contextID, if (isGLExtensionSupported(contextID,
@ -156,9 +156,8 @@ void getPossibleConfigs(GraphicsContext* gc, BufferConfigList& colorConfigs,
bool checkFramebufferStatus(GraphicsContext* gc, bool silent = false) bool checkFramebufferStatus(GraphicsContext* gc, bool silent = false)
{ {
State& state = *gc->getState(); State& state = *gc->getState();
unsigned contextID = state.getContextID(); osg::GL2Extensions* ext = gc->getState()->get<GL2Extensions>();
FBOExtensions* fboe = FBOExtensions::instance(contextID, true); switch(ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT)) {
switch(fboe->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT)) {
case GL_FRAMEBUFFER_COMPLETE_EXT: case GL_FRAMEBUFFER_COMPLETE_EXT:
break; break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT: case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
@ -242,30 +241,30 @@ bool createFBO(GraphicsContext* gc, FboConfig &config, FboData &data)
} }
State& state = *gc->getState(); State& state = *gc->getState();
unsigned int contextID = state.getContextID(); unsigned int contextID = state.getContextID();
FBOExtensions* fboe = FBOExtensions::instance(contextID, true); osg::GL2Extensions* ext = gc->getState()->get<GL2Extensions>();
data.fb->apply(state); data.fb->apply(state);
result = checkFramebufferStatus(gc, true); result = checkFramebufferStatus(gc, true);
if (!result) if (!result)
{ {
fboe->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
return false; return false;
} }
int query; int query;
if (multisample) if (multisample)
{ {
GLuint colorRBID = colorRB->getObjectID(contextID, fboe); GLuint colorRBID = colorRB->getObjectID(contextID, ext);
fboe->glBindRenderbuffer(GL_RENDERBUFFER_EXT, colorRBID); ext->glBindRenderbuffer(GL_RENDERBUFFER_EXT, colorRBID);
if (csaa) if (csaa)
{ {
fboe->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, ext->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
GL_RENDERBUFFER_COVERAGE_SAMPLES_NV, GL_RENDERBUFFER_COVERAGE_SAMPLES_NV,
&query); &query);
if (query < config.coverageSamples) if (query < config.coverageSamples)
result = false; result = false;
else else
config.coverageSamples = query; config.coverageSamples = query;
fboe->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, ext->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
GL_RENDERBUFFER_COLOR_SAMPLES_NV, GL_RENDERBUFFER_COLOR_SAMPLES_NV,
&query); &query);
@ -277,7 +276,7 @@ bool createFBO(GraphicsContext* gc, FboConfig &config, FboData &data)
} }
else else
{ {
fboe->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, ext->glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
GL_RENDERBUFFER_SAMPLES_EXT, GL_RENDERBUFFER_SAMPLES_EXT,
&query); &query);
if (query < config.depthSamples) if (query < config.depthSamples)
@ -303,7 +302,7 @@ bool createFBO(GraphicsContext* gc, FboConfig &config, FboData &data)
result = false; result = false;
} }
} }
fboe->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
return result; return result;
} }
@ -696,15 +695,15 @@ GraphicsContext* setupGC(osgViewer::Viewer& viewer, ArgumentParser& arguments)
DisplaySettings* ds = viewer.getDisplaySettings() ? viewer.getDisplaySettings() : DisplaySettings::instance().get(); DisplaySettings* ds = viewer.getDisplaySettings() ? viewer.getDisplaySettings() : DisplaySettings::instance().get();
GraphicsContext::ScreenIdentifier si; GraphicsContext::ScreenIdentifier si;
si.readDISPLAY(); si.readDISPLAY();
si.setUndefinedScreenDetailsToDefaultScreen();
// displayNum has not been set so reset it to 0.
if (si.displayNum<0) si.displayNum = 0;
bool decoration = true; bool decoration = true;
if (x < 0) if (x < 0)
{ {
unsigned int w, h; unsigned int w, h;
wsi->getScreenResolution(si, w, h); wsi->getScreenResolution(si, w, h);
OSG_NOTICE<<"Screen resolution is "<<w<<", "<<h<<std::endl;
OSG_NOTICE<<"ScreenIdentifier "<<si.displayNum<<", "<<si.screenNum<<std::endl;
x = 0; x = 0;
y = 0; y = 0;
width = w; width = w;
@ -712,8 +711,9 @@ GraphicsContext* setupGC(osgViewer::Viewer& viewer, ArgumentParser& arguments)
decoration = false; decoration = false;
} }
ref_ptr<GraphicsContext::Traits> traits OSG_NOTICE<<"x = "<<x<<", y = "<<y<<", width = "<<width<<", height = "<<height<<std::endl;
= new GraphicsContext::Traits(ds);
ref_ptr<GraphicsContext::Traits> traits = new GraphicsContext::Traits(ds);
traits->hostName = si.hostName; traits->hostName = si.hostName;
traits->displayNum = si.displayNum; traits->displayNum = si.displayNum;
traits->screenNum = si.screenNum; traits->screenNum = si.screenNum;
@ -724,10 +724,9 @@ GraphicsContext* setupGC(osgViewer::Viewer& viewer, ArgumentParser& arguments)
traits->windowDecoration = decoration; traits->windowDecoration = decoration;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
ref_ptr<GraphicsContext> gc
= GraphicsContext::createGraphicsContext(traits.get()); ref_ptr<GraphicsContext> gc = GraphicsContext::createGraphicsContext(traits.get());
osgViewer::GraphicsWindow* gw osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
= dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
if (gw) if (gw)
{ {
OSG_NOTIFY(INFO)<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<<std::endl; OSG_NOTIFY(INFO)<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<<std::endl;
@ -750,20 +749,29 @@ GraphicsContext* setupGC(osgViewer::Viewer& viewer, ArgumentParser& arguments)
} }
// Context has to be current to test for extensions // Context has to be current to test for extensions
gc->realize(); gc->realize();
gc->makeCurrent(); if (!gc->makeCurrent())
{
OSG_NOTIFY(NOTICE) << "Unable to create GraphicsWindow"<<std::endl;
gc->releaseContext();
gc->close(true);
return 0;
}
unsigned int contextID = gc->getState()->getContextID(); unsigned int contextID = gc->getState()->getContextID();
FBOExtensions* fboe = FBOExtensions::instance(contextID, true); osg::GL2Extensions* ext = gc->getState()->get<GL2Extensions>();
if (!fboe->isSupported()) if (!ext->isFrameBufferObjectSupported)
{ {
OSG_NOTIFY(NOTICE) << "Frame buffer objects are not supported\n"; OSG_NOTIFY(NOTICE) << "Frame buffer objects are not supported\n";
gc->releaseContext(); gc->releaseContext();
gc->close(true); gc->close(true);
return 0; return 0;
} }
if (isGLExtensionSupported(contextID, "GL_ARB_depth_buffer_float")) if (isGLExtensionSupported(contextID, "GL_ARB_depth_buffer_float"))
depthTextureEnum = GL_DEPTH_COMPONENT32F; depthTextureEnum = GL_DEPTH_COMPONENT32F;
else if (isGLExtensionSupported(contextID, "GL_NV_depth_buffer_float")) else if (isGLExtensionSupported(contextID, "GL_NV_depth_buffer_float"))
depthTextureEnum = GL_DEPTH_COMPONENT32F_NV; depthTextureEnum = GL_DEPTH_COMPONENT32F_NV;
BufferConfigList colorConfigs; BufferConfigList colorConfigs;
BufferConfigList depthConfigs; BufferConfigList depthConfigs;
vector<int> coverageConfigs; vector<int> coverageConfigs;

View File

@ -86,9 +86,9 @@ public:
// check if we need to do some depth buffer copying from a source FBO into the current FBO // check if we need to do some depth buffer copying from a source FBO into the current FBO
if (_source_fbo.get() != NULL) if (_source_fbo.get() != NULL)
{ {
osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(renderInfo.getContextID(),true); osg::GL2Extensions* ext = renderInfo.getState()->get<osg::GL2Extensions>();
bool fbo_supported = fbo_ext && fbo_ext->isSupported(); bool fbo_supported = ext && ext->isFrameBufferObjectSupported;
if (fbo_supported && fbo_ext->glBlitFramebuffer) if (fbo_supported && ext->glBlitFramebuffer)
{ {
// blit the depth buffer from the solid geometry fbo into the current transparency fbo // blit the depth buffer from the solid geometry fbo into the current transparency fbo
(_fbo.get())->apply(*renderInfo.getState(), osg::FrameBufferObject::DRAW_FRAMEBUFFER); (_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 // glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); // only needed to blit the color buffer
// glDrawBuffer(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<GLint>(_width), static_cast<GLint>(_height), 0, 0, static_cast<GLint>(_width), static_cast<GLint>(_height),
0, 0, static_cast<GLint>(_width), static_cast<GLint>(_height), 0, 0, static_cast<GLint>(_width), static_cast<GLint>(_height),
#ifdef USE_PACKED_DEPTH_STENCIL #ifdef USE_PACKED_DEPTH_STENCIL
@ -130,7 +130,9 @@ public:
{ {
// only unbind the fbo if this is the last transparency pass // only unbind the fbo if this is the last transparency pass
if (_restore) if (_restore)
osg::FBOExtensions::instance( renderInfo.getState()->getContextID(), false )->glBindFramebuffer( GL_FRAMEBUFFER_EXT, 0 ); {
renderInfo.getState()->get<osg::GL2Extensions>()->glBindFramebuffer( GL_FRAMEBUFFER_EXT, 0 );
}
} }
protected: protected:
bool _restore; bool _restore;

View File

@ -119,73 +119,12 @@
namespace osg 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 * RenderBuffer
**************************************************************************/ **************************************************************************/
class OSG_EXPORT RenderBuffer: public Object class OSG_EXPORT RenderBuffer: public Object
{ {
public: public:
RenderBuffer(); RenderBuffer();
RenderBuffer(int width, int height, GLenum internalFormat, int samples=0, int colorSamples=0); 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 setSamples(int samples);
inline void setColorSamples(int colorSamples); 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; inline int compare(const RenderBuffer &rb) const;
/** Mark internal RenderBuffer for deletion. /** Mark internal RenderBuffer for deletion.
@ -222,7 +161,7 @@ namespace osg
* this call is useful for when an OpenGL context has been destroyed. */ * this call is useful for when an OpenGL context has been destroyed. */
static void discardDeletedRenderBuffers(unsigned int contextID); 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. */ /** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize); virtual void resizeGLObjectBuffers(unsigned int maxSize);
@ -335,16 +274,16 @@ namespace osg
/************************************************************************** /**************************************************************************
* FrameBufferAttachement * FrameBufferAttachement
**************************************************************************/ **************************************************************************/
class Texture1D; class Texture1D;
class Texture2D; class Texture2D;
class Texture2DMultisample; class Texture2DMultisample;
class Texture3D; class Texture3D;
class Texture2DArray; class Texture2DArray;
class TextureCubeMap; class TextureCubeMap;
class TextureRectangle; class TextureRectangle;
class OSG_EXPORT FrameBufferAttachment class OSG_EXPORT FrameBufferAttachment
{ {
public: public:
FrameBufferAttachment(); FrameBufferAttachment();
FrameBufferAttachment(const FrameBufferAttachment& copy); FrameBufferAttachment(const FrameBufferAttachment& copy);
@ -364,8 +303,8 @@ namespace osg
FrameBufferAttachment&operator = (const FrameBufferAttachment& copy); FrameBufferAttachment&operator = (const FrameBufferAttachment& copy);
bool isMultisample() const; bool isMultisample() const;
void createRequiredTexturesAndApplyGenerateMipMap(State& state, const FBOExtensions* ext) const; void createRequiredTexturesAndApplyGenerateMipMap(State& state, const GL2Extensions* ext) const;
void attach(State &state, GLenum target, GLenum attachment_point, const FBOExtensions* ext) const; void attach(State &state, GLenum target, GLenum attachment_point, const GL2Extensions* ext) const;
int compare(const FrameBufferAttachment &fa) const; int compare(const FrameBufferAttachment &fa) const;
RenderBuffer* getRenderBuffer(); RenderBuffer* getRenderBuffer();
@ -389,8 +328,8 @@ namespace osg
/************************************************************************** /**************************************************************************
* FrameBufferObject * FrameBufferObject
**************************************************************************/ **************************************************************************/
class OSG_EXPORT FrameBufferObject: public StateAttribute class OSG_EXPORT FrameBufferObject: public StateAttribute
{ {
public: public:
typedef std::map<Camera::BufferComponent, FrameBufferAttachment> AttachmentMap; typedef std::map<Camera::BufferComponent, FrameBufferAttachment> AttachmentMap;
typedef std::vector<GLenum> MultipleRenderingTargets; typedef std::vector<GLenum> MultipleRenderingTargets;

View File

@ -534,6 +534,24 @@ typedef char GLchar;
#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 #define GL_MAP_UNSYNCHRONIZED_BIT 0x0020
#endif #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, // 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 //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 //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 * 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 * glUniformMatrix4x3fv)( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
void (GL_APIENTRY * glProgramParameteri)( GLuint program, GLenum pname, GLint 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 * glPatchParameteri)( GLenum pname, GLint value );
void (GL_APIENTRY * glPatchParameterfv)( GLenum pname, const GLfloat* values ); void (GL_APIENTRY * glPatchParameterfv)( GLenum pname, const GLfloat* values );
void (GL_APIENTRY * glGetUniformuiv)( GLuint program, GLint location, GLuint* params ); 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); void (GL_APIENTRY * glSampleCoverage) (GLclampf value, GLboolean invert);
// Point // Point
bool isPointParametersSupported; bool isPointParametersSupported;
bool isPointSpriteSupported; bool isPointSpriteSupported;
@ -969,6 +985,46 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced
void (GL_APIENTRY * glPointParameterf) (GLenum pname, GLfloat param); void (GL_APIENTRY * glPointParameterf) (GLenum pname, GLfloat param);
void (GL_APIENTRY * glPointParameterfv) (GLenum pname, const GLfloat *params); 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);
}; };
} }

View File

@ -533,53 +533,16 @@ class OSG_EXPORT GraphicsContext : public Object
//#include <osg/GLExtensions> //#include <osg/GLExtensions>
#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 class OSG_EXPORT SyncSwapBuffersCallback : public GraphicsContext::SwapCallback
{ {
public: public:
SyncSwapBuffersCallback(); SyncSwapBuffersCallback();
void setUpExtensions();
virtual void swapBuffersImplementation(GraphicsContext* gc); virtual void swapBuffersImplementation(GraphicsContext* gc);
typedef struct __GLsync *GLsync; 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; GLsync _previousSync;
}; };

View File

@ -264,193 +264,6 @@ void GLBufferObject::setBufferDataHasBeenRead(const osg::BufferData* bd)
++entry.numRead; ++entry.numRead;
} }
#if 0
//////////////////////////////////////////////////////////////////////////////
//
// Extension support
//
typedef buffered_value< ref_ptr<GLBufferObject::Extensions> > 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"<<std::endl;
}
void GLBufferObject::Extensions::glBindBuffer(GLenum target, GLuint buffer) const
{
if (_glBindBuffer) _glBindBuffer(target, buffer);
else OSG_WARN<<"Error: glBindBuffer not supported by OpenGL driver"<<std::endl;
}
void GLBufferObject::Extensions::glBufferData(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) const
{
if (_glBufferData) _glBufferData(target, size, data, usage);
else OSG_WARN<<"Error: glBufferData not supported by OpenGL driver"<<std::endl;
}
void GLBufferObject::Extensions::glBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data) const
{
if (_glBufferSubData) _glBufferSubData(target, offset, size, data);
else OSG_WARN<<"Error: glBufferData not supported by OpenGL driver"<<std::endl;
}
void GLBufferObject::Extensions::glDeleteBuffers(GLsizei n, const GLuint *buffers) const
{
if (_glDeleteBuffers) _glDeleteBuffers(n, buffers);
else OSG_WARN<<"Error: glBufferData not supported by OpenGL driver"<<std::endl;
}
GLboolean GLBufferObject::Extensions::glIsBuffer (GLuint buffer) const
{
if (_glIsBuffer) return _glIsBuffer(buffer);
else
{
OSG_WARN<<"Error: glIsBuffer not supported by OpenGL driver"<<std::endl;
return GL_FALSE;
}
}
void GLBufferObject::Extensions::glGetBufferSubData (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data) const
{
if (_glGetBufferSubData) _glGetBufferSubData(target,offset,size,data);
else OSG_WARN<<"Error: glGetBufferSubData not supported by OpenGL driver"<<std::endl;
}
GLvoid* GLBufferObject::Extensions::glMapBuffer (GLenum target, GLenum access) const
{
if (_glMapBuffer) return _glMapBuffer(target,access);
else
{
OSG_WARN<<"Error: glMapBuffer not supported by OpenGL driver"<<std::endl;
return 0;
}
}
GLboolean GLBufferObject::Extensions::glUnmapBuffer (GLenum target) const
{
if (_glUnmapBuffer) return _glUnmapBuffer(target);
else
{
OSG_WARN<<"Error: glUnmapBuffer not supported by OpenGL driver"<<std::endl;
return GL_FALSE;
}
}
void GLBufferObject::Extensions::glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params) const
{
if (_glGetBufferParameteriv) _glGetBufferParameteriv(target,pname,params);
else OSG_WARN<<"Error: glGetBufferParameteriv not supported by OpenGL driver"<<std::endl;
}
void GLBufferObject::Extensions::glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params) const
{
if (_glGetBufferPointerv) _glGetBufferPointerv(target,pname,params);
else OSG_WARN<<"Error: glGetBufferPointerv not supported by OpenGL driver"<<std::endl;
}
void GLBufferObject::Extensions::glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
{
if (_glBindBufferRange) _glBindBufferRange(target, index, buffer, offset, size);
else OSG_WARN<<"Error: glBindBufferRange not supported by OpenGL driver\n";
}
void GLBufferObject::Extensions::glBindBufferBase (GLenum target, GLuint index, GLuint buffer)
{
if (_glBindBufferBase) _glBindBufferBase(target, index, buffer);
else OSG_WARN<<"Error: glBindBufferBase not supported by OpenGL driver\n";
}
void GLBufferObject::Extensions::glTexBuffer( GLenum target, GLenum internalFormat, GLuint buffer ) const
{
if ( _glTexBuffer ) _glTexBuffer( target, internalFormat, buffer );
else OSG_WARN<<"Error: glTexBuffer not supported by OpenGL driver\n";
}
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// GLBufferObjectSet // GLBufferObjectSet

View File

@ -28,96 +28,6 @@
using namespace osg; using namespace osg;
static buffered_object< ref_ptr<FBOExtensions> > 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 * RenderBuffer
@ -149,8 +59,8 @@ void RenderBuffer::flushDeletedRenderBuffers(unsigned int contextID,double /*cur
// if no time available don't try to flush objects. // if no time available don't try to flush objects.
if (availableTime<=0.0) return; if (availableTime<=0.0) return;
const FBOExtensions* extensions = FBOExtensions::instance(contextID,true); const GL2Extensions* extensions = GL2Extensions::Get(contextID,true);
if(!extensions || !extensions->isSupported() ) return; if(!extensions || !extensions->isFrameBufferObjectSupported ) return;
const osg::Timer& timer = *osg::Timer::instance(); const osg::Timer& timer = *osg::Timer::instance();
osg::Timer_t start_tick = timer.tick(); 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<GLint> maxSamplesList; static osg::buffered_value<GLint> maxSamplesList;
GLint& maxSamples = maxSamplesList[contextID]; GLint& maxSamples = maxSamplesList[contextID];
if (!maxSamples && ext->isMultisampleSupported()) if (!maxSamples && ext->isMultisampleSupported)
{ {
glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples); glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples);
} }
@ -233,7 +143,7 @@ int RenderBuffer::getMaxSamples(unsigned int contextID, const FBOExtensions *ext
return maxSamples; 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]; GLuint &objectID = _objectID[contextID];
@ -261,7 +171,7 @@ GLuint RenderBuffer::getObjectID(unsigned int contextID, const FBOExtensions *ex
const_cast<RenderBuffer*>(this)->setSamples(_colorSamples); const_cast<RenderBuffer*>(this)->setSamples(_colorSamples);
} }
if (_samples > 0 && ext->isMultisampleCoverageSupported()) if (_samples > 0 && ext->isRenderbufferMultisampleCoverageSupported())
{ {
int samples = minimum(_samples, getMaxSamples(contextID, ext)); int samples = minimum(_samples, getMaxSamples(contextID, ext));
int colorSamples = minimum(_colorSamples, samples); int colorSamples = minimum(_colorSamples, samples);
@ -269,7 +179,7 @@ GLuint RenderBuffer::getObjectID(unsigned int contextID, const FBOExtensions *ex
ext->glRenderbufferStorageMultisampleCoverageNV(GL_RENDERBUFFER_EXT, ext->glRenderbufferStorageMultisampleCoverageNV(GL_RENDERBUFFER_EXT,
samples, colorSamples, _internalFormat, _width, _height); samples, colorSamples, _internalFormat, _width, _height);
} }
else if (_samples > 0 && ext->isMultisampleSupported()) else if (_samples > 0 && ext->isRenderbufferMultisampleSupported())
{ {
int samples = minimum(_samples, getMaxSamples(contextID, ext)); int samples = minimum(_samples, getMaxSamples(contextID, ext));
@ -540,7 +450,7 @@ bool FrameBufferAttachment::isMultisample() const
return false; 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(); 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(); 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 no time available don't try to flush objects.
if (availableTime<=0.0) return; if (availableTime<=0.0) return;
const FBOExtensions* extensions = FBOExtensions::instance(contextID,true); const GL2Extensions* extensions = GL2Extensions::Get(contextID,true);
if(!extensions || !extensions->isSupported() ) return; if(!extensions || !extensions->isFrameBufferObjectSupported ) return;
const osg::Timer& timer = *osg::Timer::instance(); const osg::Timer& timer = *osg::Timer::instance();
osg::Timer_t start_tick = timer.tick(); osg::Timer_t start_tick = timer.tick();
@ -862,8 +772,8 @@ void FrameBufferObject::apply(State &state, BindTarget target) const
return; return;
FBOExtensions* ext = FBOExtensions::instance(contextID,true); GL2Extensions* ext = state.get<GL2Extensions>();
if (!ext->isSupported()) if (!ext->isFrameBufferObjectSupported)
{ {
_unsupported[contextID] = 1; _unsupported[contextID] = 1;
OSG_WARN << "Warning: EXT_framebuffer_object is not supported" << std::endl; 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) switch(i->first)
{ {
case(Camera::PACKED_DEPTH_STENCIL_BUFFER): 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_DEPTH_ATTACHMENT_EXT, ext);
fa.attach(state, target, GL_STENCIL_ATTACHMENT_EXT, ext); fa.attach(state, target, GL_STENCIL_ATTACHMENT_EXT, ext);

View File

@ -222,9 +222,6 @@ GL2Extensions::GL2Extensions(unsigned int contextID)
// EXT_geometry_shader4 // EXT_geometry_shader4
setGLExtensionFuncPtr(glProgramParameteri, "glProgramParameteri", "glProgramParameteriEXT" ); setGLExtensionFuncPtr(glProgramParameteri, "glProgramParameteri", "glProgramParameteriEXT" );
setGLExtensionFuncPtr(glFramebufferTexture, "glFramebufferTexture", "glFramebufferTextureEXT" );
setGLExtensionFuncPtr(glFramebufferTextureLayer, "glFramebufferTextureLayer", "glFramebufferTextureLayerEXT" );
setGLExtensionFuncPtr(glFramebufferTextureFace, "glFramebufferTextureFace", "glFramebufferTextureFaceEXT" );
// ARB_tesselation_shader // ARB_tesselation_shader
setGLExtensionFuncPtr(glPatchParameteri, "glPatchParameteri" ); setGLExtensionFuncPtr(glPatchParameteri, "glPatchParameteri" );
@ -612,6 +609,58 @@ GL2Extensions::GL2Extensions(unsigned int contextID)
setGLExtensionFuncPtr(glSampleCoverage, "glSampleCoverageARB"); 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");
} }

View File

@ -982,30 +982,9 @@ void GraphicsContext::resizedImplementation(int x, int y, int width, int height)
// //
// SyncSwapBuffersCallback // SyncSwapBuffersCallback
// //
SyncSwapBuffersCallback::SyncSwapBuffersCallback(): SyncSwapBuffersCallback::SyncSwapBuffersCallback()
_extensionInitialized(false),
_glFenceSync(0),
_glIsSync(0),
_glDeleteSync(0),
_glClientWaitSync(0),
_glWaitSync(0),
_glGetInteger64v(0),
_glGetSynciv(0),
_previousSync(0)
{ {
OSG_NOTICE<<"Created Swap callback."<<std::endl; OSG_INFO<<"Created SyncSwapBuffersCallback."<<std::endl;
}
void SyncSwapBuffersCallback::setUpExtensions()
{
_extensionInitialized = true;
osg::setGLExtensionFuncPtr(_glFenceSync, "glFenceSync");
osg::setGLExtensionFuncPtr(_glIsSync, "glIsSync");
osg::setGLExtensionFuncPtr(_glDeleteSync, "glDeleteSync");
osg::setGLExtensionFuncPtr(_glClientWaitSync, "glClientWaitSync");
osg::setGLExtensionFuncPtr(_glWaitSync, "glWaitSync");
osg::setGLExtensionFuncPtr(_glGetInteger64v, "glGetInteger64v");
osg::setGLExtensionFuncPtr(_glGetSynciv, "glGetSynciv");
} }
void SyncSwapBuffersCallback::swapBuffersImplementation(osg::GraphicsContext* gc) void SyncSwapBuffersCallback::swapBuffersImplementation(osg::GraphicsContext* gc)
@ -1014,20 +993,19 @@ void SyncSwapBuffersCallback::swapBuffersImplementation(osg::GraphicsContext* gc
gc->swapBuffersImplementation(); gc->swapBuffersImplementation();
//glFinish(); //glFinish();
if (!_extensionInitialized) setUpExtensions(); GL2Extensions* ext = gc->getState()->get<GL2Extensions>();
if (_glClientWaitSync) if (ext->glClientWaitSync)
{ {
if (_previousSync) if (_previousSync)
{ {
unsigned int num_seconds = 1; unsigned int num_seconds = 1;
GLuint64 timeout = num_seconds * ((GLuint64)1000 * 1000 * 1000); GLuint64 timeout = num_seconds * ((GLuint64)1000 * 1000 * 1000);
_glClientWaitSync(_previousSync, 0, timeout); ext->glClientWaitSync(_previousSync, 0, timeout);
ext->glDeleteSync(_previousSync);
_glDeleteSync(_previousSync);
} }
_previousSync = _glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); _previousSync = ext->glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
} }
//gc->getState()->checkGLErrors("after glWaitSync"); //gc->getState()->checkGLErrors("after glWaitSync");

View File

@ -129,13 +129,13 @@ struct RetrieveQueriesCallback : public osg::Camera::DrawCallback
{ {
// No valid GraphicsContext in the Camera. This might happen in // No valid GraphicsContext in the Camera. This might happen in
// SceneView-based apps. Rely on the creating code to have passed // 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. // 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; ext = _extensionsFallback;
if (!ext) 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; return;
} }
} }

View File

@ -2671,17 +2671,13 @@ bool Texture::isHardwareMipmapGenerationEnabled(const State& state) const
{ {
if (_useHardwareMipMapGeneration) if (_useHardwareMipMapGeneration)
{ {
unsigned int contextID = state.getContextID();
const GL2Extensions* extensions = state.get<GL2Extensions>(); const GL2Extensions* extensions = state.get<GL2Extensions>();
if (extensions->isGenerateMipMapSupported) if (extensions->isGenerateMipMapSupported)
{ {
return true; return true;
} }
const FBOExtensions* fbo_ext = FBOExtensions::instance(contextID,true); if (extensions->glGenerateMipmap)
if (fbo_ext->isSupported() && fbo_ext->glGenerateMipmap)
{ {
return true; return true;
} }
@ -2698,13 +2694,12 @@ Texture::GenerateMipmapMode Texture::mipmapBeforeTexImage(const State& state, bo
return GENERATE_MIPMAP; return GENERATE_MIPMAP;
#else #else
FBOExtensions* fbo_ext = FBOExtensions::instance(state.getContextID(),true); const GL2Extensions* extensions = state.get<GL2Extensions>();
const GL2Extensions* tex_ext = state.get<GL2Extensions>(); bool useGenerateMipMap = extensions->glGenerateMipmap;
bool useGenerateMipMap = fbo_ext->isSupported() && fbo_ext->glGenerateMipmap;
if (useGenerateMipMap) if (useGenerateMipMap)
{ {
if (tex_ext->preferGenerateMipmapSGISForPowerOfTwo) if (extensions->preferGenerateMipmapSGISForPowerOfTwo)
{ {
int width = getTextureWidth(); int width = getTextureWidth();
int height = getTextureHeight(); int height = getTextureHeight();
@ -2736,8 +2731,8 @@ void Texture::mipmapAfterTexImage(State& state, GenerateMipmapMode beforeResult)
TextureObject* textureObject = getTextureObject(contextID); TextureObject* textureObject = getTextureObject(contextID);
if (textureObject) if (textureObject)
{ {
osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(contextID, true); osg::GL2Extensions* ext = state.get<GL2Extensions>();
fbo_ext->glGenerateMipmap(textureObject->target()); ext->glGenerateMipmap(textureObject->target());
} }
break; break;
} }
@ -2769,13 +2764,13 @@ void Texture::generateMipmap(State& state) const
} }
// get fbo extension which provides us with the glGenerateMipmapEXT function // 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<GL2Extensions>();
// check if the function is supported // check if the function is supported
if (fbo_ext->isSupported() && fbo_ext->glGenerateMipmap) if (ext->glGenerateMipmap)
{ {
textureObject->bind(); textureObject->bind();
fbo_ext->glGenerateMipmap(textureObject->target()); ext->glGenerateMipmap(textureObject->target());
// inform state that this texture is the current one bound. // inform state that this texture is the current one bound.
state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); 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."<<std::endl;
return;
}
const char* renderer = (const char*) glGetString(GL_RENDERER);
std::string rendererString(renderer ? renderer : "");
bool radeonHardwareDetected = (rendererString.find("Radeon")!=std::string::npos || rendererString.find("RADEON")!=std::string::npos);
bool fireGLHardwareDetected = (rendererString.find("FireGL")!=std::string::npos || rendererString.find("FIREGL")!=std::string::npos);
bool builtInSupport = OSG_GLES2_FEATURES || OSG_GL3_FEATURES;
_isMultiTexturingSupported = builtInSupport || OSG_GLES1_FEATURES ||
isGLExtensionOrVersionSupported( contextID,"GL_ARB_multitexture", 1.3f) ||
isGLExtensionOrVersionSupported(contextID,"GL_EXT_multitexture", 1.3f);
_isTextureFilterAnisotropicSupported = isGLExtensionSupported(contextID,"GL_EXT_texture_filter_anisotropic");
_isTextureSwizzleSupported = isGLExtensionSupported(contextID,"GL_ARB_texture_swizzle");
_isTextureCompressionARBSupported = builtInSupport || isGLExtensionOrVersionSupported(contextID,"GL_ARB_texture_compression", 1.3f);
_isTextureCompressionS3TCSupported = isGLExtensionSupported(contextID,"GL_EXT_texture_compression_s3tc");
_isTextureCompressionPVRTC2BPPSupported = isGLExtensionSupported(contextID,"GL_IMG_texture_compression_pvrtc");
_isTextureCompressionPVRTC4BPPSupported = _isTextureCompressionPVRTC2BPPSupported;//covered by same extension
_isTextureCompressionETCSupported = isGLExtensionSupported(contextID,"GL_OES_compressed_ETC1_RGB8_texture");
_isTextureCompressionETC2Supported = isGLExtensionSupported(contextID,"GL_ARB_ES3_compatibility");
_isTextureCompressionRGTCSupported = isGLExtensionSupported(contextID,"GL_EXT_texture_compression_rgtc");
_isTextureCompressionPVRTCSupported = isGLExtensionSupported(contextID,"GL_IMG_texture_compression_pvrtc");
_isTextureMirroredRepeatSupported = builtInSupport ||
isGLExtensionOrVersionSupported(contextID,"GL_IBM_texture_mirrored_repeat", 1.4f) ||
isGLExtensionOrVersionSupported(contextID,"GL_ARB_texture_mirrored_repeat", 1.4f);
_isTextureEdgeClampSupported = builtInSupport ||
isGLExtensionOrVersionSupported(contextID,"GL_EXT_texture_edge_clamp", 1.2f) ||
isGLExtensionOrVersionSupported(contextID,"GL_SGIS_texture_edge_clamp", 1.2f);
_isTextureBorderClampSupported = OSG_GL3_FEATURES ||
((OSG_GL1_FEATURES || OSG_GL2_FEATURES) && isGLExtensionOrVersionSupported(contextID,"GL_ARB_texture_border_clamp", 1.3f));
_isGenerateMipMapSupported = builtInSupport || isGLExtensionOrVersionSupported(contextID,"GL_SGIS_generate_mipmap", 1.4f);
_preferGenerateMipmapSGISForPowerOfTwo = (radeonHardwareDetected||fireGLHardwareDetected) ? false : true;
_isTextureMultisampledSupported = isGLExtensionSupported(contextID,"GL_ARB_texture_multisample");
_isShadowSupported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_ARB_shadow");
_isShadowAmbientSupported = isGLExtensionSupported(contextID,"GL_ARB_shadow_ambient");
_isClientStorageSupported = isGLExtensionSupported(contextID,"GL_APPLE_client_storage");
_isNonPowerOfTwoTextureNonMipMappedSupported = builtInSupport || isGLExtensionOrVersionSupported(contextID,"GL_ARB_texture_non_power_of_two", 2.0) || isGLExtensionSupported(contextID,"GL_APPLE_texture_2D_limited_npot");
_isNonPowerOfTwoTextureMipMappedSupported = builtInSupport || _isNonPowerOfTwoTextureNonMipMappedSupported;
_isTextureIntegerEXTSupported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID, "GL_EXT_texture_integer");
#if 0
if (rendererString.find("Radeon")!=std::string::npos || rendererString.find("RADEON")!=std::string::npos)
{
_isNonPowerOfTwoTextureMipMappedSupported = false;
OSG_INFO<<"Disabling _isNonPowerOfTwoTextureMipMappedSupported for ATI hardware."<<std::endl;
}
#endif
if (rendererString.find("GeForce FX")!=std::string::npos)
{
_isNonPowerOfTwoTextureMipMappedSupported = false;
OSG_INFO<<"Disabling _isNonPowerOfTwoTextureMipMappedSupported for GeForce FX hardware."<<std::endl;
}
_maxTextureSize=0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&_maxTextureSize);
char *ptr;
if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0)
{
GLint osg_max_size = atoi(ptr);
if (osg_max_size<_maxTextureSize)
{
_maxTextureSize = osg_max_size;
}
}
setGLExtensionFuncPtr(_glTexStorage2D,"glTexStorage2D","glTexStorage2DARB");
setGLExtensionFuncPtr(_glCompressedTexImage2D,"glCompressedTexImage2D","glCompressedTexImage2DARB");
setGLExtensionFuncPtr(_glCompressedTexSubImage2D,"glCompressedTexSubImage2D","glCompressedTexSubImage2DARB");
setGLExtensionFuncPtr(_glGetCompressedTexImage,"glGetCompressedTexImage","glGetCompressedTexImageARB");;
setGLExtensionFuncPtr(_glTexImage2DMultisample, "glTexImage2DMultisample", "glTexImage2DMultisampleARB");
setGLExtensionFuncPtr(_glTexParameterIiv, "glTexParameterIiv", "glTexParameterIivARB");
setGLExtensionFuncPtr(_glTexParameterIuiv, "glTexParameterIuiv", "glTexParameterIuivARB");
if (_glTexParameterIiv == NULL) setGLExtensionFuncPtr(_glTexParameterIiv, "glTexParameterIivEXT");
if (_glTexParameterIuiv == NULL) setGLExtensionFuncPtr(_glTexParameterIuiv, "glTexParameterIuivEXT");
setGLExtensionFuncPtr(_glBindImageTexture, "glBindImageTexture", "glBindImageTextureARB");
_isTextureMaxLevelSupported = ( getGLVersionNumber() >= 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<<std::endl;
}
#endif
} }

View File

@ -559,73 +559,3 @@ void Texture3D::allocateMipmap(State& state) const
state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this);
} }
} }
#if 0
typedef buffered_value< ref_ptr<Texture3D::Extensions> > 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

View File

@ -499,24 +499,6 @@ void TextureRectangle::copyTexImage2D(State& state, int x, int y, int width, int
applyTexParameters(GL_TEXTURE_RECTANGLE,state); 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."<<std::endl;
_min_filter = LINEAR;
}
}
*/
// if (hardwareMipMapOn) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE); // if (hardwareMipMapOn) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
glCopyTexImage2D( GL_TEXTURE_RECTANGLE, 0, _internalFormat, x, y, width, height, 0 ); glCopyTexImage2D( GL_TEXTURE_RECTANGLE, 0, _internalFormat, x, y, width, height, 0 );
@ -551,23 +533,6 @@ void TextureRectangle::copyTexSubImage2D(State& state, int xoffset, int yoffset,
applyTexParameters(GL_TEXTURE_RECTANGLE,state); 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."<<std::endl;
_min_filter = LINEAR;
}
}
*/
// if (hardwareMipMapOn) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE); // if (hardwareMipMapOn) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
glCopyTexSubImage2D( GL_TEXTURE_RECTANGLE, 0, xoffset, yoffset, x, y, width, height); glCopyTexSubImage2D( GL_TEXTURE_RECTANGLE, 0, xoffset, yoffset, x, y, width, height);

View File

@ -338,8 +338,8 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
if (renderTargetImplementation==osg::Camera::FRAME_BUFFER_OBJECT) if (renderTargetImplementation==osg::Camera::FRAME_BUFFER_OBJECT)
{ {
osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(state.getContextID(),true); osg::GL2Extensions* ext = state.get<osg::GL2Extensions>();
bool fbo_supported = fbo_ext && fbo_ext->isSupported(); bool fbo_supported = ext->isFrameBufferObjectSupported;
if (fbo_supported) if (fbo_supported)
{ {
@ -362,7 +362,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
unsigned int renderBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true); unsigned int renderBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true);
unsigned int resolveBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true); unsigned int resolveBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true);
if (fbo_ext->isMultisampleSupported()) if (ext->isRenderbufferMultisampleSupported())
{ {
for(osg::Camera::BufferAttachmentMap::iterator itr = bufferAttachments.begin(); for(osg::Camera::BufferAttachmentMap::iterator itr = bufferAttachments.begin();
itr != bufferAttachments.end(); itr != bufferAttachments.end();
@ -518,7 +518,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
#endif #endif
} }
GLenum status = fbo_ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); GLenum status = ext->glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
{ {
@ -526,7 +526,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
fbo_supported = false; fbo_supported = false;
GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0; GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0;
fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId);
fbo = 0; fbo = 0;
// clean up. // clean up.
@ -548,7 +548,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
{ {
fbo_multisample->apply(state); 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) 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::State& state = *renderInfo.getState();
osg::FBOExtensions* fbo_ext = _fbo.valid() ? osg::FBOExtensions::instance(state.getContextID(),true) : 0; osg::GL2Extensions* ext = _fbo.valid() ? state.get<osg::GL2Extensions>() : 0;
bool fbo_supported = fbo_ext && fbo_ext->isSupported(); bool fbo_supported = ext && ext->isFrameBufferObjectSupported;
bool using_multiple_render_targets = fbo_supported && _fbo->hasMultipleRenderingTargets(); 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 (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 ) if ( fbstatus != GL_FRAMEBUFFER_COMPLETE_EXT )
{ {
OSG_NOTICE<<"RenderStage::drawInner(,) FBO status = 0x"<<std::hex<<fbstatus<<std::dec<<std::endl; OSG_NOTICE<<"RenderStage::drawInner(,) FBO status = 0x"<<std::hex<<fbstatus<<std::dec<<std::endl;
@ -948,7 +948,7 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b
const FrameBufferObject* read_fbo = fbo_supported ? _fbo.get() : 0; const FrameBufferObject* read_fbo = fbo_supported ? _fbo.get() : 0;
bool apply_read_fbo = false; bool apply_read_fbo = false;
if (fbo_supported && _resolveFbo.valid() && fbo_ext->glBlitFramebuffer) if (fbo_supported && _resolveFbo.valid() && ext->glBlitFramebuffer)
{ {
GLbitfield blitMask = 0; GLbitfield blitMask = 0;
bool needToBlitColorBuffers = false; 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 // Note that (with nvidia 175.16 windows drivers at least) if the read
// framebuffer is multisampled then the dimension arguments are ignored // framebuffer is multisampled then the dimension arguments are ignored
// and the whole framebuffer is always copied. // and the whole framebuffer is always copied.
fbo_ext->glBlitFramebuffer( ext->glBlitFramebuffer(
static_cast<GLint>(_viewport->x()), static_cast<GLint>(_viewport->y()), static_cast<GLint>(_viewport->x()), static_cast<GLint>(_viewport->y()),
static_cast<GLint>(_viewport->x() + _viewport->width()), static_cast<GLint>(_viewport->y() + _viewport->height()), static_cast<GLint>(_viewport->x() + _viewport->width()), static_cast<GLint>(_viewport->y() + _viewport->height()),
static_cast<GLint>(_viewport->x()), static_cast<GLint>(_viewport->y()), static_cast<GLint>(_viewport->x()), static_cast<GLint>(_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)); glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0));
glDrawBuffer(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<GLint>(_viewport->x()), static_cast<GLint>(_viewport->y()), static_cast<GLint>(_viewport->x()), static_cast<GLint>(_viewport->y()),
static_cast<GLint>(_viewport->x() + _viewport->width()), static_cast<GLint>(_viewport->y() + _viewport->height()), static_cast<GLint>(_viewport->x() + _viewport->width()), static_cast<GLint>(_viewport->y() + _viewport->height()),
static_cast<GLint>(_viewport->x()), static_cast<GLint>(_viewport->y()), static_cast<GLint>(_viewport->x()), static_cast<GLint>(_viewport->y()),
@ -1088,7 +1088,7 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b
{ {
// switch off the frame buffer object // switch off the frame buffer object
GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0; GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0;
fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId);
} }
doCopyTexture = true; doCopyTexture = true;
@ -1106,7 +1106,7 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b
{ {
state.setActiveTextureUnit(0); state.setActiveTextureUnit(0);
state.applyTextureAttribute(0, itr->second._texture.get()); state.applyTextureAttribute(0, itr->second._texture.get());
fbo_ext->glGenerateMipmap(itr->second._texture->getTextureTarget()); ext->glGenerateMipmap(itr->second._texture->getTextureTarget());
} }
} }
} }