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()
# 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)

1
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

2
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)

10
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<Extensions::GL::KHR::debug>()) {
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<UnsignedLong>();
}
#endif
}

41
src/Magnum/OpenGLTester.h

@ -32,9 +32,8 @@
#include <Corrade/TestSuite/Tester.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"
#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<void(Derived::*)()>, std::size_t, BenchmarkType) with support
* 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) {
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
* 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) {
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
* 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) {
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)
* 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) {
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

Loading…
Cancel
Save