comparison OrthancStone/Sources/OpenGL/OpenGLIncludes.h @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/OpenGL/OpenGLIncludes.h@28c64c246312
children 5887a4f8594b
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23
24 #include "../OrthancStone.h"
25
26 #if !defined(ORTHANC_ENABLE_OPENGL)
27 # error The macro ORTHANC_ENABLE_OPENGL must be defined
28 #endif
29
30 #if ORTHANC_ENABLE_OPENGL != 1
31 # error Support for OpenGL is disabled
32 #endif
33
34 #if defined(__APPLE__)
35 # include <OpenGL/gl.h>
36 # include <OpenGL/glext.h>
37 #elif defined(QT_VERSION_MAJOR) && (QT_VERSION >= 5)
38 // Qt5 takes care of the inclusions
39 #elif defined(_WIN32)
40 // On Windows, use the compatibility headers provided by glew
41 # include <GL/glew.h>
42 #else
43 # include <GL/gl.h>
44 # include <GL/glext.h>
45 #endif
46
47 #if ORTHANC_ENABLE_SDL == 1
48 # include <SDL_video.h>
49
50 # ifdef NDEBUG
51
52 // glGetError is very expensive!
53
54 # define ORTHANC_OPENGL_CHECK(name)
55 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg)
56
57 # else
58
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
70 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) \
71 if(true) \
72 { \
73 SDL_GLContext ctx = SDL_GL_GetCurrentContext(); \
74 LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \
75 } else (void)0
76
77 # endif
78
79 #endif
80
81 #if ORTHANC_ENABLE_WASM == 1
82 #include <emscripten/html5.h>
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
116