Query objects for OpenGL ES 3.0

Query objects already existed as an extension
for OpenGL ES 2.0, so all that was needed was
to fill in the blanks in the API functions.

Change-Id: I6b48d34bdd8a92e7531bbf6cecb1f4d75b55d144
Reviewed-on: https://swiftshader-review.googlesource.com/2800
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLESv2/libGLESv3.cpp b/src/OpenGL/libGLESv2/libGLESv3.cpp
index 1fb6619..2186bae 100644
--- a/src/OpenGL/libGLESv2/libGLESv3.cpp
+++ b/src/OpenGL/libGLESv2/libGLESv3.cpp
@@ -13,6 +13,7 @@
 #include "main.h"

 #include "Framebuffer.h"

 #include "Program.h"

+#include "Query.h"

 #include "Texture.h"

 #include "common/debug.h"

 

@@ -745,7 +746,15 @@
 		return error(GL_INVALID_VALUE);

 	}

 

-	UNIMPLEMENTED();

+	es2::Context *context = es2::getContext();

+

+	if(context)

+	{

+		for(int i = 0; i < n; i++)

+		{

+			ids[i] = context->createQuery();

+		}

+	}

 }

 

 void GL_APIENTRY glDeleteQueries(GLsizei n, const GLuint *ids)

@@ -757,14 +766,38 @@
 		return error(GL_INVALID_VALUE);

 	}

 

-	UNIMPLEMENTED();

+	es2::Context *context = es2::getContext();

+

+	if(context)

+	{

+		for(int i = 0; i < n; i++)

+		{

+			context->deleteQuery(ids[i]);

+		}

+	}

 }

 

 GLboolean GL_APIENTRY glIsQuery(GLuint id)

 {

 	TRACE("(GLuint id = %d)", id);

 

-	UNIMPLEMENTED();

+	if(id == 0)

+	{

+		return GL_FALSE;

+	}

+

+	es2::Context *context = es2::getContext();

+

+	if(context)

+	{

+		es2::Query *queryObject = context->getQuery(id, false, GL_NONE);

+

+		if(queryObject)

+		{

+			return GL_TRUE;

+		}

+	}

+

 	return GL_FALSE;

 }

 

@@ -777,7 +810,17 @@
 		return error(GL_INVALID_ENUM);

 	}

 

-	UNIMPLEMENTED();

+	if(id == 0)

+	{

+		return error(GL_INVALID_OPERATION);

+	}

+

+	es2::Context *context = es2::getContext();

+

+	if(context)

+	{

+		context->beginQuery(target, id);

+	}

 }

 

 void GL_APIENTRY glEndQuery(GLenum target)

@@ -789,7 +832,12 @@
 		return error(GL_INVALID_ENUM);

 	}

 

-	UNIMPLEMENTED();

+	es2::Context *context = es2::getContext();

+

+	if(context)

+	{

+		context->endQuery(target);

+	}

 }

 

 void GL_APIENTRY glGetQueryiv(GLenum target, GLenum pname, GLint *params)

@@ -802,7 +850,12 @@
 		return error(GL_INVALID_ENUM);

 	}

 

-	UNIMPLEMENTED();

+	es2::Context *context = es2::getContext();

+

+	if(context)

+	{

+		params[0] = context->getActiveQuery(target);

+	}

 }

 

 void GL_APIENTRY glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)

@@ -819,7 +872,34 @@
 		return error(GL_INVALID_ENUM);

 	}

 

-	UNIMPLEMENTED();

+	es2::Context *context = es2::getContext();

+

+	if(context)

+	{

+		es2::Query *queryObject = context->getQuery(id, false, GL_NONE);

+

+		if(!queryObject)

+		{

+			return error(GL_INVALID_OPERATION);

+		}

+

+		if(context->getActiveQuery(queryObject->getType()) == id)

+		{

+			return error(GL_INVALID_OPERATION);

+		}

+

+		switch(pname)

+		{

+		case GL_QUERY_RESULT:

+			params[0] = queryObject->getResult();

+			break;

+		case GL_QUERY_RESULT_AVAILABLE:

+			params[0] = queryObject->isResultAvailable();

+			break;

+		default:

+			ASSERT(false);

+		}

+	}

 }

 

 GLboolean GL_APIENTRY glUnmapBuffer(GLenum target)