Browse Source

Split Query into PrimitiveQuery and TimeQuery.

It's better to group the queries on functionality and not common code.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
5f00a1926d
  1. 27
      src/Query.cpp
  2. 63
      src/Query.h

27
src/Query.cpp

@ -96,16 +96,16 @@ template<> Long AbstractQuery::result<Long>() {
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
Query::Query(): target(nullptr) {} PrimitiveQuery::PrimitiveQuery(): target(nullptr) {}
Query::~Query() { delete target; } PrimitiveQuery::~PrimitiveQuery() { delete target; }
void Query::begin(Query::Target target) { void PrimitiveQuery::begin(Target target) {
glBeginQuery(static_cast<GLenum>(target), id()); glBeginQuery(static_cast<GLenum>(target), id());
this->target = new Target(target); this->target = new Target(target);
} }
void Query::end() { void PrimitiveQuery::end() {
if(!target) return; if(!target) return;
glEndQuery(static_cast<GLenum>(*target)); glEndQuery(static_cast<GLenum>(*target));
@ -118,7 +118,7 @@ SampleQuery::SampleQuery(): target(nullptr) {}
SampleQuery::~SampleQuery() { delete target; } SampleQuery::~SampleQuery() { delete target; }
void SampleQuery::begin(SampleQuery::Target target) { void SampleQuery::begin(Target target) {
/** @todo Re-enable when extension wrangler is available for ES */ /** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
glBeginQuery(static_cast<GLenum>(target), id()); glBeginQuery(static_cast<GLenum>(target), id());
@ -138,7 +138,22 @@ void SampleQuery::end() {
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
TimeQuery::TimeQuery() = default; TimeQuery::TimeQuery(): target(nullptr) {}
TimeQuery::~TimeQuery() { delete target; }
void TimeQuery::begin(Target target) {
glBeginQuery(static_cast<GLenum>(target), id());
this->target = new Target(target);
}
void TimeQuery::end() {
if(!target) return;
glEndQuery(static_cast<GLenum>(*target));
delete target;
target = nullptr;
}
#endif #endif
} }

63
src/Query.h

@ -37,7 +37,8 @@ namespace Magnum {
/** /**
@brief Base class for queries @brief Base class for queries
See Query, SampleQuery, TimeQuery documentation for more information. See PrimitiveQuery, SampleQuery and TimeQuery documentation for more
information.
@todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object})
@requires_gles30 %Extension @es_extension{EXT,occlusion_query_boolean} @requires_gles30 %Extension @es_extension{EXT,occlusion_query_boolean}
*/ */
@ -102,7 +103,7 @@ template<> Long MAGNUM_EXPORT AbstractQuery::result<Long>();
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
/** /**
@brief %Query for primitives and elapsed time @brief Query for primitives and elapsed time
Queries count of generated primitives from vertex shader, geometry shader or Queries count of generated primitives from vertex shader, geometry shader or
transform feedback and elapsed time. Example usage: transform feedback and elapsed time. Example usage:
@ -123,9 +124,9 @@ UnsignedInt primitiveCount = q.result<UnsignedInt>();
@requires_gl30 %Extension @extension{EXT,transform_feedback} @requires_gl30 %Extension @extension{EXT,transform_feedback}
@requires_gles30 Only sample queries are available on OpenGL ES 2.0. @requires_gles30 Only sample queries are available on OpenGL ES 2.0.
*/ */
class MAGNUM_EXPORT Query: public AbstractQuery { class MAGNUM_EXPORT PrimitiveQuery: public AbstractQuery {
public: public:
/** @brief %Query target */ /** @brief Query target */
enum Target: GLenum { enum Target: GLenum {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
@ -139,23 +140,11 @@ class MAGNUM_EXPORT Query: public AbstractQuery {
/** Count of primitives written to transform feedback buffer. */ /** Count of primitives written to transform feedback buffer. */
TransformFeedbackPrimitivesWritten = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN TransformFeedbackPrimitivesWritten = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
#ifndef MAGNUM_TARGET_GLES
,
/**
* Elapsed time
* @requires_gl33 %Extension @extension{ARB,timer_query}
* @requires_gl Only transform feedback query is available in
* OpenGL ES.
*/
TimeElapsed = GL_TIME_ELAPSED
#endif
}; };
explicit Query(); explicit PrimitiveQuery();
~Query(); ~PrimitiveQuery();
/** /**
* @brief Begin query * @brief Begin query
@ -179,7 +168,7 @@ class MAGNUM_EXPORT Query: public AbstractQuery {
#endif #endif
/** /**
@brief %Query for samples @brief Query for samples
Queries count of samples passed from fragment shader or boolean value Queries count of samples passed from fragment shader or boolean value
indicating whether any samples passed. Can be used for example for conditional indicating whether any samples passed. Can be used for example for conditional
@ -216,7 +205,7 @@ q.endConditionalRender();
*/ */
class MAGNUM_EXPORT SampleQuery: public AbstractQuery { class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
public: public:
/** @brief %Query target */ /** @brief Query target */
enum Target: GLenum { enum Target: GLenum {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
@ -288,10 +277,10 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
~SampleQuery(); ~SampleQuery();
/** @copydoc Query::begin() */ /** @copydoc PrimitiveQuery::begin() */
void begin(Target target); void begin(Target target);
/** @copydoc Query::end() */ /** @copydoc PrimitiveQuery::end() */
void end(); void end();
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -324,14 +313,13 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
@brief %Query for elapsed time @brief Query for elapsed time
Queries timestamp after all previous OpenGL calls have been processed. It is Queries timestamp after all previous OpenGL calls have been processed. It can
similar to @ref Query::Target "Query::Target::TimeElapsed" query, but this query either duration of sequence of commands or absolute timestamp. Example
query just retrieves timestamp, not time duration between Query::begin() and usage of both methods:
Query::end() calls. Example usage, compared to @ref Query::Target "Query::Target::TimeElapsed":
@code @code
Query q1, q2; TimeQuery q1, q2;
q1.begin(Query::Target::TimeElapsed); q1.begin(Query::Target::TimeElapsed);
// rendering... // rendering...
q1.end(); q1.end();
@ -352,15 +340,23 @@ UnsignedInt tmp = q2.result<UnsignedInt>();
UnsignedInt timeElapsed1 = tmp-q1.result<UnsignedInt>(); UnsignedInt timeElapsed1 = tmp-q1.result<UnsignedInt>();
UnsignedInt timeElapsed2 = q3.result<UnsignedInt>()-tmp; UnsignedInt timeElapsed2 = q3.result<UnsignedInt>()-tmp;
@endcode @endcode
Using this query results in fewer OpenGL calls when doing more measures. Using the latter results in fewer OpenGL calls when doing more measures.
@requires_gl33 %Extension @extension{ARB,timer_query} @requires_gl33 %Extension @extension{ARB,timer_query}
@requires_gl Timer query is not available in OpenGL ES. @requires_gl Timer query is not available in OpenGL ES.
@todo timestamp with glGet + example usage @todo timestamp with glGet + example usage
*/ */
class TimeQuery: public AbstractQuery { class TimeQuery: public AbstractQuery {
public: public:
/** @brief Query target */
enum class Target: GLenum {
/** Elapsed time */
TimeElapsed = GL_TIME_ELAPSED
};
explicit TimeQuery(); explicit TimeQuery();
~TimeQuery();
/** /**
* @brief Query timestamp * @brief Query timestamp
* *
@ -369,6 +365,15 @@ class TimeQuery: public AbstractQuery {
inline void timestamp() { inline void timestamp() {
glQueryCounter(id(), GL_TIMESTAMP); glQueryCounter(id(), GL_TIMESTAMP);
} }
/** @copydoc PrimitiveQuery::begin() */
void begin(Target target);
/** @copydoc PrimitiveQuery::end() */
void end();
private:
Target* target;
}; };
#endif #endif

Loading…
Cancel
Save