Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Viewport/WebGLViewport.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Viewport/WebGLViewport.cpp@6abd819aa534 |
children | 314b6dc507d9 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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 "../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 WebGLViewport::WebGLViewport(const std::string& canvasId, bool enableEmscriptenMouseEvents) : | |
63 WebAssemblyViewport(canvasId,enableEmscriptenMouseEvents), | |
64 context_(GetCanvasCssSelector()) | |
65 { | |
66 AcquireCompositor(new OpenGLCompositor(context_)); | |
67 } | |
68 | |
69 boost::shared_ptr<WebGLViewport> WebGLViewport::Create( | |
70 const std::string& canvasId, bool enableEmscriptenMouseEvents) | |
71 { | |
72 boost::shared_ptr<WebGLViewport> that = boost::shared_ptr<WebGLViewport>( | |
73 new WebGLViewport(canvasId, enableEmscriptenMouseEvents)); | |
74 | |
75 that->WebAssemblyViewport::PostConstructor(); | |
76 return that; | |
77 } | |
78 | |
79 WebGLViewport::~WebGLViewport() | |
80 { | |
81 // Make sure to delete the compositor before its parent "context_" gets | |
82 // deleted | |
83 ClearCompositor(); | |
84 } | |
85 } |