0024245: TKOpenGL - use Message_Messenger interface to report issues
authorkgv <kgv@opencascade.com>
Thu, 10 Oct 2013 04:41:05 +0000 (08:41 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 10 Oct 2013 13:09:06 +0000 (17:09 +0400)
src/OpenGl/OpenGl_Context.cxx
src/OpenGl/OpenGl_Context.hxx
src/OpenGl/OpenGl_Font.cxx
src/OpenGl/OpenGl_PrimitiveArray.cxx

index a26f482..ab170f7 100644 (file)
@@ -31,6 +31,7 @@
 #include <OpenGl_ExtGS.hxx>
 #include <OpenGl_GlCore20.hxx>
 
 #include <OpenGl_ExtGS.hxx>
 #include <OpenGl_GlCore20.hxx>
 
+#include <Message_Messenger.hxx>
 #include <NCollection_Vector.hxx>
 
 #include <Standard_ProgramError.hxx>
 #include <NCollection_Vector.hxx>
 
 #include <Standard_ProgramError.hxx>
@@ -138,6 +139,18 @@ OpenGl_Context::~OpenGl_Context()
   mySharedResources.Nullify();
   myDelayed.Nullify();
 
   mySharedResources.Nullify();
   myDelayed.Nullify();
 
+  if (arbDbg != NULL
+   && caps->contextDebug)
+  {
+    // reset callback
+    void* aPtr = NULL;
+    glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM_ARB, &aPtr);
+    if (aPtr == this)
+    {
+      arbDbg->glDebugMessageCallbackARB (NULL, NULL);
+    }
+  }
+
   delete myGlCore20;
   delete arbVBO;
   delete arbTBO;
   delete myGlCore20;
   delete arbVBO;
   delete arbTBO;
@@ -241,15 +254,13 @@ Standard_Boolean OpenGl_Context::MakeCurrent()
     DWORD anErrorCode = GetLastError();
     FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                     NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL);
     DWORD anErrorCode = GetLastError();
     FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                     NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL);
+    TCollection_ExtendedString aMsg ("wglMakeCurrent() has failed. ");
     if (aMsgBuff != NULL)
     {
     if (aMsgBuff != NULL)
     {
-      std::wcerr << L"OpenGL interface: wglMakeCurrent() failed. " << aMsgBuff << L" (" << int(anErrorCode) << L")\n";
+      aMsg += (Standard_ExtString )aMsgBuff;
       LocalFree (aMsgBuff);
     }
       LocalFree (aMsgBuff);
     }
-    else
-    {
-      std::wcerr << L"OpenGL interface: wglMakeCurrent() failed with #" << int(anErrorCode) << L" error code\n";
-    }
+    PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
     return Standard_False;
   }
 #else
     return Standard_False;
   }
 #else
@@ -262,7 +273,8 @@ Standard_Boolean OpenGl_Context::MakeCurrent()
   if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext))
   {
     // if there is no current context it might be impossible to use glGetError() correctly
   if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext))
   {
     // if there is no current context it might be impossible to use glGetError() correctly
-    //std::cerr << "glXMakeCurrent() failed!\n";
+    PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB,
+                 "glXMakeCurrent() has failed!");
     return Standard_False;
   }
 #endif
     return Standard_False;
   }
 #endif
@@ -340,7 +352,7 @@ Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const
   const char* anExtString = (const char* )glGetString (GL_EXTENSIONS);
   if (anExtString == NULL)
   {
   const char* anExtString = (const char* )glGetString (GL_EXTENSIONS);
   if (anExtString == NULL)
   {
-    std::cerr << "glGetString (GL_EXTENSIONS) returns NULL! No GL context?\n";
+    Messanger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning);
     return Standard_False;
   }
   return CheckExtension (anExtString, theExtName);
     return Standard_False;
   }
   return CheckExtension (anExtString, theExtName);
