Skip to content

Commit

Permalink
WIP rendering works
Browse files Browse the repository at this point in the history
  • Loading branch information
Squareys committed Apr 26, 2019
1 parent 19d9c9f commit d8c65d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/Magnum/Platform/EmscriptenApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, const C
}
#endif

EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, NoCreateT) {
EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, NoCreateT):
_flags{Flag::Redraw}
{
Utility::Arguments args{Implementation::windowScalingArguments()};
#ifdef MAGNUM_TARGET_GL
_context.reset(new GLContext{NoCreate, args, arguments.argc, arguments.argv});
Expand Down Expand Up @@ -103,6 +105,7 @@ bool EmscriptenApplication::tryCreate(const Configuration& configuration, const
if(configuration.windowFlags() & Configuration::WindowFlag::Resizable) {
_flags |= Flag::Resizable;
}

/* Create emscripten WebGL context */
EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
Expand Down Expand Up @@ -505,7 +508,10 @@ void EmscriptenApplication::mainLoopIteration() {
}
}

drawEvent();
if(_flags & Flag::Redraw) {
_flags &= ~Flag::Redraw;
drawEvent();
}
}

int EmscriptenApplication::exec() {
Expand Down
2 changes: 1 addition & 1 deletion src/Magnum/Platform/EmscriptenApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class EmscriptenApplication {
};
typedef Containers::EnumSet<Flag> Flags;

Vector2 _dpiScaling;
Vector2 _dpiScaling{1.0f, 1.0f};
Vector2i _lastKnownCanvasSize;

Flags _flags;
Expand Down
6 changes: 4 additions & 2 deletions src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ struct EmscriptenApplicationTest: Platform::Application {
explicit EmscriptenApplicationTest(const Arguments& arguments):
Platform::Application{arguments, Configuration{}
.setWindowFlags(Configuration::WindowFlag::Resizable)} {
GL::Renderer::setClearColor(Color3{1.0, 1.0, 1.0});
}

virtual void drawEvent() override {
glViewport(0, 0, 640, 480);
GL::Renderer::setClearColor(Color4{1.0, 1.0, 1.0, 1.0});
GL::Renderer::setClearColor(Color3{1.0, 0.0, 1.0});

GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);

swapBuffers();
redraw();
}

/* For testing HiDPI resize events */
Expand Down
10 changes: 8 additions & 2 deletions src/Magnum/Platform/Test/EmscriptenApplicationTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
<h1>Magnum EmscriptenApplication Test</h1>
<div id="container" class="">
<div id="sizer"><div id="expander"><div id="listener">
<canvas id="canvas" class="hidden"></canvas>
<pre id="log"></pre>
<canvas id="canvas" tabindex="0"></canvas>
<div id="status">Initialization...</div>
<div id="status-description"></div>
<script src="EmscriptenApplication.js"></script>
<script async="async" src="PlatformEmscriptenApplicationTest.js"></script>
<script>
/* To test keyboard capture directly on the canvas */
Module.keyboardListeningElement = Module.canvas;
Module.canvas.addEventListener('mousedown', function(event) {
event.target.focus();
});
</script>
</div></div></div>
</div>
</body>
Expand Down

0 comments on commit d8c65d4

Please sign in to comment.