annotate Applications/Platforms/WebAssembly/WebGLViewport.cpp @ 1599:73cd85d7da6a

SortedFrames::LookupSopInstanceUid()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Oct 2020 10:55:45 +0100
parents 5887a4f8594b
children 9ac2a65d4172
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1271
0ca50d275b9a upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "WebGLViewport.h"
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
24 #include "../../../OrthancStone/Sources/StoneException.h"
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
25 #include "../../../OrthancStone/Sources/Scene2D/OpenGLCompositor.h"
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
26 #include "../../../OrthancStone/Sources/Scene2DViewport/ViewportController.h"
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace OrthancStone
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 void WebGLViewport::Paint(ICompositor& compositor,
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 ViewportController& controller)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 try
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 compositor.Refresh(controller.GetScene());
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 /**
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 * No need to manually swap the buffer: "Rendered WebGL content
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 * is implicitly presented (displayed to the user) on the canvas
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 * when the event handler that renders with WebGL returns back
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 * to the browser event loop."
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 * https://emscripten.org/docs/api_reference/html5.h.html#webgl-context
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 * Could call "emscripten_webgl_commit_frame()" if
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 * "explicitSwapControl" option were set to "true".
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 **/
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 catch (const StoneException& e)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 // Ignore problems about the loss of the WebGL context (edge case)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 if (e.GetErrorCode() == ErrorCode_WebGLContextLost)
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 return;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 else
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 throw;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
1346
df8bf351c23f The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
63 WebGLViewport::WebGLViewport(const std::string& canvasId, bool enableEmscriptenMouseEvents) :
df8bf351c23f The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
64 WebAssemblyViewport(canvasId,enableEmscriptenMouseEvents),
1351
1b8e37770d78 ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1346
diff changeset
65 context_(GetCanvasCssSelector())
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 AcquireCompositor(new OpenGLCompositor(context_));
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1318
diff changeset
70 boost::shared_ptr<WebGLViewport> WebGLViewport::Create(
1346
df8bf351c23f The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
71 const std::string& canvasId, bool enableEmscriptenMouseEvents)
1318
cbfdba08e039 removed SDL code in wasm + added undostack CTOR in Wasm viewport + build fix + ORTHANC_OVERRIDE
Benjamin Golinvaux <bgo@osimis.io>
parents: 1271
diff changeset
72 {
1346
df8bf351c23f The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
73 boost::shared_ptr<WebGLViewport> that = boost::shared_ptr<WebGLViewport>(
df8bf351c23f The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
74 new WebGLViewport(canvasId, enableEmscriptenMouseEvents));
df8bf351c23f The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
75
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1318
diff changeset
76 that->WebAssemblyViewport::PostConstructor();
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1318
diff changeset
77 return that;
1318
cbfdba08e039 removed SDL code in wasm + added undostack CTOR in Wasm viewport + build fix + ORTHANC_OVERRIDE
Benjamin Golinvaux <bgo@osimis.io>
parents: 1271
diff changeset
78 }
cbfdba08e039 removed SDL code in wasm + added undostack CTOR in Wasm viewport + build fix + ORTHANC_OVERRIDE
Benjamin Golinvaux <bgo@osimis.io>
parents: 1271
diff changeset
79
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 WebGLViewport::~WebGLViewport()
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1318
diff changeset
82 // Make sure to delete the compositor before its parent "context_" gets
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1318
diff changeset
83 // deleted
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ClearCompositor();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }