Commit ce2d6f47 authored by Robert Menzel's avatar Robert Menzel

debug extension and context can be simulated independently

parent a5a3d0d1
......@@ -1253,6 +1253,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1794,6 +1794,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1854,6 +1854,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1492,6 +1492,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1510,6 +1510,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1589,6 +1589,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1626,6 +1626,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1732,6 +1732,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1993,6 +1993,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -2012,6 +2012,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1492,6 +1492,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1510,6 +1510,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1589,6 +1589,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1626,6 +1626,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1732,6 +1732,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -1993,6 +1993,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -2012,6 +2012,7 @@ typedef unsigned int GLhandleARB;
int ogl_LoadFunctions();
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext );
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
......
......@@ -50,7 +50,7 @@ bool init()
return false;
}
#elif defined( ACGL_EXTENSION_LOADER_GLLOADGEN )
int loaded = ogl_LoadFunctions();
int loaded = ogl_LoadFunctionsForDebug( GL_TRUE, GL_TRUE );
if (loaded == ogl_LOAD_FAILED)
{
Utils::error() << "could not load OpenGL functions!" << std::endl;
......
......@@ -83,6 +83,8 @@ extern GLvoid (CODEGEN_FUNCPTR *_original_glDisable)( GLenum );
extern GLboolean (CODEGEN_FUNCPTR *_original_glIsEnabled)( GLenum );
extern GLvoid (CODEGEN_FUNCPTR *_original_glGetIntegerv)( GLenum, GLint * );
extern GLvoid (CODEGEN_FUNCPTR *_original_glGetPointerv)( GLenum, GLvoid ** );
// not used in here, just used to check if glClear redirects to the original function ;-)
extern GLvoid (CODEGEN_FUNCPTR *_original_glClear)(GLbitfield);
// shortcut to add OpenGL errors detected by this emulation:
#define INSERT_API_ERROR( e, m ) KHR_DEBUG_EMULATOR_lastGLError = e; KHR_DEBUG_EMULATOR_DebugMessageInsert_internal(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, e, GL_DEBUG_SEVERITY_HIGH, -1, m );
......@@ -242,10 +244,17 @@ void KHR_DEBUG_EMULATOR_DebugMessageInsert_internal(GLenum source, GLenum type,
/////////////////////////////
/// glDebugMessageCallback
/////////////////////////////
GLboolean debugContextIsSimulated();
void KHR_DEBUG_EMULATOR_DebugMessageCallback(GLDEBUGPROC callback, const void * userParam)
{
KHR_DEBUG_EMULATOR_callback = callback;
KHR_DEBUG_EMULATOR_userParam = userParam;
if (debugContextIsSimulated()) {
// we will never get here if the debug context is real in the first place!
KHR_DEBUG_EMULATOR_DebugMessageInsert_internal( GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_PERFORMANCE, 0, GL_DEBUG_SEVERITY_NOTIFICATION, -1, "Note: Application is not running in a real debug context, debug context behaviour is only simulated in a slow way!" );
}
}
......@@ -651,7 +660,11 @@ GLboolean KHR_DEBUG_EMULATOR_IsEnabled(GLenum cap){
void KHR_DEBUG_EMULATOR_GetIntegerv(GLenum pname, GLint * params){
if (pname == GL_CONTEXT_FLAGS) {
_original_glGetIntegerv(pname, params);
*params |= GL_CONTEXT_FLAG_DEBUG_BIT; // we make this a debug context ;-)
if (debugContextIsSimulated()) {
// debug context simulation
*params |= GL_CONTEXT_FLAG_DEBUG_BIT; // we make this a debug context ;-)
}
} else if (pname == GL_MAX_DEBUG_MESSAGE_LENGTH) {
*params = KHR_DEBUG_EMULATOR_MAX_DEBUG_MESSAGE_LENGTH;
} else if (pname == GL_MAX_DEBUG_LOGGED_MESSAGES) {
......@@ -728,6 +741,15 @@ void KHR_DEBUG_EMULATOR_CHECK_GL_ERROR() {
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
GLboolean debugContextIsSimulated()
{
// Test if we simulate a debug context:
// if the externally visible glClear is also the original function, we don't
// simulate a debug context. Note that if they are the same, it doesn't mean there
// is a real debug context, just that we don't mess with the original context!
return (_original_glClear != glClear);
}
GLboolean isValidSeverity( GLenum e )
{
if ((e == GL_DEBUG_SEVERITY_HIGH) || (e == GL_DEBUG_SEVERITY_MEDIUM) || (e == GL_DEBUG_SEVERITY_LOW) || (e == GL_DEBUG_SEVERITY_NOTIFICATION)) return true;
......
......@@ -7152,8 +7152,31 @@ void mapOriginalGLFunctions() {
_ptrc_glUniformMatrix4x3fv = _original_glUniformMatrix4x3fv;
}
void remapToUseKHR_debugEmulator() {
ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
void simulateKHR_debug() {
ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDebugMessageCallback = KHR_DEBUG_EMULATOR_DebugMessageCallback;
_ptrc_glDebugMessageControl = KHR_DEBUG_EMULATOR_DebugMessageControl;
_ptrc_glDebugMessageInsert = KHR_DEBUG_EMULATOR_DebugMessageInsert;
_ptrc_glGetDebugMessageLog = KHR_DEBUG_EMULATOR_GetDebugMessageLog;
_ptrc_glGetObjectLabel = KHR_DEBUG_EMULATOR_GetObjectLabel;
_ptrc_glGetObjectPtrLabel = KHR_DEBUG_EMULATOR_GetObjectPtrLabel;
_ptrc_glGetPointerv = KHR_DEBUG_EMULATOR_GetPointerv;
_ptrc_glObjectLabel = KHR_DEBUG_EMULATOR_ObjectLabel;
_ptrc_glObjectPtrLabel = KHR_DEBUG_EMULATOR_ObjectPtrLabel;
_ptrc_glPopDebugGroup = KHR_DEBUG_EMULATOR_PopDebugGroup;
_ptrc_glPushDebugGroup = KHR_DEBUG_EMULATOR_PushDebugGroup;
_ptrc_glIsEnabled = KHR_DEBUG_EMULATOR_IsEnabled;
_ptrc_glGetError = KHR_DEBUG_EMULATOR_GetError;
_ptrc_glGetIntegerv = KHR_DEBUG_EMULATOR_GetIntegerv;
_ptrc_glDisable = KHR_DEBUG_EMULATOR_Disable;
_ptrc_glEnable = KHR_DEBUG_EMULATOR_Enable;
}
void simulateDebugContext() {
simulateKHR_debug();
_ptrc_glProgramParameteriEXT = wrapperglProgramParameteriEXT;
_ptrc_glFramebufferTextureARB = wrapperglFramebufferTextureARB;
......@@ -7172,17 +7195,6 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDebugMessageInsertARB = wrapperglDebugMessageInsertARB;
_ptrc_glGetDebugMessageLogARB = wrapperglGetDebugMessageLogARB;
_ptrc_glDebugMessageCallback = KHR_DEBUG_EMULATOR_DebugMessageCallback;
_ptrc_glDebugMessageControl = KHR_DEBUG_EMULATOR_DebugMessageControl;
_ptrc_glDebugMessageInsert = KHR_DEBUG_EMULATOR_DebugMessageInsert;
_ptrc_glGetDebugMessageLog = KHR_DEBUG_EMULATOR_GetDebugMessageLog;
_ptrc_glGetObjectLabel = KHR_DEBUG_EMULATOR_GetObjectLabel;
_ptrc_glGetObjectPtrLabel = KHR_DEBUG_EMULATOR_GetObjectPtrLabel;
_ptrc_glGetPointerv = KHR_DEBUG_EMULATOR_GetPointerv;
_ptrc_glObjectLabel = KHR_DEBUG_EMULATOR_ObjectLabel;
_ptrc_glObjectPtrLabel = KHR_DEBUG_EMULATOR_ObjectPtrLabel;
_ptrc_glPopDebugGroup = KHR_DEBUG_EMULATOR_PopDebugGroup;
_ptrc_glPushDebugGroup = KHR_DEBUG_EMULATOR_PushDebugGroup;
_ptrc_glAccum = wrapperglAccum;
_ptrc_glAlphaFunc = wrapperglAlphaFunc;
......@@ -7238,12 +7250,10 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDepthFunc = wrapperglDepthFunc;
_ptrc_glDepthMask = wrapperglDepthMask;
_ptrc_glDepthRange = wrapperglDepthRange;
_ptrc_glDisable = KHR_DEBUG_EMULATOR_Disable;
_ptrc_glDrawBuffer = wrapperglDrawBuffer;
_ptrc_glDrawPixels = wrapperglDrawPixels;
_ptrc_glEdgeFlag = wrapperglEdgeFlag;
_ptrc_glEdgeFlagv = wrapperglEdgeFlagv;
_ptrc_glEnable = KHR_DEBUG_EMULATOR_Enable;
_ptrc_glEnd = wrapperglEnd;
_ptrc_glEndList = wrapperglEndList;
_ptrc_glEvalCoord1d = wrapperglEvalCoord1d;
......@@ -7271,9 +7281,7 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glGetBooleanv = wrapperglGetBooleanv;
_ptrc_glGetClipPlane = wrapperglGetClipPlane;
_ptrc_glGetDoublev = wrapperglGetDoublev;
_ptrc_glGetError = KHR_DEBUG_EMULATOR_GetError;
_ptrc_glGetFloatv = wrapperglGetFloatv;
_ptrc_glGetIntegerv = KHR_DEBUG_EMULATOR_GetIntegerv;
_ptrc_glGetLightfv = wrapperglGetLightfv;
_ptrc_glGetLightiv = wrapperglGetLightiv;
_ptrc_glGetMapdv = wrapperglGetMapdv;
......@@ -7307,7 +7315,6 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glIndexs = wrapperglIndexs;
_ptrc_glIndexsv = wrapperglIndexsv;
_ptrc_glInitNames = wrapperglInitNames;
_ptrc_glIsEnabled = KHR_DEBUG_EMULATOR_IsEnabled;
_ptrc_glIsList = wrapperglIsList;
_ptrc_glLightModelf = wrapperglLightModelf;
_ptrc_glLightModelfv = wrapperglLightModelfv;
......@@ -7920,7 +7927,20 @@ static void LoadExtByName(const char *extensionName)
int ogl_LoadFunctions()
// if enforceKHRdebug is true, the KHR_debug extension will be available
// if enforceDebugContext is true, the context will behave like a debug context
//
// This means:
// * if both bools are false, do nothing and see what we get.
// * if the OpenGL context is already a debug context (with KHR_debug) the bools will get ignored (no need to enforce something that is already there)
// * if the context is no debug context but enforceDebugContext is true, KHR_debug will also get emulated
// -> this will mean a performance loss.
// * if enforceDebugContext is false, enforceKHRdebug is true and KHR_debug is not supported, it will get emulated but no error messages will get
// generated -> no performance loss.
//
// Note: If KHR_debug gets simulated it will work like being part of the core spec -> it will not nessesarily get reported as an extension
// but the functions are save to be used.
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext )
{
int numFailed = 0;
ClearExtensionVariables();
......@@ -7931,27 +7951,51 @@ int ogl_LoadFunctions()
ProcExtsFromExtString((const char *)_original_glGetString(GL_EXTENSIONS));
numFailed = Load_Version_2_1();
// map externally visible OGL functions to real GL functions:
mapOriginalGLFunctions();
int isDebugContext = 0;
// KHR_debug detection:
if (ogl_IsVersionGEQ(4,3) || (ogl_ext_KHR_debug == 1)) {
//printf("KHR_debug is supported\n");
// map externally visible OGL functions to real GL functions:
mapOriginalGLFunctions();
int isDebugContext = 0;
int KHR_debugIsAvailable = 0;
// KHR_debug detection:
if (ogl_IsVersionGEQ(4,3) || (ogl_ext_KHR_debug == 1)) {
//printf("KHR_debug is supported\n");
KHR_debugIsAvailable = 1;
GLint v;
glGetIntegerv( GL_CONTEXT_FLAGS, &v );
if ((v & GL_CONTEXT_FLAG_DEBUG_BIT) != 0) {
GLint v;
glGetIntegerv( GL_CONTEXT_FLAGS, &v );
if ((v & GL_CONTEXT_FLAG_DEBUG_BIT) != 0) {
isDebugContext = 1;
}
}
if (isDebugContext == 0) {
remapToUseKHR_debugEmulator();
}
// if there is a debug context already, ignore our simulation
// as a debug context implies a running KHR_debug the way we tested for that
if (isDebugContext != 1) {
if (enforceDebugContext == 1) {
// we have to simulate everything
simulateDebugContext();
} else {
// if KHR_debug works already, ignore the flag
if (KHR_debugIsAvailable != 1) {
if (enforceKHRdebug) {
// only simulate KHR_debug in a non-debug context
simulateKHR_debug();
}
}
}
if(numFailed == 0)
}
if(numFailed == 0) {
return ogl_LOAD_SUCCEEDED;
else
} else {
return ogl_LOAD_SUCCEEDED + numFailed;
}
}
// parameter less loader to be compatible with the C loader from glLoadGen:
// KHR_debug extension function will always be available
int ogl_LoadFunctions() {
return ogl_LoadFunctionsForDebug( GL_TRUE, GL_FALSE );
}
......@@ -9750,8 +9750,31 @@ void mapOriginalGLFunctions() {
_ptrc_glVertexAttribIPointer = _original_glVertexAttribIPointer;
}
void remapToUseKHR_debugEmulator() {
ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
void simulateKHR_debug() {
ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDebugMessageCallback = KHR_DEBUG_EMULATOR_DebugMessageCallback;
_ptrc_glDebugMessageControl = KHR_DEBUG_EMULATOR_DebugMessageControl;
_ptrc_glDebugMessageInsert = KHR_DEBUG_EMULATOR_DebugMessageInsert;
_ptrc_glGetDebugMessageLog = KHR_DEBUG_EMULATOR_GetDebugMessageLog;
_ptrc_glGetObjectLabel = KHR_DEBUG_EMULATOR_GetObjectLabel;
_ptrc_glGetObjectPtrLabel = KHR_DEBUG_EMULATOR_GetObjectPtrLabel;
_ptrc_glGetPointerv = KHR_DEBUG_EMULATOR_GetPointerv;
_ptrc_glObjectLabel = KHR_DEBUG_EMULATOR_ObjectLabel;
_ptrc_glObjectPtrLabel = KHR_DEBUG_EMULATOR_ObjectPtrLabel;
_ptrc_glPopDebugGroup = KHR_DEBUG_EMULATOR_PopDebugGroup;
_ptrc_glPushDebugGroup = KHR_DEBUG_EMULATOR_PushDebugGroup;
_ptrc_glIsEnabled = KHR_DEBUG_EMULATOR_IsEnabled;
_ptrc_glGetError = KHR_DEBUG_EMULATOR_GetError;
_ptrc_glGetIntegerv = KHR_DEBUG_EMULATOR_GetIntegerv;
_ptrc_glDisable = KHR_DEBUG_EMULATOR_Disable;
_ptrc_glEnable = KHR_DEBUG_EMULATOR_Enable;
}
void simulateDebugContext() {
simulateKHR_debug();
_ptrc_glProgramParameteriEXT = wrapperglProgramParameteriEXT;
_ptrc_glFramebufferTextureARB = wrapperglFramebufferTextureARB;
......@@ -9770,17 +9793,6 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDebugMessageInsertARB = wrapperglDebugMessageInsertARB;
_ptrc_glGetDebugMessageLogARB = wrapperglGetDebugMessageLogARB;
_ptrc_glDebugMessageCallback = KHR_DEBUG_EMULATOR_DebugMessageCallback;
_ptrc_glDebugMessageControl = KHR_DEBUG_EMULATOR_DebugMessageControl;
_ptrc_glDebugMessageInsert = KHR_DEBUG_EMULATOR_DebugMessageInsert;
_ptrc_glGetDebugMessageLog = KHR_DEBUG_EMULATOR_GetDebugMessageLog;
_ptrc_glGetObjectLabel = KHR_DEBUG_EMULATOR_GetObjectLabel;
_ptrc_glGetObjectPtrLabel = KHR_DEBUG_EMULATOR_GetObjectPtrLabel;
_ptrc_glGetPointerv = KHR_DEBUG_EMULATOR_GetPointerv;
_ptrc_glObjectLabel = KHR_DEBUG_EMULATOR_ObjectLabel;
_ptrc_glObjectPtrLabel = KHR_DEBUG_EMULATOR_ObjectPtrLabel;
_ptrc_glPopDebugGroup = KHR_DEBUG_EMULATOR_PopDebugGroup;
_ptrc_glPushDebugGroup = KHR_DEBUG_EMULATOR_PushDebugGroup;
_ptrc_glClearDepthf = wrapperglClearDepthf;
_ptrc_glDepthRangef = wrapperglDepthRangef;
......@@ -9966,12 +9978,10 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDepthFunc = wrapperglDepthFunc;
_ptrc_glDepthMask = wrapperglDepthMask;
_ptrc_glDepthRange = wrapperglDepthRange;
_ptrc_glDisable = KHR_DEBUG_EMULATOR_Disable;
_ptrc_glDrawBuffer = wrapperglDrawBuffer;
_ptrc_glDrawPixels = wrapperglDrawPixels;
_ptrc_glEdgeFlag = wrapperglEdgeFlag;
_ptrc_glEdgeFlagv = wrapperglEdgeFlagv;
_ptrc_glEnable = KHR_DEBUG_EMULATOR_Enable;
_ptrc_glEnd = wrapperglEnd;
_ptrc_glEndList = wrapperglEndList;
_ptrc_glEvalCoord1d = wrapperglEvalCoord1d;
......@@ -9999,9 +10009,7 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glGetBooleanv = wrapperglGetBooleanv;
_ptrc_glGetClipPlane = wrapperglGetClipPlane;
_ptrc_glGetDoublev = wrapperglGetDoublev;
_ptrc_glGetError = KHR_DEBUG_EMULATOR_GetError;
_ptrc_glGetFloatv = wrapperglGetFloatv;
_ptrc_glGetIntegerv = KHR_DEBUG_EMULATOR_GetIntegerv;
_ptrc_glGetLightfv = wrapperglGetLightfv;
_ptrc_glGetLightiv = wrapperglGetLightiv;
_ptrc_glGetMapdv = wrapperglGetMapdv;
......@@ -10035,7 +10043,6 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glIndexs = wrapperglIndexs;
_ptrc_glIndexsv = wrapperglIndexsv;
_ptrc_glInitNames = wrapperglInitNames;
_ptrc_glIsEnabled = KHR_DEBUG_EMULATOR_IsEnabled;
_ptrc_glIsList = wrapperglIsList;
_ptrc_glLightModelf = wrapperglLightModelf;
_ptrc_glLightModelfv = wrapperglLightModelfv;
......@@ -10738,7 +10745,20 @@ static void LoadExtByName(const char *extensionName)
int ogl_LoadFunctions()
// if enforceKHRdebug is true, the KHR_debug extension will be available
// if enforceDebugContext is true, the context will behave like a debug context
//
// This means:
// * if both bools are false, do nothing and see what we get.
// * if the OpenGL context is already a debug context (with KHR_debug) the bools will get ignored (no need to enforce something that is already there)
// * if the context is no debug context but enforceDebugContext is true, KHR_debug will also get emulated
// -> this will mean a performance loss.
// * if enforceDebugContext is false, enforceKHRdebug is true and KHR_debug is not supported, it will get emulated but no error messages will get
// generated -> no performance loss.
//
// Note: If KHR_debug gets simulated it will work like being part of the core spec -> it will not nessesarily get reported as an extension
// but the functions are save to be used.
int ogl_LoadFunctionsForDebug( GLboolean enforceKHRdebug, GLboolean enforceDebugContext )
{
int numFailed = 0;
ClearExtensionVariables();
......@@ -10751,27 +10771,51 @@ int ogl_LoadFunctions()
ProcExtsFromExtList();
numFailed = Load_Version_3_0();
// map externally visible OGL functions to real GL functions:
mapOriginalGLFunctions();
int isDebugContext = 0;
// KHR_debug detection:
if (ogl_IsVersionGEQ(4,3) || (ogl_ext_KHR_debug == 1)) {
//printf("KHR_debug is supported\n");
// map externally visible OGL functions to real GL functions:
mapOriginalGLFunctions();
int isDebugContext = 0;
int KHR_debugIsAvailable = 0;
// KHR_debug detection:
if (ogl_IsVersionGEQ(4,3) || (ogl_ext_KHR_debug == 1)) {
//printf("KHR_debug is supported\n");
KHR_debugIsAvailable = 1;
GLint v;
glGetIntegerv( GL_CONTEXT_FLAGS, &v );
if ((v & GL_CONTEXT_FLAG_DEBUG_BIT) != 0) {
GLint v;
glGetIntegerv( GL_CONTEXT_FLAGS, &v );
if ((v & GL_CONTEXT_FLAG_DEBUG_BIT) != 0) {
isDebugContext = 1;
}
}
if (isDebugContext == 0) {
remapToUseKHR_debugEmulator();
}
// if there is a debug context already, ignore our simulation
// as a debug context implies a running KHR_debug the way we tested for that
if (isDebugContext != 1) {
if (enforceDebugContext == 1) {
// we have to simulate everything
simulateDebugContext();
} else {
// if KHR_debug works already, ignore the flag
if (KHR_debugIsAvailable != 1) {
if (enforceKHRdebug) {
// only simulate KHR_debug in a non-debug context
simulateKHR_debug();
}
}
}
if(numFailed == 0)
}
if(numFailed == 0) {
return ogl_LOAD_SUCCEEDED;
else
} else {
return ogl_LOAD_SUCCEEDED + numFailed;
}
}
// parameter less loader to be compatible with the C loader from glLoadGen:
// KHR_debug extension function will always be available
int ogl_LoadFunctions() {
return ogl_LoadFunctionsForDebug( GL_TRUE, GL_FALSE );
}
......@@ -9900,8 +9900,31 @@ void mapOriginalGLFunctions() {
_ptrc_glUniformBlockBinding = _original_glUniformBlockBinding;
}
void remapToUseKHR_debugEmulator() {
ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
void simulateKHR_debug() {
ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDebugMessageCallback = KHR_DEBUG_EMULATOR_DebugMessageCallback;
_ptrc_glDebugMessageControl = KHR_DEBUG_EMULATOR_DebugMessageControl;
_ptrc_glDebugMessageInsert = KHR_DEBUG_EMULATOR_DebugMessageInsert;
_ptrc_glGetDebugMessageLog = KHR_DEBUG_EMULATOR_GetDebugMessageLog;
_ptrc_glGetObjectLabel = KHR_DEBUG_EMULATOR_GetObjectLabel;
_ptrc_glGetObjectPtrLabel = KHR_DEBUG_EMULATOR_GetObjectPtrLabel;
_ptrc_glGetPointerv = KHR_DEBUG_EMULATOR_GetPointerv;
_ptrc_glObjectLabel = KHR_DEBUG_EMULATOR_ObjectLabel;
_ptrc_glObjectPtrLabel = KHR_DEBUG_EMULATOR_ObjectPtrLabel;
_ptrc_glPopDebugGroup = KHR_DEBUG_EMULATOR_PopDebugGroup;
_ptrc_glPushDebugGroup = KHR_DEBUG_EMULATOR_PushDebugGroup;
_ptrc_glIsEnabled = KHR_DEBUG_EMULATOR_IsEnabled;
_ptrc_glGetError = KHR_DEBUG_EMULATOR_GetError;
_ptrc_glGetIntegerv = KHR_DEBUG_EMULATOR_GetIntegerv;
_ptrc_glDisable = KHR_DEBUG_EMULATOR_Disable;
_ptrc_glEnable = KHR_DEBUG_EMULATOR_Enable;
}
void simulateDebugContext() {
simulateKHR_debug();
_ptrc_glProgramParameteriEXT = wrapperglProgramParameteriEXT;
_ptrc_glFramebufferTextureARB = wrapperglFramebufferTextureARB;
......@@ -9920,17 +9943,6 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDebugMessageInsertARB = wrapperglDebugMessageInsertARB;
_ptrc_glGetDebugMessageLogARB = wrapperglGetDebugMessageLogARB;
_ptrc_glDebugMessageCallback = KHR_DEBUG_EMULATOR_DebugMessageCallback;
_ptrc_glDebugMessageControl = KHR_DEBUG_EMULATOR_DebugMessageControl;
_ptrc_glDebugMessageInsert = KHR_DEBUG_EMULATOR_DebugMessageInsert;
_ptrc_glGetDebugMessageLog = KHR_DEBUG_EMULATOR_GetDebugMessageLog;
_ptrc_glGetObjectLabel = KHR_DEBUG_EMULATOR_GetObjectLabel;
_ptrc_glGetObjectPtrLabel = KHR_DEBUG_EMULATOR_GetObjectPtrLabel;
_ptrc_glGetPointerv = KHR_DEBUG_EMULATOR_GetPointerv;
_ptrc_glObjectLabel = KHR_DEBUG_EMULATOR_ObjectLabel;
_ptrc_glObjectPtrLabel = KHR_DEBUG_EMULATOR_ObjectPtrLabel;
_ptrc_glPopDebugGroup = KHR_DEBUG_EMULATOR_PopDebugGroup;
_ptrc_glPushDebugGroup = KHR_DEBUG_EMULATOR_PushDebugGroup;
_ptrc_glClearDepthf = wrapperglClearDepthf;
_ptrc_glDepthRangef = wrapperglDepthRangef;
......@@ -10116,12 +10128,10 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glDepthFunc = wrapperglDepthFunc;
_ptrc_glDepthMask = wrapperglDepthMask;
_ptrc_glDepthRange = wrapperglDepthRange;
_ptrc_glDisable = KHR_DEBUG_EMULATOR_Disable;
_ptrc_glDrawBuffer = wrapperglDrawBuffer;
_ptrc_glDrawPixels = wrapperglDrawPixels;
_ptrc_glEdgeFlag = wrapperglEdgeFlag;
_ptrc_glEdgeFlagv = wrapperglEdgeFlagv;
_ptrc_glEnable = KHR_DEBUG_EMULATOR_Enable;
_ptrc_glEnd = wrapperglEnd;
_ptrc_glEndList = wrapperglEndList;
_ptrc_glEvalCoord1d = wrapperglEvalCoord1d;
......@@ -10149,9 +10159,7 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glGetBooleanv = wrapperglGetBooleanv;
_ptrc_glGetClipPlane = wrapperglGetClipPlane;
_ptrc_glGetDoublev = wrapperglGetDoublev;
_ptrc_glGetError = KHR_DEBUG_EMULATOR_GetError;
_ptrc_glGetFloatv = wrapperglGetFloatv;
_ptrc_glGetIntegerv = KHR_DEBUG_EMULATOR_GetIntegerv;
_ptrc_glGetLightfv = wrapperglGetLightfv;
_ptrc_glGetLightiv = wrapperglGetLightiv;
_ptrc_glGetMapdv = wrapperglGetMapdv;
......@@ -10185,7 +10193,6 @@ ogl_ext_KHR_debug = ogl_LOAD_SUCCEEDED;
_ptrc_glIndexs = wrapperglIndexs;
_ptrc_glIndexsv = wrapperglIndexsv;
_ptrc_glInitNames = wrapperglInitNames;