Browse Source

Ported the OpenGLTester class to Emscripten.

pull/205/head
Vladimír Vondruš 8 years ago
parent
commit
330f194069
  1. 6
      CMakeLists.txt
  2. 1
      doc/changelog.dox
  3. 2
      modules/FindMagnum.cmake
  4. 10
      src/Magnum/OpenGLTester.cpp
  5. 41
      src/Magnum/OpenGLTester.h

6
CMakeLists.txt

@ -183,9 +183,7 @@ if(BUILD_TESTS)
endif() endif()
# OpenGLTester library, built by default only if GL tests are enabled # 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)
cmake_dependent_option(WITH_OPENGLTESTER "Build OpenGLTester library" OFF "NOT BUILD_GL_TESTS" ON)
endif()
# Dynamic linking is meaningless on Emscripten and too inconvenient on Android # Dynamic linking is meaningless on Emscripten and too inconvenient on Android
if(CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID) if(CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID)
@ -231,7 +229,7 @@ if(CORRADE_TARGET_EMSCRIPTEN)
endif() endif()
if(WITH_OPENGLTESTER) 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(WITH_WINDOWLESSEGLAPPLICATION ON)
set(OPENGLTESTER_APPLICATION MagnumWindowlessEglApplication) set(OPENGLTESTER_APPLICATION MagnumWindowlessEglApplication)
elseif(CORRADE_TARGET_IOS) elseif(CORRADE_TARGET_IOS)

1
doc/changelog.dox

@ -58,6 +58,7 @@ See also:
their WebGL counterparts @webgl_extension{EXT,color_buffer_half_float}, their WebGL counterparts @webgl_extension{EXT,color_buffer_half_float},
@webgl_extension{WEBGL,color_buffer_float}, @webgl_extension{WEBGL,color_buffer_float},
@webgl_extension{EXT,color_buffer_float} @webgl_extension{EXT,color_buffer_float}
- Ported @ref OpenGLTester to WebGL
@subsubsection changelog-latest-new-platform Platform libraries @subsubsection changelog-latest-new-platform Platform libraries

2
modules/FindMagnum.cmake

@ -337,7 +337,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
elseif(_component STREQUAL DebugTools) elseif(_component STREQUAL DebugTools)
set(_MAGNUM_${_COMPONENT}_DEPENDENCIES MeshTools Primitives SceneGraph Shaders Shapes) set(_MAGNUM_${_COMPONENT}_DEPENDENCIES MeshTools Primitives SceneGraph Shaders Shapes)
elseif(_component STREQUAL OpenGLTester) 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) set(_MAGNUM_${_COMPONENT}_DEPENDENCIES WindowlessEglApplication)
elseif(CORRADE_TARGET_IOS) elseif(CORRADE_TARGET_IOS)
set(_MAGNUM_${_COMPONENT}_DEPENDENCIES WindowlessIosApplication) set(_MAGNUM_${_COMPONENT}_DEPENDENCIES WindowlessIosApplication)

10
src/Magnum/OpenGLTester.cpp

