Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Error (getting the gl debug extension of opengl in the glResource class.)  (Read 2166 times)

0 Members and 1 Guest are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Hi, I'm trying to debug a project so I'm currently trying to use the openg4.1 extension in the resource class of SFML but it crash :

////////////////////////////////////////////////////////////
GlResource::GlResource(){

        // Protect from concurrent access

        #ifdef SFML_DEBUG
        #ifndef DEBUG_FUNCTIONS_LOADED
        std::cout<<"loading internal sfml debug function"<<std::endl;
        OpenGL::LoadDebugFunctions();
        #define  DEBUG_FUNCTIONS_LOADED
        #endif
        #endif
        // If this is the very first resource, trigger the global context initialization
        Lock lock(mutex);
        if (count == 0)
            priv::GlContext::globalInit();
        #ifdef SFML_DEBUG
        #ifndef DEBUG_FUNCTIONS_INITIALIZED
        std::cout<<"initializing internal opengl debug functions"<<std::endl;
        OpenGL::InitialiseDebugFunctions();
        #define DEBUG_FUNCTIONS_INITIALIZED
        #endif
        #endif // DEBUG_FUNCTIONS_INITIALIZED
        // Increment the resources counter
        count++;


    // Now make sure that there is an active OpenGL context in the current thread
    priv::GlContext::ensureContext();
}
 

Here is the file that someone passed to me :

/***************************************************************************
 * @file GlDebug.cpp
 * @author dragonjoker59
 * @date 07/03/2014
 *
 * @brief Permet l'affichage des informations de debug provenant d'OpenGL
 *
 * @details Utilise les extensions GL_ARB_debug_output et GL_AMDX_debug_output si elles sont disponibles.
 *
 ***************************************************************************/


 #include "GlDebug.hpp"

#include <cstdint>
#include <iostream>

#if defined( _WIN32 )
#   include <Windows.h>
#else
#   include <GL/glx.h>
#endif

#include <GL/gl.h>

//*************************************************************************************************

namespace gl_api
{
    /** Récupère une fonction dans la dll OpenGL actuellement chargée
    @param p_strName
        Le nom de la fonction
    @param p_func
        Reçoit la fonction
    @return
        true si la fonction a été trouvée, false sinon
    */

        template< typename Func >
        bool GetFunction( std::string const & p_strName, Func & p_func )
        {
#if defined( _WIN32 )
                p_func = reinterpret_cast< Func >( wglGetProcAddress( p_strName.c_str() ) );
#elif defined( __linux__ )
                p_func = reinterpret_cast< Func >( glXGetProcAddress( (GLubyte const *)p_strName.c_str() ) );
#endif
                return p_func != NULL;
        }

#define MAKE_GL_EXTENSION( x )  static const std::string x = "GL_"#x;

    MAKE_GL_EXTENSION( ARB_debug_output )
    MAKE_GL_EXTENSION( AMDX_debug_output )

    //! Dit que l'on veut les informations de debug en synchrone
    static const int iGL_DEBUG_OUTPUT_SYNCHRONOUS = 0x8242;

    /** Les types d'informations
    */

    typedef enum eGL_DEBUG_TYPE : uint32_t
    {   eGL_DEBUG_TYPE_ERROR                            = 0x824C
    ,   eGL_DEBUG_TYPE_DEPRECATED_BEHAVIOR      = 0x824D
    ,   eGL_DEBUG_TYPE_UNDEFINED_BEHAVIOR       = 0x824E
    ,   eGL_DEBUG_TYPE_PORTABILITY                      = 0x824F
    ,   eGL_DEBUG_TYPE_PERFORMANCE                      = 0x8250
    ,   eGL_DEBUG_TYPE_OTHER                            = 0x8251
    }   eGL_DEBUG_TYPE;

    /** Les sources des informations
    */

    typedef enum eGL_DEBUG_SOURCE : uint32_t
    {   eGL_DEBUG_SOURCE_API                = 0x8246
    ,   eGL_DEBUG_SOURCE_WINDOW_SYSTEM      = 0x8247
    ,   eGL_DEBUG_SOURCE_SHADER_COMPILER    = 0x8248
    ,   eGL_DEBUG_SOURCE_THIRD_PARTY        = 0x8249
    ,   eGL_DEBUG_SOURCE_APPLICATION        = 0x824A
    ,   eGL_DEBUG_SOURCE_OTHER                          = 0x824B
    }   eGL_DEBUG_SOURCE;

