annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
582
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
1471
28c64c246312 working on a shared library
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1397
diff changeset
24 #include "../OrthancStone.h"
28c64c246312 working on a shared library
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1397
diff changeset
25
582
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #if !defined(ORTHANC_ENABLE_OPENGL)
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # error The macro ORTHANC_ENABLE_OPENGL must be defined
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #endif
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #if ORTHANC_ENABLE_OPENGL != 1
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 # error Support for OpenGL is disabled
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #endif
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #if defined(__APPLE__)
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 # include <OpenGL/gl.h>
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 # include <OpenGL/glext.h>
1147
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1045
diff changeset
37 #elif defined(QT_VERSION_MAJOR) && (QT_VERSION >= 5)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1045
diff changeset
38 // Qt5 takes care of the inclusions
583
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 582
diff changeset
39 #elif defined(_WIN32)
607
f4b37a991dac using glew to build on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 583
diff changeset
40 // 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
41 # include <GL/glew.h>
582
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #else
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 # include <GL/gl.h>
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 # include <GL/glext.h>
e36e69a380a5 Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #endif
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
46
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
47 #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
48 # 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
49
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
50 # 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
51
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
52 // 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
53
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
54 # 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
55 # 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
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 # 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
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 # 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
60 if(true) \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
61 { \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
62 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
63 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
64 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
65 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
66 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
67 } \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
68 } 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
69
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
70 # 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
71 if(true) \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
72 { \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
73 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
74 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
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 # 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
78
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
79 #endif
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
80
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
81 #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
82 #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
83
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
84 #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
85 if(true) \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
86 { \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
87 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
88 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
89 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
90 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
91 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
92 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
93 } \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
94 } 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
95
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
96 #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
97 if(true) \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
98 { \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
99 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
100 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
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_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
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 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
108 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
109 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
110 { \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
111 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
112 } \
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
113 } 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
114
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
115 #endif
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 607
diff changeset
116