@@ -540,35 +552,50 @@ void OpenGl_Context::readGlVersion()
 static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN";
 static Standard_CString THE_DBGMSG_SOURCES[] =
 {
 static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN";
 static Standard_CString THE_DBGMSG_SOURCES[] =
 {
-  "OpenGL",          // GL_DEBUG_SOURCE_API_ARB
-  "Window System",   // GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB
-  "Shader Compiler", // GL_DEBUG_SOURCE_SHADER_COMPILER_ARB
-  "Third Party",     // GL_DEBUG_SOURCE_THIRD_PARTY_ARB
-  "Application",     // GL_DEBUG_SOURCE_APPLICATION_ARB
-  "Other"            // GL_DEBUG_SOURCE_OTHER_ARB
+  ".OpenGL",    // GL_DEBUG_SOURCE_API_ARB
+  ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB
+  ".GLSL",      // GL_DEBUG_SOURCE_SHADER_COMPILER_ARB
+  ".3rdParty",  // GL_DEBUG_SOURCE_THIRD_PARTY_ARB
+  "",           // GL_DEBUG_SOURCE_APPLICATION_ARB
+  ".Other"      // GL_DEBUG_SOURCE_OTHER_ARB
 };
 
 static Standard_CString THE_DBGMSG_TYPES[] =
 {
 };
 
 static Standard_CString THE_DBGMSG_TYPES[] =
 {
-  "Error",              // GL_DEBUG_TYPE_ERROR_ARB
-  "Deprecated",         // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB
-  "Undefined behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB
-  "Portability",        // GL_DEBUG_TYPE_PORTABILITY_ARB
-  "Performance",        // GL_DEBUG_TYPE_PERFORMANCE_ARB
-  "Other"               // GL_DEBUG_TYPE_OTHER_ARB
+  "Error",           // GL_DEBUG_TYPE_ERROR_ARB
+  "Deprecated",      // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB
+  "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB
+  "Portability",     // GL_DEBUG_TYPE_PORTABILITY_ARB
+  "Performance",     // GL_DEBUG_TYPE_PERFORMANCE_ARB
+  "Other"            // GL_DEBUG_TYPE_OTHER_ARB
 };
 
 static Standard_CString THE_DBGMSG_SEV_HIGH   = "High";   // GL_DEBUG_SEVERITY_HIGH_ARB
 static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM_ARB
 static Standard_CString THE_DBGMSG_SEV_LOW    = "Low";    // GL_DEBUG_SEVERITY_LOW_ARB
 
 };
 
 static Standard_CString THE_DBGMSG_SEV_HIGH   = "High";   // GL_DEBUG_SEVERITY_HIGH_ARB
 static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM_ARB
 static Standard_CString THE_DBGMSG_SEV_LOW    = "Low";    // GL_DEBUG_SEVERITY_LOW_ARB
 
+//! Callback for GL_ARB_debug_output extension
 static void APIENTRY debugCallbackWrap(unsigned int theSource,
                                        unsigned int theType,
                                        unsigned int theId,
                                        unsigned int theSeverity,
                                        int          /*theLength*/,
                                        const char*  theMessage,
 static void APIENTRY debugCallbackWrap(unsigned int theSource,
                                        unsigned int theType,
                                        unsigned int theId,
                                        unsigned int theSeverity,
                                        int          /*theLength*/,
                                        const char*  theMessage,
-                                       void*        /*theUserParam*/)
+                                       void*        theUserParam)
+{
+  OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
+  aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage);
+}
+
+// =======================================================================
+// function : PushMessage
+// purpose  :
+// =======================================================================
+void OpenGl_Context::PushMessage (const unsigned int theSource,
+                                  const unsigned int theType,
+                                  const unsigned int theId,
+                                  const unsigned int theSeverity,
+                                  const TCollection_ExtendedString& theMessage)
 {
   //OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
   Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API_ARB
 {
   //OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
   Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API_ARB
@@ -584,11 +611,21 @@ static void APIENTRY debugCallbackWrap(unsigned int theSource,
                          : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
                           ? THE_DBGMSG_SEV_MEDIUM
                           : THE_DBGMSG_SEV_LOW);
                          : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
                           ? THE_DBGMSG_SEV_MEDIUM
                           : THE_DBGMSG_SEV_LOW);
-  std::cerr << "Source:"  << aSrc
-            << " | Type:" << aType
-            << " | ID:"   << theId
-            << " | Severity:" << aSev
-            << " | Message:\n  " << theMessage << "\n";
+  Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH_ARB
+                        ? Message_Alarm
+                        : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
+                         ? Message_Warning
+                         : Message_Info);
+
+  TCollection_ExtendedString aMsg;
+  aMsg += "TKOpenGl"; aMsg += aSrc;
+  aMsg += " | Type: ";        aMsg += aType;
+  aMsg += " | ID: ";          aMsg += (Standard_Integer )theId;
+  aMsg += " | Severity: ";    aMsg += aSev;
+  aMsg += " | Message:\n  ";
+  aMsg += theMessage;
+
+  Messanger()->Send (aMsg, aGrav);
 }
 
 // =======================================================================
 }
 
 // =======================================================================
index 52fc999..a52bb6f 100644 (file)
@@ -29,6 +29,7 @@
 #include <NCollection_Map.hxx>
 #include <NCollection_Handle.hxx>
 #include <NCollection_Queue.hxx>
 #include <NCollection_Map.hxx>
 #include <NCollection_Handle.hxx>
 #include <NCollection_Queue.hxx>
