Browse Source

First-class WebGL support, part 8: reduced query functionality.

pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
4e75b2fb83
  1. 24
      src/Magnum/AbstractQuery.cpp
  2. 11
      src/Magnum/AbstractQuery.h
  3. 35
      src/Magnum/CMakeLists.txt
  4. 4
      src/Magnum/Implementation/QueryState.h
  5. 4
      src/Magnum/Implementation/State.cpp
  6. 4
      src/Magnum/Implementation/State.h
  7. 10
      src/Magnum/PrimitiveQuery.h
  8. 4
      src/Magnum/Query.h
  9. 23
      src/Magnum/SampleQuery.h
  10. 9
      src/Magnum/TimeQuery.h

24
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>() {
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<bool>() { return result<UnsignedInt>() != 0; }
#ifndef MAGNUM_TARGET_WEBGL
template<> Int AbstractQuery::result<Int>() {
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<Int>() {
return result;
}
#ifndef MAGNUM_TARGET_WEBGL
template<> UnsignedLong AbstractQuery::result<UnsignedLong>() {
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>() {
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
}

11
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 <Corrade/Containers/Array.h>
#include <Corrade/Utility/Assert.h>
@ -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<class T> 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

35
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 $<TARGET_OBJECTS:MagnumFlextGLObjects>)

4
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 {

4
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});

4
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<FramebufferState> framebuffer;
std::unique_ptr<MeshState> mesh;
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
std::unique_ptr<QueryState> query;
#endif
std::unique_ptr<RendererState> renderer;
std::unique_ptr<ShaderState> shader;
std::unique_ptr<ShaderProgramState> shaderProgram;

10
src/Magnum/PrimitiveQuery.h

@ -59,10 +59,10 @@ if(!q.resultAvailable()) {
// ...or block until the result is available
UnsignedInt primitiveCount = q.result<UnsignedInt>();
@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}
*/

4
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

23
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 <Corrade/Utility/Macros.h>
#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

9
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 <Corrade/Utility/Macros.h>
#endif
#ifndef MAGNUM_TARGET_WEBGL
namespace Magnum {
/**
@ -68,6 +71,7 @@ UnsignedInt timeElapsed2 = q3.result<UnsignedInt>()-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

Loading…
Cancel
Save