1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0024245: TKOpenGL - use Message_Messenger interface to report issues

This commit is contained in:
kgv 2013-10-10 08:41:05 +04:00 committed by bugmaster
parent 8be24f106b
commit cbf1862449
4 changed files with 99 additions and 27 deletions

View File

@ -31,6 +31,7 @@
#include <OpenGl_ExtGS.hxx> #include <OpenGl_ExtGS.hxx>
#include <OpenGl_GlCore20.hxx> #include <OpenGl_GlCore20.hxx>
#include <Message_Messenger.hxx>
#include <NCollection_Vector.hxx> #include <NCollection_Vector.hxx>
#include <Standard_ProgramError.hxx> #include <Standard_ProgramError.hxx>
@ -138,6 +139,18 @@ OpenGl_Context::~OpenGl_Context()
mySharedResources.Nullify(); mySharedResources.Nullify();
myDelayed.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 myGlCore20;
delete arbVBO; delete arbVBO;
delete arbTBO; delete arbTBO;
@ -241,15 +254,13 @@ Standard_Boolean OpenGl_Context::MakeCurrent()
DWORD anErrorCode = GetLastError(); DWORD anErrorCode = GetLastError();
FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 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); 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 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
{
std::wcerr << L"OpenGL interface: wglMakeCurrent() failed with #" << int(anErrorCode) << L" error code\n";
}
return Standard_False; return Standard_False;
} }
#else #else
@ -262,7 +273,8 @@ Standard_Boolean OpenGl_Context::MakeCurrent()
if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext)) if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext))
{ {
// if there is no current context it might be impossible to use glGetError() correctly // 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; return Standard_False;
} }
#endif #endif
@ -340,7 +352,7 @@ Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const
const char* anExtString = (const char* )glGetString (GL_EXTENSIONS); const char* anExtString = (const char* )glGetString (GL_EXTENSIONS);
if (anExtString == NULL) 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 Standard_False;
} }
return CheckExtension (anExtString, theExtName); return CheckExtension (anExtString, theExtName);
@ -540,35 +552,50 @@ void OpenGl_Context::readGlVersion()
static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN"; static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN";
static Standard_CString THE_DBGMSG_SOURCES[] = static Standard_CString THE_DBGMSG_SOURCES[] =
{ {
"OpenGL", // GL_DEBUG_SOURCE_API_ARB ".OpenGL", // GL_DEBUG_SOURCE_API_ARB
"Window System", // GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB
"Shader Compiler", // GL_DEBUG_SOURCE_SHADER_COMPILER_ARB ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER_ARB
"Third Party", // GL_DEBUG_SOURCE_THIRD_PARTY_ARB ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY_ARB
"Application", // GL_DEBUG_SOURCE_APPLICATION_ARB "", // GL_DEBUG_SOURCE_APPLICATION_ARB
"Other" // GL_DEBUG_SOURCE_OTHER_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 "Error", // GL_DEBUG_TYPE_ERROR_ARB
"Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB
"Undefined behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB
"Portability", // GL_DEBUG_TYPE_PORTABILITY_ARB "Portability", // GL_DEBUG_TYPE_PORTABILITY_ARB
"Performance", // GL_DEBUG_TYPE_PERFORMANCE_ARB "Performance", // GL_DEBUG_TYPE_PERFORMANCE_ARB
"Other" // GL_DEBUG_TYPE_OTHER_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_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_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_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW_ARB
//! Callback for GL_ARB_debug_output extension
static void APIENTRY debugCallbackWrap(unsigned int theSource, static void APIENTRY debugCallbackWrap(unsigned int theSource,
unsigned int theType, unsigned int theType,
unsigned int theId, unsigned int theId,
unsigned int theSeverity, unsigned int theSeverity,
int /*theLength*/, int /*theLength*/,
const char* theMessage, 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; //OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API_ARB 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 : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
? THE_DBGMSG_SEV_MEDIUM ? THE_DBGMSG_SEV_MEDIUM
: THE_DBGMSG_SEV_LOW); : THE_DBGMSG_SEV_LOW);
std::cerr << "Source:" << aSrc Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH_ARB
<< " | Type:" << aType ? Message_Alarm
<< " | ID:" << theId : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
<< " | Severity:" << aSev ? Message_Warning
<< " | Message:\n " << theMessage << "\n"; : 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);
} }
// ======================================================================= // =======================================================================

View File

@ -29,6 +29,7 @@
#include <NCollection_Map.hxx> #include <NCollection_Map.hxx>
#include <NCollection_Handle.hxx> #include <NCollection_Handle.hxx>
#include <NCollection_Queue.hxx> #include <NCollection_Queue.hxx>
#include <Message.hxx>
#include <OpenGl_Caps.hxx> #include <OpenGl_Caps.hxx>
#include <OpenGl_Resource.hxx> #include <OpenGl_Resource.hxx>
#include <Standard_Transient.hxx> #include <Standard_Transient.hxx>
@ -260,6 +261,26 @@ public:
//! @return value for GL_MAX_CLIP_PLANES //! @return value for GL_MAX_CLIP_PLANES
Standard_EXPORT Standard_Integer MaxClipPlanes() const; 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: private:
//! Wrapper to system function to retrieve GL function pointer by name. //! 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 myIsFeedback; //!< flag indicates GL_FEEDBACK mode
Standard_Boolean myIsInitialized; //!< flag indicates initialization state Standard_Boolean myIsInitialized; //!< flag indicates initialization state
private: private:
//! Copying allowed only within Handles //! Copying allowed only within Handles

View File

@ -21,6 +21,7 @@
#include <OpenGl_Context.hxx> #include <OpenGl_Context.hxx>
#include <Standard_Assert.hxx> #include <Standard_Assert.hxx>
#include <TCollection_ExtendedString.hxx>
IMPLEMENT_STANDARD_HANDLE (OpenGl_Font, OpenGl_Resource) IMPLEMENT_STANDARD_HANDLE (OpenGl_Font, OpenGl_Resource)
IMPLEMENT_STANDARD_RTTIEXT(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)) if (!aBlackImg.InitZero (Image_PixMap::ImgGray, Standard_Size(aTextureSizeX), Standard_Size(aTextureSizeY))
|| !aTexture->Init (theCtx, aBlackImg, Graphic3d_TOT_2D)) // myTextureFormat || !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;
} }

View File

@ -706,7 +706,14 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
&& aCtx->core15 != NULL && aCtx->core15 != NULL
&& (myDrawMode != GL_POINTS || anAspectMarker->Sprite().IsNull() || !anAspectMarker->Sprite()->IsDisplayList())) && (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;
} }