Commit 62666ec3 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'QueryObject' into 'master'

Query object

add query object class to ACG/globjects

See merge request !36
parents 5a7cb17e 764ad6df
Pipeline #169 passed with stage
......@@ -6,3 +6,6 @@
*.dll
*.lib
*.swp
/build_dbg
/build_rel
\ No newline at end of file
......@@ -1137,6 +1137,54 @@ bool AtomicCounter::isValid() const
return buffer_ && numCounters_ > 0;
}
//-----------------------------------------------------------------------------
QueryObject::QueryObject(GLenum _type)
: id_(0), state_(-1), type_(_type)
{
}
QueryObject::~QueryObject()
{
if (id_)
glDeleteQueries(1, &id_);
}
void QueryObject::begin()
{
if (!id_)
glGenQueries(1, &id_);
glBeginQuery(type_, id_);
state_ = 0;
}
void QueryObject::end()
{
if (!state_)
{
glEndQuery(type_);
state_ = 1;
}
}
bool QueryObject::available() const
{
GLint r = GL_FALSE;
if (state_ > 0)
glGetQueryObjectiv(id_, GL_QUERY_RESULT_AVAILABLE, &r);
return r != GL_FALSE;
}
GLuint QueryObject::result() const
{
GLuint r = 0xffffffff;
if (state_ > 0)
glGetQueryObjectuiv(id_, GL_QUERY_RESULT, &r);
return r;
}
//-----------------------------------------------------------------------------
......@@ -1450,4 +1498,7 @@ int ShaderStorageBufferObject::getMaxCombinedShaderBlocks()
}
} /* namespace ACG */
......@@ -788,6 +788,56 @@ private:
static int supportStatus_;
};
//== CLASS DEFINITION =========================================================
/*
Query object (occlusion queries):
ref: https://www.opengl.org/wiki/Query_Object
opengl-core: 1.5
usage:
query.begin(GL_SAMPLES_PASSED);
.. gl-calls
query.end();
GLuint numSamples = query.result();
\note result() method synchronizes CPU and GPU, so this might stall the cpu
*/
class ACGDLLEXPORT QueryObject
{
public:
// set the type of the query object:
// GL_SAMPLES_PASSED - number of samples that passed the depth test
// GL_ANY_SAMPLES_PASSED - return true iff there is at least one sample that passed the depth test (gl 3.3+)
// GL_ANY_SAMPLES_PASSED_CONSERVATIVE - return true if there might be a sample that passed the depth test (gl 4.3+)
// GL_TIME_ELAPSED - measure elapsed time (gl 3.3+)
// also see: https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glBeginQuery.xml
QueryObject(GLenum _type = GL_SAMPLES_PASSED);
virtual ~QueryObject();
/// begin measuring the query
void begin();
/// stop measuring the query
void end();
/// check if the result is available (does not wait for gpu to finish)
bool available() const;
/// get the measurement of the query between the begin() end() calls (waits for the gpu)
GLuint result() const;
private:
GLuint id_;
int state_; // -1 : not started, 0 : started, 1 : stopped
GLenum type_;
};
//== CLASS DEFINITION =========================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment