From 00577010e29cb88798f9a9f940019c0011709e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:29:17 +0200 Subject: [PATCH 1/9] Find Corrade _before_ checking for its configuration. --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a270208f..7778ddd04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,9 @@ cmake_minimum_required(VERSION 2.8.8) project(Magnum) +# Find Corrade first so we can check on the target +find_package(Corrade REQUIRED) + include(CMakeDependentOption) option(TARGET_GLES "Build for OpenGL ES instead of desktop OpenGL" OFF) @@ -63,8 +66,6 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules/") -find_package(Corrade REQUIRED) - # If targeting NaCl or Emscripten, set explicit OpenGL ES 2.0 support if(CORRADE_TARGET_NACL OR CORRADE_TARGET_EMSCRIPTEN) set(TARGET_GLES 1) From 7b68dc2e0ae3ed1531f2605b5fce871c7c1d6c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:37:47 +0200 Subject: [PATCH 2/9] Platform: added WindowlessNaClApplication. Stripped-down version of NaClApplication with unusable default framebuffer and no event handling, primarily for various testing usage. --- CMakeLists.txt | 1 + PKGBUILD-nacl-newlib | 2 + modules/FindMagnum.cmake | 4 +- src/Platform/CMakeLists.txt | 12 ++ src/Platform/WindowlessNaClApplication.cpp | 109 +++++++++++ src/Platform/WindowlessNaClApplication.h | 200 +++++++++++++++++++++ 6 files changed, 326 insertions(+), 2 deletions(-) create mode 100644 src/Platform/WindowlessNaClApplication.cpp create mode 100644 src/Platform/WindowlessNaClApplication.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7778ddd04..883aef87f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ option(WITH_MAGNUMINFO "Build magnum-info utility" OFF) # Application libraries if(CORRADE_TARGET_NACL) option(WITH_NACLAPPLICATION "Build NaClApplication library" OFF) + cmake_dependent_option(WITH_WINDOWLESSNACLAPPLICATION "Build WindowlessNaClApplication library" OFF "NOT WITH_MAGNUMINFO" ON) else() option(WITH_GLXAPPLICATION "Build GlxApplication library" OFF) cmake_dependent_option(WITH_WINDOWLESSGLXAPPLICATION "Build WindowlessGlxApplication library" OFF "NOT WITH_MAGNUMINFO" ON) diff --git a/PKGBUILD-nacl-newlib b/PKGBUILD-nacl-newlib index 19d95f7c9..2bf84ac4e 100644 --- a/PKGBUILD-nacl-newlib +++ b/PKGBUILD-nacl-newlib @@ -22,6 +22,7 @@ build() { -DCMAKE_INSTALL_PREFIX=/usr/nacl \ -DWITH_MAGNUMINFO=OFF \ -DWITH_NACLAPPLICATION=ON \ + -DWITH_WINDOWLESSNACLAPPLICATION=ON \ -DBUILD_STATIC=ON \ -DLIB_SUFFIX=/32 make @@ -37,6 +38,7 @@ build() { -DCMAKE_INSTALL_PREFIX=/usr/nacl \ -DWITH_MAGNUMINFO=OFF \ -DWITH_NACLAPPLICATION=ON \ + -DWITH_WINDOWLESSNACLAPPLICATION=ON \ -DBUILD_STATIC=ON make } diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 7c871037a..768449907 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -185,8 +185,8 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() endif() - # NaCl application dependencies - if(${component} STREQUAL NaClApplication) + # (Windowless) NaCl application dependencies + if(${component} STREQUAL NaClApplication OR ${component} STREQUAL WindowlessNaClApplication) set(_MAGNUM_${_COMPONENT}_LIBRARIES ppapi_cpp ppapi ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) endif() diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 6f7b75b18..4de76dcf2 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -72,6 +72,18 @@ if(WITH_NACLAPPLICATION) install(TARGETS MagnumNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() +# Windowless NaCl application +if(WITH_WINDOWLESSNACLAPPLICATION) + if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL NaCl) + message(FATAL_ERROR "WindowlessNaClApplication is available only when targeting Google Chrome Native Client. Set WITH_WINDOWLESSNACLAPPLICATION to OFF to skip building it.") + endif() + + add_library(MagnumWindowlessNaClApplication STATIC + WindowlessNaClApplication.cpp) + install(FILES WindowlessNaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(TARGETS MagnumWindowlessNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) +endif() + # GLX application if(WITH_GLXAPPLICATION) set(NEED_ABSTRACTXAPPLICATION 1) diff --git a/src/Platform/WindowlessNaClApplication.cpp b/src/Platform/WindowlessNaClApplication.cpp new file mode 100644 index 000000000..84c695b55 --- /dev/null +++ b/src/Platform/WindowlessNaClApplication.cpp @@ -0,0 +1,109 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + 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 +#include +#include + +#include "Context.h" + +namespace Magnum { namespace Platform { + +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::NaClApplication: redirecting Debug, Warning and Error output to JavaScript console"; + + Debug::setOutput(&debugOutput); + Warning::setOutput(&warningOutput); + Error::setOutput(&errorOutput); +} + +WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), c(nullptr) { + debugOutput = new ConsoleDebugOutput(this); + createContext(new Configuration); +} + +WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, Configuration* configuration): Instance(arguments), Graphics3DClient(this), graphics(nullptr), c(nullptr) { + debugOutput = new ConsoleDebugOutput(this); + if(configuration) createContext(configuration); +} + +void WindowlessNaClApplication::createContext(Configuration* configuration) { + if(!tryCreateContext(configuration)) { + Error() << "Platform::WindowlessNaClApplication::createContext(): cannot create context"; + delete configuration; + std::exit(1); + + } else delete configuration; +} + +bool WindowlessNaClApplication::tryCreateContext(Configuration* configuration) { + CORRADE_ASSERT(!c, "Platform::WindowlessNaClApplication::tryCreateContext(): context already created", false); + + 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 + }; + + graphics = new pp::Graphics3D(this, attributes); + if(graphics->is_null()) { + delete graphics; + graphics = nullptr; + return false; + } + if(!BindGraphics(*graphics)) { + Error() << "Platform::WindowlessNaClApplication::tryCreateContext(): cannot bind graphics"; + std::exit(1); + } + + glSetCurrentContextPPAPI(graphics->pp_resource()); + + c = new Context; + return true; +} + +WindowlessNaClApplication::~WindowlessNaClApplication() { + delete c; + delete graphics; + delete debugOutput; +} + +bool WindowlessNaClApplication::Init(uint32_t , const char* , const char*) { + return exec() == 0; +} + +}} diff --git a/src/Platform/WindowlessNaClApplication.h b/src/Platform/WindowlessNaClApplication.h new file mode 100644 index 000000000..89685a3dc --- /dev/null +++ b/src/Platform/WindowlessNaClApplication.h @@ -0,0 +1,200 @@ +#ifndef Magnum_Platform_WindowlessNaClApplication_h +#define Magnum_Platform_WindowlessNaClApplication_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + 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 Magnum::Platform::WindowlessNaClApplication + */ + +#include +#include +#include +#include +#include +#include + +#include "Math/Vector2.h" +#include "Magnum.h" + +#include "corradeCompatibility.h" + +namespace pp { + class Graphics3D; + class Fullscreen; +} + +namespace Magnum { namespace Platform { + +/** @nosubgrouping +@brief Windowless NaCl application + +Application running in [Google Chrome Native Client](https://developers.google.com/native-client/). +See @ref platform for brief introduction. + +@section WindowlessNaClApplication-usage Usage + +Place your code into exec(). The subclass must be then registered to NaCl API +using MAGNUM_WINDOWLESSNACLAPPLICATION_MAIN() macro. +@code +class MyApplication: public Magnum::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. + +@section WindowlessNaClApplication-html HTML markup and NMF file + +You need to provide HTML markup containing `<embed>` pointing to `*.nmf` +file describing the application. + +@todoc Document this better, add "bootstrap" examples + +@subsection WindowlessNaClApplication-html-console Redirecting output to Chrome's JavaScript console + +The application redirects @ref Debug, @ref Warning and @ref 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; + + class Configuration; + + /** + * @brief Default constructor + * @param arguments Application arguments + * + * Creates application with default configuration. See Configuration + * for more information. + */ + explicit WindowlessNaClApplication(const Arguments& arguments); + + /** + * @brief Constructor + * @param arguments Application arguments + * @param configuration Configuration + * + * The @p configuration is deleted afterwards. If `nullptr` is passed + * as @p configuration, the context is not created and must be created + * with createContext(). + */ + explicit WindowlessNaClApplication(const Arguments& arguments, Configuration* configuration); + + /** + * @brief Execute application + * @return Value for returning from `main()`. + */ + virtual int exec() = 0; + + protected: + /* Nobody will need to have (and delete) WindowlessNaClApplication*, + thus this is faster than public pure virtual destructor */ + ~WindowlessNaClApplication(); + + /** @copydoc GlutApplication::createContext() */ + void createContext(Configuration* configuration); + + /** @copydoc GlutApplication::tryCreateContext() */ + bool tryCreateContext(Configuration* configuration); + + private: + struct ConsoleDebugOutput; + + void Graphics3DContextLost() override { + CORRADE_ASSERT(false, "NaClApplication: context unexpectedly lost", ); + } + + bool Init(std::uint32_t, const char*, const char*) override; + + pp::Graphics3D* graphics; + Context* c; + ConsoleDebugOutput* debugOutput; +}; + +/** +@brief %Configuration + +@see WindowlessNaClApplication(), createContext(), tryCreateContext() +*/ +class WindowlessNaClApplication::Configuration { + Configuration(const Configuration&) = delete; + Configuration(Configuration&&) = delete; + Configuration& operator=(const Configuration&) = delete; + Configuration& operator=(Configuration&&) = delete; + + public: + constexpr explicit Configuration() {} +}; + +namespace Implementation { + template 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 application Application class name + +See WindowlessNaClApplication and @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(application) \ + namespace pp { \ + Module __attribute__ ((visibility ("default"))) * CreateModule(); \ + Module __attribute__ ((visibility ("default"))) * CreateModule() { \ + return new Magnum::Platform::Implementation::WindowlessNaClModule(); \ + } \ + } + +#ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef MAGNUM_WINDOWLESSAPPLICATION_MAIN +typedef WindowlessNaClApplication WindowlessApplication; +#define MAGNUM_WINDOWLESSAPPLICATION_MAIN(className) MAGNUM_WINDOWLESSNACLAPPLICATION_MAIN(className) +#else +#undef MAGNUM_WINDOWLESSAPPLICATION_MAIN +#endif +#endif + +}} + +#endif From 7756a0e2580ab622fde301cb5c6463fafaf497b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:38:58 +0200 Subject: [PATCH 3/9] Platform: Doxygen fixes. --- src/Platform/NaClApplication.h | 7 ++++--- src/Platform/WindowlessNaClApplication.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index ed33f57b2..e1a04d654 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -80,9 +80,10 @@ file describing the application. @subsection NaClApplication-html-console Redirecting output to Chrome's JavaScript console -The application redirects @ref Debug, @ref Warning and @ref Error output to -JavaScript console. See also @ref Corrade::Utility::NaClConsoleStreamBuffer for -more information. +The application 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: diff --git a/src/Platform/WindowlessNaClApplication.h b/src/Platform/WindowlessNaClApplication.h index 89685a3dc..d0f4ebb19 100644 --- a/src/Platform/WindowlessNaClApplication.h +++ b/src/Platform/WindowlessNaClApplication.h @@ -77,9 +77,10 @@ file describing the application. @subsection WindowlessNaClApplication-html-console Redirecting output to Chrome's JavaScript console -The application redirects @ref Debug, @ref Warning and @ref Error output to -JavaScript console. See also @ref Corrade::Utility::NaClConsoleStreamBuffer for -more information. +The application 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: From 4ffc84699b6966d3d1428341071dacf927af4414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:39:23 +0200 Subject: [PATCH 4/9] Platform: portable WindowlessApplication usage in `magnum-info`. --- src/Platform/magnum-info.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index ebf533357..169352ac4 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -30,14 +30,14 @@ namespace Magnum { -class MagnumInfo: public Platform::WindowlessGlxApplication { +class MagnumInfo: public Platform::WindowlessApplication { public: explicit MagnumInfo(const Arguments& arguments); int exec() override { return 0; } }; -MagnumInfo::MagnumInfo(const Arguments& arguments): WindowlessGlxApplication(arguments) { +MagnumInfo::MagnumInfo(const Arguments& arguments): Platform::WindowlessApplication(arguments) { Context* c = Context::current(); Debug() << ""; @@ -136,4 +136,4 @@ MagnumInfo::MagnumInfo(const Arguments& arguments): WindowlessGlxApplication(arg } -MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(Magnum::MagnumInfo) +MAGNUM_WINDOWLESSAPPLICATION_MAIN(Magnum::MagnumInfo) From 47bbc403ae989995421c36501e63d8cfaef49b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:39:43 +0200 Subject: [PATCH 5/9] FindMagnum.cmake: removed duplicate code. --- modules/FindMagnum.cmake | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 768449907..9b72c8fec 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -191,7 +191,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() # GLX application dependencies - if(${component} STREQUAL GlxApplication) + if(${component} STREQUAL GlxApplication OR ${component} STREQUAL WindowlessGlxApplication) find_package(X11) if(X11_FOUND) set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) @@ -210,16 +210,6 @@ foreach(component ${Magnum_FIND_COMPONENTS}) unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() endif() - - # Windowless GLX application dependencies - if(${component} STREQUAL WindowlessGlxApplication) - find_package(X11) - if(X11_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) - else() - unset(MAGNUM_${_COMPONENT}_LIBRARY) - endif() - endif() endif() # DebugTools library From a08978e7cb3ccd037bdcdcd859a4fd3b9cd6976e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:41:09 +0200 Subject: [PATCH 6/9] Platform: ported magnum-info to NaCl. The binary installs into `bin/`, the HTML and NMF into `share/`, the user is currently expected to copy them manually to server. --- CMakeLists.txt | 1 + PKGBUILD-nacl-newlib | 4 +- src/Platform/CMakeLists.txt | 19 +++++-- src/Platform/magnum-info-nacl.html | 91 ++++++++++++++++++++++++++++++ src/Platform/magnum-info-nacl.nmf | 6 ++ src/Platform/magnum-info.cpp | 14 +++++ 6 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 src/Platform/magnum-info-nacl.html create mode 100644 src/Platform/magnum-info-nacl.nmf diff --git a/CMakeLists.txt b/CMakeLists.txt index 883aef87f..36cf5ac91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,7 @@ endif() include(CorradeLibSuffix) set(MAGNUM_BINARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin) set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) +set(MAGNUM_DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/magnum) set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules) set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum) diff --git a/PKGBUILD-nacl-newlib b/PKGBUILD-nacl-newlib index 2bf84ac4e..e1b276339 100644 --- a/PKGBUILD-nacl-newlib +++ b/PKGBUILD-nacl-newlib @@ -20,7 +20,7 @@ build() { -DCMAKE_TOOLCHAIN_FILE="$startdir/toolchains/generic/NaCl-newlib-x86-32.cmake" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/nacl \ - -DWITH_MAGNUMINFO=OFF \ + -DWITH_MAGNUMINFO=ON \ -DWITH_NACLAPPLICATION=ON \ -DWITH_WINDOWLESSNACLAPPLICATION=ON \ -DBUILD_STATIC=ON \ @@ -36,7 +36,7 @@ build() { -DCMAKE_TOOLCHAIN_FILE="$startdir/toolchains/generic/NaCl-newlib-x86-64.cmake" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/nacl \ - -DWITH_MAGNUMINFO=OFF \ + -DWITH_MAGNUMINFO=ON \ -DWITH_NACLAPPLICATION=ON \ -DWITH_WINDOWLESSNACLAPPLICATION=ON \ -DBUILD_STATIC=ON diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 4de76dcf2..634197a4a 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -156,11 +156,20 @@ endif() # Magnum Info if(WITH_MAGNUMINFO) - if(UNIX) - add_executable(magnum-info magnum-info.cpp) + if(NOT UNIX AND NOT CORRADE_TARGET_NACL) + message(FATAL_ERROR "magnum-info is not available on this platform. Set WITH_MAGNUMINFO to OFF to suppress this warning.") + endif() + + add_executable(magnum-info magnum-info.cpp) + if(UNIX AND NOT CORRADE_TARGET_NACL) target_link_libraries(magnum-info Magnum MagnumWindowlessGlxApplication ${X11_LIBRARIES}) - install(TARGETS magnum-info DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) - else() - message(WARNING "magnum-info is currently available only on Unix. Set WITH_MAGNUMINFO to OFF to suppress this warning.") + elseif(CORRADE_TARGET_NACL) + target_link_libraries(magnum-info Magnum MagnumWindowlessNaClApplication ppapi_cpp ppapi) + endif() + + install(TARGETS magnum-info DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) + if(CORRADE_TARGET_NACL) + install(FILES magnum-info-nacl.html DESTINATION ${MAGNUM_DATA_INSTALL_DIR} RENAME magnum-info.html) + install(FILES magnum-info-nacl.nmf DESTINATION ${MAGNUM_DATA_INSTALL_DIR} RENAME magnum-info.nmf) endif() endif() diff --git a/src/Platform/magnum-info-nacl.html b/src/Platform/magnum-info-nacl.html new file mode 100644 index 000000000..f12bcf996 --- /dev/null +++ b/src/Platform/magnum-info-nacl.html @@ -0,0 +1,91 @@ + + + +Magnum Info + + + +