@ -27,20 +27,23 @@
#include "Magnum/Context.h" #include "Magnum/Context.h"
#include "Magnum/Extensions.h" #include "Magnum/Extensions.h"
#ifndef MAGNUM_TARGET_WEBGL
#include "Magnum/DebugOutput.h" #include "Magnum/DebugOutput.h"
#endif
namespace Magnum { namespace Magnum {
OpenGLTester::OpenGLTester(): TestSuite::Tester{TestSuite::Tester::TesterConfiguration{}.setSkippedArgumentPrefixes({"magnum"})}, _windowlessApplication{{arguments().first, arguments().second}} { 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 /* Try to create debug context, fallback to normal one if not possible. No
such thing on macOS or iOS. */ such thing on macOS, iOS or WebGL. */
#ifndef CORRADE_TARGET_APPLE #if !defined(CORRADE_TARGET_APPLE) && !defined(MAGNUM_TARGET_WEBGL)
if(!_windowlessApplication.tryCreateContext(Platform::WindowlessApplication::Configuration{}.setFlags(Platform::WindowlessApplication::Configuration::Flag::Debug))) if(!_windowlessApplication.tryCreateContext(Platform::WindowlessApplication::Configuration{}.setFlags(Platform::WindowlessApplication::Configuration::Flag::Debug)))
_windowlessApplication.createContext(); _windowlessApplication.createContext();
#else #else
_windowlessApplication.createContext(); _windowlessApplication.createContext();
#endif #endif
#ifndef MAGNUM_TARGET_WEBGL
if(Context::current().isExtensionSupported<Extensions::GL::KHR::debug>()) { if(Context::current().isExtensionSupported<Extensions::GL::KHR::debug>()) {
Renderer::enable(Renderer::Feature::DebugOutput); Renderer::enable(Renderer::Feature::DebugOutput);
Renderer::enable(Renderer::Feature::DebugOutputSynchronous); 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) */ /* Disable "Buffer detailed info" message on NV (too spammy) */
DebugOutput::setEnabled(DebugOutput::Source::Api, DebugOutput::Type::Other, {131185}, false); DebugOutput::setEnabled(DebugOutput::Source::Api, DebugOutput::Type::Other, {131185}, false);
} }
#endif
} }
OpenGLTester::~OpenGLTester() = default; OpenGLTester::~OpenGLTester() = default;
#ifndef MAGNUM_TARGET_WEBGL
void OpenGLTester::gpuTimeBenchmarkBegin() { void OpenGLTester::gpuTimeBenchmarkBegin() {
setBenchmarkName("GPU time"); setBenchmarkName("GPU time");
@ -66,5 +71,6 @@ std::uint64_t OpenGLTester::gpuTimeBenchmarkEnd() {
_gpuTimeQuery.end(); _gpuTimeQuery.end();
return _gpuTimeQuery.result<UnsignedLong>(); return _gpuTimeQuery.result<UnsignedLong>();
} }
#endif
} }

41
src/Magnum/OpenGLTester.h

