mirror of https://github.com/mosra/magnum.git
68 changed files with 116 additions and 4745 deletions
@ -1,65 +0,0 @@
|
||||
# Author: mosra <mosra@centrum.cz> |
||||
pkgname=nacl-magnum |
||||
pkgver=dev.glibc |
||||
pkgrel=1 |
||||
pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (NaCl glibc version)" |
||||
arch=('any') |
||||
url="http://magnum.graphics" |
||||
license=('MIT') |
||||
depends=('nacl-corrade') |
||||
makedepends=('nacl-sdk' 'cmake' 'corrade' 'ninja') |
||||
options=('!strip' '!buildflags') |
||||
|
||||
_rootdir=$startdir/../../ |
||||
|
||||
build() { |
||||
# Build 32bit |
||||
mkdir -p "$_rootdir/build-nacl-glibc-x86-32" |
||||
cd "$_rootdir/build-nacl-glibc-x86-32" |
||||
|
||||
cmake .. \ |
||||
-DCMAKE_TOOLCHAIN_FILE="$_rootdir/toolchains/generic/NaCl-glibc-x86-32.cmake" \ |
||||
-DCMAKE_BUILD_TYPE=Release \ |
||||
-DCMAKE_INSTALL_PREFIX=/usr/nacl \ |
||||
-DWITH_MAGNUMINFO=OFF \ |
||||
-DWITH_NACLAPPLICATION=ON \ |
||||
-DWITH_MAGNUMFONT=ON \ |
||||
-DWITH_MAGNUMFONTCONVERTER=ON \ |
||||
-DWITH_OBJIMPORTER=ON \ |
||||
-DWITH_TGAIMAGECONVERTER=ON \ |
||||
-DWITH_TGAIMPORTER=ON \ |
||||
-DWITH_WAVAUDIOIMPORTER=ON \ |
||||
-DLIB_SUFFIX=/32 \ |
||||
-G Ninja |
||||
ninja |
||||
|
||||
# Build 64bit |
||||
mkdir -p "$_rootdir/build-nacl-glibc-x86-64" |
||||
cd "$_rootdir/build-nacl-glibc-x86-64" |
||||
|
||||
cmake .. \ |
||||
-DCMAKE_TOOLCHAIN_FILE="$_rootdir/toolchains/generic/NaCl-glibc-x86-64.cmake" \ |
||||
-DCMAKE_BUILD_TYPE=Release \ |
||||
-DCMAKE_INSTALL_PREFIX=/usr/nacl \ |
||||
-DWITH_MAGNUMINFO=OFF \ |
||||
-DWITH_NACLAPPLICATION=ON \ |
||||
-DWITH_MAGNUMFONT=ON \ |
||||
-DWITH_MAGNUMFONTCONVERTER=ON \ |
||||
-DWITH_OBJIMPORTER=ON \ |
||||
-DWITH_TGAIMAGECONVERTER=ON \ |
||||
-DWITH_TGAIMPORTER=ON \ |
||||
-DWITH_WAVAUDIOIMPORTER=ON \ |
||||
-G Ninja |
||||
ninja |
||||
} |
||||
|
||||
package() { |
||||
# Install 32bit |
||||
cd "$_rootdir/build-nacl-glibc-x86-32" |
||||
DESTDIR="$pkgdir/" ninja install/strip |
||||
|
||||
# Install 64bit (the headers will be overwritten, but they are (and should |
||||
# be) the same for both versions |
||||
cd "$_rootdir/build-nacl-glibc-x86-64" |
||||
DESTDIR="$pkgdir/" ninja install/strip |
||||
} |
||||
@ -1,67 +0,0 @@
|
||||
# Author: mosra <mosra@centrum.cz> |
||||
pkgname=nacl-magnum |
||||
pkgver=dev.newlib |
||||
pkgrel=1 |
||||
pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (NaCl newlib version)" |
||||
arch=('any') |
||||
url="http://magnum.graphics" |
||||
license=('MIT') |
||||
depends=('nacl-corrade') |
||||
makedepends=('nacl-sdk' 'cmake' 'corrade' 'ninja') |
||||
options=('!strip' '!buildflags') |
||||
|
||||
_rootdir=$startdir/../../ |
||||
|
||||
build() { |
||||
# Build 32bit |
||||
mkdir -p "$_rootdir/build-nacl-newlib-x86-32" |
||||
cd "$_rootdir/build-nacl-newlib-x86-32" |
||||
|
||||
cmake .. \ |
||||
-DCMAKE_TOOLCHAIN_FILE="$_rootdir/toolchains/generic/NaCl-newlib-x86-32.cmake" \ |
||||
-DCMAKE_BUILD_TYPE=Release \ |
||||
-DCMAKE_INSTALL_PREFIX=/usr/nacl \ |
||||
-DWITH_MAGNUMINFO=ON \ |
||||
-DWITH_NACLAPPLICATION=ON \ |
||||
-DWITH_WINDOWLESSNACLAPPLICATION=ON \ |
||||
-DWITH_MAGNUMFONT=ON \ |
||||
-DWITH_MAGNUMFONTCONVERTER=ON \ |
||||
-DWITH_OBJIMPORTER=ON \ |
||||
-DWITH_TGAIMAGECONVERTER=ON \ |
||||
-DWITH_TGAIMPORTER=ON \ |
||||
-DWITH_WAVAUDIOIMPORTER=ON \ |
||||
-DLIB_SUFFIX=/32 \ |
||||
-G Ninja |
||||
ninja |
||||
|
||||
# Build 64bit |
||||
mkdir -p "$_rootdir/build-nacl-newlib-x86-64" |
||||
cd "$_rootdir/build-nacl-newlib-x86-64" |
||||
|
||||
cmake .. \ |
||||
-DCMAKE_TOOLCHAIN_FILE="$_rootdir/toolchains/generic/NaCl-newlib-x86-64.cmake" \ |
||||
-DCMAKE_BUILD_TYPE=Release \ |
||||
-DCMAKE_INSTALL_PREFIX=/usr/nacl \ |
||||
-DWITH_MAGNUMINFO=ON \ |
||||
-DWITH_NACLAPPLICATION=ON \ |
||||
-DWITH_WINDOWLESSNACLAPPLICATION=ON \ |
||||
-DWITH_MAGNUMFONT=ON \ |
||||
-DWITH_MAGNUMFONTCONVERTER=ON \ |
||||
-DWITH_OBJIMPORTER=ON \ |
||||
-DWITH_TGAIMAGECONVERTER=ON \ |
||||
-DWITH_TGAIMPORTER=ON \ |
||||
-DWITH_WAVAUDIOIMPORTER=ON \ |
||||
-G Ninja |
||||
ninja |
||||
} |
||||
|
||||
package() { |
||||
# Install 32bit |
||||
cd "$_rootdir/build-nacl-newlib-x86-32" |
||||
DESTDIR="$pkgdir/" ninja install/strip |
||||
|
||||
# Install 64bit (the headers will be overwritten, but they are (and should |
||||
# be) the same for both versions |
||||
cd "$_rootdir/build-nacl-newlib-x86-64" |
||||
DESTDIR="$pkgdir/" ninja install/strip |
||||
} |
||||
@ -1,276 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "NaClApplication.h" |
||||
|
||||
#include <ppapi/cpp/graphics_3d.h> |
||||
#include <ppapi/cpp/fullscreen.h> |
||||
#include <ppapi/cpp/completion_callback.h> |
||||
#include <Corrade/Utility/NaClStreamBuffer.h> |
||||
|
||||
#include "Magnum/Platform/Context.h" |
||||
#include "Magnum/Platform/ScreenedApplication.hpp" |
||||
|
||||
namespace Magnum { namespace Platform { |
||||
|
||||
static_assert(NaClApplication::MouseEvent::Button::WheelUp != NaClApplication::MouseEvent::Button::Left && |
||||
NaClApplication::MouseEvent::Button::WheelUp != NaClApplication::MouseEvent::Button::Middle && |
||||
NaClApplication::MouseEvent::Button::WheelUp != NaClApplication::MouseEvent::Button::Right && |
||||
NaClApplication::MouseEvent::Button::WheelDown != NaClApplication::MouseEvent::Button::Left && |
||||
NaClApplication::MouseEvent::Button::WheelDown != NaClApplication::MouseEvent::Button::Middle && |
||||
NaClApplication::MouseEvent::Button::WheelDown != NaClApplication::MouseEvent::Button::Right, ""); |
||||
|
||||
struct NaClApplication::ConsoleDebugOutput { |
||||
explicit ConsoleDebugOutput(pp::Instance* instance); |
||||
|
||||
Utility::NaClConsoleStreamBuffer debugBuffer, warningBuffer, errorBuffer; |
||||
std::ostream debugOutput, warningOutput, errorOutput; |
||||
}; |
||||
|
||||
NaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance): debugBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Log), warningBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Warning), errorBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Error), debugOutput(&debugBuffer), warningOutput(&warningBuffer), errorOutput(&errorBuffer) { |
||||
/* Inform about this change on standard output */ |
||||
Debug() << "Platform::NaClApplication: redirecting Debug, Warning and Error output to JavaScript console"; |
||||
|
||||
Debug::setOutput(&debugOutput); |
||||
Warning::setOutput(&warningOutput); |
||||
Error::setOutput(&errorOutput); |
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
NaClApplication::NaClApplication(const Arguments& arguments): NaClApplication{arguments, Configuration{}} {} |
||||
#endif |
||||
|
||||
NaClApplication::NaClApplication(const Arguments& arguments, const Configuration& configuration): NaClApplication{arguments, NoCreate} { |
||||
createContext(configuration); |
||||
} |
||||
|
||||
NaClApplication::NaClApplication(const Arguments& arguments, NoCreateT): Instance(arguments), Graphics3DClient(this), MouseLock(this) { |
||||
_debugOutput.reset(new ConsoleDebugOutput{this}); |
||||
} |
||||
|
||||
void NaClApplication::createContext() { createContext({}); } |
||||
|
||||
void NaClApplication::createContext(const Configuration& configuration) { |
||||
if(!tryCreateContext(configuration)) std::exit(1); |
||||
} |
||||
|
||||
bool NaClApplication::tryCreateContext(const Configuration& configuration) { |
||||
CORRADE_ASSERT(!_context, "Platform::NaClApplication::tryCreateContext(): context already created", false); |
||||
|
||||
_viewportSize = configuration.size(); |
||||
|
||||
const std::int32_t attributes[] = { |
||||
PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, |
||||
PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, |
||||
PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, |
||||
PP_GRAPHICS3DATTRIB_SAMPLES, configuration.sampleCount(), |
||||
PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, configuration.sampleCount() > 1 ? 1 : 0, |
||||
PP_GRAPHICS3DATTRIB_WIDTH, configuration.size().x(), |
||||
PP_GRAPHICS3DATTRIB_HEIGHT, configuration.size().y(), |
||||
PP_GRAPHICS3DATTRIB_NONE |
||||
}; |
||||
|
||||
_graphics.reset(new pp::Graphics3D(this, attributes)); |
||||
if(_graphics->is_null()) { |
||||
Error() << "Platform::NaClApplication::tryCreateContext(): cannot create context"; |
||||
_graphics.reset(); |
||||
return false; |
||||
} |
||||
if(!BindGraphics(*_graphics)) { |
||||
Error() << "Platform::NaClApplication::tryCreateContext(): cannot bind graphics"; |
||||
_graphics.reset(); |
||||
return false; |
||||
} |
||||
|
||||
_fullscreen.reset(new pp::Fullscreen(this)); |
||||
|
||||
glSetCurrentContextPPAPI(_graphics->pp_resource()); |
||||
|
||||
/* Enable input handling for mouse and keyboard */ |
||||
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE|PP_INPUTEVENT_CLASS_WHEEL); |
||||
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
||||
|
||||
/* Return true if the initialization succeeds */ |
||||
return !!(_context = Platform::Context::tryCreate()); |
||||
} |
||||
|
||||
NaClApplication::~NaClApplication() = default; |
||||
|
||||
bool NaClApplication::isFullscreen() { |
||||
return _fullscreen->IsFullscreen(); |
||||
} |
||||
|
||||
bool NaClApplication::setFullscreen(bool enabled) { |
||||
/* Given fullscreen mode already set or switching to it is in progress, done */ |
||||
if(isFullscreen() == enabled || ((_flags & Flag::FullscreenSwitchInProgress) && (_flags & Flag::WillBeFullscreen) == enabled)) |
||||
return true; |
||||
|
||||
/* Switch to opposite fullscreen mode is in progress, can't revert it back */ |
||||
if((_flags & Flag::FullscreenSwitchInProgress) && (_flags & Flag::WillBeFullscreen) != enabled) |
||||
return false; |
||||
|
||||
/* Set fullscreen */ |
||||
if(!_fullscreen->SetFullscreen(enabled)) |
||||
return false; |
||||
|
||||
/* Set flags */ |
||||
_flags |= Flag::FullscreenSwitchInProgress; |
||||
enabled ? _flags |= Flag::WillBeFullscreen : _flags &= ~Flag::WillBeFullscreen; |
||||
return true; |
||||
} |
||||
|
||||
void NaClApplication::DidChangeView(const pp::View& view) { |
||||
/* Fullscreen switch in progress */ |
||||
if(_flags & Flag::FullscreenSwitchInProgress) { |
||||
/* Done, remove the progress flag */ |
||||
if(isFullscreen() == bool(_flags & Flag::WillBeFullscreen)) { |
||||
_flags &= ~Flag::FullscreenSwitchInProgress; |
||||
_flags |= Flag::Redraw; |
||||
} |
||||
|
||||
/* Don't process anything during the switch */ |
||||
else return; |
||||
} |
||||
|
||||
Vector2i size(view.GetRect().width(), view.GetRect().height()); |
||||
|
||||
/* Canvas resized */ |
||||
if(_viewportSize != size) { |
||||
_graphics->ResizeBuffers(size.x(), size.y()); |
||||
viewportEvent(_viewportSize = size); |
||||
} |
||||
|
||||
drawEvent(); |
||||
} |
||||
|
||||
bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) { |
||||
/* Don't handle anything during switch from/to fullscreen */ |
||||
if(_flags & Flag::FullscreenSwitchInProgress) return false; |
||||
|
||||
Flags tmpFlags = _flags; |
||||
|
||||
switch(event.GetType()) { |
||||
case PP_INPUTEVENT_TYPE_KEYDOWN: |
||||
case PP_INPUTEVENT_TYPE_KEYUP: { |
||||
pp::KeyboardInputEvent keyEvent(event); |
||||
KeyEvent e(static_cast<KeyEvent::Key>(keyEvent.GetKeyCode()), static_cast<InputEvent::Modifier>(keyEvent.GetModifiers())); |
||||
event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN ? keyPressEvent(e) : keyReleaseEvent(e); |
||||
if(!e.isAccepted()) return false; |
||||
break; |
||||
} |
||||
|
||||
case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
||||
case PP_INPUTEVENT_TYPE_MOUSEUP: { |
||||
pp::MouseInputEvent mouseEvent(event); |
||||
MouseEvent e(static_cast<MouseEvent::Button>(mouseEvent.GetButton()), {mouseEvent.GetPosition().x(), mouseEvent.GetPosition().y()}, static_cast<InputEvent::Modifier>(mouseEvent.GetModifiers())); |
||||
event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN ? mousePressEvent(e) : mouseReleaseEvent(e); |
||||
if(!e.isAccepted()) return false; |
||||
break; |
||||
} |
||||
|
||||
case PP_INPUTEVENT_TYPE_WHEEL: { |
||||
pp::WheelInputEvent wheelEvent(event); |
||||
MouseScrollEvent e{{wheelEvent.GetDelta().x(), wheelEvent.GetDelta().y()}, static_cast<InputEvent::Modifier>(wheelEvent.GetModifiers())}; |
||||
mouseScrollEvent(e); |
||||
#ifdef MAGNUM_BUILD_DEPRECATED |
||||
if(!Math::TypeTraits<Float>::equals(wheelEvent.GetDelta().y(), 0.0f)) { |
||||
MouseEvent e2(wheelEvent.GetDelta().y() > 0 ? MouseEvent::Button::WheelUp : MouseEvent::Button::WheelDown, {}, static_cast<InputEvent::Modifier>(wheelEvent.GetModifiers())); |
||||
mousePressEvent(e2); |
||||
if(!e.isAccepted() && !e2.isAccepted()) return false; |
||||
} else if(!e.isAccepted()) return false; |
||||
#else |
||||
if(!e.isAccepted()) return false; |
||||
#endif |
||||
break; |
||||
} |
||||
|
||||
case PP_INPUTEVENT_TYPE_MOUSEMOVE: { |
||||
pp::MouseInputEvent mouseEvent(event); |
||||
MouseMoveEvent e({mouseEvent.GetPosition().x(), mouseEvent.GetPosition().y()}, {mouseEvent.GetMovement().x(), mouseEvent.GetMovement().y()}, static_cast<InputEvent::Modifier>(mouseEvent.GetModifiers())); |
||||
mouseMoveEvent(e); |
||||
if(!e.isAccepted()) return false; |
||||
break; |
||||
} |
||||
|
||||
default: return false; |
||||
} |
||||
|
||||
/* Assume everything is properly sequential here */ |
||||
CORRADE_INTERNAL_ASSERT((tmpFlags & Flag::SwapInProgress) == (_flags & Flag::SwapInProgress)); |
||||
|
||||
/* Redraw, if it won't be handled after swap automatically */ |
||||
if((_flags & Flag::Redraw) && !(_flags & Flag::SwapInProgress)) { |
||||
_flags &= ~Flag::Redraw; |
||||
drawEvent(); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
void NaClApplication::swapBuffers() { |
||||
/* Swap already in progress, do nothing */ |
||||
if(_flags & Flag::SwapInProgress) return; |
||||
|
||||
/* Swap buffers and call swapCallback() when done */ |
||||
_flags |= Flag::SwapInProgress; |
||||
_graphics->SwapBuffers(pp::CompletionCallback(&swapCallback, this)); |
||||
} |
||||
|
||||
void NaClApplication::swapCallback(void* applicationInstance, std::int32_t) { |
||||
NaClApplication* instance = static_cast<NaClApplication*>(applicationInstance); |
||||
instance->_flags &= ~Flag::SwapInProgress; |
||||
|
||||
/* Redraw, if requested */ |
||||
if(instance->_flags & Flag::Redraw) { |
||||
instance->_flags &= ~Flag::Redraw; |
||||
instance->drawEvent(); |
||||
} |
||||
} |
||||
|
||||
void NaClApplication::setMouseLocked(bool enabled) { |
||||
/* Already done, nothing to do */ |
||||
if(enabled == isMouseLocked()) return; |
||||
|
||||
if(enabled) LockMouse(pp::CompletionCallback(&mouseLockCallback, this)); |
||||
else UnlockMouse(); |
||||
} |
||||
|
||||
void NaClApplication::mouseLockCallback(void* applicationInstance, std::int32_t) { |
||||
NaClApplication* instance = static_cast<NaClApplication*>(applicationInstance); |
||||
instance->_flags |= Flag::MouseLocked; |
||||
} |
||||
|
||||
void NaClApplication::viewportEvent(const Vector2i&) {} |
||||
void NaClApplication::keyPressEvent(KeyEvent&) {} |
||||
void NaClApplication::keyReleaseEvent(KeyEvent&) {} |
||||
void NaClApplication::mousePressEvent(MouseEvent&) {} |
||||
void NaClApplication::mouseReleaseEvent(MouseEvent&) {} |
||||
void NaClApplication::mouseMoveEvent(MouseMoveEvent&) {} |
||||
void NaClApplication::mouseScrollEvent(MouseScrollEvent&) {} |
||||
|
||||
template class BasicScreen<NaClApplication>; |
||||
template class BasicScreenedApplication<NaClApplication>; |
||||
|
||||
}} |
||||
@ -1,821 +0,0 @@
|
||||
#ifndef Magnum_Platform_NaClApplication_h |
||||
#define Magnum_Platform_NaClApplication_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class @ref Magnum::Platform::NaClApplication, macro @ref MAGNUM_NACLAPPLICATION_MAIN() |
||||
*/ |
||||
|
||||
#include <memory> |
||||
#include <string> |
||||
#include <Corrade/Containers/EnumSet.h> |
||||
|
||||
/* Needs to be first */ |
||||
#include "Magnum/OpenGL.h" |
||||
|
||||
#include <ppapi/cpp/input_event.h> |
||||
#include <ppapi/cpp/instance.h> |
||||
#include <ppapi/cpp/module.h> |
||||
#include <ppapi/cpp/mouse_lock.h> |
||||
#include <ppapi/cpp/graphics_3d_client.h> |
||||
#include <ppapi/gles2/gl2ext_ppapi.h> |
||||
|
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Math/Vector2.h" |
||||
#include "Magnum/Platform/Platform.h" |
||||
|
||||
namespace pp { |
||||
class Graphics3D; |
||||
class Fullscreen; |
||||
} |
||||
|
||||
#ifndef CORRADE_TARGET_NACL |
||||
#error this header is available only on Google Chrome Native Client build |
||||
#endif |
||||
|
||||
namespace Magnum { namespace Platform { |
||||
|
||||
/** @nosubgrouping
|
||||
@brief NaCl application |
||||
|
||||
Application running in [Google Chrome Native Client](https://developers.google.com/native-client/).
|
||||
Supports keyboard and mouse handling. |
||||
|
||||
This application library is available only in |
||||
@ref CORRADE_TARGET_NACL "Google Chrome Native Client", see respective sections |
||||
in @ref building-corrade-cross-nacl "Corrade's" and @ref building-cross-nacl "Magnum's" |
||||
building documentation. It is built if `WITH_NACLAPPLICATION` is enabled in |
||||
CMake. |
||||
|
||||
## Bootstrap application |
||||
|
||||
Fully contained base application using @ref Sdl2Application for desktop build |
||||
and @ref NaClApplication for Native Client build along with full HTML markup |
||||
and CMake setup is available in `base-nacl` branch of |
||||
[Magnum Bootstrap](https://github.com/mosra/magnum-bootstrap) repository,
|
||||
download it as [tar.gz](https://github.com/mosra/magnum-bootstrap/archive/base-nacl.tar.gz)
|
||||
or [zip](https://github.com/mosra/magnum-bootstrap/archive/base-nacl.zip) file.
|
||||
After extracting the downloaded archive, you can do the desktop build in the |
||||
same way as with @ref Sdl2Application. For the Native Client build you also |
||||
need to put the contents of toolchains repository from https://github.com/mosra/toolchains
|
||||
in `toolchains/` subdirectory. Don't forget to adapt `NACL_PREFIX` variable in |
||||
`toolchains/generic/NaCl-newlib-x86-32.cmake` and |
||||
`toolchains/generic/NaCl-newlib-x86-64.cmake` to path where your SDK is |
||||
installed. Default is `/usr/nacl`. You may need to adapt also |
||||
`NACL_TOOLCHAIN_PATH` so CMake is able to find the compiler. |
||||
|
||||
Then create build directories for x86-32 and x86-64 and run `cmake` and |
||||
build/install commands in them. The toolchains need access to the platform |
||||
file, so be sure to properly set **absolute** path to `toolchains/modules/` |
||||
directory containing `Platform/NaCl.cmake`. Set `CMAKE_INSTALL_PREFIX` to |
||||
location of your webserver to have the files installed in proper location (e.g. |
||||
`/srv/http/nacl`). |
||||
|
||||
mkdir build-nacl-x86-32 && cd build-nacl-x86-32 |
||||
cmake .. \
|
||||
-DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/NaCl-newlib-x86-32.cmake" \
|
||||
-DCMAKE_INSTALL_PREFIX=/srv/http/nacl |
||||
cmake --build . |
||||
cmake --build . --target install |
||||
|
||||
mkdir build-nacl-x86-64 && cd build-nacl-x86-64 |
||||
cmake .. \
|
||||
-DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/NaCl-newlib-x86-64.cmake" \
|
||||
-DCMAKE_INSTALL_PREFIX=/srv/http/nacl |
||||
cmake --build . |
||||
cmake --build . --target install |
||||
|
||||
See @ref cmake for more information. |
||||
|
||||
You can then open `MyApplication` through your webserver in Chrome (e.g. |
||||
`http://localhost/nacl/MyApplication.html`).
|
||||
|
||||
## General usage |
||||
|
||||
For CMake you need to copy `FindOpenGLES2.cmake` from `modules/` directory in |
||||
Magnum source to `modules/` dir in your project (so it is able to find OpenGL |
||||
ES). Request `NaClApplication` component of `Magnum` package and link to |
||||
`Magnum::NaClApplication` target. If no other application is requested, you can |
||||
also use generic `Magnum::Application` alias to simplify porting. Again, see |
||||
@ref building and @ref cmake for more information. |
||||
|
||||
In C++ code you need to implement at least @ref drawEvent() to be able to draw |
||||
on the screen. The subclass must be then registered to NaCl API using |
||||
@ref MAGNUM_NACLAPPLICATION_MAIN() macro. See @ref platform for more |
||||
information. |
||||
@code |
||||
class MyApplication: public Platform::NaClApplication { |
||||
// implement required methods...
|
||||
}; |
||||
MAGNUM_NACLAPPLICATION_MAIN(MyApplication) |
||||
@endcode |
||||
|
||||
If no other application header is included, this class is also aliased to |
||||
`Platform::Application` and the macro is aliased to `MAGNUM_APPLICATION_MAIN()` |
||||
to simplify porting. |
||||
|
||||
### HTML markup and NMF file |
||||
|
||||
You need to provide HTML markup for your application. Template one is below or |
||||
in the bootstrap application, you can modify it to your liking. The markup |
||||
references two files, `NaClApplication.js` and `WebApplication.css`, both are |
||||
in `Platform/` directory in the source tree and are also installed into |
||||
`share/magnum/` inside your NaCl toolchain. Change `<application>` to |
||||
name of your executable. |
||||
@code |
||||
<!DOCTYPE html> |
||||
<html xmlns="http://www.w3.org/1999/xhtml"> |
||||
<head> |
||||
<title>Magnum NaCl Application</title> |
||||
<meta charset="utf-8" /> |
||||
<link rel="stylesheet" href="WebApplication.css" /> |
||||
</head> |
||||
<body> |
||||
<h1>Magnum NaCl Application</h1> |
||||
<div id="listener"> |
||||
<embed id="module" type="application/x-nacl" src="<application>.nmf"></embed> |
||||
<div id="status">Initialization...</div> |
||||
<div id="statusDescription"></div> |
||||
<script src="NaClApplication.js"></script> |
||||
</div> |
||||
</body> |
||||
</html> |
||||
@endcode |
||||
|
||||
You can modify all the files to your liking, but the HTML file must contain at |
||||
least the `<embed>` enclosed in listener `<div>`. The JavaScript |
||||
file contains event listeners which print loading status on the page. The |
||||
status displayed in the remaining two `<div>`s, if they are available. |
||||
The CSS file contains rudimentary style to avoid eye bleeding. |
||||
|
||||
The `<embed>` file references NMF file which you need to provide too. If |
||||
you target @ref CORRADE_TARGET_NACL_NEWLIB "newlib", the file is pretty simple, |
||||
for example (change `<application>` to name of your executable): |
||||
@code |
||||
{ |
||||
"program": { |
||||
"x86-32": {"url": "<application>-x86-32.nexe"}, |
||||
"x86-64": {"url": "<application>-x86-64.nexe"} |
||||
} |
||||
} |
||||
@endcode |
||||
|
||||
If you target @ref CORRADE_TARGET_NACL_GLIBC "glibc", you need to specify also |
||||
all additional dependencies. See [Native Client](https://developers.google.com/native-client/)
|
||||
documentation for more information. |
||||
|
||||
## Redirecting output to Chrome's JavaScript console |
||||
|
||||
The application by default redirects @ref Corrade::Utility::Debug "Debug", |
||||
@ref Corrade::Utility::Warning "Warning" and @ref Corrade::Utility::Error "Error" |
||||
output to JavaScript console. See also @ref Corrade::Utility::NaClConsoleStreamBuffer |
||||
for more information. |
||||
*/ |
||||
class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public pp::MouseLock { |
||||
public: |
||||
/** @brief Application arguments */ |
||||
typedef PP_Instance Arguments; |
||||
|
||||
class Configuration; |
||||
class InputEvent; |
||||
class KeyEvent; |
||||
class MouseEvent; |
||||
class MouseMoveEvent; |
||||
class MouseScrollEvent; |
||||
|
||||
/** @copydoc Sdl2Application::Sdl2Application(const Arguments&, const Configuration&) */ |
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
explicit NaClApplication(const Arguments& arguments, const Configuration& configuration = Configuration()); |
||||
#else |
||||
/* To avoid "invalid use of incomplete type" */ |
||||
explicit NaClApplication(const Arguments& arguments, const Configuration& configuration); |
||||
explicit NaClApplication(const Arguments& arguments); |
||||
#endif |
||||
|
||||
/** @copydoc Sdl2Application::Sdl2Application(const Arguments&, NoCreateT) */ |
||||
explicit NaClApplication(const Arguments& arguments, NoCreateT); |
||||
|
||||
#ifdef MAGNUM_BUILD_DEPRECATED |
||||
/**
|
||||
* @copybrief NaClApplication(const Arguments&, NoCreateT) |
||||
* @deprecated Use @ref NaClApplication(const Arguments&, NoCreateT) instead. |
||||
*/ |
||||
CORRADE_DEPRECATED("use NaClApplication(const Arguments&, NoCreateT) instead") explicit NaClApplication(const Arguments& arguments, std::nullptr_t): NaClApplication{arguments, NoCreate} {} |
||||
#endif |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
NaClApplication(const NaClApplication&) = delete; |
||||
|
||||
/** @brief Moving is not allowed */ |
||||
NaClApplication(NaClApplication&&) = delete; |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
NaClApplication& operator=(const NaClApplication&) = delete; |
||||
|
||||
/** @brief Moving is not allowed */ |
||||
NaClApplication& operator=(NaClApplication&&) = delete; |
||||
|
||||
protected: |
||||
/* Nobody will need to have (and delete) NaClApplication*, thus this is
|
||||
faster than public pure virtual destructor */ |
||||
~NaClApplication(); |
||||
|
||||
/** @copydoc Sdl2Application::createContext() */ |
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
void createContext(const Configuration& configuration = Configuration()); |
||||
#else |
||||
/* To avoid "invalid use of incomplete type" */ |
||||
void createContext(const Configuration& configuration); |
||||
void createContext(); |
||||
#endif |
||||
|
||||
/** @copydoc Sdl2Application::tryCreateContext() */ |
||||
bool tryCreateContext(const Configuration& configuration); |
||||
|
||||
/** @{ @name Screen handling */ |
||||
|
||||
public: |
||||
/** @brief Whether the application runs fullscreen */ |
||||
bool isFullscreen(); |
||||
|
||||
/**
|
||||
* @brief Set fullscreen |
||||
* @return `False` if switch to opposite mode is in progress or if the |
||||
* switch is not possible, `true` otherwise. |
||||
* |
||||
* The switch is done asynchronously, during the switch no event |
||||
* processing is done. |
||||
*/ |
||||
bool setFullscreen(bool enabled); |
||||
|
||||
protected: |
||||
/**
|
||||
* @brief Swap buffers |
||||
* |
||||
* Paints currently rendered framebuffer on screen. |
||||
*/ |
||||
void swapBuffers(); |
||||
|
||||
/** @copydoc Sdl2Application::redraw() */ |
||||
void redraw() { _flags |= Flag::Redraw; } |
||||
|
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
protected: |
||||
#else |
||||
private: |
||||
#endif |
||||
/** @copydoc Sdl2Application::viewportEvent() */ |
||||
virtual void viewportEvent(const Vector2i& size); |
||||
|
||||
/** @copydoc Sdl2Application::drawEvent() */ |
||||
virtual void drawEvent() = 0; |
||||
|
||||
/*@}*/ |
||||
|
||||
/** @{ @name Keyboard handling */ |
||||
|
||||
/**
|
||||
* @brief Key press event |
||||
* |
||||
* Called when an key is pressed. Default implementation does nothing. |
||||
* If you accept the event, call @ref InputEvent::setAccepted() "setAccepted()" |
||||
* on it, otherwise the event will be propagated to the browser. |
||||
*/ |
||||
virtual void keyPressEvent(KeyEvent& event); |
||||
|
||||
/**
|
||||
* @brief Key release event |
||||
* |
||||
* Called when an key is released. Default implementation does nothing. |
||||
* If you accept the event, call @ref InputEvent::setAccepted() "setAccepted()" |
||||
* on it, otherwise the event will be propagated to the browser. |
||||
*/ |
||||
virtual void keyReleaseEvent(KeyEvent& event); |
||||
|
||||
/*@}*/ |
||||
|
||||
/** @{ @name Mouse handling */ |
||||
|
||||
public: |
||||
/** @brief Whether mouse is locked */ |
||||
bool isMouseLocked() const { return _flags & Flag::MouseLocked; } |
||||
|
||||
/**
|
||||
* @brief Enable or disable mouse locking |
||||
* |
||||
* When mouse is locked, the cursor is hidden and only |
||||
* @ref MouseMoveEvent::relativePosition() is changing, absolute |
||||
* position stays the same. |
||||
*/ |
||||
void setMouseLocked(bool enabled); |
||||
|
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
protected: |
||||
#else |
||||
private: |
||||
#endif |
||||
/**
|
||||
* @brief Mouse press event |
||||
* |
||||
* Called when mouse button is pressed. Default implementation does |
||||
* nothing. If you accept the event, call @ref InputEvent::setAccepted() "setAccepted()" |
||||
* on it, otherwise the event will be propagated to the browser. |
||||
*/ |
||||
virtual void mousePressEvent(MouseEvent& event); |
||||
|
||||
/**
|
||||
* @brief Mouse release event |
||||
* |
||||
* Called when mouse button is released. Default implementation does |
||||
* nothing. If you accept the event, call @ref InputEvent::setAccepted() "setAccepted()" |
||||
* on it, otherwise the event will be propagated to the browser. |
||||
*/ |
||||
virtual void mouseReleaseEvent(MouseEvent& event); |
||||
|
||||
/**
|
||||
* @brief Mouse move event |
||||
* |
||||
* Called when mouse is moved. Default implementation does nothing. If |
||||
* you accept the event, call @ref InputEvent::setAccepted() "setAccepted()" |
||||
* on it, otherwise the event will be propagated to the browser. |
||||
*/ |
||||
virtual void mouseMoveEvent(MouseMoveEvent& event); |
||||
|
||||
/**
|
||||
* @brief Mouse scroll event |
||||
* |
||||
* Called when a scrolling device is used (mouse wheel or scrolling |
||||
* area on a touchpad). Default implementation does nothing. If you |
||||
* accept the event, call @ref InputEvent::setAccepted() "setAccepted()" |
||||
* on it, otherwise the event will be propagated to the browser. |
||||
*/ |
||||
virtual void mouseScrollEvent(MouseScrollEvent& event); |
||||
|
||||
/*@}*/ |
||||
|
||||
private: |
||||
struct ConsoleDebugOutput; |
||||
|
||||
enum class Flag: UnsignedByte { |
||||
SwapInProgress = 1 << 0, |
||||
Redraw = 1 << 1, |
||||
FullscreenSwitchInProgress = 1 << 2, |
||||
WillBeFullscreen = 1 << 3, |
||||
MouseLocked = 1 << 4 |
||||
}; |
||||
typedef Containers::EnumSet<Flag> Flags; |
||||
|
||||
void Graphics3DContextLost() override { |
||||
CORRADE_ASSERT(false, "NaClApplication: context unexpectedly lost", ); |
||||
} |
||||
|
||||
void MouseLockLost() override { |
||||
_flags &= ~Flag::MouseLocked; |
||||
} |
||||
|
||||
void DidChangeView(const pp::View& view) override; |
||||
|
||||
bool HandleInputEvent(const pp::InputEvent& event) override; |
||||
|
||||
static void swapCallback(void* applicationInstance, std::int32_t); |
||||
static void mouseLockCallback(void* applicationInstance, std::int32_t); |
||||
|
||||
std::unique_ptr<pp::Graphics3D> _graphics; |
||||
std::unique_ptr<pp::Fullscreen> _fullscreen; |
||||
Vector2i _viewportSize; |
||||
Flags _flags; |
||||
|
||||
std::unique_ptr<ConsoleDebugOutput> _debugOutput; |
||||
std::unique_ptr<Platform::Context> _context; |
||||
|
||||
CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) |
||||
}; |
||||
|
||||
/**
|
||||
@brief Configuration |
||||
|
||||
Double-buffered RGBA canvas with depth and stencil buffers. |
||||
@see @ref NaClApplication(), @ref createContext(), @ref tryCreateContext() |
||||
*/ |
||||
class NaClApplication::Configuration { |
||||
public: |
||||
constexpr /*implicit*/ Configuration(): _size(640, 480), _sampleCount(0) {} |
||||
|
||||
/**
|
||||
* @brief Set window title |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* @note This function does nothing and is included only for |
||||
* compatibility with other toolkits. You need to set the title |
||||
* separately in application's HTML markup. |
||||
*/ |
||||
template<class T> Configuration& setTitle(const T&) { return *this; } |
||||
|
||||
/** @brief Window size */ |
||||
Vector2i size() const { return _size; } |
||||
|
||||
/**
|
||||
* @brief Set window size |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Default is `{640, 480}`. |
||||
*/ |
||||
Configuration& setSize(const Vector2i& size) { |
||||
_size = size; |
||||
return *this; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Set context version |
||||
* |
||||
* @note This function does nothing and is included only for |
||||
* compatibility with other toolkits. @ref Version::GLES200 is |
||||
* always used. |
||||
*/ |
||||
Configuration& setVersion(Version) { return *this; } |
||||
|
||||
/** @brief Sample count */ |
||||
Int sampleCount() const { return _sampleCount; } |
||||
|
||||
/**
|
||||
* @brief Set sample count |
||||
* @return Reference to self (for method chaining) |
||||
* |
||||
* Default is `0`, thus no multisampling. See also |
||||
* @ref Renderer::Feature::Multisampling. |
||||
*/ |
||||
Configuration& setSampleCount(Int count) { |
||||
_sampleCount = count; |
||||
return *this; |
||||
} |
||||
|
||||
private: |
||||
Vector2i _size; |
||||
Int _sampleCount; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Base for input events |
||||
|
||||
If you accept the event, call @ref setAccepted(), otherwise the event will be |
||||
propagated to the browser. |
||||
@see @ref KeyEvent, @ref MouseEvent, @ref MouseMoveEvent, @ref keyPressEvent(), |
||||
@ref keyReleaseEvent(), @ref mousePressEvent(), @ref mouseReleaseEvent(), |
||||
@ref mouseMoveEvent() |
||||
*/ |
||||
class NaClApplication::InputEvent { |
||||
public: |
||||
/**
|
||||
* @brief Modifier |
||||
* |
||||
* @see @ref Modifiers, @ref modifiers() |
||||
* @todo AltGr + PP_INPUTEVENT_MODIFIER_ISKEYPAD, PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT |
||||
*/ |
||||
enum class Modifier: std::uint32_t { |
||||
Shift = PP_INPUTEVENT_MODIFIER_SHIFTKEY, /**< Shift */ |
||||
Ctrl = PP_INPUTEVENT_MODIFIER_CONTROLKEY, /**< Ctrl */ |
||||
Alt = PP_INPUTEVENT_MODIFIER_ALTKEY, /**< Alt */ |
||||
Meta = PP_INPUTEVENT_MODIFIER_METAKEY, /**< Meta */ |
||||
CapsLock = PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY, /**< Caps lock */ |
||||
NumLock = PP_INPUTEVENT_MODIFIER_NUMLOCKKEY /**< Num lock */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Set of modifiers |
||||
* |
||||
* @see @ref modifiers() |
||||
*/ |
||||
typedef Containers::EnumSet<Modifier> Modifiers; |
||||
|
||||
/**
|
||||
* @brief Mouse button |
||||
* |
||||
* @see @ref Buttons, @ref buttons() |
||||
*/ |
||||
enum class Button: std::uint32_t { |
||||
Left = PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN, /**< Left button */ |
||||
Middle = PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN, /**< Middle button */ |
||||
Right = PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN /**< Right button */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Set of mouse buttons |
||||
* |
||||
* @see @ref buttons() |
||||
*/ |
||||
typedef Containers::EnumSet<Button> Buttons; |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
InputEvent(const InputEvent&) = delete; |
||||
|
||||
/** @brief Moving is not allowed */ |
||||
InputEvent(InputEvent&&) = delete; |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
InputEvent& operator=(const InputEvent&) = delete; |
||||
|
||||
/** @brief Moving is not allowed */ |
||||
InputEvent& operator=(InputEvent&&) = delete; |
||||
|
||||
/** @brief Modifiers */ |
||||
constexpr Modifiers modifiers() const { return _modifiers; } |
||||
|
||||
/** @brief Mouse buttons */ |
||||
constexpr Buttons buttons() const { return Button(static_cast<std::uint32_t>(_modifiers)); } |
||||
|
||||
/**
|
||||
* @brief Set event as accepted |
||||
* |
||||
* If the event is ignored (i.e., not set as accepted), it is |
||||
* propagated elsewhere (e.g. to the browser). By default is each |
||||
* event ignored. |
||||
*/ |
||||
void setAccepted(bool accepted = true) { _accepted = accepted; } |
||||
|
||||
/** @brief Whether the event is accepted */ |
||||
constexpr bool isAccepted() const { return _accepted; } |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
protected: |
||||
constexpr InputEvent(Modifiers modifiers): _accepted(false), _modifiers(modifiers) {} |
||||
|
||||
~InputEvent() = default; |
||||
#endif |
||||
|
||||
private: |
||||
bool _accepted; |
||||
const Modifiers _modifiers; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Key event |
||||
|
||||
See also @ref InputEvent for more information. |
||||
@see @ref keyPressEvent(), @ref keyReleaseEvent() |
||||
*/ |
||||
class NaClApplication::KeyEvent: public NaClApplication::InputEvent { |
||||
friend NaClApplication; |
||||
|
||||
public: |
||||
/**
|
||||
* @brief Key |
||||
* |
||||
* @see @ref key() |
||||
* @todo Slash, percent, equal to be compatible with *XApplication |
||||
*/ |
||||
enum class Key: std::uint32_t { |
||||
Enter = 0x0D, /**< Enter */ |
||||
Esc = 0x1B, /**< Escape */ |
||||
|
||||
Up = 0x26, /**< Up arrow */ |
||||
Down = 0x28, /**< Down arrow */ |
||||
Left = 0x25, /**< Left arrow */ |
||||
Right = 0x27, /**< Right arrow */ |
||||
F1 = 0x70, /**< F1 */ |
||||
F2 = 0x71, /**< F2 */ |
||||
F3 = 0x72, /**< F3 */ |
||||
F4 = 0x73, /**< F4 */ |
||||
F5 = 0x74, /**< F5 */ |
||||
F6 = 0x75, /**< F6 */ |
||||
F7 = 0x76, /**< F7 */ |
||||
F8 = 0x77, /**< F8 */ |
||||
F9 = 0x78, /**< F9 */ |
||||
F10 = 0x79, /**< F10 */ |
||||
F11 = 0x7A, /**< F11 */ |
||||
F12 = 0x7B, /**< F12 */ |
||||
Home = 0x24, /**< Home */ |
||||
End = 0x23, /**< End */ |
||||
PageUp = 0x21, /**< Page up */ |
||||
PageDown = 0x22, /**< Page down */ |
||||
|
||||
Space = 0x20, /**< Space */ |
||||
Comma = 0xBC, /**< Comma */ |
||||
Period = 0xBE, /**< Period */ |
||||
Minus = 0xBD, /**< Minus */ |
||||
Plus = 0xBB, /**< Plus */ |
||||
|
||||
Zero = '0', /**< Zero */ |
||||
One = '1', /**< One */ |
||||
Two = '2', /**< Two */ |
||||
Three = '3', /**< Three */ |
||||
Four = '4', /**< Four */ |
||||
Five = '5', /**< Five */ |
||||
Six = '6', /**< Six */ |
||||
Seven = '7', /**< Seven */ |
||||
Eight = '8', /**< Eight */ |
||||
Nine = '9', /**< Nine */ |
||||
|
||||
A = 'A', /**< Letter A */ |
||||
B = 'B', /**< Letter B */ |
||||
C = 'C', /**< Letter C */ |
||||
D = 'D', /**< Letter D */ |
||||
E = 'E', /**< Letter E */ |
||||
F = 'F', /**< Letter F */ |
||||
G = 'G', /**< Letter G */ |
||||
H = 'H', /**< Letter H */ |
||||
I = 'I', /**< Letter I */ |
||||
J = 'J', /**< Letter J */ |
||||
K = 'K', /**< Letter K */ |
||||
L = 'L', /**< Letter L */ |
||||
M = 'M', /**< Letter M */ |
||||
N = 'N', /**< Letter N */ |
||||
O = 'O', /**< Letter O */ |
||||
P = 'P', /**< Letter P */ |
||||
Q = 'Q', /**< Letter Q */ |
||||
R = 'R', /**< Letter R */ |
||||
S = 'S', /**< Letter S */ |
||||
T = 'T', /**< Letter T */ |
||||
U = 'U', /**< Letter U */ |
||||
V = 'V', /**< Letter V */ |
||||
W = 'W', /**< Letter W */ |
||||
X = 'X', /**< Letter X */ |
||||
Y = 'Y', /**< Letter Y */ |
||||
Z = 'Z' /**< Letter Z */ |
||||
}; |
||||
|
||||
/** @brief Key */ |
||||
constexpr Key key() const { return _key; } |
||||
|
||||
private: |
||||
constexpr KeyEvent(Key key, Modifiers modifiers): InputEvent(modifiers), _key(key) {} |
||||
|
||||
const Key _key; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Mouse event |
||||
|
||||
See also @ref InputEvent for more information. |
||||
@see @ref MouseMoveEvent, @ref MouseScrollEvent, @ref mousePressEvent(), |
||||
@ref mouseReleaseEvent() |
||||
*/ |
||||
class NaClApplication::MouseEvent: public NaClApplication::InputEvent { |
||||
friend NaClApplication; |
||||
|
||||
public: |
||||
/**
|
||||
* @brief Button |
||||
* |
||||
* @see @ref button() |
||||
*/ |
||||
enum class Button: unsigned int { |
||||
Left = PP_INPUTEVENT_MOUSEBUTTON_LEFT, /**< Left button */ |
||||
Middle = PP_INPUTEVENT_MOUSEBUTTON_MIDDLE, /**< Middle button */ |
||||
Right = PP_INPUTEVENT_MOUSEBUTTON_RIGHT, /**< Right button */ |
||||
|
||||
#ifdef MAGNUM_BUILD_DEPRECATED |
||||
/**
|
||||
* Wheel up |
||||
* @deprecated Use @ref MouseScrollEvent and @ref mouseScrollEvent() instead. |
||||
*/ |
||||
WheelUp CORRADE_DEPRECATED_ENUM("use mouseScrollEvent() and MouseScrollEvent instead") = 0xFFFF01, |
||||
|
||||
/**
|
||||
* Wheel down |
||||
* @deprecated Use @ref MouseScrollEvent and @ref mouseScrollEvent() instead. |
||||
*/ |
||||
WheelDown CORRADE_DEPRECATED_ENUM("use mouseScrollEvent() and MouseScrollEvent instead") = 0xFFFF02 |
||||
#endif |
||||
}; |
||||
|
||||
/** @brief Button */ |
||||
constexpr Button button() const { return _button; } |
||||
|
||||
/**
|
||||
* @brief Position |
||||
* |
||||
* @attention Note that due to the way the @ref Button::WheelUp and |
||||
* @ref Button::WheelDown events are handled by Native Client, the |
||||
* position information is not available, i.e. it is set to zero. |
||||
*/ |
||||
constexpr Vector2i position() const { return _position; } |
||||
|
||||
private: |
||||
constexpr MouseEvent(Button button, const Vector2i& position, Modifiers modifiers): InputEvent(modifiers), _button(button), _position(position) {} |
||||
|
||||
const Button _button; |
||||
const Vector2i _position; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Mouse move event |
||||
|
||||
See also @ref InputEvent for more information. |
||||
@see @ref MouseEvent, @ref MouseScrollEvent, @ref mouseMoveEvent() |
||||
*/ |
||||
class NaClApplication::MouseMoveEvent: public NaClApplication::InputEvent { |
||||
friend NaClApplication; |
||||
|
||||
public: |
||||
/** @brief Position */ |
||||
constexpr Vector2i position() const { return _position; } |
||||
|
||||
/**
|
||||
* @brief Relative position |
||||
* |
||||
* Position relative to previous event. |
||||
*/ |
||||
constexpr Vector2i relativePosition() const { return _relativePosition; } |
||||
|
||||
private: |
||||
constexpr MouseMoveEvent(const Vector2i& position, const Vector2i& relativePosition, Modifiers modifiers): InputEvent(modifiers), _position(position), _relativePosition(relativePosition) {} |
||||
|
||||
const Vector2i _position, _relativePosition; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Mouse scroll event |
||||
|
||||
See also @ref InputEvent for more information. |
||||
@see @ref MouseEvent, @ref MouseMoveEvent, @ref mouseScrollEvent() |
||||
*/ |
||||
class NaClApplication::MouseScrollEvent: public NaClApplication::InputEvent { |
||||
friend NaClApplication; |
||||
|
||||
public: |
||||
/** @brief Scroll offset */ |
||||
constexpr Vector2 offset() const { return _offset; } |
||||
|
||||
private: |
||||
constexpr MouseScrollEvent(const Vector2& offset, Modifiers modifiers): InputEvent{modifiers}, _offset{offset} {} |
||||
|
||||
const Vector2 _offset; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(NaClApplication::Flags) |
||||
|
||||
namespace Implementation { |
||||
template<class Application> class NaClModule: public pp::Module { |
||||
public: |
||||
~NaClModule() { glTerminatePPAPI(); } |
||||
|
||||
bool Init() override { |
||||
return glInitializePPAPI(get_browser_interface()); |
||||
} |
||||
|
||||
pp::Instance* CreateInstance(PP_Instance instance) { |
||||
return new Application(instance); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
/** @hideinitializer
|
||||
@brief Entry point for NaCl application |
||||
@param className Class name |
||||
|
||||
See @ref Magnum::Platform::NaClApplication "Platform::NaClApplication" for |
||||
usage information. This macro abstracts out platform-specific entry point code |
||||
(the classic `main()` function cannot be used in NaCl). See |
||||
@ref portability-applications for more information. When no other application |
||||
header is included this macro is also aliased to `MAGNUM_APPLICATION_MAIN()`. |
||||
*/ |
||||
/* look at that insane placement of __attribute__. WTF. */ |
||||
#define MAGNUM_NACLAPPLICATION_MAIN(className) \ |
||||
namespace pp { \
|
||||
Module __attribute__ ((visibility ("default"))) * CreateModule(); \
|
||||
Module __attribute__ ((visibility ("default"))) * CreateModule() { \
|
||||
return new Magnum::Platform::Implementation::NaClModule<className>(); \
|
||||
} \
|
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
#ifndef MAGNUM_APPLICATION_MAIN |
||||
typedef NaClApplication Application; |
||||
typedef BasicScreen<NaClApplication> Screen; |
||||
typedef BasicScreenedApplication<NaClApplication> ScreenedApplication; |
||||
#define MAGNUM_APPLICATION_MAIN(className) MAGNUM_NACLAPPLICATION_MAIN(className) |
||||
#else |
||||
#undef MAGNUM_APPLICATION_MAIN |
||||
#endif |
||||
#endif |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(NaClApplication::InputEvent::Modifiers) |
||||
CORRADE_ENUMSET_OPERATORS(NaClApplication::InputEvent::Buttons) |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -1,43 +0,0 @@
|
||||
function setStatus(message) { |
||||
var status = document.getElementById('status'); |
||||
if(status) status.innerHTML = message; |
||||
} |
||||
|
||||
function setStatusDescription(message) { |
||||
var statusDescription = document.getElementById('statusDescription'); |
||||
if(statusDescription) statusDescription.innerHTML = message; |
||||
} |
||||
|
||||
var listener = document.getElementById('listener'); |
||||
|
||||
listener.addEventListener('loadstart', function() { |
||||
setStatus('Loading...'); |
||||
}, true); |
||||
|
||||
listener.addEventListener('progress', function(event) { |
||||
setStatus('Downloading...'); |
||||
|
||||
/* Show progress */ |
||||
if(event.lengthComputable && event.total > 0) |
||||
setStatusDescription(Math.round(event.loaded*100/event.total) + '% of ' |
||||
+ Math.round(event.total/1024) + ' kB'); |
||||
|
||||
/* Unknown total size */ |
||||
else setStatusDescription(Math.round(event.loaded/1024) + ' kB'); |
||||
|
||||
}, true); |
||||
|
||||
listener.addEventListener('error', function() { |
||||
setStatus('Loading failed'); |
||||
setStatusDescription(document.getElementById('module').lastError + '<br />Check JavaScript console for more information.'); |
||||
}, true); |
||||
|
||||
listener.addEventListener('abort', function() { |
||||
setStatus('Loading aborted'); |
||||
setStatusDescription(''); |
||||
}, true); |
||||
|
||||
listener.addEventListener('load', function() { |
||||
setStatus(''); |
||||
setStatusDescription(''); |
||||
}, true); |
||||
@ -1,125 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "WindowlessNaClApplication.h" |
||||
|
||||
#include <ppapi/cpp/graphics_3d.h> |
||||
#include <ppapi/cpp/completion_callback.h> |
||||
#include <Corrade/Utility/Assert.h> |
||||
#include <Corrade/Utility/NaClStreamBuffer.h> |
||||
|
||||
#include "Magnum/Platform/Context.h" |
||||
|
||||
namespace Magnum { namespace Platform { |
||||
|
||||
WindowlessNaClContext::WindowlessNaClContext(pp::Instance& instance, const Configuration&, Context*) { |
||||
const std::int32_t attributes[] = { |
||||
PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, |
||||
PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, |
||||
PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, |
||||
PP_GRAPHICS3DATTRIB_WIDTH, 1, |
||||
PP_GRAPHICS3DATTRIB_HEIGHT, 1, |
||||
PP_GRAPHICS3DATTRIB_NONE |
||||
}; |
||||
|
||||
std::unique_ptr<pp::Graphics3D> context{new pp::Graphics3D{*instance, attributes}}; |
||||
if(context->is_null()) |
||||
Error() << "Platform::WindowlessNaClContext: cannot create context"; |
||||
|
||||
if(!BindGraphics(*context)) |
||||
Error() << "Platform::WindowlessNaClContext: cannot bind graphics"; |
||||
|
||||
/* All went well, save the context */ |
||||
_context = std::move(context); |
||||
} |
||||
|
||||
WindowlessNaClContext::WindowlessNaClContext(WindowlessNaClContext&&) = default; |
||||
|
||||
WindowlessNaClContext::~WindowlessNaClContext() = default; |
||||
|
||||
WindowlessNaClContext& WindowlessNaClContext::operator=(WindowlessNaClContext&&) = default; |
||||
|
||||
bool WindowlessNaClContext::makeCurrent() { |
||||
if(!_context) return false; |
||||
|
||||
glSetCurrentContextPPAPI(_context->pp_resource()); |
||||
return true; |
||||
} |
||||
|
||||
struct WindowlessNaClApplication::ConsoleDebugOutput { |
||||
explicit ConsoleDebugOutput(pp::Instance* instance); |
||||
|
||||
Utility::NaClConsoleStreamBuffer debugBuffer, warningBuffer, errorBuffer; |
||||
std::ostream debugOutput, warningOutput, errorOutput; |
||||
}; |
||||
|
||||
WindowlessNaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance): debugBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Log), warningBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Warning), errorBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Error), debugOutput(&debugBuffer), warningOutput(&warningBuffer), errorOutput(&errorBuffer) { |
||||
/* Inform about this change on standard output */ |
||||
Debug() << "Platform::WindowlessNaClApplication: redirecting Debug, Warning and Error output to JavaScript console"; |
||||
|
||||
Debug::setOutput(&debugOutput); |
||||
Warning::setOutput(&warningOutput); |
||||
Error::setOutput(&errorOutput); |
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments): WindowlessNaClApplication{arguments, Configuration{}} {} |
||||
#endif |
||||
|
||||
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration): |
||||
WindowlessNaClApplication{arguments, NoCreate} { |
||||
createContext(configuration); |
||||
} |
||||
|
||||
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, NoCreateT): Instance(arguments), Graphics3DClient(this), _glContext{NoCreate}, _debugOutput{new ConsoleDebugOutput{this}} {} |
||||
|
||||
void WindowlessNaClApplication::createContext() { createContext({}); } |
||||
|
||||
void WindowlessNaClApplication::createContext(const Configuration& configuration) { |
||||
if(!tryCreateContext(configuration)) std::exit(1); |
||||
} |
||||
|
||||
bool WindowlessNaClApplication::tryCreateContext(const Configuration& configuration) { |
||||
CORRADE_ASSERT(_context->version() == Version::None, "Platform::WindowlessNaClApplication::tryCreateContext(): context already created", false); |
||||
|
||||
WindowlessNaClContext glContext{*this, configuration, _context.get()}; |
||||
if(!glContext.isCreated() || !glContext.makeCurrent() || !_context->tryCreate()) |
||||
return false; |
||||
|
||||
_glContext = std::move(glContext); |
||||
return true; |
||||
} |
||||
|
||||
WindowlessNaClApplication::~WindowlessNaClApplication() = default; |
||||
|
||||
bool WindowlessNaClApplication::Init(uint32_t , const char* , const char*) { |
||||
return exec() == 0; |
||||
} |
||||
|
||||
void WindowlessNaClApplication::Graphics3DContextLost() { |
||||
CORRADE_ASSERT(false, "NaClApplication: context unexpectedly lost", ); |
||||
} |
||||
|
||||
}} |
||||
@ -1,356 +0,0 @@
|
||||
#ifndef Magnum_Platform_WindowlessNaClApplication_h |
||||
#define Magnum_Platform_WindowlessNaClApplication_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class @ref Magnum::Platform::WindowlessNaClApplication, @ref Magnum::Platform::WindowlessNaClContext, macro @ref MAGNUM_WINDOWLESSNACLAPPLICATION_MAIN() |
||||
*/ |
||||
|
||||
#include <memory> |
||||
#include <string> |
||||
#include <Corrade/Containers/EnumSet.h> |
||||
|
||||
/* Needs to be first */ |
||||
#include "Magnum/OpenGL.h" |
||||
|
||||
#include <ppapi/cpp/instance.h> |
||||
#include <ppapi/cpp/module.h> |
||||
#include <ppapi/cpp/graphics_3d_client.h> |
||||
#include <ppapi/gles2/gl2ext_ppapi.h> |
||||
|
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/Tags.h" |
||||
#include "Magnum/Platform/Platform.h" |
||||
|
||||
namespace pp { |
||||
class Graphics3D; |
||||
class Fullscreen; |
||||
} |
||||
|
||||
namespace Magnum { namespace Platform { |
||||
|
||||
/**
|
||||
@brief Windowless NaCl context |
||||
|
||||
GL context running in [Google Chrome Native Client](https://developers.google.com/native-client/),
|
||||
used in @ref WindowlessNaClApplication. Does not have any default framebuffer. |
||||
It is built if `WITH_WINDOWLESSNACLAPPLICATION` is enabled in CMake. |
||||
|
||||
Meant to be used when there is a need to manage (multiple) GL contexts |
||||
manually. See @ref platform-windowless-contexts for more information. If no |
||||
other application header is included, this class is also aliased to |
||||
`Platform::WindowlessGLContext`. |
||||
*/ |
||||
class WindowlessNaClContext { |
||||
public: |
||||
class Configuration; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param instance Pepper instance handle |
||||
* @param configuration Context configuration |
||||
* @param context Optional Magnum context instance constructed |
||||
* using @ref NoCreate to manage driver workarounds |
||||
* |
||||
* Once the context is created, make it current using @ref makeCurrent() |
||||
* and create @ref Platform::Context instance to be able to use Magnum. |
||||
* @see @ref isCreated() |
||||
*/ |
||||
explicit WindowlessNaClContext(pp::Instance& instance, const Configuration& configuration, Context* context = nullptr); |
||||
|
||||
/**
|
||||
* @brief Construct without creating the context |
||||
* |
||||
* Move a instance with created context over to make it usable. |
||||
*/ |
||||
explicit WindowlessNaClContext(NoCreateT) {} |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
WindowlessNaClContext(const WindowlessNaClContext&) = delete; |
||||
|
||||
/** @brief Move constructor */ |
||||
WindowlessNaClContext(WindowlessNaClContext&&); |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
WindowlessNaClContext& operator=(const WindowlessNaClContext&) = delete; |
||||
|
||||
/** @brief Move assignment */ |
||||
WindowlessNaClContext& operator=(WindowlessNaClContext&&); |
||||
|
||||
/**
|
||||
* @brief Destructor |
||||
* |
||||
* Destroys the context, if any. |
||||
*/ |
||||
~WindowlessNaClContext(); |
||||
|
||||
/** @brief Whether the context is created */ |
||||
bool isCreated() const { return _context; } |
||||
|
||||
/**
|
||||
* @brief Make the context current |
||||
* |
||||
* Prints error message and returns `false` on failure, otherwise |
||||
* returns `true`. |
||||
*/ |
||||
bool makeCurrent(); |
||||
|
||||
private: |
||||
std::unique_ptr<pp::Graphics3D> _context; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Configuration |
||||
|
||||
@see @ref WindowlessNaClContext(), |
||||
@ref WindowlessNaClApplication::WindowlessNaClApplication(), |
||||
@ref WindowlessNaClApplication::createContext(), |
||||
@ref WindowlessNaClApplication::tryCreateContext() |
||||
*/ |
||||
class WindowlessNaClContext::Configuration { |
||||
public: |
||||
constexpr /*implicit*/ Configuration() {} |
||||
}; |
||||
|
||||
/** @nosubgrouping
|
||||
@brief Windowless NaCl application |
||||
|
||||
Application for offscreen rendering using @ref WindowlessNaClContext. This |
||||
application library is available only in @ref CORRADE_TARGET_NACL "Native Client", |
||||
see respective sections in @ref building-corrade-cross-nacl "Corrade's" and |
||||
@ref building-cross-nacl "Magnum's" building documentation. It is built if |
||||
`WITH_WINDOWLESSNACLAPPLICATION` is enabled in CMake. |
||||
|
||||
## Bootstrap application |
||||
|
||||
The usage is very similar to @ref NaClApplication, for which fully contained |
||||
base application along with CMake setup is available, see its documentation for |
||||
more information. |
||||
|
||||
## General Usage |
||||
|
||||
In CMake you need to request `WindowlessNaClApplication` component, add |
||||
`${MAGNUM_WINDOWLESSNACLAPPLICATION_INCLUDE_DIRS}` to include path and link to |
||||
`${MAGNUM_WINDOWLESSNACLAPPLICATION_LIBRARIES}`. If no other windowless |
||||
application is requested, you can also use generic |
||||
`${MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS}` and |
||||
`${MAGNUM_WINDOWLESSAPPLICATION_LIBRARIES}` aliases to simplify porting. See |
||||
@ref building and @ref cmake for more information. |
||||
|
||||
Place your code into @ref exec(). The subclass must be then registered to NaCl |
||||
API using @ref MAGNUM_WINDOWLESSNACLAPPLICATION_MAIN() macro. See @ref platform |
||||
for more information. |
||||
@code |
||||
class MyApplication: public Platform::WindowlessNaClApplication { |
||||
// implement required methods...
|
||||
}; |
||||
MAGNUM_WINDOWLESSNACLAPPLICATION_MAIN(MyApplication) |
||||
@endcode |
||||
|
||||
If no other application header is included, this class is also aliased to |
||||
`Platform::WindowlessApplication` and the macro is aliased to |
||||
`MAGNUM_WINDOWLESSAPPLICATION_MAIN()` to simplify porting. |
||||
|
||||
### HTML markup and NMF file |
||||
|
||||
You need to provide HTML markup containing `<embed>` pointing to `*.nmf` |
||||
file describing the application. See @ref NaClApplication for more information. |
||||
You may want to hide the `<embed>` (for example using CSS |
||||
`visibility: hidden;`), as it probably won't display anything to default |
||||
framebuffer. |
||||
|
||||
## Redirecting output to Chrome's JavaScript console |
||||
|
||||
The application by default redirects @ref Corrade::Utility::Debug "Debug", |
||||
@ref Corrade::Utility::Warning "Warning" and @ref Corrade::Utility::Error "Error" |
||||
output to JavaScript console. See also @ref Corrade::Utility::NaClConsoleStreamBuffer |
||||
for more information. |
||||
*/ |
||||
class WindowlessNaClApplication: public pp::Instance, public pp::Graphics3DClient { |
||||
public: |
||||
/** @brief Application arguments */ |
||||
typedef PP_Instance Arguments; |
||||
|
||||
/**
|
||||
* @brief Configuration |
||||
* |
||||
* @see @ref WindowlessNaClApplication(), @ref createContext(), |
||||
* @ref tryCreateContext() |
||||
*/ |
||||
typedef WindowlessNaClContext::Configuration Configuration; |
||||
|
||||
/**
|
||||
* @brief Default constructor |
||||
* @param arguments Application arguments |
||||
* @param configuration Configuration |
||||
* |
||||
* Creates application with default or user-specified configuration. |
||||
* See @ref Configuration for more information. The program exits if |
||||
* the context cannot be created, see @ref tryCreateContext() for an |
||||
* alternative. |
||||
* @see @ref WindowlessNaClContext |
||||
*/ |
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
explicit WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration = Configuration()); |
||||
#else |
||||
/* To avoid "invalid use of incomplete type" */ |
||||
explicit WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration); |
||||
explicit WindowlessNaClApplication(const Arguments& arguments); |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param arguments Application arguments |
||||
* |
||||
* Unlike above, the context is not created and must be created later |
||||
* with @ref createContext() or @ref tryCreateContext(). |
||||
*/ |
||||
explicit WindowlessNaClApplication(const Arguments& arguments, NoCreateT); |
||||
|
||||
#ifdef MAGNUM_BUILD_DEPRECATED |
||||
/**
|
||||
* @copybrief WindowlessNaClApplication(const Arguments&, NoCreateT) |
||||
* @deprecated Use @ref WindowlessNaClApplication(const Arguments&, NoCreateT) instead. |
||||
*/ |
||||
CORRADE_DEPRECATED("use WindowlessNaClApplication(const Arguments&, NoCreateT) instead") explicit WindowlessNaClApplication(const Arguments& arguments, std::nullptr_t): WindowlessNaClApplication{arguments, NoCreate} {} |
||||
#endif |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
WindowlessNaClApplication(const WindowlessNaClApplication&) = delete; |
||||
|
||||
/** @brief Moving is not allowed */ |
||||
WindowlessNaClApplication(WindowlessNaClApplication&&) = delete; |
||||
|
||||
/** @brief Copying is not allowed */ |
||||
WindowlessNaClApplication& operator=(const WindowlessNaClApplication&) = delete; |
||||
|
||||
/** @brief Moving is not allowed */ |
||||
WindowlessNaClApplication& operator=(WindowlessNaClApplication&&) = delete; |
||||
|
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
protected: |
||||
#else |
||||
private: |
||||
#endif |
||||
/**
|
||||
* @brief Execute application |
||||
* @return Value for returning from `main()` |
||||
* |
||||
* This function is not meant to be called from user code, see |
||||
* @ref MAGNUM_WINDOWLESSNACLAPPLICATION_MAIN() for usage information. |
||||
*/ |
||||
virtual int exec() = 0; |
||||
|
||||
protected: |
||||
/* Nobody will need to have (and delete) WindowlessNaClApplication*,
|
||||
thus this is faster than public pure virtual destructor */ |
||||
~WindowlessNaClApplication(); |
||||
|
||||
/**
|
||||
* @brief Create context with given configuration |
||||
* |
||||
* Must be called if and only if the context wasn't created by the |
||||
* constructor itself. Error message is printed and the program exits |
||||
* if the context cannot be created, see @ref tryCreateContext() for an |
||||
* alternative. |
||||
* @see @ref WindowlessNaClContext |
||||
*/ |
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
void createContext(const Configuration& configuration = Configuration()); |
||||
#else |
||||
/* To avoid "invalid use of incomplete type" */ |
||||
void createContext(const Configuration& configuration); |
||||
void createContext(); |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Try to create context with given configuration |
||||
* |
||||
* Unlike @ref createContext() returns `false` if the context cannot be |
||||
* created, `true` otherwise. |
||||
*/ |
||||
bool tryCreateContext(const Configuration& configuration); |
||||
|
||||
private: |
||||
struct ConsoleDebugOutput; |
||||
|
||||
void Graphics3DContextLost() override; |
||||
|
||||
bool Init(std::uint32_t, const char*, const char*) override; |
||||
|
||||
WindowlessNaClContext _glContext; |
||||
std::unique_ptr<Platform::Context> _context; |
||||
std::unique_ptr<ConsoleDebugOutput> _debugOutput; |
||||
}; |
||||
|
||||
namespace Implementation { |
||||
template<class Application> class WindowlessNaClModule: public pp::Module { |
||||
public: |
||||
~WindowlessNaClModule() { glTerminatePPAPI(); } |
||||
|
||||
bool Init() override { |
||||
return glInitializePPAPI(get_browser_interface()); |
||||
} |
||||
|
||||
pp::Instance* CreateInstance(PP_Instance instance) { |
||||
return new Application(instance); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
/** @hideinitializer
|
||||
@brief Entry point for windowless NaCl application |
||||
@param className Class name |
||||
|
||||
See @ref Magnum::Platform::WindowlessNaClApplication "Platform::WindowlessNaClApplication" |
||||
for usage information. This macro abstracts out platform-specific entry point |
||||
code (the classic `main()` function cannot be used in NaCl). See |
||||
@ref portability-applications for more information. When no other windowless |
||||
application header is included this macro is also aliased to |
||||
`MAGNUM_WINDOWLESSAPPLICATION_MAIN()`. |
||||
*/ |
||||
/* look at that insane placement of __attribute__. WTF. */ |
||||
#define MAGNUM_WINDOWLESSNACLAPPLICATION_MAIN(className) \ |
||||
namespace pp { \
|
||||
Module __attribute__ ((visibility ("default"))) * CreateModule(); \
|
||||
Module __attribute__ ((visibility ("default"))) * CreateModule() { \
|
||||
return new Magnum::Platform::Implementation::WindowlessNaClModule<className>(); \
|
||||
} \
|
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
#ifndef MAGNUM_WINDOWLESSAPPLICATION_MAIN |
||||
typedef WindowlessNaClApplication WindowlessApplication; |
||||
typedef WindowlessNaClContext WindowlessGLContext; |
||||
#define MAGNUM_WINDOWLESSAPPLICATION_MAIN(className) MAGNUM_WINDOWLESSNACLAPPLICATION_MAIN(className) |
||||
#else |
||||
#undef MAGNUM_WINDOWLESSAPPLICATION_MAIN |
||||
#endif |
||||
#endif |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -1,41 +0,0 @@
|
||||
<!DOCTYPE html> |
||||
<html xmlns="http://www.w3.org/1999/xhtml"> |
||||
<head> |
||||
<title>Magnum Info</title> |
||||
<meta charset="utf-8" /> |
||||
<link rel="stylesheet" href="WebApplication.css" /> |
||||
<style type="text/css"> |
||||
#module { |
||||
position: absolute; |
||||
visibility: hidden; /* The module doesn't display anything */ |
||||
} |
||||
|
||||
#info { |
||||
width: 640px; |
||||
height: 480px; |
||||
overflow: auto; |
||||
font-family: monospace; |
||||
white-space: pre-wrap; |
||||
} |
||||
</style> |
||||
</head> |
||||
<body> |
||||
<h1>Magnum Info</h1> |
||||
<div id="listener"> |
||||
<embed id="module" type="application/x-nacl" src="magnum-info.nmf"></embed> |
||||
<div id="status">Initialization...</div> |
||||
<div id="statusDescription"></div> |
||||
<div id="info"></div> |
||||
<script src="NaClApplication.js"></script> |
||||
<script type="text/javascript"> |
||||
function messageReceived(message) { |
||||
var info = document.getElementById('info'); |
||||
info.innerHTML += message.data; |
||||
} |
||||
|
||||
var listener = document.getElementById('listener'); |
||||
listener.addEventListener('message', messageReceived, true); |
||||
</script> |
||||
</div> |
||||
</body> |
||||
</html> |
||||
@ -1,6 +0,0 @@
|
||||
{ |
||||
"program": { |
||||
"x86-32": {"url": "magnum-info-x86-32.nexe"}, |
||||
"x86-64": {"url": "magnum-info-x86-64.nexe"} |
||||
} |
||||
} |
||||
@ -1,60 +0,0 @@
|
||||
@require(passthru, functions, enums, options, version, extensions) |
||||
#ifndef _flextgl_h_ |
||||
#define _flextgl_h_ |
||||
|
||||
/* Defensive include guards */ |
||||
|
||||
#if defined(__gl2_h_) |
||||
#error Attempt to include auto-generated header after including gl2.h |
||||
#endif |
||||
#if defined(__gl2platform_h_) |
||||
#error Attempt to include auto-generated header after including gl2platform.h |
||||
#endif |
||||
|
||||
#define __gl2_h_ |
||||
#define __gl2platform_h_ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
void flextGLInit(); |
||||
|
||||
/* Function declaration macros */ |
||||
#define FLEXTGL_EXPORT __attribute__ ((visibility ("default"))) |
||||
|
||||
#define APIENTRY |
||||
#ifndef GL_APICALL |
||||
#define GL_APICALL KHRONOS_APICALL |
||||
#endif |
||||
#ifndef GL_APIENTRY |
||||
#define GL_APIENTRY KHRONOS_APIENTRY |
||||
#endif |
||||
|
||||
/* Data types */ |
||||
|
||||
@passthru |
||||
|
||||
/* Enums */ |
||||
|
||||
@enums |
||||
|
||||
/* Function prototypes */ |
||||
@for cat,funcs in functions: |
||||
|
||||
/* GL_@cat */ |
||||
#ifndef GL_@cat |
||||
#define GL_@cat 1 |
||||
@for f in funcs: |
||||
GL_APICALL @f.returntype GL_APIENTRY GLES2@f.name\ |
||||
(@f.param_type_list_string()); |
||||
#define gl@f.name GLES2@f.name |
||||
@end |
||||
#endif |
||||
@end |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif |
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue