Panagiotis Christopoulos Charitos 14 years ago
parent
commit
149960d4ce
3 changed files with 53 additions and 1 deletions
  1. 38 1
      anki/gl/GlQuery.cpp
  2. 14 0
      anki/gl/Query.h
  3. 1 0
      anki/gl/TimeQuery.cpp

+ 38 - 1
anki/gl/GlQuery.cpp

@@ -11,7 +11,7 @@ namespace anki {
 // QueryImpl                                                                   =
 //==============================================================================
 
-/// XXX
+/// Query implementation
 struct QueryImpl
 {
 	GLuint glId;
@@ -34,6 +34,12 @@ Query::Query(QueryQuestion q)
 		case QQ_SAMPLES_PASSED:
 			impl->question = GL_SAMPLES_PASSED;
 			break;
+		case QQ_ANY_SAMPLES_PASSED:
+			impl->question = GL_ANY_SAMPLES_PASSED;
+			break;
+		case QQ_TIME_ELAPSED:
+			impl->question = GL_TIME_ELAPSED;
+			break;
 		default:
 			ANKI_ASSERT(0);
 	};
@@ -68,4 +74,35 @@ void Query::endQuery()
 }
 
 
+//==============================================================================
+uint64_t Query::getResult()
+{
+	GLuint64 result;
+	glGetQueryObjectui64v(impl->glId, GL_QUERY_RESULT, &result);
+	return result;
+}
+
+
+//==============================================================================
+uint64_t Query::getResultNoWait(bool& finished)
+{
+	GLuint resi;
+	glGetQueryObjectuiv(impl->glId, GL_QUERY_RESULT_AVAILABLE, &resi);
+
+	GLuint64 result;
+	if(resi)
+	{
+		glGetQueryObjectui64v(impl->glId, GL_QUERY_RESULT, &result);
+		finished = true;
+	}
+	else
+	{
+		finished = false;
+		result = 0;
+	}
+
+	return result;
+}
+
+
 } // end namespace anki

+ 14 - 0
anki/gl/Query.h

@@ -2,6 +2,7 @@
 #define ANKI_GL_QUERY_H
 
 #include <boost/scoped_ptr.hpp>
+#include <boost/integer.hpp>
 
 
 namespace anki {
@@ -17,6 +18,8 @@ public:
 	enum QueryQuestion
 	{
 		QQ_SAMPLES_PASSED,
+		QQ_ANY_SAMPLES_PASSED, ///< Faster than the QQ_SAMPLES_PASSED
+		QQ_TIME_ELAPSED, ///< Time elapsed in ms
 		QQ_COUNT
 	};
 
@@ -26,9 +29,20 @@ public:
 	~Query();
 	/// @}
 
+	/// Start
 	void beginQuery();
+
+	/// End
 	void endQuery();
 
+	/// Get results
+	/// @note Waits for operations to finish
+	uint64_t getResult();
+
+	/// Get results
+	/// @note Doesn't Wait for operations to finish
+	uint64_t getResultNoWait(bool& finished);
+
 private:
 	boost::scoped_ptr<QueryImpl> impl;
 };

+ 1 - 0
anki/gl/TimeQuery.cpp

@@ -43,6 +43,7 @@ double TimeQuery::end()
 	GLint done = 0;
 	while(!done)
 	{
+		/// XXX BAD BAD BAD BAD!!!!!
 		glGetQueryObjectiv(glIds[1], GL_QUERY_RESULT_AVAILABLE, &done);
 	}