On 05/23/2012 12:01 AM, Tapani Pälli wrote:
introduce a new test which checks that GL_COLOR_MATERIAL state
does not get lost with sequential queries.

Signed-off-by: Tapani Pälli<tapani.pa...@intel.com>
---
  tests/all.tests                     |    1 +
  tests/general/CMakeLists.gl.txt     |    1 +
  tests/general/colormaterial-query.c |   80 +++++++++++++++++++++++++++++++++++
  3 files changed, 82 insertions(+), 0 deletions(-)
  create mode 100644 tests/general/colormaterial-query.c

diff --git a/tests/all.tests b/tests/all.tests
index 59d2983..5286f55 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -260,6 +260,7 @@ add_plain_test(general, 'dlist-fdo3129-01')
  add_plain_test(general, 'dlist-fdo3129-02')
  add_plain_test(general, 'dlist-fdo31590')
  add_plain_test(general, 'draw-arrays-colormaterial')
+add_plain_test(general, 'colormaterial-query')
  add_plain_test(general, 'draw-batch')
  add_plain_test(general, 'draw-copypixels-sync')
  add_plain_test(general, 'draw-elements')
diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index 2c93b56..5929d3b 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -31,6 +31,7 @@ piglit_add_executable (depth_clamp depth_clamp.c)
  piglit_add_executable (depthfunc depthfunc.c)
  piglit_add_executable (depthrange-clear depthrange-clear.c)
  piglit_add_executable (draw-arrays-colormaterial draw-arrays-colormaterial.c)
+piglit_add_executable (colormaterial-query colormaterial-query.c)
  piglit_add_executable (draw-batch draw-batch.c)
  piglit_add_executable (draw-copypixels-sync draw-copypixels-sync.c)
  piglit_add_executable (draw-elements draw-elements.c)
diff --git a/tests/general/colormaterial-query.c 
b/tests/general/colormaterial-query.c
new file mode 100644
index 0000000..4934dca
--- /dev/null
+++ b/tests/general/colormaterial-query.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file colormaterial-query.c
+ * Test sequential calls to glMaterialfv and glGetMaterialfv
+ *
+ * This test exercises a Mesa bug where 2 sequential queries with
+ * glGetMaterialfv get wrong result.
+ *
+ * \author Tapani Pälli<tapani.pa...@intel.com>
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE;
+
+enum piglit_result
+piglit_display(void)
+{
+       static const GLfloat ambient[4] = { 0.6f, 0.6f, 0.6f, 1.0f};
+       static const GLfloat color[4] = { 1.0f, 0.0f, 0.0f, 1.0f};
+       static GLfloat result[4];
+
+       GLboolean pass = GL_TRUE;
+
+       glEnable(GL_COLOR_MATERIAL);

You're not calling glColorMaterial() to indicate which material values are tracking glColor. The defaults are GL_FRONT_AND_BACK / GL_AMBIENT_AND_DIFFUSE. It might be nice to have a call to glColorMaterial() even with the default values to make things a little more obvious to the reader.


> +  glEnable(GL_LIGHTING);

I don't think you need to enable GL_LIGHTING for these material tests (unless that somehow factors into the original bug).


The comments could be beefed up a bit...

+       /* set a color */

/* call glColor to set the front+back GL_AMBIENT materials */


+       glColor4f(color[0], color[1], color[2], color[3]);
+
+       /* 1st query that works */

/* This glMaterial call should be a no-op since GL_AMBIENT is tracking glColor */

+       glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
+       glGetMaterialfv(GL_FRONT, GL_AMBIENT, (GLfloat*)result);
+
+       if(memcmp(color, result, sizeof(&color)) != 0)

Minor nit: we usually put a space between 'if' and '('.


+               pass = GL_FALSE;
+
+       /* 2nd query that fails if the bug exists */

/* This glMaterial call should also be a no-op (see above) */

+       glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
+       glGetMaterialfv(GL_FRONT, GL_AMBIENT, (GLfloat*)result);
+
+       if(memcmp(color, result, sizeof(&color)) != 0)
+               pass = GL_FALSE;
+
+       glDisable(GL_LIGHTING);
+       glDisable(GL_COLOR_MATERIAL);
+
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+       /* nop */
+}

Ideally, a test called "colormaterial-query" would test querying all the different material attributes in various circumstances. But I guess this is OK. Others might feel differently.

-Brian
_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to