Panagiotis Christopoulos Charitos 14 лет назад
Родитель
Сommit
5cf34db242
2 измененных файлов с 111 добавлено и 0 удалено
  1. 71 0
      anki/gl/GlQuery.cpp
  2. 40 0
      anki/gl/Query.h

+ 71 - 0
anki/gl/GlQuery.cpp

@@ -0,0 +1,71 @@
+#include "anki/gl/Query.h"
+#include "anki/util/Exception.h"
+#include "anki/util/Assert.h"
+#include <GL/glew.h>
+
+
+namespace anki {
+
+
+//==============================================================================
+// QueryImpl                                                                   =
+//==============================================================================
+
+/// XXX
+struct QueryImpl
+{
+	GLuint glId;
+	GLenum question;
+};
+
+
+//==============================================================================
+// Query                                                                       =
+//==============================================================================
+
+//==============================================================================
+Query::Query(QueryQuestion q)
+{
+	impl.reset(new QueryImpl);
+
+	// question
+	switch(q)
+	{
+		case QQ_SAMPLES_PASSED:
+			impl->question = GL_SAMPLES_PASSED;
+			break;
+		default:
+			ANKI_ASSERT(0);
+	};
+
+	// glId
+	glGenQueries(1, &impl->glId);
+	if(impl->glId == 0)
+	{
+		throw ANKI_EXCEPTION("Query generation failed");
+	}
+}
+
+
+//==============================================================================
+Query::~Query()
+{
+	glDeleteQueries(1, &impl->glId);
+}
+
+
+//==============================================================================
+void Query::beginQuery()
+{
+	glBeginQuery(impl->question, impl->glId);
+}
+
+
+//==============================================================================
+void Query::endQuery()
+{
+	glEndQuery(impl->question);
+}
+
+
+} // end namespace anki

+ 40 - 0
anki/gl/Query.h

@@ -0,0 +1,40 @@
+#ifndef ANKI_GL_QUERY_H
+#define ANKI_GL_QUERY_H
+
+#include <boost/scoped_ptr.hpp>
+
+
+namespace anki {
+
+
+class QueryImpl;
+
+
+/// XXX
+class Query
+{
+public:
+	enum QueryQuestion
+	{
+		QQ_SAMPLES_PASSED,
+		QQ_COUNT
+	};
+
+	/// @name Constructors/Destructor
+	/// @{
+	Query(QueryQuestion q);
+	~Query();
+	/// @}
+
+	void beginQuery();
+	void endQuery();
+
+private:
+	boost::scoped_ptr<QueryImpl> impl;
+};
+
+
+} // end namespace anki
+
+
+#endif