0025162: Visualization, TKOpenGl - drop GLU library dependency
authorisk <isk@opencascade.com>
Tue, 8 Sep 2015 12:15:04 +0000 (15:15 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 10 Sep 2015 13:50:17 +0000 (16:50 +0300)
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
samples/qt/VoxelDemo/src/VoxelClient_VisDrawer.cxx
src/OpenGl/OpenGl_GlFunctions.hxx
src/OpenGl/OpenGl_Texture.cxx
src/TKOpenGl/CMakeLists.txt
src/TKService/CMakeLists.txt
src/TKV3d/CMakeLists.txt
src/TKViewerTest/CMakeLists.txt

index 0b2e3c9..af862eb 100644 (file)
@@ -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"
index 79d2bb4..ee315c2 100644 (file)
 // 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 <windows.h>
+#endif
+
+#if defined(__APPLE__)
+  #include <OpenGL/glu.h>
+#else
+  #include <GL/glu.h>
+#endif
+
 #include "VoxelClient_VisDrawer.h"
 
 #include <OpenGl_GlCore11.hxx>
index c036cbf..d75d686 100644 (file)
@@ -43,7 +43,6 @@
     #include <OpenGLES/ES2/gl.h>
   #else
     #include <OpenGL/gl.h>
-    #include <OpenGL/glu.h>
   #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 <GLES3/gl3.h>
 #else
   #include <GL/gl.h>
-  #include <GL/glu.h>
 #endif
 
 #if defined(GL_ES_VERSION_2_0)
index 0f08435..dde0ff7 100644 (file)
@@ -18,6 +18,7 @@
 #include <OpenGl_Context.hxx>
 #include <OpenGl_GlCore15.hxx>
 #include <Graphic3d_TextureParams.hxx>
+#include <TCollection_ExtendedString.hxx>
 #include <Standard_Assert.hxx>
 #include <Image_PixMap.hxx>
 
@@ -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)
+      {
+        // 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)
       {
-      #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
+        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:
     {
index 8458346..ad0094f 100644 (file)
@@ -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()
index 6e7a627..8290ea1 100644 (file)
@@ -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 )
index b8654ed..5944aaf 100644 (file)
@@ -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()
index 30c52e9..d51bb0d 100644 (file)
@@ -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()