From fa4dcbe04f048869c933e4723baa836660928ccc Mon Sep 17 00:00:00 2001 From: isk Date: Tue, 8 Sep 2015 15:15:04 +0300 Subject: [PATCH] 0025162: Visualization, TKOpenGl - drop GLU library dependency Drop gluScaleImage() and gluBuild2DMipmaps(). Drop gluUnPorject() from samples. Output message if NPOT is unsupported and texture coordinates was scaled. Texture initialization is fail in this case. Output message if texture dimension exceed the max dimension. Texture initialization is fail in this case. TKOpenGl does not depends on deprecated GLU anymore. --- adm/genproj.tcl | 5 +- .../VoxelDemo/src/VoxelClient_VisDrawer.cxx | 12 + src/OpenGl/OpenGl_GlFunctions.hxx | 2 - src/OpenGl/OpenGl_Texture.cxx | 215 +++++++++--------- src/TKOpenGl/CMakeLists.txt | 3 - src/TKService/CMakeLists.txt | 3 - src/TKV3d/CMakeLists.txt | 3 - src/TKViewerTest/CMakeLists.txt | 3 - 8 files changed, 118 insertions(+), 128 deletions(-) diff --git a/adm/genproj.tcl b/adm/genproj.tcl index 0b2e3c9c3f..af862eb25f 100644 --- a/adm/genproj.tcl +++ b/adm/genproj.tcl @@ -1089,12 +1089,11 @@ proc osutils:csfList { theOS theCsfLibsMap theCsfFrmsMap } { set aLibsMap(CSF_advapi32) "advapi32.lib" set aLibsMap(CSF_gdi32) "gdi32.lib" set aLibsMap(CSF_user32) "user32.lib" - set aLibsMap(CSF_glu32) "glu32.lib" set aLibsMap(CSF_opengl32) "opengl32.lib" set aLibsMap(CSF_wsock32) "wsock32.lib" set aLibsMap(CSF_netapi32) "netapi32.lib" set aLibsMap(CSF_AviLibs) "ws2_32.lib vfw32.lib" - set aLibsMap(CSF_OpenGlLibs) "opengl32.lib glu32.lib" + set aLibsMap(CSF_OpenGlLibs) "opengl32.lib" set aLibsMap(CSF_QT) "QtCore4.lib QtGui4.lib" @@ -1111,7 +1110,7 @@ proc osutils:csfList { theOS theCsfLibsMap theCsfFrmsMap } { set aFrmsMap(CSF_TclTkLibs) "Tk" } else { set aLibsMap(CSF_ThreadLibs) "pthread rt" - set aLibsMap(CSF_OpenGlLibs) "GLU GL" + set aLibsMap(CSF_OpenGlLibs) "GL" set aLibsMap(CSF_TclLibs) "tcl8.6" set aLibsMap(CSF_TclTkLibs) "X11 tk8.6" set aLibsMap(CSF_XwLibs) "X11 Xext Xmu Xi" diff --git a/samples/qt/VoxelDemo/src/VoxelClient_VisDrawer.cxx b/samples/qt/VoxelDemo/src/VoxelClient_VisDrawer.cxx index 79d2bb43ef..ee315c2710 100644 --- a/samples/qt/VoxelDemo/src/VoxelClient_VisDrawer.cxx +++ b/samples/qt/VoxelDemo/src/VoxelClient_VisDrawer.cxx @@ -11,6 +11,18 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +// required for correct APIENTRY definition +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) + #define WIN32_LEAN_AND_MEAN + #include +#endif + +#if defined(__APPLE__) + #include +#else + #include +#endif + #include "VoxelClient_VisDrawer.h" #include diff --git a/src/OpenGl/OpenGl_GlFunctions.hxx b/src/OpenGl/OpenGl_GlFunctions.hxx index c036cbf0da..d75d686ca7 100644 --- a/src/OpenGl/OpenGl_GlFunctions.hxx +++ b/src/OpenGl/OpenGl_GlFunctions.hxx @@ -43,7 +43,6 @@ #include #else #include - #include #endif #define __X_GL_H // prevent chaotic gl.h inclusions to avoid compile errors #elif defined(HAVE_GLES2) || defined(__ANDROID__) @@ -51,7 +50,6 @@ //#include #else #include - #include #endif #if defined(GL_ES_VERSION_2_0) diff --git a/src/OpenGl/OpenGl_Texture.cxx b/src/OpenGl/OpenGl_Texture.cxx index 0f08435216..dde0ff748a 100644 --- a/src/OpenGl/OpenGl_Texture.cxx +++ b/src/OpenGl/OpenGl_Texture.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -381,15 +382,58 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, const GLsizei aHeight = theSizeY; const GLsizei aMaxSize = theCtx->MaxTextureSize(); - // Notice that formally general NPOT textures are required by OpenGL 2.0 specifications - // however some hardware (NV30 - GeForce FX, RadeOn 9xxx and Xxxx) supports GLSL but not NPOT! - // Trying to create NPOT textures on such hardware will not fail - // but driver will fall back into software rendering, - const bool toForceP2 = !theCtx->IsGlGreaterEqual (3, 0) && !theCtx->arbNPTW; - const GLsizei aWidthOut = toForceP2 ? OpenGl_Context::GetPowerOfTwo (aWidth, aMaxSize) : Min (aWidth, aMaxSize); - const GLsizei aHeightOut = toForceP2 ? OpenGl_Context::GetPowerOfTwo (aHeight, aMaxSize) : Min (aHeight, aMaxSize); - const GLenum aFilter = (myParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR; - const GLenum aWrapMode = myParams->IsRepeat() ? GL_REPEAT : theCtx->TextureWrapClamp(); + if (aWidth > aMaxSize || aHeight > aMaxSize) + { + TCollection_ExtendedString aWarnMessage = TCollection_ExtendedString ("Error: Texture dimension - ") + + aWidth + "x" + aHeight + " exceeds hardware limits (" + aMaxSize + "x" + aMaxSize + ")"; + + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aWarnMessage); + Release (theCtx.operator->()); + return false; + } +#if !defined(GL_ES_VERSION_2_0) + else if (!theCtx->IsGlGreaterEqual (3, 0) && !theCtx->arbNPTW) + { + // Notice that formally general NPOT textures are required by OpenGL 2.0 specifications + // however some hardware (NV30 - GeForce FX, RadeOn 9xxx and Xxxx) supports GLSL but not NPOT! + // Trying to create NPOT textures on such hardware will not fail + // but driver will fall back into software rendering, + const GLsizei aWidthP2 = OpenGl_Context::GetPowerOfTwo (aWidth, aMaxSize); + const GLsizei aHeightP2 = OpenGl_Context::GetPowerOfTwo (aHeight, aMaxSize); + + if (aWidth != aWidthP2 || (theType != Graphic3d_TOT_1D && aHeight != aHeightP2)) + { + TCollection_ExtendedString aWarnMessage = + TCollection_ExtendedString ("Error: NPOT Textures (") + aWidth + "x" + aHeight + ") are not supported by hardware."; + + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aWarnMessage); + + Release (theCtx.operator->()); + return false; + } + } +#else + else if (!theCtx->IsGlGreaterEqual (3, 0) && theType == Graphic3d_TOT_2D_MIPMAP) + { + // Mipmap NPOT textures are not supported by OpenGL ES 2.0. + const GLsizei aWidthP2 = OpenGl_Context::GetPowerOfTwo (aWidth, aMaxSize); + const GLsizei aHeightP2 = OpenGl_Context::GetPowerOfTwo (aHeight, aMaxSize); + + if (aWidth != aWidthP2 || aHeight != aHeightP2) + { + TCollection_ExtendedString aWarnMessage = + TCollection_ExtendedString ("Error: Mipmap NPOT Textures (") + aWidth + "x" + aHeight + ") are not supported by OpenGL ES 2.0"; + + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aWarnMessage); + + Release (theCtx.operator->()); + return false; + } + } +#endif + + const GLenum aFilter = (myParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR; + const GLenum aWrapMode = myParams->IsRepeat() ? GL_REPEAT : theCtx->TextureWrapClamp(); #if !defined(GL_ES_VERSION_2_0) GLint aTestWidth = 0; @@ -399,6 +443,8 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, // setup the alignment OpenGl_UnpackAlignmentSentry anUnpackSentry; + (void)anUnpackSentry; // avoid compiler warning + if (aDataPtr != NULL) { const GLint anAligment = Min ((GLint )theImage->MaxRowAligmentBytes(), 8); // OpenGL supports alignment upto 8 bytes @@ -423,31 +469,9 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, aFilter); glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, aWrapMode); - Image_PixMap aCopy; - if (aDataPtr != NULL) - { - if (aWidth != aWidthOut) - { - glPixelStorei (GL_PACK_ALIGNMENT, 1); - glPixelStorei (GL_PACK_ROW_LENGTH, 0); - if (!aCopy.InitTrash (theImage->Format(), Standard_Size(aWidthOut), 1) - || gluScaleImage (thePixelFormat, - aWidth, 1, theDataType, theImage->Data(), - aWidthOut, 1, theDataType, aCopy.ChangeData()) != 0) - { - Unbind (theCtx); - Release (theCtx.operator->()); - return false; - } - - aDataPtr = (GLvoid* )aCopy.Data(); - anUnpackSentry.Reset(); - } - } - // use proxy to check texture could be created or not glTexImage1D (GL_PROXY_TEXTURE_1D, 0, anIntFormat, - aWidthOut, 0, + aWidth, 0, thePixelFormat, theDataType, NULL); glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth); if (aTestWidth == 0) @@ -459,7 +483,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, } glTexImage1D (GL_TEXTURE_1D, 0, anIntFormat, - aWidthOut, 0, + aWidth, 0, thePixelFormat, theDataType, aDataPtr); if (glGetError() != GL_NO_ERROR) { @@ -468,12 +492,13 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, return false; } - mySizeX = aWidthOut; + mySizeX = aWidth; mySizeY = 1; Unbind (theCtx); return true; #else + Release (theCtx.operator->()); return false; #endif } @@ -486,39 +511,10 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aWrapMode); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aWrapMode); - Image_PixMap aCopy; - if (aDataPtr != NULL) - { - if (aWidth != aWidthOut || aHeight != aHeightOut) - { - #if !defined(GL_ES_VERSION_2_0) - // scale texture - glPixelStorei (GL_PACK_ALIGNMENT, 1); - glPixelStorei (GL_PACK_ROW_LENGTH, 0); - if (!aCopy.InitTrash (theImage->Format(), Standard_Size(aWidthOut), Standard_Size(aHeightOut)) - || gluScaleImage (thePixelFormat, - aWidth, aHeight, theDataType, theImage->Data(), - aWidthOut, aHeightOut, theDataType, aCopy.ChangeData()) != 0) - { - Unbind (theCtx); - Release (theCtx.operator->()); - return false; - } - - aDataPtr = (GLvoid* )aCopy.Data(); - anUnpackSentry.Reset(); - #else - Unbind (theCtx); - Release (theCtx.operator->()); - return false; - #endif - } - } - #if !defined(GL_ES_VERSION_2_0) // use proxy to check texture could be created or not glTexImage2D (GL_PROXY_TEXTURE_2D, 0, anIntFormat, - aWidthOut, aHeightOut, 0, + aWidth, aHeight, 0, thePixelFormat, theDataType, NULL); glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth); glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight); @@ -532,7 +528,7 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, #endif glTexImage2D (GL_TEXTURE_2D, 0, anIntFormat, - aWidthOut, aHeightOut, 0, + aWidth, aHeight, 0, thePixelFormat, theDataType, aDataPtr); if (glGetError() != GL_NO_ERROR) { @@ -541,8 +537,8 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, return false; } - mySizeX = aWidthOut; - mySizeY = aHeightOut; + mySizeX = aWidth; + mySizeY = aHeight; Unbind (theCtx); return true; @@ -569,65 +565,62 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aWrapMode); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aWrapMode); - if (theCtx->arbFBO != NULL - && aWidth == aWidthOut && aHeight == aHeightOut) + #if !defined(GL_ES_VERSION_2_0) + // use proxy to check texture could be created or not + glTexImage2D (GL_PROXY_TEXTURE_2D, 0, anIntFormat, + aWidth, aHeight, 0, + thePixelFormat, theDataType, NULL); + glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth); + glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight); + if (aTestWidth == 0 || aTestHeight == 0) { - #if !defined(GL_ES_VERSION_2_0) - // use proxy to check texture could be created or not - glTexImage2D (GL_PROXY_TEXTURE_2D, 0, anIntFormat, - aWidthOut, aHeightOut, 0, - thePixelFormat, theDataType, NULL); - glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth); - glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight); - if (aTestWidth == 0 || aTestHeight == 0) - { - // no memory or broken input parameters - Unbind (theCtx); - Release (theCtx.operator->()); - return false; - } - #endif + // no memory or broken input parameters + Unbind (theCtx); + Release (theCtx.operator->()); + return false; + } + #endif + + // upload main picture + glTexImage2D (GL_TEXTURE_2D, 0, anIntFormat, + aWidth, aHeight, 0, + thePixelFormat, theDataType, theImage->Data()); + if (glGetError() != GL_NO_ERROR) + { + Unbind (theCtx); + Release (theCtx.operator->()); + return false; + } + + mySizeX = aWidth; + mySizeY = aHeight; + + if (theCtx->arbFBO != NULL) + { + // generate mipmaps + //glHint (GL_GENERATE_MIPMAP_HINT, GL_NICEST); + theCtx->arbFBO->glGenerateMipmap (GL_TEXTURE_2D); - // upload main picture - glTexImage2D (GL_TEXTURE_2D, 0, anIntFormat, - aWidthOut, aHeightOut, 0, - thePixelFormat, theDataType, theImage->Data()); if (glGetError() != GL_NO_ERROR) { Unbind (theCtx); Release (theCtx.operator->()); return false; } - - mySizeX = aWidthOut; - mySizeY = aHeightOut; - - // generate mipmaps - //glHint (GL_GENERATE_MIPMAP_HINT, GL_NICEST); - theCtx->arbFBO->glGenerateMipmap (GL_TEXTURE_2D); - - Unbind (theCtx); - return true; } else { - #if !defined(GL_ES_VERSION_2_0) - bool isCreated = gluBuild2DMipmaps (GL_TEXTURE_2D, anIntFormat, - aWidth, aHeight, - thePixelFormat, theDataType, theImage->Data()) == 0; - if (isCreated) - { - glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &mySizeX); - glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &mySizeY); - } + const TCollection_ExtendedString aWarnMessage ("Warning: generating mipmaps requires GL_ARB_framebuffer_object extension which is missing."); + + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_PORTABILITY_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, aWarnMessage); Unbind (theCtx); - return isCreated; - #else - Unbind (theCtx); + Release (theCtx.operator->()); return false; - #endif } + + Unbind (theCtx); + return true; } default: { diff --git a/src/TKOpenGl/CMakeLists.txt b/src/TKOpenGl/CMakeLists.txt index 8458346ab4..ad0094f954 100644 --- a/src/TKOpenGl/CMakeLists.txt +++ b/src/TKOpenGl/CMakeLists.txt @@ -6,7 +6,6 @@ set (TOOLKIT_MODULES if (WIN32) list( APPEND USED_LIBS opengl32.lib ) - list( APPEND USED_LIBS glu32.lib ) list( APPEND USED_LIBS user32.lib ) list( APPEND USED_LIBS gdi32.lib ) list( APPEND USED_LIBS ws2_32.lib ) @@ -15,7 +14,6 @@ elseif(APPLE) find_library(FRAMEWORKS_OPENGL NAMES OpenGL) if(USE_GLX) list( APPEND USED_LIBS GL ) - list( APPEND USED_LIBS GLU ) else() list( APPEND USED_LIBS ${FRAMEWORKS_OPENGL} ) endif() @@ -26,7 +24,6 @@ elseif(APPLE) list( APPEND USED_LIBS ${FRAMEWORKS_IOKIT} ) list( APPEND USED_LIBS freetype ) else() - list( APPEND USED_LIBS GLU ) list( APPEND USED_LIBS GL ) list( APPEND USED_LIBS freetype ) endif() diff --git a/src/TKService/CMakeLists.txt b/src/TKService/CMakeLists.txt index 6e7a6274a1..8290ea104a 100644 --- a/src/TKService/CMakeLists.txt +++ b/src/TKService/CMakeLists.txt @@ -18,12 +18,10 @@ endif() if (WIN32) list( APPEND USED_LIBS opengl32.lib ) - list( APPEND USED_LIBS glu32.lib ) elseif(APPLE) find_library(FRAMEWORKS_OPENGL NAMES OpenGL) if(USE_GLX) list( APPEND USED_LIBS GL ) - list( APPEND USED_LIBS GLU ) find_package(X11 COMPONENTS X11 Xext Xmu Xi) list( APPEND USED_LIBS ${X11_LIBRARIES} ) list( APPEND USED_LIBS ${X11_Xi_LIB} ) @@ -40,7 +38,6 @@ elseif(APPLE) find_library(FRAMEWORKS_IOKIT NAMES IOKit) list( APPEND USED_LIBS ${FRAMEWORKS_IOKIT} ) else() - list( APPEND USED_LIBS GLU ) list( APPEND USED_LIBS GL ) list( APPEND USED_LIBS X11 ) list( APPEND USED_LIBS Xext ) diff --git a/src/TKV3d/CMakeLists.txt b/src/TKV3d/CMakeLists.txt index b8654ed89e..5944aaf7f3 100644 --- a/src/TKV3d/CMakeLists.txt +++ b/src/TKV3d/CMakeLists.txt @@ -18,18 +18,15 @@ if (WIN32) list( APPEND USED_LIBS user32.lib ) list( APPEND USED_LIBS gdi32.lib ) list( APPEND USED_LIBS opengl32.lib ) - list( APPEND USED_LIBS glu32.lib ) elseif(APPLE) find_library(FRAMEWORKS_OPENGL NAMES OpenGL) if(USE_GLX) list( APPEND USED_LIBS GL ) - list( APPEND USED_LIBS GLU ) else() list( APPEND USED_LIBS ${FRAMEWORKS_OPENGL} ) endif() list( APPEND USED_LIBS freetype ) else() - list( APPEND USED_LIBS GLU ) list( APPEND USED_LIBS GL ) list( APPEND USED_LIBS freetype ) endif() diff --git a/src/TKViewerTest/CMakeLists.txt b/src/TKViewerTest/CMakeLists.txt index 30c52e9ea7..d51bb0d198 100644 --- a/src/TKViewerTest/CMakeLists.txt +++ b/src/TKViewerTest/CMakeLists.txt @@ -8,7 +8,6 @@ if (WIN32) list( APPEND USED_LIBS user32.lib ) list( APPEND USED_LIBS gdi32.lib ) list( APPEND USED_LIBS opengl32.lib ) - list( APPEND USED_LIBS glu32.lib ) elseif(APPLE) find_library(FRAMEWORKS_TCL NAMES Tcl) list( APPEND USED_LIBS ${FRAMEWORKS_TCL} ) @@ -17,7 +16,6 @@ elseif(APPLE) find_library(FRAMEWORKS_OPENGL NAMES OpenGL) if(USE_GLX) list( APPEND USED_LIBS GL ) - list( APPEND USED_LIBS GLU ) else() list( APPEND USED_LIBS ${FRAMEWORKS_OPENGL} ) endif() @@ -31,7 +29,6 @@ else() list( APPEND USED_LIBS tcl8.6 ) list( APPEND USED_LIBS X11 ) list( APPEND USED_LIBS tk8.6 ) - list( APPEND USED_LIBS GLU ) list( APPEND USED_LIBS GL ) list( APPEND USED_LIBS freetype ) endif()