Mercurial > hg > orthanc-stone
annotate Framework/OpenGL/OpenGLIncludes.h @ 1303:83af7e562b45 broker
IGeometryProvider interface for deprecated loaders (required for AB testing in older app)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 04 Mar 2020 09:44:09 +0100 |
parents | 7ec8fea061b9 |
children | 1c2d065ba372 |
rev | line source |
---|---|
582 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
582 | 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 #if !defined(ORTHANC_ENABLE_OPENGL) | |
25 # error The macro ORTHANC_ENABLE_OPENGL must be defined | |
26 #endif | |
27 | |
28 #if ORTHANC_ENABLE_OPENGL != 1 | |
29 # error Support for OpenGL is disabled | |
30 #endif | |
31 | |
32 #if defined(__APPLE__) | |
33 # include <OpenGL/gl.h> | |
34 # include <OpenGL/glext.h> | |
1147 | 35 #elif defined(QT_VERSION_MAJOR) && (QT_VERSION >= 5) |
36 // Qt5 takes care of the inclusions | |
583 | 37 #elif defined(_WIN32) |
607
f4b37a991dac
using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
583
diff
changeset
|
38 // On Windows, use the compatibility headers provided by glew |
f4b37a991dac
using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
583
diff
changeset
|
39 # include <GL/glew.h> |
582 | 40 #else |
41 # include <GL/gl.h> | |
42 # include <GL/glext.h> | |
43 #endif | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
44 |
990 | 45 #if ORTHANC_ENABLE_QT == 1 |
46 // TODO: currently there are no checks in QT | |
47 | |
48 # define ORTHANC_OPENGL_CHECK(name) | |
49 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) | |
50 # define ORTHANC_CHECK_CURRENT_CONTEXT(context) | |
51 | |
52 #endif | |
53 | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
54 #if ORTHANC_ENABLE_SDL == 1 |
961
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
55 # include <SDL_video.h> |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
56 |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
57 # ifdef NDEBUG |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
58 |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
59 // glGetError is very expensive! |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
60 |
961
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
61 # define ORTHANC_OPENGL_CHECK(name) |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
62 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
63 |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
64 # else |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
65 |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
66 # define ORTHANC_OPENGL_CHECK(name) \ |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
67 if(true) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
68 { \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
69 GLenum error = glGetError(); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
70 if (error != GL_NO_ERROR) { \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
71 SDL_GLContext ctx = SDL_GL_GetCurrentContext(); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
72 LOG(ERROR) << "Error when calling " << name << " | current context is: 0x" << std::hex << ctx << " | error code is " << error; \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
73 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,"OpenGL error in " name " | See log."); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
74 } \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
75 } else (void)0 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
76 |
961
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
77 # define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) \ |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
78 if(true) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
79 { \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
80 SDL_GLContext ctx = SDL_GL_GetCurrentContext(); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
81 LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
82 } else (void)0 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
83 |
961
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
84 # endif |
92e32e263ae9
Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
85 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
86 #endif |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
87 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
88 #if ORTHANC_ENABLE_WASM == 1 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
89 #include <emscripten/html5.h> |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
90 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
91 #define ORTHANC_OPENGL_CHECK(name) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
92 if(true) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
93 { \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
94 GLenum error = glGetError(); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
95 if (error != GL_NO_ERROR) { \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
96 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
97 EM_BOOL lost = emscripten_is_webgl_context_lost(ctx); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
98 LOG(ERROR) << "Error when calling " << name << " | current context is: 0x" << std::hex << ctx << " | error code is " << error << " | emscripten_is_webgl_context_lost = " << lost; \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
99 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,"OpenGL error in " name " | See log."); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
100 } \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
101 } else (void)0 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
102 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
103 #define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
104 if(true) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
105 { \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
106 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
107 LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
108 } else (void)0 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
109 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
110 #define ORTHANC_CHECK_CURRENT_CONTEXT(context) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
111 if(true) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
112 { \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
113 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
114 void* actualCtx = reinterpret_cast<void*>(ctx); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
115 void* expectedCtx = context.DebugGetInternalContext(); \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
116 if(expectedCtx != actualCtx) \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
117 { \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
118 LOG(ERROR) << "Expected context was " << std::hex << expectedCtx << " while actual context is " << std::hex << actualCtx; \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
119 } \ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
120 } else (void)0 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
121 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
122 #endif |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
607
diff
changeset
|
123 |