    /** Les catégories d'informations
    */

    typedef enum eGL_DEBUG_CATEGORY : uint32_t
    {   eGL_DEBUG_CATEGORY_API_ERROR                    = 0x9149
    ,   eGL_DEBUG_CATEGORY_WINDOW_SYSTEM                = 0x914A
    ,   eGL_DEBUG_CATEGORY_DEPRECATION                  = 0x914B
    ,   eGL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR   = 0x914C
    ,   eGL_DEBUG_CATEGORY_PERFORMANCE                  = 0x914D
    ,   eGL_DEBUG_CATEGORY_SHADER_COMPILER              = 0x914E
    ,   eGL_DEBUG_CATEGORY_APPLICATION                  = 0x914F
    ,   eGL_DEBUG_CATEGORY_OTHER                                = 0x9150
    }   eGL_DEBUG_CATEGORY;

    /** Les importances des informations
    */

    typedef enum eGL_DEBUG_SEVERITY : uint32_t
    {   eGL_DEBUG_SEVERITY_HIGH         = 0x9146
    ,   eGL_DEBUG_SEVERITY_MEDIUM       = 0x9147
    ,   eGL_DEBUG_SEVERITY_LOW          = 0x9148
    }   eGL_DEBUG_SEVERITY;
}

//*************************************************************************************************

typedef void (CALLBACK * PFNGLDEBUGPROC)( uint32_t source, uint32_t type, uint32_t id, uint32_t severity, int length, const char * message, void * userParam );
typedef void (CALLBACK * PFNGLDEBUGAMDPROC)( uint32_t id, uint32_t category, uint32_t severity, int length, const char* message, void* userParam );
typedef void (CALLBACK * PFNGLDEBUGMESSAGECALLBACK)( PFNGLDEBUGPROC callback, void * userParam );
typedef void (CALLBACK * PFNGLDEBUGMESSAGECALLBACKAMD)( PFNGLDEBUGAMDPROC callback, void * userParam );

PFNGLDEBUGMESSAGECALLBACK glDebugMessageCallback = NULL;
PFNGLDEBUGMESSAGECALLBACKAMD glDebugMessageCallbackAMD = NULL;

void OpenGL::LoadDebugFunctions()
{
    std::string l_strExtensions = (char const *)glGetString( GL_EXTENSIONS );

    if( l_strExtensions.find( gl_api::ARB_debug_output ) != std::string::npos )
    {
        if( !gl_api::GetFunction( "glDebugMessageCallback", glDebugMessageCallback ) )
        {
            if( !gl_api::GetFunction( "glDebugMessageCallbackARB", glDebugMessageCallback ) )
            {
                std::cout << "Unable to retrieve function glDebugMessageCallback" << std::endl;
            }
        }
    }
    else if( l_strExtensions.find( gl_api::AMDX_debug_output ) != std::string::npos )
    {
        if( !gl_api::GetFunction( "glDebugMessageCallbackAMD", glDebugMessageCallbackAMD ) )
        {
            std::cout << "Unable to retrieve function glDebugMessageCallbackAMD" << std::endl;
        }
    }
}

void OpenGL::InitialiseDebugFunctions()
{
    if( glDebugMessageCallback )
    {
        glDebugMessageCallback( PFNGLDEBUGPROC( &CallbackDebugLog ), NULL );
        glEnable( gl_api::iGL_DEBUG_OUTPUT_SYNCHRONOUS );
    }
    else if( glDebugMessageCallbackAMD )
    {
         glDebugMessageCallbackAMD( PFNGLDEBUGAMDPROC( &CallbackDebugLogAMD ), NULL );
        glEnable( gl_api::iGL_DEBUG_OUTPUT_SYNCHRONOUS );
    }
}

