annotate Framework/OpenGL/WebAssemblyOpenGLContext.cpp @ 942:685c9a2d115f

Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 05 Aug 2019 12:27:27 +0200
parents f557b18d287f
children 2db3ef713664
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "WebAssemblyOpenGLContext.h"
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <Core/OrthancException.h>
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <emscripten/html5.h>
942
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
27 #include <emscripten/em_asm.h>
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
28
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <boost/math/special_functions/round.hpp>
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancStone
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace OpenGL
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 class WebAssemblyOpenGLContext::PImpl
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 private:
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 std::string canvas_;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context_;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 unsigned int canvasWidth_;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 unsigned int canvasHeight_;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 public:
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 PImpl(const std::string& canvas) :
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 canvas_(canvas)
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 // Context configuration
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 EmscriptenWebGLContextAttributes attr;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 emscripten_webgl_init_context_attributes(&attr);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 context_ = emscripten_webgl_create_context(canvas.c_str(), &attr);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 if (context_ < 0)
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
894
f557b18d287f wasm: error log if canvas GL context can't be created
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
54 std::string message("Cannot create an OpenGL context for canvas: ");
f557b18d287f wasm: error log if canvas GL context can't be created
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
55 message += canvas;
f557b18d287f wasm: error log if canvas GL context can't be created
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
56 LOG(ERROR) << message;
f557b18d287f wasm: error log if canvas GL context can't be created
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, message);
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 UpdateSize();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 ~PImpl()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 emscripten_webgl_destroy_context(context_);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
68 const std::string& GetCanvasIdentifier() const
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
69 {
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
70 return canvas_;
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
71 }
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
72
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 void MakeCurrent()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
942
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
75 if (emscripten_is_webgl_context_lost(context_))
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
76 {
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
77 LOG(ERROR) << "OpenGL context has been lost! for canvas: " << canvas_;
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
79 "OpenGL context has been lost!");
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
80 }
685c9a2d115f Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents: 894
diff changeset
81
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 if (emscripten_webgl_make_context_current(context_) != EMSCRIPTEN_RESULT_SUCCESS)
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 "Cannot set the OpenGL context");
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 void SwapBuffer()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 /**
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 * "Rendered WebGL content is implicitly presented (displayed to
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 * the user) on the canvas when the event handler that renders with
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 * WebGL returns back to the browser event loop."
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 * https://emscripten.org/docs/api_reference/html5.h.html#webgl-context
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 *
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 * Could call "emscripten_webgl_commit_frame()" if
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 * "explicitSwapControl" option were set to "true".
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 **/
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 unsigned int GetCanvasWidth() const
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 return canvasWidth_;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 unsigned int GetCanvasHeight() const
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 return canvasHeight_;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 void UpdateSize()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 double w, h;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 emscripten_get_element_css_size(canvas_.c_str(), &w, &h);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 /**
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 * Emscripten has the function emscripten_get_element_css_size()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 * to query the width and height of a named HTML element. I'm
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 * calling this first to get the initial size of the canvas DOM
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 * element, and then call emscripten_set_canvas_size() to
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 * initialize the framebuffer size of the canvas to the same
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 * size as its DOM element.
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 * https://floooh.github.io/2017/02/22/emsc-html.html
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 **/
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 if (w <= 0 ||
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 h <= 0)
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 canvasWidth_ = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 canvasHeight_ = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 else
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 canvasWidth_ = static_cast<unsigned int>(boost::math::iround(w));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 canvasHeight_ = static_cast<unsigned int>(boost::math::iround(h));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 emscripten_set_canvas_element_size(canvas_.c_str(), canvasWidth_, canvasHeight_);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 };
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 WebAssemblyOpenGLContext::WebAssemblyOpenGLContext(const std::string& canvas) :
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 pimpl_(new PImpl(canvas))
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 void WebAssemblyOpenGLContext::MakeCurrent()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 assert(pimpl_.get() != NULL);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 pimpl_->MakeCurrent();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 void WebAssemblyOpenGLContext::SwapBuffer()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 assert(pimpl_.get() != NULL);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 pimpl_->SwapBuffer();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 unsigned int WebAssemblyOpenGLContext::GetCanvasWidth() const
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 assert(pimpl_.get() != NULL);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 return pimpl_->GetCanvasWidth();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 unsigned int WebAssemblyOpenGLContext::GetCanvasHeight() const
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 assert(pimpl_.get() != NULL);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 return pimpl_->GetCanvasHeight();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 void WebAssemblyOpenGLContext::UpdateSize()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 assert(pimpl_.get() != NULL);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 pimpl_->UpdateSize();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
179
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
180 const std::string& WebAssemblyOpenGLContext::GetCanvasIdentifier() const
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
181 {
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
182 assert(pimpl_.get() != NULL);
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
183 return pimpl_->GetCanvasIdentifier();
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
184 }
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }