diff --git a/CMakeLists.txt b/CMakeLists.txt index d7bdda4fc..6cb1ba73e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,9 +183,7 @@ if(BUILD_TESTS) endif() # OpenGLTester library, built by default only if GL tests are enabled -if(NOT CORRADE_TARGET_EMSCRIPTEN) - cmake_dependent_option(WITH_OPENGLTESTER "Build OpenGLTester library" OFF "NOT BUILD_GL_TESTS" ON) -endif() +cmake_dependent_option(WITH_OPENGLTESTER "Build OpenGLTester library" OFF "NOT BUILD_GL_TESTS" ON) # Dynamic linking is meaningless on Emscripten and too inconvenient on Android if(CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID) @@ -231,7 +229,7 @@ if(CORRADE_TARGET_EMSCRIPTEN) endif() if(WITH_OPENGLTESTER) - if(MAGNUM_TARGET_HEADLESS OR CORRADE_TARGET_ANDROID) + if(MAGNUM_TARGET_HEADLESS OR CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID) set(WITH_WINDOWLESSEGLAPPLICATION ON) set(OPENGLTESTER_APPLICATION MagnumWindowlessEglApplication) elseif(CORRADE_TARGET_IOS) diff --git a/doc/changelog.dox b/doc/changelog.dox index e08a64307..30c37c3c7 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -58,6 +58,7 @@ See also: their WebGL counterparts @webgl_extension{EXT,color_buffer_half_float}, @webgl_extension{WEBGL,color_buffer_float}, @webgl_extension{EXT,color_buffer_float} +- Ported @ref OpenGLTester to WebGL @subsubsection changelog-latest-new-platform Platform libraries diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 97cc64921..632b3a82a 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -337,7 +337,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) elseif(_component STREQUAL DebugTools) set(_MAGNUM_${_COMPONENT}_DEPENDENCIES MeshTools Primitives SceneGraph Shaders Shapes) elseif(_component STREQUAL OpenGLTester) - if(MAGNUM_TARGET_HEADLESS) + if(MAGNUM_TARGET_HEADLESS OR CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID) set(_MAGNUM_${_COMPONENT}_DEPENDENCIES WindowlessEglApplication) elseif(CORRADE_TARGET_IOS) set(_MAGNUM_${_COMPONENT}_DEPENDENCIES WindowlessIosApplication) diff --git a/src/Magnum/OpenGLTester.cpp b/src/Magnum/OpenGLTester.cpp index 7dc5ccb27..896dfbb69 100644 --- a/src/Magnum/OpenGLTester.cpp +++ b/src/Magnum/OpenGLTester.cpp @@ -27,20 +27,23 @@ #include "Magnum/Context.h" #include "Magnum/Extensions.h" +#ifndef MAGNUM_TARGET_WEBGL #include "Magnum/DebugOutput.h" +#endif namespace Magnum { OpenGLTester::OpenGLTester(): TestSuite::Tester{TestSuite::Tester::TesterConfiguration{}.setSkippedArgumentPrefixes({"magnum"})}, _windowlessApplication{{arguments().first, arguments().second}} { /* Try to create debug context, fallback to normal one if not possible. No - such thing on macOS or iOS. */ - #ifndef CORRADE_TARGET_APPLE + such thing on macOS, iOS or WebGL. */ + #if !defined(CORRADE_TARGET_APPLE) && !defined(MAGNUM_TARGET_WEBGL) if(!_windowlessApplication.tryCreateContext(Platform::WindowlessApplication::Configuration{}.setFlags(Platform::WindowlessApplication::Configuration::Flag::Debug))) _windowlessApplication.createContext(); #else _windowlessApplication.createContext(); #endif + #ifndef MAGNUM_TARGET_WEBGL if(Context::current().isExtensionSupported()) { Renderer::enable(Renderer::Feature::DebugOutput); Renderer::enable(Renderer::Feature::DebugOutputSynchronous); @@ -49,10 +52,12 @@ OpenGLTester::OpenGLTester(): TestSuite::Tester{TestSuite::Tester::TesterConfigu /* Disable "Buffer detailed info" message on NV (too spammy) */ DebugOutput::setEnabled(DebugOutput::Source::Api, DebugOutput::Type::Other, {131185}, false); } + #endif } OpenGLTester::~OpenGLTester() = default; +#ifndef MAGNUM_TARGET_WEBGL void OpenGLTester::gpuTimeBenchmarkBegin() { setBenchmarkName("GPU time"); @@ -66,5 +71,6 @@ std::uint64_t OpenGLTester::gpuTimeBenchmarkEnd() { _gpuTimeQuery.end(); return _gpuTimeQuery.result(); } +#endif } diff --git a/src/Magnum/OpenGLTester.h b/src/Magnum/OpenGLTester.h index d2aa3caf8..297b47414 100644 --- a/src/Magnum/OpenGLTester.h +++ b/src/Magnum/OpenGLTester.h @@ -32,9 +32,8 @@ #include #include "Magnum/Renderer.h" -#include "Magnum/TimeQuery.h" -#if defined(MAGNUM_TARGET_HEADLESS) || defined(CORRADE_TARGET_ANDROID) +#if defined(MAGNUM_TARGET_HEADLESS) || defined(CORRADE_TARGET_EMSCRIPTEN) || defined(CORRADE_TARGET_ANDROID) #include "Magnum/Platform/WindowlessEglApplication.h" #elif defined(CORRADE_TARGET_IOS) #include "Magnum/Platform/WindowlessIosApplication.h" @@ -56,6 +55,10 @@ #error cannot run OpenGL tests on this platform #endif +#ifndef MAGNUM_TARGET_WEBGL +#include "Magnum/TimeQuery.h" +#endif + namespace Magnum { /** @@ -65,15 +68,14 @@ Extends @ref Corrade::TestSuite::Tester with features for OpenGL testing and benchmarking. Be sure to read its documentation first to have an overview of the base features. -This class is available only on platforms with corresponding -`Platform::Windowless*Application` implementation. That currently means all -platforms except @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten". It is built into -a separate static library and only if `WITH_OPENGLTESTER` is enabled when -building Magnum. To use it with CMake, you need to request the `OpenGLTester` -component of the `Magnum` package. Derive your test class from this class -instead of @ref Corrade::TestSuite::Tester and either link to -`Magnum::OpenGLTester` target or add it to the `LIBRARIES` section of the -@ref corrade-cmake-add-test "corrade_add_test()" macro: +This class is available on platforms with corresponding +`Platform::Windowless*Application` implementation, which currently means all +platforms. It is built into a separate static library and only if +`WITH_OPENGLTESTER` is enabled when building Magnum. To use it with CMake, you +need to request the `OpenGLTester` component of the `Magnum` package. Derive +your test class from this class instead of @ref Corrade::TestSuite::Tester and +either link to `Magnum::OpenGLTester` target or add it to the `LIBRARIES` +section of the @ref corrade-cmake-add-test "corrade_add_test()" macro: @code{.cmake} find_package(Magnum REQUIRED OpenGLTester) @@ -91,7 +93,8 @@ drivers. In addition, on desktop, unless Magnum is built with `MAGNUM_TARGET_HEADLESS`, OpenGL context creation requires a graphical desktop to be running. On embedded systems (and @ref CORRADE_TARGET_IOS "iOS", @ref CORRADE_TARGET_ANDROID "Android" in particular) running the tests has no -special requirements. +special requirements. On Emscripten the tests have to be running in a browser, +as Node.js environment doesn't provide a WebGL context. On virtualized systems and systems without a GPU (e.g. CI servers) it's possible to link against e.g. Mesa softpipe or @@ -126,9 +129,11 @@ all platforms and not all GL errors are fatal. This class adds @ref BenchmarkType::GpuTime to the benchmark type enum, allowing you to measure time spent on GPU as opposed to CPU or wall clock time. +@requires_gles GPU time benchmarking is not available on WebGL. */ class OpenGLTester: public TestSuite::Tester { public: + #ifndef MAGNUM_TARGET_WEBGL /** * @brief Benchmark type * @@ -167,9 +172,11 @@ class OpenGLTester: public TestSuite::Tester { * thus may cause pipeline bubble. Increase number of iterations * passed to @ref CORRADE_BENCHMARK() to amortize the measurement * error. + * @requires_gles GPU time benchmarking is not available on WebGL. */ GpuTime = 32 }; + #endif /** * @brief Constructor @@ -180,11 +187,13 @@ class OpenGLTester: public TestSuite::Tester { ~OpenGLTester(); + #ifndef MAGNUM_TARGET_WEBGL /** * @brief Add benchmarks * * Extends @ref Corrade::TestSuite::Tester::addBenchmarks(std::initializer_list, std::size_t, BenchmarkType) with support * for GPU benchmark types. + * @requires_gles GPU time benchmarking is not available on WebGL. */ template void addBenchmarks(std::initializer_list benchmarks, std::size_t batchCount, BenchmarkType benchmarkType = BenchmarkType::Default) { if(benchmarkType == BenchmarkType::GpuTime) @@ -198,6 +207,7 @@ class OpenGLTester: public TestSuite::Tester { * * Extends @ref Corrade::TestSuite::Tester::addBenchmarks(std::initializer_list, std::size_t, void(Derived::*)(), void(Derived::*)(), BenchmarkType) with support * for GPU benchmark types. + * @requires_gles GPU time benchmarking is not available on WebGL. */ template void addBenchmarks(std::initializer_list benchmarks, std::size_t batchCount, void(Derived::*setup)(), void(Derived::*teardown)(), BenchmarkType benchmarkType = BenchmarkType::Default) { if(benchmarkType == BenchmarkType::GpuTime) @@ -211,6 +221,7 @@ class OpenGLTester: public TestSuite::Tester { * * Extends @ref Corrade::TestSuite::Tester::addInstancedBenchmarks(std::initializer_list, std::size_t, std::size_t, BenchmarkType) with support for GPU * benchmark types. + * @requires_gles GPU time benchmarking is not available on WebGL. */ template void addInstancedBenchmarks(std::initializer_list benchmarks, std::size_t batchCount, std::size_t instanceCount, BenchmarkType benchmarkType = BenchmarkType::Default) { if(benchmarkType == BenchmarkType::GpuTime) @@ -224,6 +235,7 @@ class OpenGLTester: public TestSuite::Tester { * * Extends @ref Corrade::TestSuite::Tester::addInstancedBenchmarks(std::initializer_list, std::size_t, std::size_t, void(Derived::*)(), void(Derived::*)(), BenchmarkType) * with support for GPU benchmark types. + * @requires_gles GPU time benchmarking is not available on WebGL. */ template void addInstancedBenchmarks(std::initializer_list benchmarks, std::size_t batchCount, std::size_t instanceCount, void(Derived::*setup)(), void(Derived::*teardown)(), BenchmarkType benchmarkType = BenchmarkType::Default) { if(benchmarkType == BenchmarkType::GpuTime) @@ -231,10 +243,13 @@ class OpenGLTester: public TestSuite::Tester { else Tester::addInstancedBenchmarks(benchmarks, batchCount, instanceCount, setup, teardown, Tester::BenchmarkType(Int(benchmarkType))); } + #endif private: + #ifndef MAGNUM_TARGET_WEBGL void gpuTimeBenchmarkBegin(); std::uint64_t gpuTimeBenchmarkEnd(); + #endif struct WindowlessApplication: Platform::WindowlessApplication { explicit WindowlessApplication(const Arguments& arguments): Platform::WindowlessApplication{arguments, NoCreate} {} @@ -245,7 +260,9 @@ class OpenGLTester: public TestSuite::Tester { } _windowlessApplication; + #ifndef MAGNUM_TARGET_WEBGL TimeQuery _gpuTimeQuery{NoCreate}; + #endif }; /** @hideinitializer