Mercurial > hg > orthanc-stone
comparison Applications/Platforms/WebAssembly/WebGLViewport.cpp @ 1591:5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 23 Oct 2020 13:15:03 +0200 |
parents | OrthancStone/Sources/Viewport/WebGLViewport.cpp@314b6dc507d9 |
children | 9ac2a65d4172 |
comparison
equal
deleted
inserted
replaced
1590:7b963bccafef | 1591:5887a4f8594b |
---|---|
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-2020 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 "../../../OrthancStone/Sources/StoneException.h" | |
25 #include "../../../OrthancStone/Sources/Scene2D/OpenGLCompositor.h" | |
26 #include "../../../OrthancStone/Sources/Scene2DViewport/ViewportController.h" | |
27 | |
28 namespace OrthancStone | |
29 { | |
30 void WebGLViewport::Paint(ICompositor& compositor, | |
31 ViewportController& controller) | |
32 { | |
33 try | |
34 { | |
35 compositor.Refresh(controller.GetScene()); | |
36 | |
37 /** | |
38 * No need to manually swap the buffer: "Rendered WebGL content | |
39 * is implicitly presented (displayed to the user) on the canvas | |
40 * when the event handler that renders with WebGL returns back | |
41 * to the browser event loop." | |
42 * https://emscripten.org/docs/api_reference/html5.h.html#webgl-context | |
43 * | |
44 * Could call "emscripten_webgl_commit_frame()" if | |
45 * "explicitSwapControl" option were set to "true". | |
46 **/ | |
47 } | |
48 catch (const StoneException& e) | |
49 { | |
50 // Ignore problems about the loss of the WebGL context (edge case) | |
51 if (e.GetErrorCode() == ErrorCode_WebGLContextLost) | |
52 { | |
53 return; | |
54 } | |
55 else | |
56 { | |
57 throw; | |
58 } | |
59 } | |
60 } | |
61 | |
62 | |
63 WebGLViewport::WebGLViewport(const std::string& canvasId, bool enableEmscriptenMouseEvents) : | |
64 WebAssemblyViewport(canvasId,enableEmscriptenMouseEvents), | |
65 context_(GetCanvasCssSelector()) | |
66 { | |
67 AcquireCompositor(new OpenGLCompositor(context_)); | |
68 } | |
69 | |
70 boost::shared_ptr<WebGLViewport> WebGLViewport::Create( | |
71 const std::string& canvasId, bool enableEmscriptenMouseEvents) | |
72 { | |
73 boost::shared_ptr<WebGLViewport> that = boost::shared_ptr<WebGLViewport>( | |
74 new WebGLViewport(canvasId, enableEmscriptenMouseEvents)); | |
75 | |
76 that->WebAssemblyViewport::PostConstructor(); | |
77 return that; | |
78 } | |
79 | |
80 WebGLViewport::~WebGLViewport() | |
81 { | |
82 // Make sure to delete the compositor before its parent "context_" gets | |
83 // deleted | |
84 ClearCompositor(); | |
85 } | |
86 } |