@ -32,9 +32,8 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include "Magnum/Renderer.h" #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" #include "Magnum/Platform/WindowlessEglApplication.h"
#elif defined(CORRADE_TARGET_IOS) #elif defined(CORRADE_TARGET_IOS)
#include "Magnum/Platform/WindowlessIosApplication.h" #include "Magnum/Platform/WindowlessIosApplication.h"
@ -56,6 +55,10 @@
#error cannot run OpenGL tests on this platform #error cannot run OpenGL tests on this platform
#endif #endif
#ifndef MAGNUM_TARGET_WEBGL
#include "Magnum/TimeQuery.h"
#endif
namespace Magnum { 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 benchmarking. Be sure to read its documentation first to have an overview of
the base features. the base features.
This class is available only on platforms with corresponding This class is available on platforms with corresponding
`Platform::Windowless*Application` implementation. That currently means all `Platform::Windowless*Application` implementation, which currently means all
platforms except @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten". It is built into platforms. It is built into a separate static library and only if
a separate static library and only if `WITH_OPENGLTESTER` is enabled when `WITH_OPENGLTESTER` is enabled when building Magnum. To use it with CMake, you
building Magnum. To use it with CMake, you need to request the `OpenGLTester` need to request the `OpenGLTester` component of the `Magnum` package. Derive
component of the `Magnum` package. Derive your test class from this class your test class from this class instead of @ref Corrade::TestSuite::Tester and
instead of @ref Corrade::TestSuite::Tester and either link to either link to `Magnum::OpenGLTester` target or add it to the `LIBRARIES`
`Magnum::OpenGLTester` target or add it to the `LIBRARIES` section of the section of the @ref corrade-cmake-add-test "corrade_add_test()" macro:
@ref corrade-cmake-add-test "corrade_add_test()" macro:
@code{.cmake} @code{.cmake}
find_package(Magnum REQUIRED OpenGLTester) 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 `MAGNUM_TARGET_HEADLESS`, OpenGL context creation requires a graphical desktop
to be running. On embedded systems (and @ref CORRADE_TARGET_IOS "iOS", to be running. On embedded systems (and @ref CORRADE_TARGET_IOS "iOS",
@ref CORRADE_TARGET_ANDROID "Android" in particular) running the tests has no @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 On virtualized systems and systems without a GPU (e.g. CI servers) it's
possible to link against e.g. Mesa softpipe or 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, 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. 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 { class OpenGLTester: public TestSuite::Tester {
public: public:
#ifndef MAGNUM_TARGET_WEBGL
/** /**
* @brief Benchmark type * @brief Benchmark type
* *
@ -167,9 +172,11 @@ class OpenGLTester: public TestSuite::Tester {
* thus may cause pipeline bubble. Increase number of iterations * thus may cause pipeline bubble. Increase number of iterations
* passed to @ref CORRADE_BENCHMARK() to amortize the measurement * passed to @ref CORRADE_BENCHMARK() to amortize the measurement
* error. * error.
* @requires_gles GPU time benchmarking is not available on WebGL.
*/ */
GpuTime = 32 GpuTime = 32
}; };
#endif
/** /**
* @brief Constructor * @brief Constructor
@ -180,11 +187,13 @@ class OpenGLTester: public TestSuite::Tester {
~OpenGLTester(); ~OpenGLTester();
#ifndef MAGNUM_TARGET_WEBGL
/** /**
* @brief Add benchmarks * @brief Add benchmarks
* *
* Extends @ref Corrade::TestSuite::Tester::addBenchmarks(std::initializer_list<void(Derived::*)()>, std::size_t, BenchmarkType) with support * Extends @ref Corrade::TestSuite::Tester::addBenchmarks(std::initializer_list<void(Derived::*)()>, std::size_t, BenchmarkType) with support
* for GPU benchmark types. * for GPU benchmark types.
* @requires_gles GPU time benchmarking is not available on WebGL.
*/ */
template<class Derived> void addBenchmarks(std::initializer_list<void(Derived::*)()> benchmarks, std::size_t batchCount, BenchmarkType benchmarkType = BenchmarkType::Default) { template<class Derived> void addBenchmarks(std::initializer_list<void(Derived::*)()> benchmarks, std::size_t batchCount, BenchmarkType benchmarkType = BenchmarkType::Default) {
if(benchmarkType == BenchmarkType::GpuTime) if(benchmarkType == BenchmarkType::GpuTime)
@ -198,6 +207,7 @@ class OpenGLTester: public TestSuite::Tester {
* *
* Extends @ref Corrade::TestSuite::Tester::addBenchmarks(std::initializer_list<void(Derived::*)()>, std::size_t, void(Derived::*)(), void(Derived::*)(), BenchmarkType) with support * Extends @ref Corrade::TestSuite::Tester::addBenchmarks(std::initializer_list<void(Derived::*)()>, std::size_t, void(Derived::*)(), void(Derived::*)(), BenchmarkType) with support
* for GPU benchmark types. * for GPU benchmark types.
* @requires_gles GPU time benchmarking is not available on WebGL.
*/ */
template<class Derived> void addBenchmarks(std::initializer_list<void(Derived::*)()> benchmarks, std::size_t batchCount, void(Derived::*setup)(), void(Derived::*teardown)(), BenchmarkType benchmarkType = BenchmarkType::Default) { template<class Derived> void addBenchmarks(std::initializer_list<void(Derived::*)()> benchmarks, std::size_t batchCount, void(Derived::*setup)(), void(Derived::*teardown)(), BenchmarkType benchmarkType = BenchmarkType::Default) {
if(benchmarkType == BenchmarkType::GpuTime) if(benchmarkType == BenchmarkType::GpuTime)
@ -211,6 +221,7 @@ class OpenGLTester: public TestSuite::Tester {
* *
* Extends @ref Corrade::TestSuite::Tester::addInstancedBenchmarks(std::initializer_list<void(Derived::*)()>, std::size_t, std::size_t, BenchmarkType) with support for GPU * Extends @ref Corrade::TestSuite::Tester::addInstancedBenchmarks(std::initializer_list<void(Derived::*)()>, std::size_t, std::size_t, BenchmarkType) with support for GPU
* benchmark types. * benchmark types.
* @requires_gles GPU time benchmarking is not available on WebGL.
*/ */
template<class Derived> void addInstancedBenchmarks(std::initializer_list<void(Derived::*)()> benchmarks, std::size_t batchCount, std::size_t instanceCount, BenchmarkType benchmarkType = BenchmarkType::Default) { template<class Derived> void addInstancedBenchmarks(std::initializer_list<void(Derived::*)()> benchmarks, std::size_t batchCount, std::size_t instanceCount, BenchmarkType benchmarkType = BenchmarkType::Default) {
if(benchmarkType == BenchmarkType::GpuTime) if(benchmarkType == BenchmarkType::GpuTime)
@ -224,6 +235,7 @@ class OpenGLTester: public TestSuite::Tester {
* *
* Extends @ref Corrade::TestSuite::Tester::addInstancedBenchmarks(std::initializer_list<void(Derived::*)()>, std::size_t, std::size_t, void(Derived::*)(), void(Derived::*)(), BenchmarkType) * Extends @ref Corrade::TestSuite::Tester::addInstancedBenchmarks(std::initializer_list<void(Derived::*)()>, std::size_t, std::size_t, void(Derived::*)(), void(Derived::*)(), BenchmarkType)
* with support for GPU benchmark types. * with support for GPU benchmark types.
* @requires_gles GPU time benchmarking is not available on WebGL.
*/ */
template<class Derived> void addInstancedBenchmarks(std::initializer_list<void(Derived::*)()> benchmarks, std::size_t batchCount, std::size_t instanceCount, void(Derived::*setup)(), void(Derived::*teardown)(), BenchmarkType benchmarkType = BenchmarkType::Default) { template<class Derived> void addInstancedBenchmarks(std::initializer_list<void(Derived::*)()> benchmarks, std::size_t batchCount, std::size_t instanceCount, void(Derived::*setup)(), void(Derived::*teardown)(), BenchmarkType benchmarkType = BenchmarkType::Default) {
if(benchmarkType == BenchmarkType::GpuTime) if(benchmarkType == BenchmarkType::GpuTime)
@ -231,10 +243,13 @@ class OpenGLTester: public TestSuite::Tester {
else else
Tester::addInstancedBenchmarks(benchmarks, batchCount, instanceCount, setup, teardown, Tester::BenchmarkType(Int(benchmarkType))); Tester::addInstancedBenchmarks(benchmarks, batchCount, instanceCount, setup, teardown, Tester::BenchmarkType(Int(benchmarkType)));
} }
#endif
private: private:
#ifndef MAGNUM_TARGET_WEBGL
void gpuTimeBenchmarkBegin(); void gpuTimeBenchmarkBegin();
std::uint64_t gpuTimeBenchmarkEnd(); std::uint64_t gpuTimeBenchmarkEnd();
#endif
struct WindowlessApplication: Platform::WindowlessApplication { struct WindowlessApplication: Platform::WindowlessApplication {
explicit WindowlessApplication(const Arguments& arguments): Platform::WindowlessApplication{arguments, NoCreate} {} explicit WindowlessApplication(const Arguments& arguments): Platform::WindowlessApplication{arguments, NoCreate} {}
@ -245,7 +260,9 @@ class OpenGLTester: public TestSuite::Tester {
} _windowlessApplication; } _windowlessApplication;
#ifndef MAGNUM_TARGET_WEBGL
TimeQuery _gpuTimeQuery{NoCreate}; TimeQuery _gpuTimeQuery{NoCreate};
#endif
}; };
/** @hideinitializer /** @hideinitializer

Loading…
Cancel
Save