Browse Source

Support for EXT_disjoint_timer_query ES2 extension.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
06a8341e9b
  1. 1
      src/Context.cpp
  2. 1
      src/Extensions.h
  3. 54
      src/Query.cpp
  4. 24
      src/Query.h

1
src/Context.cpp

@ -210,6 +210,7 @@ const std::vector<Extension>& Extension::extensions(Version version) {
_extension(GL,EXT,texture_format_BGRA8888),
_extension(GL,EXT,read_format_bgra),
_extension(GL,EXT,debug_marker),
_extension(GL,EXT,disjoint_timer_query),
_extension(GL,EXT,separate_shader_objects),
_extension(GL,EXT,sRGB),
_extension(GL,EXT,robustness),

1
src/Extensions.h

@ -208,6 +208,7 @@ namespace GL {
_extension(GL,EXT,robustness, GLES200, None) // #105
_extension(GL,EXT,texture_storage, GLES200, GLES300) // #108
_extension(GL,EXT,map_buffer_range, GLES200, GLES300) // #121
_extension(GL,EXT,disjoint_timer_query, GLES200, None) // #150
} namespace NV {
_extension(GL,NV,draw_buffers, GLES200, GLES300) // #91
_extension(GL,NV,read_buffer, GLES200, GLES300) // #93

54
src/Query.cpp

@ -32,6 +32,9 @@ AbstractQuery::AbstractQuery(): target() {
/** @todo Get some extension wrangler instead to avoid undeclared glGenQueries() on ES2 */
#ifndef MAGNUM_TARGET_GLES2
glGenQueries(1, &_id);
#else
CORRADE_INTERNAL_ASSERT(false);
//glGenQueriesEXT(1, &_id);
#endif
}
@ -39,6 +42,9 @@ AbstractQuery::~AbstractQuery() {
/** @todo Get some extension wrangler instead to avoid undeclared glGenQueries() on ES2 */
#ifndef MAGNUM_TARGET_GLES2
glDeleteQueries(1, &_id);
#else
CORRADE_INTERNAL_ASSERT(false);
//glDeleteQueriesEXT(1, &_id);
#endif
}
@ -46,13 +52,14 @@ bool AbstractQuery::resultAvailable() {
CORRADE_ASSERT(!target, "AbstractQuery::resultAvailable(): the query is currently running", false);
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
GLuint result;
#ifndef MAGNUM_TARGET_GLES2
glGetQueryObjectuiv(_id, GL_QUERY_RESULT_AVAILABLE, &result);
return result == GL_TRUE;
#else
return false;
CORRADE_INTERNAL_ASSERT(false);
//glGetQueryObjectuivEXT(_id, GL_QUERY_RESULT_AVAILABLE, &result);
#endif
return result == GL_TRUE;
}
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -60,50 +67,70 @@ template<> bool AbstractQuery::result<bool>() {
CORRADE_ASSERT(!target, "AbstractQuery::result(): the query is currently running", {});
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
GLuint result;
#ifndef MAGNUM_TARGET_GLES2
glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result);
return result == GL_TRUE;
#else
return false;
CORRADE_INTERNAL_ASSERT(false);
//glGetQueryObjectuivEXT(_id, GL_QUERY_RESULT, &result);
#endif
return result == GL_TRUE;
}
template<> UnsignedInt AbstractQuery::result<UnsignedInt>() {
CORRADE_ASSERT(!target, "AbstractQuery::result(): the query is currently running", {});
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
UnsignedInt result;
#ifndef MAGNUM_TARGET_GLES2
glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result);
return result;
#else
return 0;
CORRADE_INTERNAL_ASSERT(false);
//glGetQueryObjectuivEXT(_id, GL_QUERY_RESULT, &result);
#endif
return result;
}
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES3
template<> Int AbstractQuery::result<Int>() {
CORRADE_ASSERT(!target, "AbstractQuery::result(): the query is currently running", {});
/** @todo Re-enable when extension wrangler is available for ES */
Int result;
#ifndef MAGNUM_TARGET_GLES2
glGetQueryObjectiv(_id, GL_QUERY_RESULT, &result);
#else
CORRADE_INTERNAL_ASSERT(false);
//glGetQueryObjectivEXT(_id, GL_QUERY_RESULT, &result);
#endif
return result;
}
template<> UnsignedLong AbstractQuery::result<UnsignedLong>() {
CORRADE_ASSERT(!target, "AbstractQuery::result(): the query is currently running", {});
/** @todo Re-enable when extension wrangler is available for ES */
UnsignedLong result;
#ifndef MAGNUM_TARGET_GLES2
glGetQueryObjectui64v(_id, GL_QUERY_RESULT, &result);
#else
CORRADE_INTERNAL_ASSERT(false);
//glGetQueryObjectui64vEXT(_id, GL_QUERY_RESULT, &result);
#endif
return result;
}
template<> Long AbstractQuery::result<Long>() {
CORRADE_ASSERT(!target, "AbstractQuery::result(): the query is currently running", {});
/** @todo Re-enable when extension wrangler is available for ES */
Long result;
#ifndef MAGNUM_TARGET_GLES2
glGetQueryObjecti64v(_id, GL_QUERY_RESULT, &result);
#else
CORRADE_INTERNAL_ASSERT(false);
//glGetQueryObjecti64vEXT(_id, GL_QUERY_RESULT, &result);
#endif
return result;
}
#endif
@ -115,6 +142,10 @@ void AbstractQuery::begin(GLenum target) {
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
glBeginQuery(this->target = target, id());
#else
CORRADE_INTERNAL_ASSERT(false);
static_cast<void>(target);
//glBeginQueryEXT(this->target = target, id());
#endif
}
@ -124,6 +155,9 @@ void AbstractQuery::end() {
/** @todo Re-enable when extension wrangler is available for ES */
#ifndef MAGNUM_TARGET_GLES2
glEndQuery(target);
#else
CORRADE_INTERNAL_ASSERT(false);
//glEndQueryEXT(target);
#endif
target = {};
}

