annotate OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.cpp @ 1901:184b0aeae1af

fix build of sdl
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 29 Jan 2022 16:55:14 +0100
parents 917500c46fe0
children e5c812a36746 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1899
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 /**
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 * Stone of Orthanc
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 *
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
11 * the License, or (at your option) any later version.
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
12 *
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 * Lesser General Public License for more details.
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 *
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
19 * License along with this program. If not, see
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
20 * <http://www.gnu.org/licenses/>.
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
21 **/
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
22
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
23
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 #include "WebAssemblyOpenGLContext.h"
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
25
1901
184b0aeae1af fix build of sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1899
diff changeset
26 #include "../../StoneException.h"
1899
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
27
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 #include <Logging.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 #include <OrthancException.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
30
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 #include <emscripten/html5.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
32 #include <emscripten/em_asm.h>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
33
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
34 #include <boost/math/special_functions/round.hpp>
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
35
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 namespace OrthancStone
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 namespace OpenGL
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 class WebAssemblyOpenGLContext::PImpl
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
41 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
42 private:
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
43 std::string canvasSelector_;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
44 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context_;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 bool isContextLost_;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
46
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
47 public:
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
48 explicit PImpl(const std::string& canvasSelector) :
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 canvasSelector_(canvasSelector),
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
50 isContextLost_(false)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
51 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
52 // Context configuration
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
53 EmscriptenWebGLContextAttributes attr;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
54 emscripten_webgl_init_context_attributes(&attr);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
55
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 // The next line might be necessary to print using
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 // WebGL. Sometimes, if set to "false" (the default value),
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 // the canvas was rendered as a fully white or black
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 // area. UNCONFIRMED.
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
60 attr.preserveDrawingBuffer = true;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
61
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 context_ = emscripten_webgl_create_context(canvasSelector.c_str(), &attr);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 if (context_ == 0)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
64 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
65 std::string message("Cannot create an OpenGL context for the element with the following CSS selector: \"");
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
66 message += canvasSelector;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
67 message += "\" Please make sure the -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 flag has been passed to Emscripten when building.";
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
68 LOG(ERROR) << message;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, message);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
71 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
72
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
73 void* DebugGetInternalContext() const
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
74 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
75 return reinterpret_cast<void*>(context_);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
76 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
77
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 bool IsContextLost()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
79 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
80 //LOG(TRACE) << "IsContextLost() for context " << std::hex << context_ << std::dec;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
81 bool apiFlag = (emscripten_is_webgl_context_lost(context_) != 0);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
82 isContextLost_ = apiFlag;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
83 return isContextLost_;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
84 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
85
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
86 void SetLostContext()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
87 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
88 isContextLost_ = true;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
89 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
90
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 ~PImpl()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
92 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
93 try
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 EMSCRIPTEN_RESULT result = emscripten_webgl_destroy_context(context_);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
96 if (result != EMSCRIPTEN_RESULT_SUCCESS)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 LOG(ERROR) << "emscripten_webgl_destroy_context returned code " << result;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
99 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
100 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 catch (const Orthanc::OrthancException& e)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
102 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
103 if (e.HasDetails())
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::~PImpl: " << e.What() << " Details: " << e.GetDetails();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 else
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
108 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
109 LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::~PImpl: " << e.What();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
110 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
111 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 catch (const std::exception& e)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
113 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
114 LOG(ERROR) << "std::exception in WebAssemblyOpenGLContext::~PImpl: " << e.what();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
115 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
116 catch (...)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
117 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
118 LOG(ERROR) << "Unknown exception in WebAssemblyOpenGLContext::~PImpl";
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
119 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
120 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
121
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
122 const std::string& GetCanvasSelector() const
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
123 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
124 return canvasSelector_;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
125 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
126
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
127 void MakeCurrent()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
128 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
129 if (IsContextLost())
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
130 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
131 LOG(ERROR) << "MakeCurrent() called on lost context " << context_;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
132 throw StoneException(ErrorCode_WebGLContextLost);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
133 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
134
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
135 if (emscripten_is_webgl_context_lost(context_))
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
136 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
137 LOG(ERROR) << "OpenGL context has been lost for canvas selector: " << canvasSelector_;
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
138 SetLostContext();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
139 throw StoneException(ErrorCode_WebGLContextLost);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
140 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
141
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
142 if (emscripten_webgl_make_context_current(context_) != EMSCRIPTEN_RESULT_SUCCESS)
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
143 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
144 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
145 "Cannot set the OpenGL context");
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
146 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
147 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
148
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
149 void SwapBuffer()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
150 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
151 /**
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
152 * "Rendered WebGL content is implicitly presented (displayed to
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
153 * the user) on the canvas when the event handler that renders with
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
154 * WebGL returns back to the browser event loop."
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
155 * https://emscripten.org/docs/api_reference/html5.h.html#webgl-context
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
156 *
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
157 * Could call "emscripten_webgl_commit_frame()" if
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
158 * "explicitSwapControl" option were set to "true".
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
159 **/
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
160 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
161 };
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
162
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
163
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
164 WebAssemblyOpenGLContext::WebAssemblyOpenGLContext(const std::string& canvasSelector) :
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
165 pimpl_(new PImpl(canvasSelector))
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
166 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
167 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
168
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
169 bool WebAssemblyOpenGLContext::IsContextLost()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
170 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
171 return pimpl_->IsContextLost();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
172 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
173
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
174 void WebAssemblyOpenGLContext::SetLostContext()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
175 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
176 pimpl_->SetLostContext();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
177 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
178
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
179 void* WebAssemblyOpenGLContext::DebugGetInternalContext() const
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
180 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
181 return pimpl_->DebugGetInternalContext();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
182 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
183
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
184 void WebAssemblyOpenGLContext::MakeCurrent()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
185 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
186 assert(pimpl_.get() != NULL);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
187 pimpl_->MakeCurrent();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
188 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
189
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
190 void WebAssemblyOpenGLContext::SwapBuffer()
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
191 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
192 assert(pimpl_.get() != NULL);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
193 pimpl_->SwapBuffer();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
194 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
195
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
196 const std::string& WebAssemblyOpenGLContext::GetCanvasSelector() const
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
197 {
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
198 assert(pimpl_.get() != NULL);
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
199 return pimpl_->GetCanvasSelector();
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
200 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
201 }
917500c46fe0 moved the Platform folder from the Applications folder to the Stone library itself
Alain Mazy <am@osimis.io>
parents:
diff changeset
202 }