Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Squareys committed Dec 16, 2018
1 parent 7337ac5 commit 6646a2a
Show file tree
Hide file tree
Showing 2 changed files with 462 additions and 94 deletions.
94 changes: 87 additions & 7 deletions src/Magnum/Platform/EmscriptenApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,23 @@ bool EmscriptenApplication::tryCreate(const Configuration& configuration, const
attrs.depth = glConfiguration.depthBufferSize() > 0;
attrs.stencil = glConfiguration.stencilBufferSize() > 0;
attrs.antialias = glConfiguration.sampleCount() > 0;
// attrs.premultipliedAlpha = ;
// attrs.preserveDrawingBuffer = ;
// attrs.preferLowPowerToHighPerformance = ;
// attrs.failIfMajorPerformanceCaveat = ;
// attrs.enableExtensionsByDefault = ;

attrs.premultipliedAlpha =
(glConfiguration.flags() & GLConfiguration::Flag::PremultipliedAlpha) != GLConfiguration::Flags{};
attrs.preserveDrawingBuffer =
(glConfiguration.flags() & GLConfiguration::Flag::PreserveDrawingBuffer) != GLConfiguration::Flags{};
attrs.preferLowPowerToHighPerformance =
(glConfiguration.flags() & GLConfiguration::Flag::PreferLowPowerToHighPerformance) != GLConfiguration::Flags{};
attrs.failIfMajorPerformanceCaveat =
(glConfiguration.flags() & GLConfiguration::Flag::FailIfMajorPerformanceCaveat) != GLConfiguration::Flags{};
attrs.enableExtensionsByDefault =
(glConfiguration.flags() & GLConfiguration::Flag::EnableExtensionsByDefault) != GLConfiguration::Flags{};
attrs.renderViaOffscreenBackBuffer =
(glConfiguration.flags() & GLConfiguration::Flag::RenderViaOffscreenBackBuffer) != GLConfiguration::Flags{};
attrs.proxyContextToMainThread =
(glConfiguration.flags() & GLConfiguration::Flag::ProxyContextToMainThread) != GLConfiguration::Flags{};

attrs.explicitSwapControl = true;
// attrs.proxyContextToMainThread = ;
// attrs.renderViaOffscreenBackBuffer = ;

/* Resize window and match it to the selected format */
double w, h;
Expand Down Expand Up @@ -122,7 +131,78 @@ void EmscriptenApplication::swapBuffers() {
emscripten_webgl_commit_frame();
}

void EmscriptenApplication::setupCallbacks() {
auto mousePressedCallback =
[](int, const EmscriptenMouseEvent* event, void* userData) -> Int {
MouseEvent e{event};
reinterpret_cast<EmscriptenApplication*>(userData)->mousePressEvent(e);
return e.isAccepted();
};
emscripten_set_mousedown_callback(nullptr, this, false, mousePressedCallback);

auto mouseReleaseCallback =
[](int, const EmscriptenMouseEvent* event, void* userData) -> Int {
MouseEvent e{event};
reinterpret_cast<EmscriptenApplication*>(userData)->mouseReleaseEvent(e);
return e.isAccepted();
};
emscripten_set_mouseup_callback(nullptr, this, false, mouseReleaseCallback);

auto mouseMoveCallback =
[](int, const EmscriptenMouseEvent* event, void* userData) -> Int {
MouseMoveEvent e{event};
reinterpret_cast<EmscriptenApplication*>(userData)->mouseMoveEvent(e);
return e.isAccepted();
};
emscripten_set_mousemove_callback(nullptr, this, false, mouseMoveCallback);

/*
emscripten_set_touchstart_callback(nullptr, this, false,
[](int, const EmscriptenTouchEvent* event, void* userData) -> Int {
MouseEvent e{event};
reinterpret_cast<EmscriptenApplication*>(userData)->mousePressEvent(e);
return e.isAccepted();
});
emscripten_set_touchend_callback(nullptr, this, false,
[](int, const EmscriptenTouchEvent* event, void* userData) -> Int {
MouseEvent e{event};
reinterpret_cast<EmscriptenApplication*>(userData)->mouseReleaseEvent(e);
return e.isAccepted();
});
emscripten_set_touchmove_callback(nullptr, this, false,
[](int, const EmscriptenTouchEvent* event, void* userData) -> Int {
MouseMoveEvent e{event};
reinterpret_cast<EmscriptenApplication*>(userData)->mouseMoveEvent(e);
return e.isAccepted();
});
// TODO: touchcancel event?
// TODO: multiTouchGesture event?
*/
auto keyPressCallback =
[](int, const EmscriptenKeyboardEvent* event, void* userData) -> Int {
KeyEvent e{event};
reinterpret_cast<EmscriptenApplication*>(userData)->keyPressEvent(e);
return e.isAccepted();
};
emscripten_set_keypress_callback(nullptr, this, false, keyPressCallback);

auto keyReleaseCallback =
[](int, const EmscriptenKeyboardEvent* event, void* userData) -> Int {
KeyEvent e{event};
reinterpret_cast<EmscriptenApplication*>(userData)->keyReleaseEvent(e);
return e.isAccepted();
};
emscripten_set_keyup_callback(nullptr, this, false, keyReleaseCallback);
}

EmscriptenApplication::KeyEvent::Key EmscriptenApplication::KeyEvent::toKey(const EM_UTF8* keyCode) {
return Key::A;
}

void EmscriptenApplication::viewportEvent(ViewportEvent&) {}
void EmscriptenApplication::keyPressEvent(KeyEvent&) {}
void EmscriptenApplication::keyReleaseEvent(KeyEvent&) {}
void EmscriptenApplication::mousePressEvent(MouseEvent&) {}
void EmscriptenApplication::mouseReleaseEvent(MouseEvent&) {}
void EmscriptenApplication::mouseMoveEvent(MouseMoveEvent&) {}
Expand Down
Loading

0 comments on commit 6646a2a

Please sign in to comment.