Magnum Info

+
+ + +
Initialization...
+
+
+ + diff --git a/src/Platform/magnum-info-nacl.nmf b/src/Platform/magnum-info-nacl.nmf new file mode 100644 index 000000000..c9de3d8c9 --- /dev/null +++ b/src/Platform/magnum-info-nacl.nmf @@ -0,0 +1,6 @@ +{ + "program": { + "x86-32": {"url": "magnum-info-x86-32.nexe"}, + "x86-64": {"url": "magnum-info-x86-64.nexe"} + } +} diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index 169352ac4..5879421b8 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -24,9 +24,16 @@ #include #include +#ifdef CORRADE_TARGET_NACL +#include +#endif #include "Context.h" +#ifndef CORRADE_TARGET_NACL #include "Platform/WindowlessGlxApplication.h" +#else +#include "Platform/WindowlessNaClApplication.h" +#endif namespace Magnum { @@ -40,6 +47,13 @@ class MagnumInfo: public Platform::WindowlessApplication { MagnumInfo::MagnumInfo(const Arguments& arguments): Platform::WindowlessApplication(arguments) { Context* c = Context::current(); + /* Pass debug output as messages to JavaScript */ + #ifdef CORRADE_TARGET_NACL + Utility::NaClMessageStreamBuffer buffer(this); + std::ostream out(&buffer); + Debug::setOutput(&out); + #endif + Debug() << ""; Debug() << " +---------------------------------------------------------+"; Debug() << " | Information about Magnum engine and OpenGL capabilities |"; From 184617c4bd5acce17ae72a77c0a122746893b54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:42:27 +0200 Subject: [PATCH 7/9] Strip binaries in NaCl's PKGBUILD. Saves 10 MB. --- PKGBUILD-nacl-newlib | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/PKGBUILD-nacl-newlib b/PKGBUILD-nacl-newlib index e1b276339..524572544 100644 --- a/PKGBUILD-nacl-newlib +++ b/PKGBUILD-nacl-newlib @@ -48,8 +48,16 @@ package() { cd "$startdir/build-nacl-newlib-x86-32" make DESTDIR="$pkgdir/" install + # Strip 32bit binaries + /usr/nacl/toolchain/linux_x86_newlib/bin/i686-nacl-strip ${pkgdir}/usr/nacl/lib/32/*.a + /usr/nacl/toolchain/linux_x86_newlib/bin/i686-nacl-strip ${pkgdir}/usr/nacl/bin/*x86-32.nexe + # Install 64bit (the headers will be overwritten, but they are (and should # be) the same for both versions cd "$startdir/build-nacl-newlib-x86-64" make DESTDIR="$pkgdir/" install + + # Strip 64bit binaries + /usr/nacl/toolchain/linux_x86_newlib/bin/x86_64-nacl-strip ${pkgdir}/usr/nacl/lib/*.a + /usr/nacl/toolchain/linux_x86_newlib/bin/x86_64-nacl-strip ${pkgdir}/usr/nacl/bin/*x86-64.nexe } From b62db63c579c47260244a3d44b18a682ef2867af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:43:43 +0200 Subject: [PATCH 8/9] Platform: added CORRADE_GCC47_COMPATIBILITY to `magnum-info`. --- src/Platform/magnum-info.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index 5879421b8..c9947a167 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -67,6 +67,9 @@ MagnumInfo::MagnumInfo(const Arguments& arguments): Platform::WindowlessApplicat #ifdef CORRADE_GCC46_COMPATIBILITY d << "CORRADE_GCC46_COMPATIBILITY"; #endif + #ifdef CORRADE_GCC47_COMPATIBILITY + d << "CORRADE_GCC47_COMPATIBILITY"; + #endif #ifdef CORRADE_BUILD_STATIC d << "CORRADE_BUILD_STATIC"; #endif From ea7bf5038df3f312c142d7a53b9b56bc42a9d4bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Jun 2013 17:46:22 +0200 Subject: [PATCH 9/9] Platform: print each flag on separate line in `magnum-info`. It's more readable. --- src/Platform/magnum-info.cpp | 66 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index c9947a167..212f5c2cc 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -61,40 +61,38 @@ MagnumInfo::MagnumInfo(const Arguments& arguments): Platform::WindowlessApplicat Debug() << ""; Debug() << "Used application: Platform::WindowlessGlxApplication"; - { - Debug d; - d << "Compilation flags:"; - #ifdef CORRADE_GCC46_COMPATIBILITY - d << "CORRADE_GCC46_COMPATIBILITY"; - #endif - #ifdef CORRADE_GCC47_COMPATIBILITY - d << "CORRADE_GCC47_COMPATIBILITY"; - #endif - #ifdef CORRADE_BUILD_STATIC - d << "CORRADE_BUILD_STATIC"; - #endif - #ifdef MAGNUM_BUILD_STATIC - d << "MAGNUM_BUILD_STATIC"; - #endif - #ifdef CORRADE_TARGET_NACL - d << "CORRADE_TARGET_NACL"; - #endif - #ifdef CORRADE_TARGET_NACL_NEWLIB - d << "CORRADE_TARGET_NACL_NEWLIB"; - #endif - #ifdef CORRADE_TARGET_NACL_GLIBC - d << "CORRADE_TARGET_NACL_GLIBC"; - #endif - #ifdef MAGNUM_TARGET_GLES - d << "MAGNUM_TARGET_GLES"; - #endif - #ifdef MAGNUM_TARGET_GLES2 - d << "MAGNUM_TARGET_GLES2"; - #endif - #ifdef MAGNUM_TARGET_DESKTOP_GLES - d << "MAGNUM_TARGET_DESKTOP_GLES"; - #endif - } + + Debug() << "Compilation flags:"; + #ifdef CORRADE_GCC46_COMPATIBILITY + Debug() << " CORRADE_GCC46_COMPATIBILITY"; + #endif + #ifdef CORRADE_GCC47_COMPATIBILITY + Debug() << " CORRADE_GCC47_COMPATIBILITY"; + #endif + #ifdef CORRADE_BUILD_STATIC + Debug() << " CORRADE_BUILD_STATIC"; + #endif + #ifdef MAGNUM_BUILD_STATIC + Debug() << " MAGNUM_BUILD_STATIC"; + #endif + #ifdef CORRADE_TARGET_NACL + Debug() << " CORRADE_TARGET_NACL"; + #endif + #ifdef CORRADE_TARGET_NACL_NEWLIB + Debug() << " CORRADE_TARGET_NACL_NEWLIB"; + #endif + #ifdef CORRADE_TARGET_NACL_GLIBC + Debug() << " CORRADE_TARGET_NACL_GLIBC"; + #endif + #ifdef MAGNUM_TARGET_GLES + Debug() << " MAGNUM_TARGET_GLES"; + #endif + #ifdef MAGNUM_TARGET_GLES2 + Debug() << " MAGNUM_TARGET_GLES2"; + #endif + #ifdef MAGNUM_TARGET_DESKTOP_GLES + Debug() << " MAGNUM_TARGET_DESKTOP_GLES"; + #endif Debug() << ""; Debug() << "Vendor:" << c->vendorString();