From 93fb935b6fdb2cd29cd166e619b7cc765822700a Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 27 Feb 2008 21:20:09 +0000 Subject: [PATCH] MIN_GL_VERSION, MIN_MESA_VERSION --- dtool/Config.pp | 18 ++++ dtool/LocalSetup.pp | 8 ++ panda/src/glgsg/glgsg.h | 24 +++++ .../glstuff/glGraphicsStateGuardian_src.cxx | 100 ++++++++++++++++++ panda/src/mesadisplay/mesagsg.h | 24 +++++ .../osMesaGraphicsStateGuardian.cxx | 4 +- 6 files changed, 176 insertions(+), 2 deletions(-) diff --git a/dtool/Config.pp b/dtool/Config.pp index 982515cd56..caeded5d37 100644 --- a/dtool/Config.pp +++ b/dtool/Config.pp @@ -567,6 +567,21 @@ // but is sometimes missing (e.g. the default FC5 installation). #defer HAVE_GLU $[libtest $[GL_LPATH],$[GLU_LIBS]] +// If you are having trouble linking in OpenGL extension functions at +// runtime for some reason, you can set this variable. This defines +// the minimum runtime version of OpenGL that Panda will require. +// Setting it to a higher version will compile in hard references to +// the extension functions provided by that OpenGL version and below, +// which may reduce runtime portability to other systems, but it will +// avoid issues with getting extension function pointers. It also, of +// course, requires you to install the OpenGL header files and +// compile-time libraries appropriate to the version you want to +// compile against. + +// The variable is the major, minor version of OpenGL, separated by a +// space (instead of a dot). Thus, "1 1" means OpenGL version 1.1. +#define MIN_GL_VERSION 1 1 + // Is Mesa installed separately from OpenGL? Mesa is an open-source // software-only OpenGL renderer. Panda can link with it // independently from OpenGL (and if Mesa is built statically, and/or @@ -598,6 +613,9 @@ #define MESA_MGL #defer HAVE_MESA $[libtest $[MESA_LPATH],$[MESA_LIBS]] +// Similar to MIN_GL_VERSION, above. +#define MIN_MESA_VERSION 1 1 + // Is the Chromium remote-rendering library installed, and where? // This should include libcr_opengl32. diff --git a/dtool/LocalSetup.pp b/dtool/LocalSetup.pp index 44613912ed..1a4ffee50f 100644 --- a/dtool/LocalSetup.pp +++ b/dtool/LocalSetup.pp @@ -244,6 +244,10 @@ $[cdefine HAVE_ZLIB] /* Define if we have OpenGL installed and want to build for GL. */ $[cdefine HAVE_GL] $[cdefine HAVE_GLU] +#if HAVE_GL +# define MIN_GL_VERSION_MAJOR $[word 1,$[MIN_GL_VERSION]] +# define MIN_GL_VERSION_MINOR $[word 2,$[MIN_GL_VERSION]] +#endif /* Define if we have OpenCV installed and want to build for OpenCV. */ $[cdefine HAVE_OPENCV] @@ -257,6 +261,10 @@ $[cdefine HAVE_ODE] /* Define if we have Mesa installed and want to build mesadisplay. */ $[cdefine HAVE_MESA] $[cdefine MESA_MGL] +#if HAVE_MESA +# define MIN_MESA_VERSION_MAJOR $[word 1,$[MIN_MESA_VERSION]] +# define MIN_MESA_VERSION_MINOR $[word 2,$[MIN_MESA_VERSION]] +#endif /* Define if we want to build with SGI OpenGL extensions. */ $[cdefine HAVE_SGIGL] diff --git a/panda/src/glgsg/glgsg.h b/panda/src/glgsg/glgsg.h index 4d3a1cf34e..37c2160412 100644 --- a/panda/src/glgsg/glgsg.h +++ b/panda/src/glgsg/glgsg.h @@ -37,6 +37,30 @@ #define EXPCL_GL EXPCL_PANDAGL #define EXPTP_GL EXPTP_PANDAGL +#if MIN_GL_VERSION_MAJOR > 1 || (MIN_GL_VERSION_MAJOR == 1 && MIN_GL_VERSION_MINOR >= 2) +#define EXPECT_GL_VERSION_1_2 +#endif + +#if MIN_GL_VERSION_MAJOR > 1 || (MIN_GL_VERSION_MAJOR == 1 && MIN_GL_VERSION_MINOR >= 3) +#define EXPECT_GL_VERSION_1_3 +#endif + +#if MIN_GL_VERSION_MAJOR > 1 || (MIN_GL_VERSION_MAJOR == 1 && MIN_GL_VERSION_MINOR >= 4) +#define EXPECT_GL_VERSION_1_4 +#endif + +#if MIN_GL_VERSION_MAJOR > 1 || (MIN_GL_VERSION_MAJOR == 1 && MIN_GL_VERSION_MINOR >= 5) +#define EXPECT_GL_VERSION_1_5 +#endif + +#if MIN_GL_VERSION_MAJOR > 2 || (MIN_GL_VERSION_MAJOR == 2 && MIN_GL_VERSION_MINOR >= 0) +#define EXPECT_GL_VERSION_2_0 +#endif + +#if MIN_GL_VERSION_MAJOR > 2 || (MIN_GL_VERSION_MAJOR == 2 && MIN_GL_VERSION_MINOR >= 1) +#define EXPECT_GL_VERSION_2_1 +#endif + // Before including gl.h, need to include windows.h #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN 1 diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index ec48b0533d..944a23c2df 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -305,8 +305,16 @@ reset() { if (is_at_least_version(1, 4)) { _supports_point_parameters = true; +#ifdef EXPECT_GL_VERSION_1_4 + GLCAT.debug() + << "Getting compile-time PointParameter pointers\n"; + _glPointParameterfv = (PFNGLPOINTPARAMETERFVPROC)&GLP(PointParameterfv); +#else // EXPECT_GL_VERSION_1_4 + GLCAT.debug() + << "Getting run-time PointParameter pointers\n"; _glPointParameterfv = (PFNGLPOINTPARAMETERFVPROC) get_extension_func(GLPREFIX_QUOTED, "PointParameterfv"); +#endif // EXPECT_GL_VERSION_1_4 } else if (has_extension("GL_ARB_point_parameters")) { _supports_point_parameters = true; @@ -416,8 +424,16 @@ reset() { if (is_at_least_version(1, 2)) { _supports_draw_range_elements = true; +#ifdef EXPECT_GL_VERSION_1_2 + GLCAT.debug() + << "Getting compile-time DrawRangeElements pointers\n"; + _glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)&GLP(DrawRangeElements); +#else // EXPECT_GL_VERSION_1_2 + GLCAT.debug() + << "Getting run-time DrawRangeElements pointers\n"; _glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) get_extension_func(GLPREFIX_QUOTED, "DrawRangeElements"); +#endif // EXPECT_GL_VERSION_1_2 } else if (has_extension("GL_EXT_draw_range_elements")) { _supports_draw_range_elements = true; @@ -449,10 +465,19 @@ reset() { if (is_at_least_version(1, 2)) { _supports_3d_texture = true; +#ifdef EXPECT_GL_VERSION_1_2 + GLCAT.debug() + << "Getting compile-time 3-D textures pointers\n"; + _glTexImage3D = (PFNGLTEXIMAGE3DPROC)&GLP(TexImage3D); + _glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC)&GLP(TexSubImage3D); +#else // EXPECT_GL_VERSION_1_2 + GLCAT.debug() + << "Getting run-time 3-D textures pointers\n"; _glTexImage3D = (PFNGLTEXIMAGE3DPROC) get_extension_func(GLPREFIX_QUOTED, "TexImage3D"); _glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC) get_extension_func(GLPREFIX_QUOTED, "TexSubImage3D"); +#endif // EXPECT_GL_VERSION_1_2 } else if (has_extension("GL_EXT_texture3D")) { _supports_3d_texture = true; @@ -478,6 +503,19 @@ reset() { if (is_at_least_version(1, 3)) { _supports_compressed_texture = true; +#ifdef EXPECT_GL_VERSION_1_3 + GLCAT.debug() + << "Getting compile-time compressed textures pointers\n"; + _glCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC)&GLP(CompressedTexImage1D); + _glCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC)&GLP(CompressedTexImage2D); + _glCompressedTexImage3D = (PFNGLCOMPRESSEDTEXIMAGE3DPROC)&GLP(CompressedTexImage3D); + _glCompressedTexSubImage1D = (PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC)&GLP(CompressedTexSubImage1D); + _glCompressedTexSubImage2D = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC)&GLP(CompressedTexSubImage2D); + _glCompressedTexSubImage3D = (PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC)&GLP(CompressedTexSubImage3D); + _glGetCompressedTexImage = (PFNGLGETCOMPRESSEDTEXIMAGEPROC)&GLP(GetCompressedTexImage); +#else // EXPECT_GL_VERSION_1_3 + GLCAT.debug() + << "Getting run-time compressed textures pointers\n"; _glCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC) get_extension_func(GLPREFIX_QUOTED, "CompressedTexImage1D"); _glCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) @@ -492,6 +530,7 @@ reset() { get_extension_func(GLPREFIX_QUOTED, "CompressedTexSubImage3D"); _glGetCompressedTexImage = (PFNGLGETCOMPRESSEDTEXIMAGEPROC) get_extension_func(GLPREFIX_QUOTED, "GetCompressedTexImage"); +#endif // EXPECT_GL_VERSION_1_3 } else if (has_extension("GL_ARB_texture_compression")) { _supports_compressed_texture = true; @@ -586,6 +625,19 @@ reset() { if (is_at_least_version(1, 3)) { _supports_multitexture = true; +#ifdef EXPECT_GL_VERSION_1_3 + GLCAT.debug() + << "Getting compile-time multitexture pointers\n"; + _glActiveTexture = (PFNGLACTIVETEXTUREPROC)&GLP(ActiveTexture); + _glClientActiveTexture = (PFNGLACTIVETEXTUREPROC)&GLP(ClientActiveTexture); + _glMultiTexCoord1f = (PFNGLMULTITEXCOORD1FPROC)&GLP(MultiTexCoord1f); + _glMultiTexCoord2f = (PFNGLMULTITEXCOORD2FPROC)&GLP(MultiTexCoord2f); + _glMultiTexCoord3f = (PFNGLMULTITEXCOORD3FPROC)&GLP(MultiTexCoord3f); + _glMultiTexCoord4f = (PFNGLMULTITEXCOORD4FPROC)&GLP(MultiTexCoord4f); + +#else // EXPECT_GL_VERSION_1_3 + GLCAT.debug() + << "Getting run-time multitexture pointers\n"; _glActiveTexture = (PFNGLACTIVETEXTUREPROC) get_extension_func(GLPREFIX_QUOTED, "ActiveTexture"); _glClientActiveTexture = (PFNGLACTIVETEXTUREPROC) @@ -598,6 +650,7 @@ reset() { get_extension_func(GLPREFIX_QUOTED, "MultiTexCoord3f"); _glMultiTexCoord4f = (PFNGLMULTITEXCOORD4FPROC) get_extension_func(GLPREFIX_QUOTED, "MultiTexCoord4f"); +#endif // EXPECT_GL_VERSION_1_3 } else if (has_extension("GL_ARB_multitexture")) { _supports_multitexture = true; @@ -652,6 +705,17 @@ reset() { if (is_at_least_version(1, 5)) { _supports_buffers = true; +#ifdef EXPECT_GL_VERSION_1_5 + GLCAT.debug() + << "Getting compile-time buffer pointers\n"; + _glGenBuffers = (PFNGLGENBUFFERSPROC)&GLP(GenBuffers); + _glBindBuffer = (PFNGLBINDBUFFERPROC)&GLP(BindBuffer); + _glBufferData = (PFNGLBUFFERDATAPROC)&GLP(BufferData); + _glBufferSubData = (PFNGLBUFFERSUBDATAPROC)&GLP(BufferSubData); + _glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)&GLP(DeleteBuffers); +#else // EXPECT_GL_VERSION_1_5 + GLCAT.debug() + << "Getting run-time buffer pointers\n"; _glGenBuffers = (PFNGLGENBUFFERSPROC) get_extension_func(GLPREFIX_QUOTED, "GenBuffers"); _glBindBuffer = (PFNGLBINDBUFFERPROC) @@ -662,6 +726,7 @@ reset() { get_extension_func(GLPREFIX_QUOTED, "BufferSubData"); _glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) get_extension_func(GLPREFIX_QUOTED, "DeleteBuffers"); +#endif // EXPECT_GL_VERSION_1_5 } else if (has_extension("GL_ARB_vertex_buffer_object")) { _supports_buffers = true; @@ -770,6 +835,20 @@ reset() { if (CLP(support_occlusion_query)) { if (is_at_least_version(1, 5)) { _supports_occlusion_query = true; + +#ifdef EXPECT_GL_VERSION_1_5 + GLCAT.debug() + << "Getting compile-time occlusion pointers\n"; + _glGenQueries = (PFNGLGENQUERIESPROC)&GLP(GenQueries); + _glBeginQuery = (PFNGLBEGINQUERYPROC)&GLP(BeginQuery); + _glEndQuery = (PFNGLENDQUERYPROC)&GLP(EndQuery); + _glDeleteQueries = (PFNGLDELETEQUERIESPROC)&GLP(DeleteQueries); + _glGetQueryiv = (PFNGLGETQUERYIVPROC)&GLP(GetQueryiv); + _glGetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVPROC)&GLP(GetQueryObjectuiv); + +#else // EXPECT_GL_VERSION_1_5 + GLCAT.debug() + << "Getting run-time occlusion pointers\n"; _glGenQueries = (PFNGLGENQUERIESPROC) get_extension_func(GLPREFIX_QUOTED, "GenQueries"); _glBeginQuery = (PFNGLBEGINQUERYPROC) @@ -782,6 +861,8 @@ reset() { get_extension_func(GLPREFIX_QUOTED, "GetQueryiv"); _glGetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVPROC) get_extension_func(GLPREFIX_QUOTED, "GetQueryObjectuiv"); +#endif // EXPECT_GL_VERSION_1_5 + } else if (has_extension("GL_ARB_occlusion_query")) { _supports_occlusion_query = true; _glGenQueries = (PFNGLGENQUERIESPROC) @@ -823,8 +904,16 @@ reset() { bool supports_blend_equation = false; if (is_at_least_version(1, 2)) { supports_blend_equation = true; +#ifdef EXPECT_GL_VERSION_1_2 + GLCAT.debug() + << "Getting compile-time BlendEquation pointers\n"; + _glBlendEquation = (PFNGLBLENDEQUATIONPROC)&GLP(BlendEquation); +#else // EXPECT_GL_VERSION_1_2 + GLCAT.debug() + << "Getting run-time blend pointers\n"; _glBlendEquation = (PFNGLBLENDEQUATIONPROC) get_extension_func(GLPREFIX_QUOTED, "BlendEquation"); +#endif // EXPECT_GL_VERSION_1_2 } else if (has_extension("GL_EXT_blend_minmax")) { supports_blend_equation = true; _glBlendEquation = (PFNGLBLENDEQUATIONPROC) @@ -842,8 +931,16 @@ reset() { bool supports_blend_color = false; if (is_at_least_version(1, 2)) { supports_blend_color = true; +#ifdef EXPECT_GL_VERSION_1_2 + GLCAT.debug() + << "Getting compile-time BlendColor pointers\n"; + _glBlendColor = (PFNGLBLENDCOLORPROC)&GLP(BlendColor); +#else // EXPECT_GL_VERSION_1_2 + GLCAT.debug() + << "Getting run-time BlendColor pointers\n"; _glBlendColor = (PFNGLBLENDCOLORPROC) get_extension_func(GLPREFIX_QUOTED, "BlendColor"); +#endif // EXPECT_GL_VERSION_1_2 } else if (has_extension("GL_EXT_blend_color")) { supports_blend_color = true; _glBlendColor = (PFNGLBLENDCOLORPROC) @@ -1208,11 +1305,14 @@ reset() { vertex_profile = cgGLGetLatestProfile (CG_GL_VERTEX); pixel_profile = cgGLGetLatestProfile (CG_GL_FRAGMENT); if (GLCAT.is_debug()) { + // Temp ifdef: this crashes Mesa. +#ifndef OSMESA_MAJOR_VERSION GLCAT.debug() << "\nCg vertex profile = " << cgGetProfileString(vertex_profile) << " id = " << vertex_profile << "\nCg pixel profile = " << cgGetProfileString(pixel_profile) << " id = " << pixel_profile << "\nshader model = " << _shader_model << "\n"; +#endif } #endif diff --git a/panda/src/mesadisplay/mesagsg.h b/panda/src/mesadisplay/mesagsg.h index 29700b3e9d..2afdd86a06 100644 --- a/panda/src/mesadisplay/mesagsg.h +++ b/panda/src/mesadisplay/mesagsg.h @@ -44,6 +44,30 @@ #define EXPCL_GL EXPCL_PANDAMESA #define EXPTP_GL EXPTP_PANDAMESA +#if MIN_MESA_VERSION_MAJOR > 1 || (MIN_MESA_VERSION_MAJOR == 1 && MIN_MESA_VERSION_MINOR >= 2) +#define EXPECT_GL_VERSION_1_2 +#endif + +#if MIN_MESA_VERSION_MAJOR > 1 || (MIN_MESA_VERSION_MAJOR == 1 && MIN_MESA_VERSION_MINOR >= 3) +#define EXPECT_GL_VERSION_1_3 +#endif + +#if MIN_MESA_VERSION_MAJOR > 1 || (MIN_MESA_VERSION_MAJOR == 1 && MIN_MESA_VERSION_MINOR >= 4) +#define EXPECT_GL_VERSION_1_4 +#endif + +#if MIN_MESA_VERSION_MAJOR > 1 || (MIN_MESA_VERSION_MAJOR == 1 && MIN_MESA_VERSION_MINOR >= 5) +#define EXPECT_GL_VERSION_1_5 +#endif + +#if MIN_MESA_VERSION_MAJOR > 2 || (MIN_MESA_VERSION_MAJOR == 2 && MIN_MESA_VERSION_MINOR >= 0) +#define EXPECT_GL_VERSION_2_0 +#endif + +#if MIN_MESA_VERSION_MAJOR > 2 || (MIN_MESA_VERSION_MAJOR == 2 && MIN_MESA_VERSION_MINOR >= 1) +#define EXPECT_GL_VERSION_2_1 +#endif + // This prevents glext.h from getting included by gl.h // That way, we can provide our own, better version. #define __glext_h_ diff --git a/panda/src/mesadisplay/osMesaGraphicsStateGuardian.cxx b/panda/src/mesadisplay/osMesaGraphicsStateGuardian.cxx index 62e5e2c5ab..19559e57d9 100644 --- a/panda/src/mesadisplay/osMesaGraphicsStateGuardian.cxx +++ b/panda/src/mesadisplay/osMesaGraphicsStateGuardian.cxx @@ -80,7 +80,7 @@ get_extension_func(const char *prefix, const char *name) { } if (ptr == (void *)NULL) { // Well, try for the more accurate name. - fullname = string(prefix) + name; + fullname = string(prefix) + string(name); ptr = (void *)OSMesaGetProcAddress(fullname.c_str()); if (mesadisplay_cat.is_debug()) { mesadisplay_cat.debug() @@ -93,7 +93,7 @@ get_extension_func(const char *prefix, const char *name) { #else if (mesadisplay_cat.is_debug()) { mesadisplay_cat.debug() - << "Couldn't look up extension function: compied with Mesa version " + << "Couldn't look up extension function: compiled with Mesa version " << OSMESA_MAJOR_VERSION << "." << OSMESA_MINOR_VERSION << "\n"; }