From 4e75b2fb8381584f29c5a05094c5220c2b108c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 May 2015 13:28:11 +0200 Subject: [PATCH] First-class WebGL support, part 8: reduced query functionality. --- src/Magnum/AbstractQuery.cpp | 24 ++++++------------ src/Magnum/AbstractQuery.h | 11 ++++++-- src/Magnum/CMakeLists.txt | 35 ++++++++++++++++---------- src/Magnum/Implementation/QueryState.h | 4 +++ src/Magnum/Implementation/State.cpp | 4 +++ src/Magnum/Implementation/State.h | 4 +++ src/Magnum/PrimitiveQuery.h | 10 ++++---- src/Magnum/Query.h | 4 +++ src/Magnum/SampleQuery.h | 23 ++++++++++++----- src/Magnum/TimeQuery.h | 9 ++++++- 10 files changed, 85 insertions(+), 43 deletions(-) diff --git a/src/Magnum/AbstractQuery.cpp b/src/Magnum/AbstractQuery.cpp index 3e224a5b8..0ce9fb1d6 100644 --- a/src/Magnum/AbstractQuery.cpp +++ b/src/Magnum/AbstractQuery.cpp @@ -98,10 +98,8 @@ bool AbstractQuery::resultAvailable() { GLuint result; #ifndef MAGNUM_TARGET_GLES2 glGetQueryObjectuiv(_id, GL_QUERY_RESULT_AVAILABLE, &result); - #elif !defined(CORRADE_TARGET_EMSCRIPTEN) - glGetQueryObjectuivEXT(_id, GL_QUERY_RESULT_AVAILABLE_EXT, &result); #else - CORRADE_ASSERT_UNREACHABLE(); + glGetQueryObjectuivEXT(_id, GL_QUERY_RESULT_AVAILABLE_EXT, &result); #endif return result == GL_TRUE; } @@ -111,21 +109,20 @@ template<> UnsignedInt AbstractQuery::result() { UnsignedInt result; #ifndef MAGNUM_TARGET_GLES2 glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); - #elif !defined(CORRADE_TARGET_EMSCRIPTEN) - glGetQueryObjectuivEXT(_id, GL_QUERY_RESULT_EXT, &result); #else - CORRADE_ASSERT_UNREACHABLE(); + glGetQueryObjectuivEXT(_id, GL_QUERY_RESULT_EXT, &result); #endif return result; } template<> bool AbstractQuery::result() { return result() != 0; } +#ifndef MAGNUM_TARGET_WEBGL template<> Int AbstractQuery::result() { Int result; #ifndef MAGNUM_TARGET_GLES glGetQueryObjectiv(_id, GL_QUERY_RESULT, &result); - #elif !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_NACL) + #elif !defined(CORRADE_TARGET_NACL) glGetQueryObjectivEXT(_id, GL_QUERY_RESULT_EXT, &result); #else CORRADE_ASSERT_UNREACHABLE(); @@ -133,12 +130,11 @@ template<> Int AbstractQuery::result() { return result; } -#ifndef MAGNUM_TARGET_WEBGL template<> UnsignedLong AbstractQuery::result() { UnsignedLong result; #ifndef MAGNUM_TARGET_GLES glGetQueryObjectui64v(_id, GL_QUERY_RESULT, &result); - #elif !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_NACL) + #elif !defined(CORRADE_TARGET_NACL) glGetQueryObjectui64vEXT(_id, GL_QUERY_RESULT_EXT, &result); #else CORRADE_ASSERT_UNREACHABLE(); @@ -150,7 +146,7 @@ template<> Long AbstractQuery::result() { Long result; #ifndef MAGNUM_TARGET_GLES glGetQueryObjecti64v(_id, GL_QUERY_RESULT, &result); - #elif !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_NACL) + #elif !defined(CORRADE_TARGET_NACL) glGetQueryObjecti64vEXT(_id, GL_QUERY_RESULT_EXT, &result); #else CORRADE_ASSERT_UNREACHABLE(); @@ -167,10 +163,8 @@ void AbstractQuery::begin() { #ifndef MAGNUM_TARGET_GLES2 glBeginQuery(_target, _id); - #elif !defined(CORRADE_TARGET_EMSCRIPTEN) - glBeginQueryEXT(_target, _id); #else - CORRADE_ASSERT_UNREACHABLE(); + glBeginQueryEXT(_target, _id); #endif } @@ -190,10 +184,8 @@ void AbstractQuery::end() { #ifndef MAGNUM_TARGET_GLES2 glEndQuery(_target); - #elif !defined(CORRADE_TARGET_EMSCRIPTEN) - glEndQueryEXT(_target); #else - CORRADE_ASSERT_UNREACHABLE(); + glEndQueryEXT(_target); #endif } diff --git a/src/Magnum/AbstractQuery.h b/src/Magnum/AbstractQuery.h index fa851f2d7..5f0c0730a 100644 --- a/src/Magnum/AbstractQuery.h +++ b/src/Magnum/AbstractQuery.h @@ -25,9 +25,11 @@ DEALINGS IN THE SOFTWARE. */ +#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) /** @file * @brief Class @ref Magnum::AbstractQuery */ +#endif #include #include @@ -35,6 +37,7 @@ #include "Magnum/AbstractObject.h" #include "Magnum/configure.h" +#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) namespace Magnum { namespace Implementation { struct QueryState; } @@ -44,6 +47,7 @@ namespace Implementation { struct QueryState; } See @ref PrimitiveQuery, @ref SampleQuery and @ref TimeQuery documentation for more information. +@requires_webgl20 Queries are not available in WebGL 1.0. @todo `QUERY_COUNTER_BITS` (not sure since when this is supported) */ class MAGNUM_EXPORT AbstractQuery: public AbstractObject { @@ -116,8 +120,6 @@ class MAGNUM_EXPORT AbstractQuery: public AbstractObject { * * Note that this function is blocking until the result is available. * See @ref resultAvailable(). - * @attention @ref Magnum::UnsignedLong "UnsignedLong" and @ref Magnum::Long "Long" - * result type is not available in @ref MAGNUM_TARGET_WEBGL "WebGL". * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT} * @requires_gl33 Extension @extension{ARB,timer_query} for result * type @ref Magnum::UnsignedInt "UnsignedInt" and @ref Magnum::Long @@ -125,6 +127,8 @@ class MAGNUM_EXPORT AbstractQuery: public AbstractObject { * @requires_es_extension Extension @es_extension{EXT,disjoint_timer_query} * for result types @ref Magnum::Int "Int", @ref Magnum::UnsignedLong "UnsignedLong" * @ref Magnum::Long "Long". + * @requires_gles Only @ref Magnum::UnsignedInt "UnsignedInt" result + * type is available in WebGL. */ template T result(); @@ -199,5 +203,8 @@ inline AbstractQuery& AbstractQuery::operator=(AbstractQuery&& other) noexcept { } } +#else +#error this header is not available in WebGL 1.0 build +#endif #endif diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index 35bcb09a9..0a90005a6 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -31,7 +31,6 @@ set(Magnum_SRCS AbstractFramebuffer.cpp AbstractImage.cpp AbstractObject.cpp - AbstractQuery.cpp AbstractTexture.cpp AbstractShaderProgram.cpp Attribute.cpp @@ -57,7 +56,6 @@ set(Magnum_SRCS Implementation/BufferState.cpp Implementation/FramebufferState.cpp Implementation/MeshState.cpp - Implementation/QueryState.cpp Implementation/RendererState.cpp Implementation/ShaderProgramState.cpp Implementation/State.cpp @@ -83,7 +81,6 @@ set(Magnum_HEADERS AbstractFramebuffer.h AbstractImage.h AbstractObject.h - AbstractQuery.h AbstractResourceLoader.h AbstractShaderProgram.h AbstractTexture.h @@ -110,13 +107,11 @@ set(Magnum_HEADERS Resource.h ResourceManager.h ResourceManager.hpp - SampleQuery.h Sampler.h Shader.h Texture.h TextureFormat.h Timeline.h - TimeQuery.h Types.h Version.h @@ -128,19 +123,12 @@ set(Magnum_PRIVATE_HEADERS Implementation/FramebufferState.h Implementation/maxTextureSize.h Implementation/MeshState.h - Implementation/QueryState.h Implementation/RendererState.h Implementation/ShaderProgramState.h Implementation/ShaderState.h Implementation/State.h Implementation/TextureState.h) -# Deprecated headers -if(BUILD_DEPRECATED) - set(Magnum_HEADERS ${Magnum_HEADERS} - Query.h) -endif() - # Desktop-only stuff if(NOT TARGET_GLES) list(APPEND Magnum_SRCS @@ -182,7 +170,8 @@ if(NOT TARGET_WEBGL) Implementation/DebugState.cpp) list(APPEND Magnum_HEADERS - DebugOutput.h) + DebugOutput.h + TimeQuery.h) list(APPEND Magnum_PRIVATE_HEADERS Implementation/DebugState.h) @@ -199,6 +188,26 @@ if(NOT TARGET_WEBGL) endif() endif() +# Desktop, OpenGL ES and WebGL 2.0 stuff that is not available in WebGL 1.0 +if(NOT (TARGET_WEBGL AND TARGET_GLES2)) + list(APPEND Magnum_SRCS + AbstractQuery.cpp + + Implementation/QueryState.cpp) + + list(APPEND Magnum_HEADERS + AbstractQuery.h + SampleQuery.h) + + list(APPEND Magnum_PRIVATE_HEADERS + Implementation/QueryState.h) + + if(BUILD_DEPRECATED) + list(APPEND Magnum_HEADERS + Query.h) + endif() +endif() + # Link in GL function pointer variables on platforms that support it if(NOT CORRADE_TARGET_EMSCRIPTEN AND NOT CORRADE_TARGET_NACL) list(APPEND Magnum_SRCS $) diff --git a/src/Magnum/Implementation/QueryState.h b/src/Magnum/Implementation/QueryState.h index e05a3d45d..363ec5b8f 100644 --- a/src/Magnum/Implementation/QueryState.h +++ b/src/Magnum/Implementation/QueryState.h @@ -29,6 +29,10 @@ #include "Magnum/AbstractQuery.h" +#if defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2) +#error this header is not available in WebGL 1.0 build +#endif + namespace Magnum { namespace Implementation { struct QueryState { diff --git a/src/Magnum/Implementation/State.cpp b/src/Magnum/Implementation/State.cpp index 7f2b8ca8a..5779529f1 100644 --- a/src/Magnum/Implementation/State.cpp +++ b/src/Magnum/Implementation/State.cpp @@ -36,7 +36,9 @@ #endif #include "FramebufferState.h" #include "MeshState.h" +#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) #include "QueryState.h" +#endif #include "RendererState.h" #include "ShaderState.h" #include "ShaderProgramState.h" @@ -63,7 +65,9 @@ State::State(Context& context) { #endif framebuffer.reset(new FramebufferState{context, extensions}); mesh.reset(new MeshState{context, extensions}); + #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) query.reset(new QueryState{context, extensions}); + #endif renderer.reset(new RendererState{context, extensions}); shader.reset(new ShaderState); shaderProgram.reset(new ShaderProgramState{context, extensions}); diff --git a/src/Magnum/Implementation/State.h b/src/Magnum/Implementation/State.h index 8519f8a73..76a786478 100644 --- a/src/Magnum/Implementation/State.h +++ b/src/Magnum/Implementation/State.h @@ -38,7 +38,9 @@ struct DebugState; #endif struct FramebufferState; struct MeshState; +#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) struct QueryState; +#endif struct RendererState; struct ShaderState; struct ShaderProgramState; @@ -61,7 +63,9 @@ struct State { #endif std::unique_ptr framebuffer; std::unique_ptr mesh; + #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) std::unique_ptr query; + #endif std::unique_ptr renderer; std::unique_ptr shader; std::unique_ptr shaderProgram; diff --git a/src/Magnum/PrimitiveQuery.h b/src/Magnum/PrimitiveQuery.h index 398ff59c4..eb3fdf40d 100644 --- a/src/Magnum/PrimitiveQuery.h +++ b/src/Magnum/PrimitiveQuery.h @@ -59,10 +59,10 @@ if(!q.resultAvailable()) { // ...or block until the result is available UnsignedInt primitiveCount = q.result(); @endcode -@requires_gl30 Extension @extension{EXT,transform_feedback} -@requires_gles30 Only sample queries are available on OpenGL ES 2.0. - @see @ref SampleQuery, @ref TimeQuery, @ref TransformFeedback +@requires_gl30 Extension @extension{EXT,transform_feedback} +@requires_gles30 Only sample queries are available in OpenGL ES 2.0. +@requires_webgl20 Queries are not available in WebGL 1.0. @todo glBeginQueryIndexed @todo @extension{ARB,transform_feedback_overflow_query} */ @@ -75,7 +75,7 @@ class PrimitiveQuery: public AbstractQuery { * Count of primitives generated from vertex shader or geometry * shader. * @requires_gl Only transform feedback query is available in - * OpenGL ES. + * OpenGL ES and WebGL. */ PrimitivesGenerated = GL_PRIMITIVES_GENERATED, #endif @@ -96,7 +96,7 @@ class PrimitiveQuery: public AbstractQuery { * @brief Constructor * * Creates new OpenGL query object. If @extension{ARB,direct_state_access} - * (part of OpenGL 4.5) is not supported, the query is created on first + * (part of OpenGL 4.5) is not available, the query is created on first * use. * @see @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries} */ diff --git a/src/Magnum/Query.h b/src/Magnum/Query.h index 452a03f09..9a1ae0b3f 100644 --- a/src/Magnum/Query.h +++ b/src/Magnum/Query.h @@ -32,6 +32,7 @@ #include "Magnum/configure.h" +#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) #ifdef MAGNUM_BUILD_DEPRECATED #include "Magnum/PrimitiveQuery.h" #include "Magnum/SampleQuery.h" @@ -39,5 +40,8 @@ #else #error use Magnum/PrimitiveQuery.h, Magnum/SampleQuery.h or Magnum/TimeQuery.h instead. #endif +#else +#error this header is not available in WebGL 1.0 build +#endif #endif diff --git a/src/Magnum/SampleQuery.h b/src/Magnum/SampleQuery.h index 74f8c7d43..2fe71d2bc 100644 --- a/src/Magnum/SampleQuery.h +++ b/src/Magnum/SampleQuery.h @@ -25,9 +25,11 @@ DEALINGS IN THE SOFTWARE. */ +#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) /** @file * @brief Class @ref Magnum::SampleQuery */ +#endif #include "Magnum/AbstractQuery.h" @@ -35,6 +37,7 @@ #include #endif +#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) namespace Magnum { /** @@ -74,7 +77,8 @@ q.endConditionalRender(); @see @ref PrimitiveQuery, @ref TimeQuery @requires_gles30 Extension @es_extension{EXT,occlusion_query_boolean} in - OpenGL ES 2.0 + OpenGL ES 2.0. +@requires_webgl20 Queries are not available in WebGL 1.0. */ class SampleQuery: public AbstractQuery { public: @@ -83,7 +87,8 @@ class SampleQuery: public AbstractQuery { #ifndef MAGNUM_TARGET_GLES /** * Count of samples passed from fragment shader - * @requires_gl Only boolean query is available in OpenGL ES. + * @requires_gl Only boolean query is available in OpenGL ES and + * WebGL. */ SamplesPassed = GL_SAMPLES_PASSED, #endif @@ -117,7 +122,8 @@ class SampleQuery: public AbstractQuery { * @brief Conditional render mode * * @requires_gl30 Extension @extension{NV,conditional_render} - * @requires_gl Conditional rendering is not available in OpenGL ES. + * @requires_gl Conditional rendering is not available in OpenGL ES or + * WebGL. */ enum class ConditionalRenderMode: GLenum { /** @@ -189,7 +195,7 @@ class SampleQuery: public AbstractQuery { * @brief Constructor * * Creates new OpenGL query object. If @extension{ARB,direct_state_access} - * (part of OpenGL 4.5) is not supported, the query is created on first + * (part of OpenGL 4.5) is not available, the query is created on first * use. * @see @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries} */ @@ -213,7 +219,8 @@ class SampleQuery: public AbstractQuery { * * @see @fn_gl{BeginConditionalRender} * @requires_gl30 Extension @extension{NV,conditional_render} - * @requires_gl Conditional rendering is not available in OpenGL ES. + * @requires_gl Conditional rendering is not available in OpenGL ES or + * WebGL. */ void beginConditionalRender(ConditionalRenderMode mode) { glBeginConditionalRender(id(), GLenum(mode)); @@ -224,7 +231,8 @@ class SampleQuery: public AbstractQuery { * * @see @fn_gl{EndConditionalRender} * @requires_gl30 Extension @extension{NV,conditional_render} - * @requires_gl Conditional rendering is not available in OpenGL ES. + * @requires_gl Conditional rendering is not available in OpenGL ES or + * WebGL. */ void endConditionalRender() { glEndConditionalRender(); @@ -245,5 +253,8 @@ class SampleQuery: public AbstractQuery { }; } +#else +#error this header is not available in WebGL 1.0 build +#endif #endif diff --git a/src/Magnum/TimeQuery.h b/src/Magnum/TimeQuery.h index 662f5e541..1315ea14c 100644 --- a/src/Magnum/TimeQuery.h +++ b/src/Magnum/TimeQuery.h @@ -25,9 +25,11 @@ DEALINGS IN THE SOFTWARE. */ +#ifndef MAGNUM_TARGET_WEBGL /** @file * @brief Class @ref Magnum::TimeQuery */ +#endif #include "Magnum/AbstractQuery.h" @@ -35,6 +37,7 @@ #include #endif +#ifndef MAGNUM_TARGET_WEBGL namespace Magnum { /** @@ -68,6 +71,7 @@ UnsignedInt timeElapsed2 = q3.result()-tmp; Using the latter results in fewer OpenGL calls when doing more measures. @requires_gl33 Extension @extension{ARB,timer_query} @requires_es_extension Extension @es_extension{EXT,disjoint_timer_query} +@requires_gles Time query is not available in WebGL. @see @ref PrimitiveQuery, @ref SampleQuery @todo timestamp with glGet + example usage @@ -104,7 +108,7 @@ class TimeQuery: public AbstractQuery { * @brief Constructor * * Creates new OpenGL query object. If @extension{ARB,direct_state_access} - * (part of OpenGL 4.5) is not supported, the query is created on first + * (part of OpenGL 4.5) is not available, the query is created on first * use. * @see @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries} */ @@ -151,5 +155,8 @@ class TimeQuery: public AbstractQuery { }; } +#else +#error this header is not available in WebGL 1.0 build +#endif #endif