Browse Source

ARB_direct_state_access support for creating queries.

With DSA there is slightly different (but completely understandable)
usage -- it's needed to specify the target upon creation, not deferring
it to begin() call. Timestamp queries (TimeQuery::timestamp()) must now
also be created with new TimeQuery::Target::Timestamp target.

The old way (parameterless constructor and begin(Target)) is still
supported, but is marked as deprecated and will be removed in future
release. Also, using the old way the DSA function is simply not used.

Also fixed SampleQuery test to account for cases where the driver might
not support ARB_occlusion_query2.
pull/71/head
Vladimír Vondruš 12 years ago
parent
commit
bfb58d0b55
  1. 66
      src/Magnum/AbstractQuery.cpp
  2. 30
      src/Magnum/AbstractQuery.h
  3. 2
      src/Magnum/CMakeLists.txt
  4. 52
      src/Magnum/Implementation/QueryState.cpp
  5. 44
      src/Magnum/Implementation/QueryState.h
  6. 2
      src/Magnum/Implementation/State.cpp
  7. 2
      src/Magnum/Implementation/State.h
  8. 30
      src/Magnum/PrimitiveQuery.h
  9. 32
      src/Magnum/SampleQuery.h
  10. 35
      src/Magnum/Test/AbstractQueryGLTest.cpp
  11. 4
      src/Magnum/Test/PrimitiveQueryGLTest.cpp
  12. 18
      src/Magnum/Test/SampleQueryGLTest.cpp
  13. 14
      src/Magnum/Test/TimeQueryGLTest.cpp
  14. 42
      src/Magnum/TimeQuery.h

66
src/Magnum/AbstractQuery.cpp

