Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/OpenGL/OpenGLIncludes.h @ 1591:5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 23 Oct 2020 13:15:03 +0200 |
parents | 244ad1e4e76a |
children | 4fb8fdf03314 |
comparison
equal
deleted
inserted
replaced
1590:7b963bccafef | 1591:5887a4f8594b |
---|---|
21 | 21 |
22 #pragma once | 22 #pragma once |
23 | 23 |
24 #include "../OrthancStone.h" | 24 #include "../OrthancStone.h" |
25 | 25 |
26 #if !defined(ORTHANC_ENABLE_SDL) | |
27 # error The macro ORTHANC_ENABLE_SDL must be defined | |
28 #endif | |
29 | |
30 #if !defined(ORTHANC_ENABLE_WASM) | |
31 # error The macro ORTHANC_ENABLE_WASM must be defined | |
32 #endif | |
33 | |
26 #if !defined(ORTHANC_ENABLE_OPENGL) | 34 #if !defined(ORTHANC_ENABLE_OPENGL) |
27 # error The macro ORTHANC_ENABLE_OPENGL must be defined | 35 # error The macro ORTHANC_ENABLE_OPENGL must be defined |
28 #endif | 36 #endif |
29 | 37 |
30 #if ORTHANC_ENABLE_OPENGL != 1 | 38 #if ORTHANC_ENABLE_OPENGL != 1 |
42 #else | 50 #else |
43 # include <GL/gl.h> | 51 # include <GL/gl.h> |
44 # include <GL/glext.h> | 52 # include <GL/glext.h> |
45 #endif | 53 #endif |
46 | 54 |
55 | |
56 | |
47 #if ORTHANC_ENABLE_SDL == 1 | 57 #if ORTHANC_ENABLE_SDL == 1 |
48 # include <SDL_video.h> | 58 # include <SDL_video.h> |
49 | 59 |
50 # ifdef NDEBUG | 60 # if !defined(NDEBUG) // Is build type "debug"? |
61 // glGetError is very expensive! | |
62 # include <OrthancException.h> | |
63 # define ORTHANC_OPENGL_CHECK(name) \ | |
64 if(true) \ | |
65 { \ | |
66 GLenum error = glGetError(); \ | |
67 if (error != GL_NO_ERROR) { \ | |
68 SDL_GLContext ctx = SDL_GL_GetCurrentContext(); \ | |
69 LOG(ERROR) << "Error when calling " << name << " | current context is: 0x" \ | |
70 << std::hex << ctx << " | error code is " << error; \ | |
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,"OpenGL error in " name " | See log."); \ | |
72 } \ | |
73 } else (void)0 | |
51 | 74 |
52 // glGetError is very expensive! | 75 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) \ |
76 if(true) \ | |
77 { \ | |
78 SDL_GLContext ctx = SDL_GL_GetCurrentContext(); \ | |
79 LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \ | |
80 } else (void)0 | |
53 | 81 |
54 # define ORTHANC_OPENGL_CHECK(name) | 82 # endif /* NDEBUG */ |
55 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) | 83 #endif /* SDL */ |
56 | 84 |
57 # else | |
58 | 85 |
59 # define ORTHANC_OPENGL_CHECK(name) \ | |
60 if(true) \ | |
61 { \ | |
62 GLenum error = glGetError(); \ | |
63 if (error != GL_NO_ERROR) { \ | |
64 SDL_GLContext ctx = SDL_GL_GetCurrentContext(); \ | |
65 LOG(ERROR) << "Error when calling " << name << " | current context is: 0x" << std::hex << ctx << " | error code is " << error; \ | |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,"OpenGL error in " name " | See log."); \ | |
67 } \ | |
68 } else (void)0 | |
69 | 86 |
70 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) \ | 87 #if ORTHANC_ENABLE_WASM == 1 |
71 if(true) \ | 88 # include <emscripten/html5.h> |
72 { \ | |
73 SDL_GLContext ctx = SDL_GL_GetCurrentContext(); \ | |
74 LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \ | |
75 } else (void)0 | |
76 | 89 |
77 # endif | 90 # if !defined(NDEBUG) // Is build type "debug"? |
91 # include <OrthancException.h> | |
92 # define ORTHANC_OPENGL_CHECK(name) \ | |
93 if(true) \ | |
94 { \ | |
95 GLenum error = glGetError(); \ | |
96 if (error != GL_NO_ERROR) { \ | |
97 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ | |
98 EM_BOOL lost = emscripten_is_webgl_context_lost(ctx); \ | |
99 LOG(ERROR) << "Error when calling " << name << " | current context is: 0x" \ | |
100 << std::hex << ctx << " | error code is " << error << " | emscripten_is_webgl_context_lost = " << lost; \ | |
101 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,"OpenGL error in " name " | See log."); \ | |
102 } \ | |
103 } else (void)0 | |
78 | 104 |
105 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) \ | |
106 if(true) \ | |
107 { \ | |
108 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ | |
109 LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \ | |
110 } else (void)0 | |
111 | |
112 # define ORTHANC_CHECK_CURRENT_CONTEXT(context) \ | |
113 if(true) \ | |
114 { \ | |
115 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ | |
116 void* actualCtx = reinterpret_cast<void*>(ctx); \ | |
117 void* expectedCtx = context.DebugGetInternalContext(); \ | |
118 if(expectedCtx != actualCtx) \ | |
119 { \ | |
120 LOG(ERROR) << "Expected context was " << std::hex << expectedCtx \ | |
121 << " while actual context is " << std::hex << actualCtx; \ | |
122 } \ | |
123 } else (void)0 | |
124 | |
125 # endif /* NDEBUG */ | |
126 #endif /* WASM */ | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 // Define void implementation of debug macros if they were not defined above | |
133 | |
134 #if !defined(ORTHANC_OPENGL_CHECK) | |
135 # define ORTHANC_OPENGL_CHECK(name) | |
79 #endif | 136 #endif |
80 | 137 |
81 #if ORTHANC_ENABLE_WASM == 1 | 138 #if !defined(ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT) |
82 #include <emscripten/html5.h> | 139 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) |
83 | |
84 #define ORTHANC_OPENGL_CHECK(name) \ | |
85 if(true) \ | |
86 { \ | |
87 GLenum error = glGetError(); \ | |
88 if (error != GL_NO_ERROR) { \ | |
89 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ | |
90 EM_BOOL lost = emscripten_is_webgl_context_lost(ctx); \ | |
91 LOG(ERROR) << "Error when calling " << name << " | current context is: 0x" << std::hex << ctx << " | error code is " << error << " | emscripten_is_webgl_context_lost = " << lost; \ | |
92 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,"OpenGL error in " name " | See log."); \ | |
93 } \ | |
94 } else (void)0 | |
95 | |
96 #define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) \ | |
97 if(true) \ | |
98 { \ | |
99 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ | |
100 LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \ | |
101 } else (void)0 | |
102 | |
103 #define ORTHANC_CHECK_CURRENT_CONTEXT(context) \ | |
104 if(true) \ | |
105 { \ | |
106 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ | |
107 void* actualCtx = reinterpret_cast<void*>(ctx); \ | |
108 void* expectedCtx = context.DebugGetInternalContext(); \ | |
109 if(expectedCtx != actualCtx) \ | |
110 { \ | |
111 LOG(ERROR) << "Expected context was " << std::hex << expectedCtx << " while actual context is " << std::hex << actualCtx; \ | |
112 } \ | |
113 } else (void)0 | |
114 | |
115 #endif | 140 #endif |
116 | 141 |
142 #if !defined(ORTHANC_CHECK_CURRENT_CONTEXT) | |
143 # define ORTHANC_CHECK_CURRENT_CONTEXT(context) | |
144 #endif | |
145 |