Hi,

On Monday 17 May 2010 21:02:00 Brian Paul wrote:
> It would be nice to have a piglit test to exercise EXT_timer_query
> too.  We should really have tests for all extensions.
I am not completely sure if this is completely correct in the context of 
piglit.
But so far a simple test that just uses the timer query if it is announced.
Tell me if we need something different/more?

Greetings

Mathias
diff --git a/tests/general/CMakeLists.txt b/tests/general/CMakeLists.txt
index fa1cdc5..e01e519 100644
--- a/tests/general/CMakeLists.txt
+++ b/tests/general/CMakeLists.txt
@@ -56,6 +56,7 @@ add_executable (stencil-drawpixels stencil-drawpixels.c)
 add_executable (sync_api sync_api.c)
 add_executable (texgen texgen.c)
 add_executable (texunits texunits.c)
+add_executable (timer_query timer_query.c)
 add_executable (user-clip user-clip.c)
 add_executable (varray-disabled varray-disabled.c)
 add_executable (vbo-map-remap vbo-map-remap.c)
/*
 * Copyright © 2009 Intel Corporation
 * Copyright © 2010 Mathias Fröhlich
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Ian Romanick <ian.d.roman...@intel.com>
 *    Mathias Fröhlich <m.froehl...@web.de>
 */

/**
 * \file timer_query.c
 * Simple test for GL_EXT_timer_query.
 */

#include "piglit-util.h"

int piglit_width = 180, piglit_height = 100;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;

static GLuint timer_query;
static PFNGLGENQUERIESPROC gen_queries = NULL;
static PFNGLBEGINQUERYPROC begin_query = NULL;
static PFNGLENDQUERYPROC end_query = NULL;
static PFNGLGETQUERYIVPROC get_queryiv = NULL;
static PFNGLGETQUERYOBJECTIVPROC get_query_objectiv = NULL;

void
piglit_init(int argc, char **argv)
{
	GLint query_bits;

        piglit_require_extension("GL_EXT_timer_query");

	/* glViewport(0, 0, piglit_width, piglit_height); */
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	/* glClearColor(0.0, 0.2, 0.3, 0.0); */
	/* glClearDepth(1.0); */

	/* glEnable(GL_DEPTH_TEST); */
	/* glDepthFunc(GL_LESS); */


	if (GLEW_VERSION_1_5) {
		gen_queries = GLEW_GET_FUN(__glewGenQueries);
		begin_query = GLEW_GET_FUN(__glewBeginQuery);
		end_query = GLEW_GET_FUN(__glewEndQuery);
		get_queryiv = GLEW_GET_FUN(__glewGetQueryiv);
		get_query_objectiv = GLEW_GET_FUN(__glewGetQueryObjectiv);
	} else if (GLEW_EXT_timer_query) {
		gen_queries = GLEW_GET_FUN(__glewGenQueriesARB);
		begin_query = GLEW_GET_FUN(__glewBeginQueryARB);
		end_query = GLEW_GET_FUN(__glewEndQueryARB);
		get_queryiv = GLEW_GET_FUN(__glewGetQueryivARB);
		get_query_objectiv = GLEW_GET_FUN(__glewGetQueryObjectivARB);
	} else {
		piglit_report_result(PIGLIT_SKIP);
	}


	/* It is legal for a driver to support the query API but not have
	 * any query bits.  I wonder how many applications actually check for
	 * this case...
	 */
	(*get_queryiv)(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &query_bits);
	if (query_bits == 0) {
		piglit_report_result(PIGLIT_SKIP);
	}

	(*gen_queries)(1, &timer_query);
}

enum piglit_result
piglit_display(void)
{
	GLint available = 0;
	GLint nsecs;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        /* Start a query */
        (*begin_query)(GL_TIME_ELAPSED_EXT, timer_query);

        /* Paint something */
	glColor3ub(0xff, 0xff, 0xff);

	glBegin(GL_QUADS);
	glVertex3f(0, 0, 0);
	glVertex3f(piglit_width, 0, 0);
	glVertex3f(piglit_width, piglit_height, 0);
	glVertex3f(0, piglit_height, 0);
	glEnd();

        /* Stop a query */
        (*end_query)(GL_TIME_ELAPSED_EXT);

        /* In this case poll until available */
        while (!available)
          (*get_query_objectiv)(timer_query, GL_QUERY_RESULT_AVAILABLE, &available);

        /* Get the result */
        (*get_query_objectiv)(timer_query, GL_QUERY_RESULT, &nsecs);

	glutSwapBuffers();

	return PIGLIT_SUCCESS;
}


_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to