Mercurial > hg > orthanc-stone
comparison Framework/Viewport/WebGLViewport.cpp @ 1232:a28861abf888 broker
viewports for WebAssembly
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Dec 2019 17:46:33 +0100 |
parents | |
children | 0ca50d275b9a |
comparison
equal
deleted
inserted
replaced
1229:b9f2a111c5b9 | 1232:a28861abf888 |
---|---|
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-2019 Osimis S.A., Belgium | |
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 #include "WebGLViewport.h" | |
23 | |
24 #include "../StoneException.h" | |
25 #include "../Scene2D/OpenGLCompositor.h" | |
26 | |
27 namespace OrthancStone | |
28 { | |
29 void WebGLViewport::Paint(ICompositor& compositor, | |
30 ViewportController& controller) | |
31 { | |
32 try | |
33 { | |
34 compositor.Refresh(controller.GetScene()); | |
35 | |
36 /** | |
37 * No need to manually swap the buffer: "Rendered WebGL content | |
38 * is implicitly presented (displayed to the user) on the canvas | |
39 * when the event handler that renders with WebGL returns back | |
40 * to the browser event loop." | |
41 * https://emscripten.org/docs/api_reference/html5.h.html#webgl-context | |
42 * | |
43 * Could call "emscripten_webgl_commit_frame()" if | |
44 * "explicitSwapControl" option were set to "true". | |
45 **/ | |
46 } | |
47 catch (const StoneException& e) | |
48 { | |
49 // Ignore problems about the loss of the WebGL context (edge case) | |
50 if (e.GetErrorCode() == ErrorCode_WebGLContextLost) | |
51 { | |
52 return; | |
53 } | |
54 else | |
55 { | |
56 throw; | |
57 } | |
58 } | |
59 } | |
60 | |
61 | |
62 void WebGLViewport::UpdateSize(ICompositor& compositor) | |
63 { | |
64 try | |
65 { | |
66 context_.UpdateSize(); | |
67 } | |
68 catch (const StoneException& e) | |
69 { | |
70 // Ignore problems about the loss of the WebGL context (edge case) | |
71 if (e.GetErrorCode() == ErrorCode_WebGLContextLost) | |
72 { | |
73 return; | |
74 } | |
75 else | |
76 { | |
77 throw; | |
78 } | |
79 } | |
80 } | |
81 | |
82 | |
83 WebGLViewport::WebGLViewport(const std::string& canvasId) : | |
84 WebAssemblyViewport(canvasId, NULL), | |
85 context_(GetFullCanvasId()) | |
86 { | |
87 AcquireCompositor(new OpenGLCompositor(context_)); | |
88 } | |
89 | |
90 | |
91 WebGLViewport::WebGLViewport(const std::string& canvasId, | |
92 const Scene2D& scene) : | |
93 WebAssemblyViewport(canvasId, &scene), | |
94 context_(GetFullCanvasId()) | |
95 { | |
96 AcquireCompositor(new OpenGLCompositor(context_)); | |
97 } | |
98 | |
99 | |
100 WebGLViewport::~WebGLViewport() | |
101 { | |
102 // Make sure to delete the compositor before its parent "context_" gets deleted | |
103 ClearCompositor(); | |
104 } | |
105 } |