From 393f1580c87c3cbabf3825fb2654d66c7aff3524 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 9 Dec 2003 11:20:44 +0000 Subject: [PATCH] From Pavel Moloshtan, extension support for ARB_occlusion_querry --- include/osg/Drawable | 41 +++++++++++++++++++++ src/osg/Drawable.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/include/osg/Drawable b/include/osg/Drawable index 3738d472f..b366b614b 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -87,6 +87,16 @@ class Geometry; #endif +#ifndef GL_ARB_occlusion_query + + #define GL_SAMPLES_PASSED_ARB 0x8914 + #define GL_QUERY_COUNTER_BITS_ARB 0x8864 + #define GL_CURRENT_QUERY_ARB 0x8865 + #define GL_QUERY_RESULT_ARB 0x8866 + #define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 + +#endif + // this is define to alter the way display lists are compiled inside the // the draw method, it has been found that the NVidia drivers fail completely // to optimize COMPILE_AND_EXECUTE in fact make it go slower than for no display @@ -498,6 +508,9 @@ class SG_EXPORT Drawable : public Object void setOcclusionQuerySupported(bool flag) { _isOcclusionQuerySupported=flag; } bool isOcclusionQuerySupported() const { return _isOcclusionQuerySupported; } + void setARBOcclusionQuerySupported(bool flag) { _isARBOcclusionQuerySupported=flag; } + bool isARBOcclusionQuerySupported() const { return _isARBOcclusionQuerySupported; } + void glSecondaryColor3ubv(const GLubyte* coord) const; void glSecondaryColor3fv(const GLfloat* coord) const; @@ -530,6 +543,14 @@ class SG_EXPORT Drawable : public Object void glGetOcclusionQueryiv( GLuint id, GLenum pname, GLint *params ) const; void glGetOcclusionQueryuiv( GLuint id, GLenum pname, GLuint *params ) const; + void glGetQueryiv(GLenum target, GLenum pname, GLint *params) const; + void glGenQueries(GLsizei n, GLuint *ids) const; + void glBeginQuery(GLenum target, GLuint id) const; + void glEndQuery(GLenum target) const; + GLboolean glIsQuery(GLuint id) const; + void glGetQueryObjectiv(GLuint id, GLenum pname, GLint *params) const; + void glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) const; + protected: typedef void (APIENTRY * FogCoordProc) (const GLfloat* coord); @@ -559,6 +580,15 @@ class SG_EXPORT Drawable : public Object typedef void (APIENTRY * GetOcclusionQueryivProc) ( GLuint id, GLenum pname, GLint *params ); typedef void (APIENTRY * GetOcclusionQueryuivProc) ( GLuint id, GLenum pname, GLuint *params ); + typedef void (APIENTRY *GenQueriesProc) (GLsizei n, GLuint *ids); + typedef void (APIENTRY *DeleteQueriesProc) (GLsizei n, const GLuint *ids); + typedef GLboolean (APIENTRY *IsQueryProc) (GLuint id); + typedef void (APIENTRY *BeginQueryProc) (GLenum target, GLuint id); + typedef void (APIENTRY *EndQueryProc) (GLenum target); + typedef void (APIENTRY *GetQueryivProc) (GLenum target, GLenum pname, GLint *params); + typedef void (APIENTRY *GetQueryObjectivProc) (GLuint id, GLenum pname, GLint *params); + typedef void (APIENTRY *GetQueryObjectuivProc) (GLuint id, GLenum pname, GLuint *params); + ~Extensions() {} bool _isVertexProgramSupported; @@ -566,6 +596,7 @@ class SG_EXPORT Drawable : public Object bool _isFogCoordSupported; bool _isMultiTexSupported; bool _isOcclusionQuerySupported; + bool _isARBOcclusionQuerySupported; FogCoordProc _glFogCoordfv; @@ -598,6 +629,16 @@ class SG_EXPORT Drawable : public Object EndOcclusionQueryProc _glEndOcclusionQuery; GetOcclusionQueryivProc _glGetOcclusionQueryiv; GetOcclusionQueryuivProc _glGetOcclusionQueryuiv; + + GenQueriesProc _gl_gen_queries_arb; + DeleteQueriesProc _gl_delete_queries_arb; + IsQueryProc _gl_is_query_arb; + BeginQueryProc _gl_begin_query_arb; + EndQueryProc _gl_end_query_arb; + GetQueryivProc _gl_get_queryiv_arb; + GetQueryObjectivProc _gl_get_query_objectiv_arb; + GetQueryObjectuivProc _gl_get_query_objectuiv_arb; + }; /** Function to call to get the extension of a specified context. diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 5ccfa6f44..4e3a9fa2f 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -498,6 +498,14 @@ Drawable::Extensions::Extensions(const Extensions& rhs): _glEndOcclusionQuery = rhs._glEndOcclusionQuery; _glGetOcclusionQueryiv = rhs._glGetOcclusionQueryiv; _glGetOcclusionQueryuiv = rhs._glGetOcclusionQueryuiv; + _gl_gen_queries_arb = rhs._gl_gen_queries_arb; + _gl_delete_queries_arb = rhs._gl_delete_queries_arb; + _gl_is_query_arb = rhs._gl_is_query_arb; + _gl_begin_query_arb = rhs._gl_begin_query_arb; + _gl_end_query_arb = rhs._gl_end_query_arb; + _gl_get_queryiv_arb = rhs._gl_get_queryiv_arb; + _gl_get_query_objectiv_arb = rhs._gl_get_query_objectiv_arb; + _gl_get_query_objectuiv_arb = rhs._gl_get_query_objectuiv_arb; } @@ -508,6 +516,7 @@ void Drawable::Extensions::lowestCommonDenominator(const Extensions& rhs) if (!rhs._isFogCoordSupported) _isFogCoordSupported = false; if (!rhs._isMultiTexSupported) _isMultiTexSupported = false; if (!rhs._isOcclusionQuerySupported) _isOcclusionQuerySupported = false; + if (!rhs._isARBOcclusionQuerySupported) _isARBOcclusionQuerySupported = false; if (!rhs._glFogCoordfv) _glFogCoordfv = 0; if (!rhs._glSecondaryColor3ubv) _glSecondaryColor3ubv = 0; @@ -538,6 +547,15 @@ void Drawable::Extensions::lowestCommonDenominator(const Extensions& rhs) if (!rhs._glEndOcclusionQuery) _glEndOcclusionQuery = 0; if (!rhs._glGetOcclusionQueryiv) _glGetOcclusionQueryiv = 0; if (!rhs._glGetOcclusionQueryuiv) _glGetOcclusionQueryuiv = 0; + + if (!rhs._gl_gen_queries_arb) _gl_gen_queries_arb = 0; + if (!rhs._gl_delete_queries_arb) _gl_delete_queries_arb = 0; + if (!rhs._gl_is_query_arb) _gl_is_query_arb = 0; + if (!rhs._gl_begin_query_arb) _gl_begin_query_arb = 0; + if (!rhs._gl_end_query_arb) _gl_end_query_arb = 0; + if (!rhs._gl_get_queryiv_arb) _gl_get_queryiv_arb = 0; + if (!rhs._gl_get_query_objectiv_arb) _gl_get_query_objectiv_arb = 0; + if (!rhs._gl_get_query_objectuiv_arb) _gl_get_query_objectuiv_arb = 0; } void Drawable::Extensions::setupGLExtenions() @@ -547,6 +565,7 @@ void Drawable::Extensions::setupGLExtenions() _isFogCoordSupported = isGLExtensionSupported("GL_EXT_fog_coord"); _isMultiTexSupported = isGLExtensionSupported("GL_ARB_multitexture"); _isOcclusionQuerySupported = osg::isGLExtensionSupported( "GL_NV_occlusion_query" ); + _isARBOcclusionQuerySupported = osg::isGLExtensionSupported( "GL_ARB_occlusion_query" ); _glFogCoordfv = ((FogCoordProc)osg::getGLExtensionFuncPtr("glFogCoordfv","glFogCoordfvEXT")); _glSecondaryColor3ubv = ((SecondaryColor3ubvProc)osg::getGLExtensionFuncPtr("glSecondaryColor3ubv","glSecondaryColor3ubvEXT")); @@ -577,6 +596,15 @@ void Drawable::Extensions::setupGLExtenions() _glEndOcclusionQuery = ((EndOcclusionQueryProc)osg::getGLExtensionFuncPtr("glEndOcclusionQuery","glEndOcclusionQueryNV")); _glGetOcclusionQueryiv = ((GetOcclusionQueryivProc)osg::getGLExtensionFuncPtr("glGetOcclusionQueryiv","glGetOcclusionQueryivNV")); _glGetOcclusionQueryuiv = ((GetOcclusionQueryuivProc)osg::getGLExtensionFuncPtr("glGetOcclusionQueryuiv","glGetOcclusionQueryuivNV")); + + _gl_gen_queries_arb = (GenQueriesProc)osg::getGLExtensionFuncPtr("glGenQueries", "glGenQueriesARB"); + _gl_delete_queries_arb = (DeleteQueriesProc)osg::getGLExtensionFuncPtr("glDeleteQueries", "glDeleteQueriesARB"); + _gl_is_query_arb = (IsQueryProc)osg::getGLExtensionFuncPtr("glIsQuery", "glIsQueryARB"); + _gl_begin_query_arb = (BeginQueryProc)osg::getGLExtensionFuncPtr("glBeginQuery", "glBeginQueryARB"); + _gl_end_query_arb = (EndQueryProc)osg::getGLExtensionFuncPtr("glEndQuery", "glEndQueryARB"); + _gl_get_queryiv_arb = (GetQueryivProc)osg::getGLExtensionFuncPtr("glGetQueryiv", "glGetQueryivARB"); + _gl_get_query_objectiv_arb = (GetQueryObjectivProc)osg::getGLExtensionFuncPtr("glGetQueryObjectiv","glGetQueryObjectivARB"); + _gl_get_query_objectuiv_arb = (GetQueryObjectuivProc)osg::getGLExtensionFuncPtr("glGetQueryObjectuiv","glGetQueryObjectuivARB"); } void Drawable::Extensions::glFogCoordfv(const GLfloat* coord) const @@ -893,6 +921,63 @@ void Drawable::Extensions::glGetOcclusionQueryuiv( GLuint id, GLenum pname, GLui } } +void Drawable::Extensions::glGetQueryiv(GLenum target, GLenum pname, GLint *params) const +{ + if (_gl_get_queryiv_arb) + _gl_get_queryiv_arb(target, pname, params); + else + osg::notify(osg::WARN) << "Error: glGetQueryiv not supported by OpenGL driver" << std::endl; +} + +void Drawable::Extensions::glGenQueries(GLsizei n, GLuint *ids) const +{ + if (_gl_gen_queries_arb) + _gl_gen_queries_arb(n, ids); + else + osg::notify(osg::WARN) << "Error: glGenQueries not supported by OpenGL driver" << std::endl; +} + +void Drawable::Extensions::glBeginQuery(GLenum target, GLuint id) const +{ + if (_gl_begin_query_arb) + _gl_begin_query_arb(target, id); + else + osg::notify(osg::WARN) << "Error: glBeginQuery not supported by OpenGL driver" << std::endl; +} + +void Drawable::Extensions::glEndQuery(GLenum target) const +{ + if (_gl_end_query_arb) + _gl_end_query_arb(target); + else + osg::notify(osg::WARN) << "Error: glEndQuery not supported by OpenGL driver" << std::endl; +} + +GLboolean Drawable::Extensions::glIsQuery(GLuint id) const +{ + if (_gl_is_query_arb) return _gl_is_query_arb(id); + + osg::notify(osg::WARN) << "Error: glIsQuery not supported by OpenGL driver" << std::endl; + return false; +} + +void Drawable::Extensions::glGetQueryObjectiv(GLuint id, GLenum pname, GLint *params) const +{ + if (_gl_get_query_objectiv_arb) + _gl_get_query_objectiv_arb(id, pname, params); + else + osg::notify(osg::WARN) << "Error: glGetQueryObjectiv not supported by OpenGL driver" << std::endl; +} + +void Drawable::Extensions::glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) const +{ + if (_gl_get_query_objectuiv_arb) + _gl_get_query_objectuiv_arb(id, pname, params); + else + osg::notify(osg::WARN) << "Error: glGetQueryObjectuiv not supported by OpenGL driver" << std::endl; +} + + /////////////////////////////////////////////////////////////////////////////////////////// // // Cluster culling callback