void OpenGL::CallbackDebugLog( uint32_t source, uint32_t type, uint32_t id, uint32_t severity, int length, const char * message, void * userParam  )
{
    std::cout << "OpenGL Debug - ";

    switch( source )
    {
    case gl_api::eGL_DEBUG_SOURCE_API:                          std::cout << "Source:OpenGL\t";                     break;
    case gl_api::eGL_DEBUG_SOURCE_WINDOW_SYSTEM:        std::cout << "Source:Windows\t";                        break;
    case gl_api::eGL_DEBUG_SOURCE_SHADER_COMPILER:      std::cout << "Source:Shader compiler\t";        break;
    case gl_api::eGL_DEBUG_SOURCE_THIRD_PARTY:          std::cout << "Source:Third party\t";            break;
    case gl_api::eGL_DEBUG_SOURCE_APPLICATION:          std::cout << "Source:Application\t";            break;
    case gl_api::eGL_DEBUG_SOURCE_OTHER:                        std::cout << "Source:Other\t";                          break;
    }

    switch( type )
    {
    case gl_api::eGL_DEBUG_TYPE_ERROR:                                  std::cout << "Type:Error\t";                            break;
    case gl_api::eGL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:    std::cout << "Type:Deprecated behavior\t";      break;
    case gl_api::eGL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:             std::cout << "Type:Undefined behavior\t";       break;
    case gl_api::eGL_DEBUG_TYPE_PORTABILITY:                    std::cout << "Type:Portability\t";                      break;
    case gl_api::eGL_DEBUG_TYPE_PERFORMANCE:                    std::cout << "Type:Performance\t";                      break;
    case gl_api::eGL_DEBUG_TYPE_OTHER:                                  std::cout << "Type:Other\t";                            break;
    }

    std::cout << "ID:" << id << "\t";

    switch( severity )
    {
    case gl_api::eGL_DEBUG_SEVERITY_HIGH:       std::cout << "Severity:High\t";     break;
    case gl_api::eGL_DEBUG_SEVERITY_MEDIUM:     std::cout << "Severity:Medium\t";       break;
    case gl_api::eGL_DEBUG_SEVERITY_LOW:        std::cout << "Severity:Low\t";          break;
    }

    std::cout << "Message:" << message << std::endl;
}

void OpenGL::CallbackDebugLogAMD( uint32_t id, uint32_t category, uint32_t severity, int length, const char* message, void* userParam )
{
    std::cout << "OpenGL Debug - ";

    switch( category )
    {
    case gl_api::eGL_DEBUG_CATEGORY_API_ERROR:                  std::cout << "Category:OpenGL\t";                               break;
    case gl_api::eGL_DEBUG_CATEGORY_WINDOW_SYSTEM:              std::cout << "Category:Windows\t";                              break;
    case gl_api::eGL_DEBUG_CATEGORY_DEPRECATION:                std::cout << "Category:Deprecated behavior\t";  break;
    case gl_api::eGL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR: std::cout << "Category:Undefined behavior\t";   break;
    case gl_api::eGL_DEBUG_CATEGORY_PERFORMANCE:                std::cout << "Category:Performance\t";                  break;
    case gl_api::eGL_DEBUG_CATEGORY_SHADER_COMPILER:    std::cout << "Category:Shader compiler\t";              break;
    case gl_api::eGL_DEBUG_CATEGORY_APPLICATION:                std::cout << "Category:Application\t";                  break;
    case gl_api::eGL_DEBUG_CATEGORY_OTHER:                              std::cout << "Category:Other\t";                                break;
    }

    std::cout << "ID:" << id << "\t";

    switch( severity )
    {
    case gl_api::eGL_DEBUG_SEVERITY_HIGH:       std::cout << "Severity:High\t"; break;
    case gl_api::eGL_DEBUG_SEVERITY_MEDIUM:     std::cout << "Severity:Medium\t";       break;
    case gl_api::eGL_DEBUG_SEVERITY_LOW:        std::cout << "Severity:Low\t";  break;
    }

    std::cout << "Message:" << message << std::endl;
}

//*************************************************************************************************
 

It crash in the function loadDebugFunctions and give me this error :
#0 0044CAA0     __cxa_throw () (??:??)
#1 0044AFDB     std::__throw_logic_error(char const*) () (??:??)
#2 004A3714     char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) () (??:??)
 

Does the version of glew used by SFML support the new opengl4.1 extension ?

Or should I get a newest version of glew ?


Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Ok it's solved, I've found why.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Yesterday someone told you to try to solve your problems before posting. Today you come back with a new problem, and again, you solve it two hours after posting. I just hope you didn't do it on purpose.
Laurent Gomila - SFML developer

 

anything