Browse Source

Queries (except for timing ones) are available in OpenGL ES 3.0.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
7a066672cd
  1. 4
      src/Query.cpp
  2. 47
      src/Query.h

4
src/Query.cpp

@ -17,7 +17,6 @@
namespace Magnum { namespace Magnum {
#ifndef MAGNUM_TARGET_GLES
bool AbstractQuery::resultAvailable() { bool AbstractQuery::resultAvailable() {
GLuint result; GLuint result;
glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &result); glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &result);
@ -36,6 +35,7 @@ template<> GLuint AbstractQuery::result<GLuint>() {
return result; return result;
} }
#ifndef MAGNUM_TARGET_GLES
template<> GLint AbstractQuery::result<GLint>() { template<> GLint AbstractQuery::result<GLint>() {
GLint result; GLint result;
glGetQueryObjectiv(query, GL_QUERY_RESULT, &result); glGetQueryObjectiv(query, GL_QUERY_RESULT, &result);
@ -53,6 +53,7 @@ template<> GLint64 AbstractQuery::result<GLint64>() {
glGetQueryObjecti64v(query, GL_QUERY_RESULT, &result); glGetQueryObjecti64v(query, GL_QUERY_RESULT, &result);
return result; return result;
} }
#endif
void Query::begin(Query::Target target) { void Query::begin(Query::Target target) {
glBeginQuery(static_cast<GLenum>(target), query); glBeginQuery(static_cast<GLenum>(target), query);
@ -79,6 +80,5 @@ void SampleQuery::end() {
delete target; delete target;
target = nullptr; target = nullptr;
} }
#endif
} }

47
src/Query.h

@ -25,13 +25,12 @@
namespace Magnum { namespace Magnum {
#ifndef MAGNUM_TARGET_GLES
/** /**
@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_gl @requires_gles30 (no extension providing this functionality)
*/ */
class MAGNUM_EXPORT AbstractQuery { class MAGNUM_EXPORT AbstractQuery {
public: public:
@ -66,6 +65,7 @@ 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`)
*/ */
template<class T> T result(); template<class T> T result();
@ -78,10 +78,12 @@ class MAGNUM_EXPORT AbstractQuery {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<> bool MAGNUM_EXPORT AbstractQuery::result<bool>(); template<> bool MAGNUM_EXPORT AbstractQuery::result<bool>();
template<> GLuint MAGNUM_EXPORT AbstractQuery::result<GLuint>(); template<> GLuint MAGNUM_EXPORT AbstractQuery::result<GLuint>();
#ifndef MAGNUM_TARGET_GLES
template<> GLint MAGNUM_EXPORT AbstractQuery::result<GLint>(); 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
@ -102,28 +104,35 @@ if(!q.resultAvailable()) {
// ...or block until the result is available // ...or block until the result is available
GLuint primitiveCount = q.result<GLuint>(); GLuint primitiveCount = q.result<GLuint>();
@endcode @endcode
@requires_gl
@requires_gl30 Extension @extension{EXT,transform_feedback} @requires_gl30 Extension @extension{EXT,transform_feedback}
@requires_gles30 (no extension providing this functionality)
*/ */
class MAGNUM_EXPORT Query: public AbstractQuery { class MAGNUM_EXPORT Query: public AbstractQuery {
public: public:
/** @brief %Query target */ /** @brief %Query target */
enum Target: GLenum { enum Target: GLenum {
#ifndef MAGNUM_TARGET_GLES
/** /**
* Count of primitives generated from vertex shader or geometry * Count of primitives generated from vertex shader or geometry
* shader. * shader.
* @requires_gl
*/ */
PrimitivesGenerated = GL_PRIMITIVES_GENERATED, PrimitivesGenerated = GL_PRIMITIVES_GENERATED,
#endif
/** 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 * Elapsed time
* * @requires_gl
* @requires_gl33 Extension @extension{ARB,timer_query} * @requires_gl33 Extension @extension{ARB,timer_query}
*/ */
TimeElapsed = GL_TIME_ELAPSED TimeElapsed = GL_TIME_ELAPSED
#endif
}; };
inline Query(): target(nullptr) {} inline Query(): target(nullptr) {}
@ -184,26 +193,41 @@ 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_gl @requires_gles30 (no extension providing this functionality)
*/ */
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 {
/** Count of samples passed from fragment shader */ #ifndef MAGNUM_TARGET_GLES
/**
* Count of samples passed from fragment shader
* @requires_gl
*/
SamplesPassed = GL_SAMPLES_PASSED, SamplesPassed = GL_SAMPLES_PASSED,
#endif
/** /**
* Whether any samples passed from fragment shader * Whether any samples passed from fragment shader
*
* @requires_gl33 Extension @extension{ARB,occlusion_query2} * @requires_gl33 Extension @extension{ARB,occlusion_query2}
*/ */
AnySamplesPassed = GL_ANY_SAMPLES_PASSED AnySamplesPassed = GL_ANY_SAMPLES_PASSED,
/**
* Whether any samples passed from fragment shader (conservative)
*
* An implementation may choose a less precise version of the
* test at the expense of some false positives.
* @requires_gl43 Extension @extension{ARB,ES3_compatibility}
*/
AnySamplesPassedConservative = GL_ANY_SAMPLES_PASSED_CONSERVATIVE
}; };
#ifndef MAGNUM_TARGET_GLES
/** /**
* @brief Conditional render mode * @brief Conditional render mode
* *
* @requires_gl
* @requires_gl30 Extension @extension{NV,conditional_render} * @requires_gl30 Extension @extension{NV,conditional_render}
*/ */
enum class ConditionalRenderMode: GLenum { enum class ConditionalRenderMode: GLenum {
@ -231,6 +255,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
*/ */
ByRegionNoWait = GL_QUERY_BY_REGION_NO_WAIT ByRegionNoWait = GL_QUERY_BY_REGION_NO_WAIT
}; };
#endif
inline SampleQuery(): target(nullptr) {} inline SampleQuery(): target(nullptr) {}
@ -242,6 +267,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
/** @copydoc Query::end() */ /** @copydoc Query::end() */
void end(); void end();
#ifndef MAGNUM_TARGET_GLES
/** /**
* @brief Begin conditional rendering based on result value * @brief Begin conditional rendering based on result value
* *
@ -261,11 +287,13 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery {
inline void endConditionalRender() { inline void endConditionalRender() {
glEndConditionalRender(); glEndConditionalRender();
} }
#endif
private: private:
Target* target; Target* target;
}; };
#ifndef MAGNUM_TARGET_GLES
/** /**
@brief %Query for elapsed time @brief %Query for elapsed time
@ -310,7 +338,6 @@ class TimeQuery: public AbstractQuery {
glQueryCounter(query, GL_TIMESTAMP); glQueryCounter(query, GL_TIMESTAMP);
} }
}; };
#endif #endif
} }

Loading…
Cancel
Save