Browse Source

Updated OpenGL ES support in queries.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
4bfc745970
  1. 25
      src/Query.cpp
  2. 25
      src/Query.h

25
src/Query.cpp

@ -17,23 +17,37 @@
namespace Magnum { namespace Magnum {
#ifndef MAGNUM_TARGET_GLES2
bool AbstractQuery::resultAvailable() { bool AbstractQuery::resultAvailable() {
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
GLuint result; GLuint result;
glGetQueryObjectuiv(_id, GL_QUERY_RESULT_AVAILABLE, &result); glGetQueryObjectuiv(_id, GL_QUERY_RESULT_AVAILABLE, &result);
return result == GL_TRUE; return result == GL_TRUE;
#else
return false;
#endif
} }
template<> bool AbstractQuery::result<bool>() { template<> bool AbstractQuery::result<bool>() {
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
GLuint result; GLuint result;
glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result);
return result == GL_TRUE; return result == GL_TRUE;
#else
return false;
#endif
} }
template<> GLuint AbstractQuery::result<GLuint>() { template<> GLuint AbstractQuery::result<GLuint>() {
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
GLuint result; GLuint result;
glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result);
return result; return result;
#else
return 0;
#endif
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -56,6 +70,7 @@ template<> GLint64 AbstractQuery::result<GLint64>() {
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2
void Query::begin(Query::Target target) { void Query::begin(Query::Target target) {
glBeginQuery(static_cast<GLenum>(target), id()); glBeginQuery(static_cast<GLenum>(target), id());
this->target = new Target(target); this->target = new Target(target);
@ -68,19 +83,25 @@ void Query::end() {
delete target; delete target;
target = nullptr; target = nullptr;
} }
#endif
void SampleQuery::begin(SampleQuery::Target target) { void SampleQuery::begin(SampleQuery::Target target) {
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
glBeginQuery(static_cast<GLenum>(target), id()); glBeginQuery(static_cast<GLenum>(target), id());
#endif
this->target = new Target(target); this->target = new Target(target);
} }
void SampleQuery::end() { void SampleQuery::end() {
if(!target) return; if(!target) return;
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
glEndQuery(static_cast<GLenum>(*target)); glEndQuery(static_cast<GLenum>(*target));
#endif
delete target; delete target;
target = nullptr; target = nullptr;
} }
#endif
} }

25
src/Query.h

@ -25,13 +25,12 @@
namespace Magnum { namespace Magnum {
#ifndef MAGNUM_TARGET_GLES2
/** /**
@brief Base class for queries @brief Base class for queries
See Query, SampleQuery, TimeQuery documentation for more information. See Query, SampleQuery, 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 (no extension providing this functionality) @requires_gles30 %Extension @es_extension{EXT,occlusion_query_boolean}
*/ */
class MAGNUM_EXPORT AbstractQuery { class MAGNUM_EXPORT AbstractQuery {
public: public:
@ -69,8 +68,9 @@ class MAGNUM_EXPORT AbstractQuery {
* Note that this function is blocking until the result is available. * Note that this function is blocking until the result is available.
* See resultAvailable(). * See resultAvailable().
* @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT} * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT}
* @requires_gl Result type `GLint`, `GLuint64`, `GLint64`
* @requires_gl33 Extension @extension{ARB,timer_query} (result type `GLuint64` and `GLint64`) * @requires_gl33 Extension @extension{ARB,timer_query} (result type `GLuint64` and `GLint64`)
* @requires_gl Result types @c GLint, @c GLuint64 and @c GLint64 are
* not available in OpenGL ES.
*/ */
template<class T> T result(); template<class T> T result();
@ -87,7 +87,6 @@ template<> GLint MAGNUM_EXPORT AbstractQuery::result<GLint>();
template<> GLuint64 MAGNUM_EXPORT AbstractQuery::result<GLuint64>(); template<> GLuint64 MAGNUM_EXPORT AbstractQuery::result<GLuint64>();
template<> GLint64 MAGNUM_EXPORT AbstractQuery::result<GLint64>(); template<> GLint64 MAGNUM_EXPORT AbstractQuery::result<GLint64>();
#endif #endif
#endif
/** /**
@brief %Query for primitives and elapsed time @brief %Query for primitives and elapsed time
@ -109,7 +108,7 @@ if(!q.resultAvailable()) {
GLuint primitiveCount = q.result<GLuint>(); GLuint primitiveCount = q.result<GLuint>();
@endcode @endcode
@requires_gl30 Extension @extension{EXT,transform_feedback} @requires_gl30 Extension @extension{EXT,transform_feedback}
@requires_gles30 (no extension providing this functionality) @requires_gles30 Only sample queries are available on OpenGL ES 2.0.
*/ */
class MAGNUM_EXPORT Query: public AbstractQuery { class MAGNUM_EXPORT Query: public AbstractQuery {
public: public:
@ -119,7 +118,8 @@ class MAGNUM_EXPORT Query: public AbstractQuery {
/** /**
* Count of primitives generated from vertex shader or geometry * Count of primitives generated from vertex shader or geometry
* shader. * shader.
* @requires_gl * @requires_gl Only transform feedback query is available in
* OpenGL ES.
*/ */
PrimitivesGenerated = GL_PRIMITIVES_GENERATED, PrimitivesGenerated = GL_PRIMITIVES_GENERATED,
#endif #endif
@ -132,8 +132,9 @@ class MAGNUM_EXPORT Query: public AbstractQuery {
/** /**
* Elapsed time * Elapsed time
* @requires_gl
* @requires_gl33 Extension @extension{ARB,timer_query} * @requires_gl33 Extension @extension{ARB,timer_query}
* @requires_gl Only transform feedback query is available in
* OpenGL ES.
*/ */
TimeElapsed = GL_TIME_ELAPSED TimeElapsed = GL_TIME_ELAPSED
#endif #endif
@ -197,7 +198,7 @@ q.beginConditionalRender(SampleQuery::ConditionalRenderMode::Wait);
// render full version of the object only if the query returns nonzero result // render full version of the object only if the query returns nonzero result
q.endConditionalRender(); q.endConditionalRender();
@endcode @endcode
@requires_gles30 (no extension providing this functionality) @requires_gles30 %Extension @es_extension{EXT,occlusion_query_boolean}
*/ */
class MAGNUM_EXPORT SampleQuery: public AbstractQuery { class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
public: public:
@ -206,7 +207,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
* Count of samples passed from fragment shader * Count of samples passed from fragment shader
* @requires_gl * @requires_gl Only boolean query is available in OpenGL ES.
*/ */
SamplesPassed = GL_SAMPLES_PASSED, SamplesPassed = GL_SAMPLES_PASSED,
#endif #endif
@ -231,8 +232,8 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
/** /**
* @brief Conditional render mode * @brief Conditional render mode
* *
* @requires_gl
* @requires_gl30 Extension @extension{NV,conditional_render} * @requires_gl30 Extension @extension{NV,conditional_render}
* @requires_gl Conditional rendering is not available in OpenGL ES.
*/ */
enum class ConditionalRenderMode: GLenum { enum class ConditionalRenderMode: GLenum {
/** /**
@ -277,6 +278,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
* *
* @see @fn_gl{BeginConditionalRender} * @see @fn_gl{BeginConditionalRender}
* @requires_gl30 Extension @extension{NV,conditional_render} * @requires_gl30 Extension @extension{NV,conditional_render}
* @requires_gl Conditional rendering is not available in OpenGL ES.
*/ */
inline void beginConditionalRender(ConditionalRenderMode mode) { inline void beginConditionalRender(ConditionalRenderMode mode) {
glBeginConditionalRender(id(), static_cast<GLenum>(mode)); glBeginConditionalRender(id(), static_cast<GLenum>(mode));
@ -287,6 +289,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
* *
* @see @fn_gl{EndConditionalRender} * @see @fn_gl{EndConditionalRender}
* @requires_gl30 Extension @extension{NV,conditional_render} * @requires_gl30 Extension @extension{NV,conditional_render}
* @requires_gl Conditional rendering is not available in OpenGL ES.
*/ */
inline void endConditionalRender() { inline void endConditionalRender() {
glEndConditionalRender(); glEndConditionalRender();
@ -328,8 +331,8 @@ GLuint timeElapsed1 = tmp-q1.result<GLuint>();
GLuint timeElapsed2 = q3.result<GLuint>()-tmp; GLuint timeElapsed2 = q3.result<GLuint>()-tmp;
@endcode @endcode
Using this query results in fewer OpenGL calls when doing more measures. Using this query results in fewer OpenGL calls when doing more measures.
@requires_gl
@requires_gl33 Extension @extension{ARB,timer_query} @requires_gl33 Extension @extension{ARB,timer_query}
@requires_gl Timer query is not available in OpenGL ES.
*/ */
class TimeQuery: public AbstractQuery { class TimeQuery: public AbstractQuery {
public: public:

Loading…
Cancel
Save