24
src/Query.h

@ -28,6 +28,8 @@
* @brief Class Magnum::AbstractQuery, Magnum::PrimitiveQuery, Magnum::SampleQuery, Magnum::TimeQuery
*/
#include <Utility/Assert.h>
#include "OpenGL.h"
#include "Types.h"
#include "magnumConfigure.h"
@ -84,8 +86,9 @@ class MAGNUM_EXPORT AbstractQuery {
* @requires_gl33 %Extension @extension{ARB,timer_query} (result type
* @ref Magnum::UnsignedInt "UnsignedInt" and @ref Magnum::Long
* "Long")
* @requires_gl Result types @ref Magnum::Int "Int", @ref Magnum::UnsignedLong "UnsignedLong"
* and @ref Magnum::Long "Long" are not available in OpenGL ES.
* @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".
*/
template<class T> T result();
@ -114,7 +117,7 @@ class MAGNUM_EXPORT AbstractQuery {
#ifndef DOXYGEN_GENERATING_OUTPUT
template<> bool MAGNUM_EXPORT AbstractQuery::result<bool>();
template<> UnsignedInt MAGNUM_EXPORT AbstractQuery::result<UnsignedInt>();
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES3
template<> Int MAGNUM_EXPORT AbstractQuery::result<Int>();
template<> UnsignedLong MAGNUM_EXPORT AbstractQuery::result<UnsignedLong>();
template<> Long MAGNUM_EXPORT AbstractQuery::result<Long>();
@ -310,7 +313,7 @@ class SampleQuery: public AbstractQuery {
#endif
};
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES3
/**
@brief Query for elapsed time
@ -341,15 +344,20 @@ UnsignedInt timeElapsed2 = q3.result<UnsignedInt>()-tmp;
@endcode
Using the latter results in fewer OpenGL calls when doing more measures.
@requires_gl33 %Extension @extension{ARB,timer_query}
@requires_gl Timer query is not available in OpenGL ES.
@requires_es_extension %Extension @es_extension{EXT,disjoint_timer_query}
@todo timestamp with glGet + example usage
@todo @es_extension{EXT,disjoint_timer_query} -- GL_GPU_DISJOINT_EXT support? where?
*/
class TimeQuery: public AbstractQuery {
public:
/** @brief Query target */
enum class Target: GLenum {
/** Elapsed time */
#ifndef MAGNUM_TARGET_GLES
TimeElapsed = GL_TIME_ELAPSED
#else
TimeElapsed = GL_TIME_ELAPSED_EXT
#endif
};
/**
@ -358,7 +366,13 @@ class TimeQuery: public AbstractQuery {
* @see @fn_gl{QueryCounter} with @def_gl{TIMESTAMP}
*/
inline void timestamp() {
/** @todo Enable when extension wrangler for ES is available */
#ifndef MAGNUM_TARGET_GLES
glQueryCounter(id(), GL_TIMESTAMP);
#else
//glQueryCounterEXT(id(), GL_TIMESTAMP);
CORRADE_INTERNAL_ASSERT(false);
#endif
}
/** @copydoc PrimitiveQuery::begin() */

Loading…
Cancel
Save