+#include <Message.hxx>
 #include <OpenGl_Caps.hxx>
 #include <OpenGl_Resource.hxx>
 #include <Standard_Transient.hxx>
 #include <OpenGl_Caps.hxx>
 #include <OpenGl_Resource.hxx>
 #include <Standard_Transient.hxx>
@@ -260,6 +261,26 @@ public:
   //! @return value for GL_MAX_CLIP_PLANES
   Standard_EXPORT Standard_Integer MaxClipPlanes() const;
 
   //! @return value for GL_MAX_CLIP_PLANES
   Standard_EXPORT Standard_Integer MaxClipPlanes() const;
 
+public:
+
+  //! @return messanger instance
+  inline const Handle_Message_Messenger& Messanger() const
+  {
+    return Message::DefaultMessenger();
+  }
+
+  //! Callback for GL_ARB_debug_output extension
+  //! @param theSource   message source   within GL_DEBUG_SOURCE_   enumeration
+  //! @param theType     message type     within GL_DEBUG_TYPE_     enumeration
+  //! @param theId       message ID       within source
+  //! @param theSeverity message severity within GL_DEBUG_SEVERITY_ enumeration
+  //! @param theMessage  the message itself
+  Standard_EXPORT void PushMessage (const unsigned int theSource,
+                                    const unsigned int theType,
+                                    const unsigned int theId,
+                                    const unsigned int theSeverity,
+                                    const TCollection_ExtendedString& theMessage);
+
 private:
 
   //! Wrapper to system function to retrieve GL function pointer by name.
 private:
 
   //! Wrapper to system function to retrieve GL function pointer by name.
@@ -334,7 +355,6 @@ private: // context info
   Standard_Boolean myIsFeedback;    //!< flag indicates GL_FEEDBACK mode
   Standard_Boolean myIsInitialized; //!< flag indicates initialization state
 
   Standard_Boolean myIsFeedback;    //!< flag indicates GL_FEEDBACK mode
   Standard_Boolean myIsInitialized; //!< flag indicates initialization state
 
-
 private:
 
   //! Copying allowed only within Handles
 private:
 
   //! Copying allowed only within Handles
index 3f1736c..34e1fb7 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <OpenGl_Context.hxx>
 #include <Standard_Assert.hxx>
 
 #include <OpenGl_Context.hxx>
 #include <Standard_Assert.hxx>
+#include <TCollection_ExtendedString.hxx>
 
 IMPLEMENT_STANDARD_HANDLE (OpenGl_Font, OpenGl_Resource)
 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Font, OpenGl_Resource)
 
 IMPLEMENT_STANDARD_HANDLE (OpenGl_Font, OpenGl_Resource)
 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Font, OpenGl_Resource)
@@ -123,6 +124,13 @@ bool OpenGl_Font::createTexture (const Handle(OpenGl_Context)& theCtx)
   if (!aBlackImg.InitZero (Image_PixMap::ImgGray, Standard_Size(aTextureSizeX), Standard_Size(aTextureSizeY))
    || !aTexture->Init (theCtx, aBlackImg, Graphic3d_TOT_2D)) // myTextureFormat
   {
   if (!aBlackImg.InitZero (Image_PixMap::ImgGray, Standard_Size(aTextureSizeX), Standard_Size(aTextureSizeY))
    || !aTexture->Init (theCtx, aBlackImg, Graphic3d_TOT_2D)) // myTextureFormat
   {
+    TCollection_ExtendedString aMsg;
+    aMsg += "New texture intialization of size ";
+    aMsg += aTextureSizeX;
+    aMsg += "x";
+    aMsg += aTextureSizeY;
+    aMsg += " for textured font has failed.";
+    theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
     return false;
   }
 
     return false;
   }
 
index 396258d..415f02a 100755 (executable)
@@ -706,7 +706,14 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
    && aCtx->core15 != NULL
    && (myDrawMode != GL_POINTS || anAspectMarker->Sprite().IsNull() || !anAspectMarker->Sprite()->IsDisplayList()))
   {
    && aCtx->core15 != NULL
    && (myDrawMode != GL_POINTS || anAspectMarker->Sprite().IsNull() || !anAspectMarker->Sprite()->IsDisplayList()))
   {
-    BuildVBO (theWorkspace);
+    if (!BuildVBO (theWorkspace))
+    {
+      TCollection_ExtendedString aMsg;
+      aMsg += "VBO creation for Primitive Array has failed for ";
+      aMsg += myPArray->num_vertexs;
+      aMsg += " vertices. Out of memory?";
+      aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_PERFORMANCE_ARB, 0, GL_DEBUG_SEVERITY_LOW_ARB, aMsg);
+    }
     myIsVboInit = Standard_True;
   }
 
     myIsVboInit = Standard_True;
   }