annotate OrthancStone/Sources/OpenGL/WebAssemblyOpenGLContext.cpp @ 1578:1f812f4c95be

comments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Sep 2020 17:20:36 +0200
parents 92fca2b3ba3d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
97926984d5d0 WebAssembly sample using 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: 1052
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "WebAssemblyOpenGLContext.h"
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
24 #include "../StoneException.h"
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
25
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1351
diff changeset
26 #include <OrthancException.h>
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <emscripten/html5.h>
942
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
29 #include <emscripten/em_asm.h>
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
30
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <boost/math/special_functions/round.hpp>
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace OrthancStone
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace OpenGL
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 class WebAssemblyOpenGLContext::PImpl
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 private:
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
40 std::string canvasSelector_;
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
41 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context_;
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
42 bool isContextLost_;
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 public:
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
45 explicit PImpl(const std::string& canvasSelector) :
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
46 canvasSelector_(canvasSelector),
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
47 isContextLost_(false)
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 // Context configuration
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 EmscriptenWebGLContextAttributes attr;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 emscripten_webgl_init_context_attributes(&attr);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
1578
1f812f4c95be comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
53 // The next line might be necessary to print using
1f812f4c95be comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
54 // WebGL. Sometimes, if set to "false" (the default value),
1f812f4c95be comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
55 // the canvas was rendered as a fully white or black
1f812f4c95be comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
56 // area. UNCONFIRMED.
1575
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
57 attr.preserveDrawingBuffer = true;
e4a52cbbdd70 working on print
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
58
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
59 context_ = emscripten_webgl_create_context(canvasSelector.c_str(), &attr);
945
2db3ef713664 Fixed error handling for WebGL context creation
Benjamin Golinvaux <bgo@osimis.io>
parents: 942
diff changeset
60 if (context_ == 0)
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
62 std::string message("Cannot create an OpenGL context for the element with the following CSS selector: \"");
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
63 message += canvasSelector;
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
64 message += "\" Please make sure the -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 flag has been passed to Emscripten when building.";
894
f557b18d287f wasm: error log if canvas GL context can't be created
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
65 LOG(ERROR) << message;
f557b18d287f wasm: error log if canvas GL context can't be created
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, message);
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
70 void* DebugGetInternalContext() const
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
71 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
72 return reinterpret_cast<void*>(context_);
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
73 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
74
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
75 bool IsContextLost()
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
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: 958
diff changeset
77 //LOG(TRACE) << "IsContextLost() for context " << std::hex << context_ << std::dec;
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
78 bool apiFlag = (emscripten_is_webgl_context_lost(context_) != 0);
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
79 isContextLost_ = apiFlag;
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
80 return isContextLost_;
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
81 }
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
82
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
83 void SetLostContext()
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
84 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
85 isContextLost_ = true;
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
86 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
87
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ~PImpl()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
90 try
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
91 {
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
92 EMSCRIPTEN_RESULT result = emscripten_webgl_destroy_context(context_);
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
93 if (result != EMSCRIPTEN_RESULT_SUCCESS)
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
94 {
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
95 LOG(ERROR) << "emscripten_webgl_destroy_context returned code " << result;
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
96 }
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
97 }
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
98 catch (const Orthanc::OrthancException& e)
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
99 {
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
100 if (e.HasDetails())
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
101 {
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
102 LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::~PImpl: " << e.What() << " Details: " << e.GetDetails();
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
103 }
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
104 else
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
105 {
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
106 LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::~PImpl: " << e.What();
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
107 }
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
108 }
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
109 catch (const std::exception& e)
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
110 {
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
111 LOG(ERROR) << "std::exception in WebAssemblyOpenGLContext::~PImpl: " << e.what();
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
112 }
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
113 catch (...)
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
114 {
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
115 LOG(ERROR) << "Unknown exception in WebAssemblyOpenGLContext::~PImpl";
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
116 }
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
119 const std::string& GetCanvasSelector() const
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
120 {
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
121 return canvasSelector_;
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
122 }
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
123
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 void MakeCurrent()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
126 if (IsContextLost())
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
127 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
128 LOG(ERROR) << "MakeCurrent() called on lost context " << context_;
1050
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
129 throw StoneException(ErrorCode_WebGLContextLost);
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
130 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
131
942
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
132 if (emscripten_is_webgl_context_lost(context_))
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
133 {
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
134 LOG(ERROR) << "OpenGL context has been lost for canvas selector: " << canvasSelector_;
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
135 SetLostContext();
1050
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
136 throw StoneException(ErrorCode_WebGLContextLost);
942
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
137 }
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
138
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 if (emscripten_webgl_make_context_current(context_) != EMSCRIPTEN_RESULT_SUCCESS)
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 "Cannot set the OpenGL context");
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 void SwapBuffer()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 /**
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 * "Rendered WebGL content is implicitly presented (displayed to
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 * the user) on the canvas when the event handler that renders with
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 * WebGL returns back to the browser event loop."
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 * https://emscripten.org/docs/api_reference/html5.h.html#webgl-context
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 *
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 * Could call "emscripten_webgl_commit_frame()" if
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 * "explicitSwapControl" option were set to "true".
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 **/
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 };
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
161 WebAssemblyOpenGLContext::WebAssemblyOpenGLContext(const std::string& canvasSelector) :
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
162 pimpl_(new PImpl(canvasSelector))
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 947
diff changeset
166 bool WebAssemblyOpenGLContext::IsContextLost()
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
167 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
168 return pimpl_->IsContextLost();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
169 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
170
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
171 void WebAssemblyOpenGLContext::SetLostContext()
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
172 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
173 pimpl_->SetLostContext();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
174 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
175
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
176 void* WebAssemblyOpenGLContext::DebugGetInternalContext() const
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
177 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
178 return pimpl_->DebugGetInternalContext();
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
179 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 945
diff changeset
180
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 void WebAssemblyOpenGLContext::MakeCurrent()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 assert(pimpl_.get() != NULL);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 pimpl_->MakeCurrent();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 void WebAssemblyOpenGLContext::SwapBuffer()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 assert(pimpl_.get() != NULL);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 pimpl_->SwapBuffer();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
193 const std::string& WebAssemblyOpenGLContext::GetCanvasSelector() const
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
194 {
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
195 assert(pimpl_.get() != NULL);
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1338
diff changeset
196 return pimpl_->GetCanvasSelector();
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
197 }
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }