diff Framework/OpenGL/OpenGLIncludes.h @ 947:1091b2adeb5a toa2019081001

Fixed animation frame stopping when returning false + big work on the OpenGL objects to make them lost context-safe + debug code to forcefully tag a context as lost + debug macros
author Benjamin Golinvaux <bgo@osimis.io>
date Sat, 10 Aug 2019 13:07:31 +0200
parents f4b37a991dac
children 92e32e263ae9
line wrap: on
line diff
--- a/Framework/OpenGL/OpenGLIncludes.h	Tue Aug 06 15:07:23 2019 +0200
+++ b/Framework/OpenGL/OpenGLIncludes.h	Sat Aug 10 13:07:31 2019 +0200
@@ -39,3 +39,74 @@
 #  include <GL/gl.h>
 #  include <GL/glext.h>
 #endif
+
+#if ORTHANC_ENABLE_SDL == 1
+#include <SDL_video.h>
+
+#define ORTHANC_OPENGL_CHECK(name) \
+if(true)                                                                                                                                \
+{                                                                                                                                       \
+  GLenum error = glGetError();                                                                                                          \
+  if (error != GL_NO_ERROR) {                                                                                                           \
+    SDL_GLContext ctx = SDL_GL_GetCurrentContext();                                                                                     \
+    LOG(ERROR) << "Error when calling " << name << " | current context is: 0x" << std::hex << ctx <<  " | error code is " << error;     \
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,"OpenGL error in " name " | See log.");                            \
+  }                                                                                                                                     \
+} else (void)0
+
+#define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg)                          \
+if(true)                                                                   \
+{                                                                          \
+  SDL_GLContext ctx = SDL_GL_GetCurrentContext();                          \
+  LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \
+} else (void)0
+
+#define ORTHANC_CHECK_CURRENT_CONTEXT(context)                                                                                                         \
+if(true)                                                                                                                                               \
+{                                                                                                                                                      \
+  SDL_GLContext actualCtx = SDL_GL_GetCurrentContext();                                                                                                \
+  void* expectedCtx = context.DebugGetInternalContext();                                                                                               \
+  if(expectedCtx != actualCtx)                                                                                                                         \
+  {                                                                                                                                                    \
+    LOG(ERROR) << "Expected context was " << std::hex << expectedCtx << " while actual context is " << std::hex << actualCtx;                          \
+  }                                                                                                                                                    \
+} else (void)0
+
+#endif
+
+#if ORTHANC_ENABLE_WASM == 1
+#include <emscripten/html5.h>
+
+#define ORTHANC_OPENGL_CHECK(name) \
+if(true)                                                                                                                                                                                    \
+{                                                                                                                                                                                           \
+  GLenum error = glGetError();                                                                                                                                                              \
+  if (error != GL_NO_ERROR) {                                                                                                                                                               \
+    EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();                                                                                                           \
+    EM_BOOL lost = emscripten_is_webgl_context_lost(ctx);                                                                                                                                   \
+    LOG(ERROR) << "Error when calling " << name << " | current context is: 0x" << std::hex << ctx <<  " | error code is " << error << " | emscripten_is_webgl_context_lost = " << lost;     \
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,"OpenGL error in " name " | See log.");                                                                                \
+  }                                                                                                                                                                                         \
+} else (void)0
+
+#define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg)                                 \
+if(true)                                                                          \
+{                                                                                 \
+  EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();   \
+  LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx;        \
+} else (void)0
+
+#define ORTHANC_CHECK_CURRENT_CONTEXT(context)                                                                                                         \
+if(true)                                                                                                                                               \
+{                                                                                                                                                      \
+  EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();                                                                        \
+  void* actualCtx = reinterpret_cast<void*>(ctx);                                                                                                      \
+  void* expectedCtx = context.DebugGetInternalContext();                                                                                               \
+  if(expectedCtx != actualCtx)                                                                                                                         \
+  {                                                                                                                                                    \
+    LOG(ERROR) << "Expected context was " << std::hex << expectedCtx << " while actual context is " << std::hex << actualCtx;                          \
+  }                                                                                                                                                    \
+} else (void)0
+
+#endif
+