Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Platforms/WebAssembly/WebGLViewport.cpp @ 1899:917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
author | Alain Mazy <am@osimis.io> |
---|---|
date | Sat, 29 Jan 2022 12:47:32 +0100 |
parents | |
children | 184b0aeae1af |
comparison
equal
deleted
inserted
replaced
1898:a5e54bd87b25 | 1899:917500c46fe0 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium | |
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
7 * | |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with this program. If not, see | |
20 * <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "WebGLViewport.h" | |
25 | |
26 #include "../../../OrthancStone/Sources/StoneException.h" | |
27 #include "../../../OrthancStone/Sources/Scene2D/OpenGLCompositor.h" | |
28 #include "../../../OrthancStone/Sources/Scene2DViewport/ViewportController.h" | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 void WebGLViewport::Paint(ICompositor& compositor, | |
33 ViewportController& controller) | |
34 { | |
35 try | |
36 { | |
37 compositor.Refresh(controller.GetScene()); | |
38 | |
39 /** | |
40 * No need to manually swap the buffer: "Rendered WebGL content | |
41 * is implicitly presented (displayed to the user) on the canvas | |
42 * when the event handler that renders with WebGL returns back | |
43 * to the browser event loop." | |
44 * https://emscripten.org/docs/api_reference/html5.h.html#webgl-context | |
45 * | |
46 * Could call "emscripten_webgl_commit_frame()" if | |
47 * "explicitSwapControl" option were set to "true". | |
48 **/ | |
49 } | |
50 catch (const StoneException& e) | |
51 { | |
52 // Ignore problems about the loss of the WebGL context (edge case) | |
53 if (e.GetErrorCode() == ErrorCode_WebGLContextLost) | |
54 { | |
55 return; | |
56 } | |
57 else | |
58 { | |
59 throw; | |
60 } | |
61 } | |
62 } | |
63 | |
64 | |
65 WebGLViewport::WebGLViewport(const std::string& canvasId, bool enableEmscriptenMouseEvents) : | |
66 WebAssemblyViewport(canvasId,enableEmscriptenMouseEvents), | |
67 context_(GetCanvasCssSelector()) | |
68 { | |
69 AcquireCompositor(new OpenGLCompositor(context_)); | |
70 } | |
71 | |
72 boost::shared_ptr<WebGLViewport> WebGLViewport::Create( | |
73 const std::string& canvasId, bool enableEmscriptenMouseEvents) | |
74 { | |
75 boost::shared_ptr<WebGLViewport> that = boost::shared_ptr<WebGLViewport>( | |
76 new WebGLViewport(canvasId, enableEmscriptenMouseEvents)); | |
77 | |
78 that->WebAssemblyViewport::PostConstructor(); | |
79 return that; | |
80 } | |
81 | |
82 WebGLViewport::~WebGLViewport() | |
83 { | |
84 // Make sure to delete the compositor before its parent "context_" gets | |
85 // deleted | |
86 ClearCompositor(); | |
87 } | |
88 } |