@ -29,19 +29,20 @@
#include "Magnum/Context.h" #include "Magnum/Context.h"
#include "Magnum/Implementation/DebugState.h" #include "Magnum/Implementation/DebugState.h"
#include "Magnum/Implementation/QueryState.h"
#include "Magnum/Implementation/State.h" #include "Magnum/Implementation/State.h"
namespace Magnum { namespace Magnum {
AbstractQuery::AbstractQuery(GLenum target): _target{target} {
(this->*Context::current()->state().query->createImplementation)();
}
#ifdef MAGNUM_BUILD_DEPRECATED
AbstractQuery::AbstractQuery(): _target{} { AbstractQuery::AbstractQuery(): _target{} {
#ifndef MAGNUM_TARGET_GLES2 createImplementationDefault();
glGenQueries(1, &_id);
#elif !defined(CORRADE_TARGET_EMSCRIPTEN)
glGenQueriesEXT(1, &_id);
#else
CORRADE_ASSERT_UNREACHABLE();
#endif
} }
#endif
AbstractQuery::~AbstractQuery() { AbstractQuery::~AbstractQuery() {
/* Moved out, nothing to do */ /* Moved out, nothing to do */
@ -56,6 +57,22 @@ AbstractQuery::~AbstractQuery() {
#endif #endif
} }
void AbstractQuery::createImplementationDefault() {
#ifndef MAGNUM_TARGET_GLES2
glGenQueries(1, &_id);
#elif !defined(CORRADE_TARGET_EMSCRIPTEN)
glGenQueriesEXT(1, &_id);
#else
CORRADE_ASSERT_UNREACHABLE();
#endif
}
#ifndef MAGNUM_TARGET_GLES
void AbstractQuery::createImplementationDSA() {
glCreateQueries(_target, 1, &_id);
}
#endif
std::string AbstractQuery::label() const { std::string AbstractQuery::label() const {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
return Context::current()->state().debug->getLabelImplementation(GL_QUERY, _id); return Context::current()->state().debug->getLabelImplementation(GL_QUERY, _id);
@ -74,8 +91,6 @@ AbstractQuery& AbstractQuery::setLabelInternal(const Containers::ArrayReference<
} }
bool AbstractQuery::resultAvailable() { bool AbstractQuery::resultAvailable() {
CORRADE_ASSERT(!_target, "AbstractQuery::resultAvailable(): the query is currently running", false);
GLuint result; GLuint result;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
glGetQueryObjectuiv(_id, GL_QUERY_RESULT_AVAILABLE, &result); glGetQueryObjectuiv(_id, GL_QUERY_RESULT_AVAILABLE, &result);
@ -89,8 +104,6 @@ bool AbstractQuery::resultAvailable() {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<> UnsignedInt AbstractQuery::result<UnsignedInt>() { template<> UnsignedInt AbstractQuery::result<UnsignedInt>() {
CORRADE_ASSERT(!_target, "AbstractQuery::result(): the query is currently running", {});
UnsignedInt result; UnsignedInt result;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result);
@ -105,8 +118,6 @@ template<> UnsignedInt AbstractQuery::result<UnsignedInt>() {
template<> bool AbstractQuery::result<bool>() { return result<UnsignedInt>() != 0; } template<> bool AbstractQuery::result<bool>() { return result<UnsignedInt>() != 0; }
template<> Int AbstractQuery::result<Int>() { template<> Int AbstractQuery::result<Int>() {
CORRADE_ASSERT(!_target, "AbstractQuery::result(): the query is currently running", {});
Int result; Int result;
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
glGetQueryObjectiv(_id, GL_QUERY_RESULT, &result); glGetQueryObjectiv(_id, GL_QUERY_RESULT, &result);
@ -120,8 +131,6 @@ template<> Int AbstractQuery::result<Int>() {
#ifndef MAGNUM_TARGET_WEBGL #ifndef MAGNUM_TARGET_WEBGL
template<> UnsignedLong AbstractQuery::result<UnsignedLong>() { template<> UnsignedLong AbstractQuery::result<UnsignedLong>() {
CORRADE_ASSERT(!_target, "AbstractQuery::result(): the query is currently running", {});
UnsignedLong result; UnsignedLong result;
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
glGetQueryObjectui64v(_id, GL_QUERY_RESULT, &result); glGetQueryObjectui64v(_id, GL_QUERY_RESULT, &result);
@ -134,8 +143,6 @@ template<> UnsignedLong AbstractQuery::result<UnsignedLong>() {
} }
template<> Long AbstractQuery::result<Long>() { template<> Long AbstractQuery::result<Long>() {
CORRADE_ASSERT(!_target, "AbstractQuery::result(): the query is currently running", {});
Long result; Long result;
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
glGetQueryObjecti64v(_id, GL_QUERY_RESULT, &result); glGetQueryObjecti64v(_id, GL_QUERY_RESULT, &result);
@ -149,21 +156,33 @@ template<> Long AbstractQuery::result<Long>() {
#endif #endif
#endif #endif
void AbstractQuery::begin(const GLenum target) { void AbstractQuery::begin() {
CORRADE_ASSERT(!_target, "AbstractQuery::begin(): the query is already running", ); #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_INTERNAL_ASSERT(_target);
#endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
glBeginQuery(_target = target, _id); glBeginQuery(_target, _id);
#elif !defined(CORRADE_TARGET_EMSCRIPTEN) #elif !defined(CORRADE_TARGET_EMSCRIPTEN)
glBeginQueryEXT(_target = target, _id); glBeginQueryEXT(_target, _id);
#else #else
static_cast<void>(target);
CORRADE_ASSERT_UNREACHABLE(); CORRADE_ASSERT_UNREACHABLE();
#endif #endif
} }
#ifdef MAGNUM_BUILD_DEPRECATED
void AbstractQuery::begin(const GLenum target) {
CORRADE_INTERNAL_ASSERT(!_target || _target == target);
_target = target;
begin();
}
#endif
void AbstractQuery::end() { void AbstractQuery::end() {
CORRADE_ASSERT(_target, "AbstractQuery::end(): the query is not running", ); #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_INTERNAL_ASSERT(_target);
#endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
glEndQuery(_target); glEndQuery(_target);
@ -172,7 +191,6 @@ void AbstractQuery::end() {
#else #else
CORRADE_ASSERT_UNREACHABLE(); CORRADE_ASSERT_UNREACHABLE();
#endif #endif
_target = {};
} }
} }

30
src/Magnum/AbstractQuery.h

@ -37,6 +37,8 @@
namespace Magnum { namespace Magnum {
namespace Implementation { class QueryState; }
/** /**
@brief Base class for queries @brief Base class for queries
@ -45,6 +47,8 @@ more information.
@todo `QUERY_COUNTER_BITS` (not sure since when this is supported) @todo `QUERY_COUNTER_BITS` (not sure since when this is supported)
*/ */
class MAGNUM_EXPORT AbstractQuery: public AbstractObject { class MAGNUM_EXPORT AbstractQuery: public AbstractObject {
friend class Implementation::QueryState;
public: public:
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
AbstractQuery(const AbstractQuery&) = delete; AbstractQuery(const AbstractQuery&) = delete;
@ -120,6 +124,14 @@ class MAGNUM_EXPORT AbstractQuery: public AbstractObject {
*/ */
template<class T> T result(); template<class T> T result();
/**
* @brief Begin query
*
* Begins counting until @ref end() is called.
* @see @fn_gl{BeginQuery}
*/
void begin();
/** /**
* @brief End query * @brief End query
* *
@ -129,14 +141,6 @@ class MAGNUM_EXPORT AbstractQuery: public AbstractObject {
void end(); void end();
protected: protected:
/**
* @brief Constructor
*
* Generates one OpenGL query.
* @see @fn_gl{GenQueries}
*/
explicit AbstractQuery();
/** /**
* @brief Destructor * @brief Destructor
* *
@ -148,11 +152,21 @@ class MAGNUM_EXPORT AbstractQuery: public AbstractObject {
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
private: private:
#endif #endif
explicit AbstractQuery(GLenum target);
#ifdef MAGNUM_BUILD_DEPRECATED
explicit AbstractQuery();
void begin(GLenum target); void begin(GLenum target);
#endif
private: private:
AbstractQuery& setLabelInternal(Containers::ArrayReference<const char> label); AbstractQuery& setLabelInternal(Containers::ArrayReference<const char> label);
void MAGNUM_LOCAL createImplementationDefault();
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL createImplementationDSA();
#endif
GLuint _id; GLuint _id;
GLenum _target; GLenum _target;
}; };

2
src/Magnum/CMakeLists.txt

@ -58,6 +58,7 @@ set(Magnum_SRCS
Implementation/DebugState.cpp Implementation/DebugState.cpp
Implementation/FramebufferState.cpp Implementation/FramebufferState.cpp
Implementation/MeshState.cpp Implementation/MeshState.cpp
Implementation/QueryState.cpp
Implementation/RendererState.cpp Implementation/RendererState.cpp
Implementation/ShaderProgramState.cpp Implementation/ShaderProgramState.cpp
Implementation/State.cpp Implementation/State.cpp
@ -128,6 +129,7 @@ set(Magnum_PRIVATE_HEADERS
Implementation/FramebufferState.h Implementation/FramebufferState.h
Implementation/maxTextureSize.h Implementation/maxTextureSize.h
Implementation/MeshState.h Implementation/MeshState.h
Implementation/QueryState.h
Implementation/RendererState.h Implementation/RendererState.h
Implementation/ShaderProgramState.h Implementation/ShaderProgramState.h
Implementation/ShaderState.h Implementation/ShaderState.h

52
src/Magnum/Implementation/QueryState.cpp

@ -0,0 +1,52 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "QueryState.h"
#include "Magnum/Context.h"
#include "Magnum/Extensions.h"
namespace Magnum { namespace Implementation {
QueryState::QueryState(Context& context, std::vector<std::string>& extensions) {
/* Create implementation */
#ifndef MAGNUM_TARGET_GLES
if(context.isExtensionSupported<Extensions::GL::ARB::direct_state_access>()) {
extensions.push_back(Extensions::GL::ARB::direct_state_access::string());
createImplementation = &AbstractQuery::createImplementationDSA;
} else
#endif
{
createImplementation = &AbstractQuery::createImplementationDefault;
}
#ifdef MAGNUM_TARGET_GLES
static_cast<void>(context);
static_cast<void>(extensions);
#endif
}
}}

44
src/Magnum/Implementation/QueryState.h

@ -0,0 +1,44 @@
#ifndef Magnum_Implementation_QueryState_h
#define Magnum_Implementation_QueryState_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <vector>
#include "Magnum/AbstractQuery.h"
namespace Magnum { namespace Implementation {
struct QueryState {
explicit QueryState(Context& context, std::vector<std::string>& extensions);
void reset();
void(AbstractQuery::*createImplementation)();
};
}}
#endif

2
src/Magnum/Implementation/State.cpp

@ -34,6 +34,7 @@
#include "DebugState.h" #include "DebugState.h"
#include "FramebufferState.h" #include "FramebufferState.h"
#include "MeshState.h" #include "MeshState.h"
#include "QueryState.h"
#include "RendererState.h" #include "RendererState.h"
#include "ShaderState.h" #include "ShaderState.h"
#include "ShaderProgramState.h" #include "ShaderProgramState.h"
@ -55,6 +56,7 @@ State::State(Context& context) {
debug = new DebugState(context, extensions); debug = new DebugState(context, extensions);
framebuffer = new FramebufferState(context, extensions); framebuffer = new FramebufferState(context, extensions);
mesh = new MeshState(context, extensions); mesh = new MeshState(context, extensions);
query = new QueryState(context, extensions);
renderer = new RendererState(context, extensions); renderer = new RendererState(context, extensions);
shader = new ShaderState; shader = new ShaderState;
shaderProgram = new ShaderProgramState(context, extensions); shaderProgram = new ShaderProgramState(context, extensions);

2
src/Magnum/Implementation/State.h

@ -34,6 +34,7 @@ struct BufferState;
struct DebugState; struct DebugState;
struct FramebufferState; struct FramebufferState;
struct MeshState; struct MeshState;
struct QueryState;
struct RendererState; struct RendererState;
struct ShaderState; struct ShaderState;
struct ShaderProgramState; struct ShaderProgramState;
@ -51,6 +52,7 @@ struct State {
DebugState* debug; DebugState* debug;
FramebufferState* framebuffer; FramebufferState* framebuffer;
MeshState* mesh; MeshState* mesh;
QueryState* query;
RendererState* renderer; RendererState* renderer;
ShaderState* shader; ShaderState* shader;
ShaderProgramState* shaderProgram; ShaderProgramState* shaderProgram;

30
src/Magnum/PrimitiveQuery.h

@ -79,18 +79,38 @@ class PrimitiveQuery: public AbstractQuery {
TransformFeedbackPrimitivesWritten = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN TransformFeedbackPrimitivesWritten = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
}; };
explicit PrimitiveQuery() {} #ifdef MAGNUM_BUILD_DEPRECATED
/**
* @copybrief PrimitiveQuery(Target)
* @deprecated Use @ref Magnum::PrimitiveQuery::PrimitiveQuery(Target) "PrimitiveQuery(Target)"
* instead.
*/
CORRADE_DEPRECATED("use PrimitiveQuery(Target) instead") explicit PrimitiveQuery() {}
#endif
/** /**
* @brief Begin query * @brief Constructor
* *
* Begins counting of given @p target until @ref end() is called. * Creates new OpenGL query object. If @extension{ARB,direct_state_access}
* @see @fn_gl{BeginQuery} * (part of OpenGL 4.5) is not supported, the query is created on first
* use.
* @see @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries}
*/
explicit PrimitiveQuery(Target target): AbstractQuery(GLenum(target)) {}
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @copybrief AbstractQuery::begin()
* @deprecated Use @ref Magnum::AbstractQuery::begin() "begin()"
* instead.
*/ */
void begin(Target target) { CORRADE_DEPRECATED("use begin() instead") void begin(Target target) {
AbstractQuery::begin(GLenum(target)); AbstractQuery::begin(GLenum(target));
} }
using AbstractQuery::begin;
#endif
/* Overloads to remove WTF-factor from method chaining order */ /* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
PrimitiveQuery& setLabel(const std::string& label) { PrimitiveQuery& setLabel(const std::string& label) {

32
src/Magnum/SampleQuery.h

@ -172,13 +172,39 @@ class SampleQuery: public AbstractQuery {
}; };
#endif #endif
explicit SampleQuery() {}
/** @copydoc PrimitiveQuery::begin() */ #ifdef MAGNUM_BUILD_DEPRECATED
void begin(Target target) { /**
* @copybrief SampleQuery(Target)
* @deprecated Use @ref Magnum::SampleQuery::SampleQuery(Target) "SampleQuery(Target)"
* instead.
*/
CORRADE_DEPRECATED("use SampleQuery(Target) instead") explicit SampleQuery() {}
#endif
/**
* @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
* use.
* @see @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries}
*/
explicit SampleQuery(Target target): AbstractQuery(GLenum(target)) {}
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @copybrief AbstractQuery::begin()
* @deprecated Use @ref Magnum::AbstractQuery::begin() "begin()"
* instead.
*/
CORRADE_DEPRECATED("use begin() instead") void begin(Target target) {
AbstractQuery::begin(GLenum(target)); AbstractQuery::begin(GLenum(target));
} }
using AbstractQuery::begin;
#endif
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
* @brief Begin conditional rendering based on result value * @brief Begin conditional rendering based on result value

35
src/Magnum/Test/AbstractQueryGLTest.cpp

@ -54,7 +54,11 @@ void AbstractQueryGLTest::construct() {
#endif #endif
{ {
const SampleQuery query; #ifndef MAGNUM_TARGET_GLES
const SampleQuery query{SampleQuery::Target::SamplesPassed};
#else
const SampleQuery query{SampleQuery::Target::AnySamplesPassed};
#endif
MAGNUM_VERIFY_NO_ERROR(); MAGNUM_VERIFY_NO_ERROR();
CORRADE_VERIFY(query.id() > 0); CORRADE_VERIFY(query.id() > 0);
@ -74,7 +78,11 @@ void AbstractQueryGLTest::constructMove() {
CORRADE_SKIP(Extensions::GL::EXT::occlusion_query_boolean::string() + std::string(" is not supported.")); CORRADE_SKIP(Extensions::GL::EXT::occlusion_query_boolean::string() + std::string(" is not supported."));
#endif #endif
SampleQuery a; #ifndef MAGNUM_TARGET_GLES
SampleQuery a{SampleQuery::Target::SamplesPassed};
#else
SampleQuery a{SampleQuery::Target::AnySamplesPassed};
#endif
const Int id = a.id(); const Int id = a.id();
MAGNUM_VERIFY_NO_ERROR(); MAGNUM_VERIFY_NO_ERROR();
@ -85,7 +93,11 @@ void AbstractQueryGLTest::constructMove() {
CORRADE_COMPARE(a.id(), 0); CORRADE_COMPARE(a.id(), 0);
CORRADE_COMPARE(b.id(), id); CORRADE_COMPARE(b.id(), id);
SampleQuery c; #ifndef MAGNUM_TARGET_GLES
SampleQuery c{SampleQuery::Target::SamplesPassed};
#else
SampleQuery c{SampleQuery::Target::AnySamplesPassed};
#endif
const Int cId = c.id(); const Int cId = c.id();
c = std::move(b); c = std::move(b);
@ -106,14 +118,21 @@ void AbstractQueryGLTest::label() {
!Context::current()->isExtensionSupported<Extensions::GL::EXT::debug_label>()) !Context::current()->isExtensionSupported<Extensions::GL::EXT::debug_label>())
CORRADE_SKIP("Required extension is not available"); CORRADE_SKIP("Required extension is not available");
#ifndef MAGNUM_TARGET_GLES
SampleQuery query{SampleQuery::Target::SamplesPassed};
#else
SampleQuery query{SampleQuery::Target::AnySamplesPassed};
#endif
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::direct_state_access>())
#endif
{ {
/** @todo Is this even legal optimization? */ query.begin(); query.end();
CORRADE_EXPECT_FAIL("The object must be used at least once before setting/querying label.");
CORRADE_EXPECT_FAIL("Without ARB_direct_state_access, the object must be used at least once before setting/querying label.");
CORRADE_VERIFY(false); CORRADE_VERIFY(false);
} }
SampleQuery query;
query.begin(SampleQuery::Target::AnySamplesPassed);
query.end();
CORRADE_COMPARE(query.label(), ""); CORRADE_COMPARE(query.label(), "");

4
src/Magnum/Test/PrimitiveQueryGLTest.cpp

@ -94,8 +94,8 @@ void PrimitiveQueryGLTest::query() {
MAGNUM_VERIFY_NO_ERROR(); MAGNUM_VERIFY_NO_ERROR();
PrimitiveQuery q; PrimitiveQuery q{PrimitiveQuery::Target::PrimitivesGenerated};
q.begin(PrimitiveQuery::Target::PrimitivesGenerated); q.begin();
framebuffer.bind(FramebufferTarget::ReadDraw); framebuffer.bind(FramebufferTarget::ReadDraw);
mesh.draw(shader); mesh.draw(shader);

18
src/Magnum/Test/SampleQueryGLTest.cpp

@ -117,12 +117,12 @@ void SampleQueryGLTest::querySamplesPassed() {
MAGNUM_VERIFY_NO_ERROR(); MAGNUM_VERIFY_NO_ERROR();
SampleQuery q;
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
q.begin(SampleQuery::Target::SamplesPassed); SampleQuery q{SampleQuery::Target::SamplesPassed};
#else #else
q.begin(SampleQuery::Target::AnySamplesPassed); SampleQuery q{SampleQuery::Target::AnySamplesPassed};
#endif #endif
q.begin();
framebuffer.bind(FramebufferTarget::ReadDraw); framebuffer.bind(FramebufferTarget::ReadDraw);
mesh.draw(shader); mesh.draw(shader);
@ -167,16 +167,18 @@ void SampleQueryGLTest::conditionalRender() {
MAGNUM_VERIFY_NO_ERROR(); MAGNUM_VERIFY_NO_ERROR();
SampleQuery qYes, qNo, q; SampleQuery qYes{SampleQuery::Target::SamplesPassed},
qNo{SampleQuery::Target::SamplesPassed},
q{SampleQuery::Target::SamplesPassed};
/* This should generate some samples */ /* This should generate some samples */
qYes.begin(SampleQuery::Target::SamplesPassed); qYes.begin();
mesh.draw(shader); mesh.draw(shader);
qYes.end(); qYes.end();
/* Thus this should be rendered */ /* Thus this should be rendered */
qYes.beginConditionalRender(SampleQuery::ConditionalRenderMode::Wait); qYes.beginConditionalRender(SampleQuery::ConditionalRenderMode::Wait);
q.begin(SampleQuery::Target::SamplesPassed); q.begin();
mesh.draw(shader); mesh.draw(shader);
q.end(); q.end();
qYes.endConditionalRender(); qYes.endConditionalRender();
@ -186,12 +188,12 @@ void SampleQueryGLTest::conditionalRender() {
CORRADE_VERIFY(q.result<bool>()); CORRADE_VERIFY(q.result<bool>());
/* This shouldn't generate any samples */ /* This shouldn't generate any samples */
qNo.begin(SampleQuery::Target::SamplesPassed); qNo.begin();
qNo.end(); qNo.end();
/* Thus this should not be rendered */ /* Thus this should not be rendered */
qNo.beginConditionalRender(SampleQuery::ConditionalRenderMode::Wait); qNo.beginConditionalRender(SampleQuery::ConditionalRenderMode::Wait);
q.begin(SampleQuery::Target::SamplesPassed); q.begin();
mesh.draw(shader); mesh.draw(shader);
q.end(); q.end();
qNo.endConditionalRender(); qNo.endConditionalRender();

14
src/Magnum/Test/TimeQueryGLTest.cpp

@ -50,15 +50,15 @@ void TimeQueryGLTest::queryTime() {
CORRADE_SKIP(Extensions::GL::EXT::disjoint_timer_query::string() + std::string(" is not available")); CORRADE_SKIP(Extensions::GL::EXT::disjoint_timer_query::string() + std::string(" is not available"));
#endif #endif
TimeQuery q1; TimeQuery q1{TimeQuery::Target::TimeElapsed};
q1.begin(TimeQuery::Target::TimeElapsed); q1.begin();
q1.end(); q1.end();
const auto result1 = q1.result<UnsignedInt>(); const auto result1 = q1.result<UnsignedInt>();
MAGNUM_VERIFY_NO_ERROR(); MAGNUM_VERIFY_NO_ERROR();
TimeQuery q2; TimeQuery q2{TimeQuery::Target::TimeElapsed};
q2.begin(TimeQuery::Target::TimeElapsed); q2.begin();
Renderer::enable(Renderer::Feature::Blending); Renderer::enable(Renderer::Feature::Blending);
Renderer::finish(); Renderer::finish();
q2.end(); q2.end();
@ -74,11 +74,13 @@ void TimeQueryGLTest::queryTimestamp() {
CORRADE_SKIP(Extensions::GL::EXT::disjoint_timer_query::string() + std::string(" is not available")); CORRADE_SKIP(Extensions::GL::EXT::disjoint_timer_query::string() + std::string(" is not available"));
#endif #endif
TimeQuery q1, q2, q; TimeQuery q1{TimeQuery::Target::Timestamp},
q2{TimeQuery::Target::Timestamp},
q{TimeQuery::Target::TimeElapsed};
q1.timestamp(); q1.timestamp();
q.begin(TimeQuery::Target::TimeElapsed); q.begin();
Renderer::enable(Renderer::Feature::Blending); Renderer::enable(Renderer::Feature::Blending);
Renderer::finish(); Renderer::finish();
q.end(); q.end();

42
src/Magnum/TimeQuery.h

@ -75,13 +75,37 @@ class TimeQuery: public AbstractQuery {
enum class Target: GLenum { enum class Target: GLenum {
/** Elapsed time */ /** Elapsed time */
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
TimeElapsed = GL_TIME_ELAPSED TimeElapsed = GL_TIME_ELAPSED,
#else #else
TimeElapsed = GL_TIME_ELAPSED_EXT TimeElapsed = GL_TIME_ELAPSED_EXT,
#endif
/** Timestamp (for use with @ref timestamp() only) */
#ifndef MAGNUM_TARGET_GLES
Timestamp = GL_TIMESTAMP
#else
Timestamp = GL_TIMESTAMP_EXT
#endif #endif
}; };
explicit TimeQuery() {} #ifdef MAGNUM_BUILD_DEPRECATED
/**
* @copybrief TimeQuery(Target)
* @deprecated Use @ref Magnum::TimeQuery::TimeQuery(Target) "TimeQuery(Target)"
* instead.
*/
CORRADE_DEPRECATED("use TimeQuery(Target) instead") explicit TimeQuery() {}
#endif
/**
* @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
* use.
* @see @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries}
*/
explicit TimeQuery(Target target): AbstractQuery(GLenum(target)) {}
/** /**
* @brief Query timestamp * @brief Query timestamp
@ -98,11 +122,19 @@ class TimeQuery: public AbstractQuery {
#endif #endif
} }
/** @copydoc PrimitiveQuery::begin() */ #ifdef MAGNUM_BUILD_DEPRECATED
void begin(Target target) { /**
* @copybrief AbstractQuery::begin()
* @deprecated Use @ref Magnum::AbstractQuery::begin() "begin()"
* instead.
*/
CORRADE_DEPRECATED("use begin() instead") void begin(Target target) {
AbstractQuery::begin(GLenum(target)); AbstractQuery::begin(GLenum(target));
} }
using AbstractQuery::begin;
#endif
/* Overloads to remove WTF-factor from method chaining order */ /* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
TimeQuery& setLabel(const std::string& label) { TimeQuery& setLabel(const std::string& label) {

Loading…
Cancel
Save