[Piglit] [PATCH] Add new arb_draw_buffers_blend-state_set_get test

Brian Paul brianp at vmware.com
Thu Oct 15 06:40:46 PDT 2015


Test glBlendFuncSeparate, glBlendEquationSeparate, and the indexed
versions to make sure all state is set properly.
---
 tests/all.py                                       |   1 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../spec/arb_draw_buffers_blend/CMakeLists.gl.txt  |  13 ++
 tests/spec/arb_draw_buffers_blend/CMakeLists.txt   |   1 +
 tests/spec/arb_draw_buffers_blend/state_set_get.c  | 228 +++++++++++++++++++++
 5 files changed, 244 insertions(+)
 create mode 100644 tests/spec/arb_draw_buffers_blend/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_draw_buffers_blend/CMakeLists.txt
 create mode 100644 tests/spec/arb_draw_buffers_blend/state_set_get.c

diff --git a/tests/all.py b/tests/all.py
index 4531b01..fff4403 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3954,6 +3954,7 @@ with profile.group_manager(
 with profile.group_manager(
         PiglitGLTest,
         grouptools.join('spec', 'arb_draw_buffers_blend')) as g:
+    g(['arb_draw_buffers_blend-state_set_get'])
     g(['fbo-draw-buffers-blend'], run_concurrent=False)
 
 with profile.group_manager(
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 5dc37a1..34e5260 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -118,6 +118,7 @@ add_subdirectory (arb_vertex_type_2_10_10_10_rev)
 add_subdirectory (ext_texture_array)
 add_subdirectory (ext_texture_integer)
 add_subdirectory (arb_draw_buffers)
+add_subdirectory (arb_draw_buffers_blend)
 add_subdirectory (oes_draw_texture)
 add_subdirectory (oes_fixed_point)
 add_subdirectory (ext_image_dma_buf_import)
diff --git a/tests/spec/arb_draw_buffers_blend/CMakeLists.gl.txt b/tests/spec/arb_draw_buffers_blend/CMakeLists.gl.txt
new file mode 100644
index 0000000..784886f
--- /dev/null
+++ b/tests/spec/arb_draw_buffers_blend/CMakeLists.gl.txt
@@ -0,0 +1,13 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+)
+
+piglit_add_executable (arb_draw_buffers_blend-state_set_get state_set_get.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_draw_buffers_blend/CMakeLists.txt b/tests/spec/arb_draw_buffers_blend/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_draw_buffers_blend/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_draw_buffers_blend/state_set_get.c b/tests/spec/arb_draw_buffers_blend/state_set_get.c
new file mode 100644
index 0000000..a1bb35e
--- /dev/null
+++ b/tests/spec/arb_draw_buffers_blend/state_set_get.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright 2015 VMware, Inc.
+ *
+ * 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.
+ *
+ */
+
+/**
+ * Test setting/getting state related to GL_ARB_draw_buffers_blend.
+ * In particular, make sure glBlendFunc and glBlendEquation updates
+ * all buffer state.
+ *
+ * Brian Paul
+ * October 2015
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+	config.supports_gl_compat_version = 20;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLint num_buffers;
+
+struct blend_state
+{
+	GLenum srcRGB, srcA, dstRGB, dstA;
+	GLenum eqRGB, eqA;
+};
+
+#define MAX_BUFFERS 16
+
+static struct blend_state state[MAX_BUFFERS];
+
+
+static void
+set_state(int buffer,
+	  GLenum srcRGB, GLenum srcA,
+	  GLenum dstRGB, GLenum dstA,
+	  GLenum eqRGB, GLenum eqA)
+{
+	state[buffer].srcRGB = srcRGB;
+	state[buffer].srcA = srcA;
+	state[buffer].dstRGB = dstRGB;
+	state[buffer].dstA = dstA;
+	state[buffer].eqRGB = eqRGB;
+	state[buffer].eqA = eqA;
+
+	glBlendFuncSeparateiARB(buffer, srcRGB, dstRGB, srcA, dstA);
+	glBlendEquationSeparateiARB(buffer, eqRGB, eqA);
+
+	piglit_check_gl_error(GL_NO_ERROR);
+}
+
+
+static void
+set_state_all_buffers(GLenum srcRGB, GLenum srcA,
+		      GLenum dstRGB, GLenum dstA,
+		      GLenum eqRGB, GLenum eqA)
+{
+	int i;
+
+	for (i = 0; i < num_buffers; i++) {
+		state[i].srcRGB = srcRGB;
+		state[i].srcA = srcA;
+		state[i].dstRGB = dstRGB;
+		state[i].dstA = dstA;
+		state[i].eqRGB = eqRGB;
+		state[i].eqA = eqA;
+	}
+
+	glBlendFuncSeparate(srcRGB, dstRGB, srcA, dstA);
+	glBlendEquationSeparate(eqRGB, eqA);
+
+	piglit_check_gl_error(GL_NO_ERROR);
+}
+
+
+static bool
+check_state(int buffer)
+{
+	GLint srcRGB, srcA;
+	GLint dstRGB, dstA;
+	GLint eqRGB, eqA;
+
+	glGetIntegeri_v(GL_BLEND_SRC_RGB, buffer, &srcRGB);
+	glGetIntegeri_v(GL_BLEND_DST_RGB, buffer, &dstRGB);
+	glGetIntegeri_v(GL_BLEND_SRC_ALPHA, buffer, &srcA);
+	glGetIntegeri_v(GL_BLEND_DST_ALPHA, buffer, &dstA);
+	glGetIntegeri_v(GL_BLEND_EQUATION_RGB, buffer, &eqRGB);
+	glGetIntegeri_v(GL_BLEND_EQUATION_ALPHA, buffer, &eqA);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		printf("Unexpected GL error.\n");
+		return false;
+	}
+
+	if (srcRGB != state[buffer].srcRGB ||
+	    dstRGB != state[buffer].dstRGB ||
+	    srcA != state[buffer].srcA ||
+	    dstA != state[buffer].dstA ||
+	    eqRGB != state[buffer].eqRGB ||
+	    eqA != state[buffer].eqA) {
+		printf("State doesn't match for buffer %d\n", buffer);
+		return false;
+	}
+
+	return true;
+}
+
+
+static bool
+check_state_all_buffers(void)
+{
+	int i;
+
+	for (i = 0; i < num_buffers; i++) {
+		if (!check_state(i)) {
+			return false;
+		}
+	}
+
+	return true;
+}
+
+
+static bool
+test_modes(void)
+{
+	bool pass = true;
+
+	/* Initial setup and check */
+	set_state_all_buffers(GL_ONE, GL_ZERO,
+			      GL_ONE, GL_ZERO,
+			      GL_FUNC_ADD, GL_FUNC_ADD);
+	if (!check_state_all_buffers()) {
+		printf("Initial state check failed.\n");
+		pass = false;
+	}
+
+	/* set one buffer's state */
+	set_state(1,
+		  GL_SRC_ALPHA, GL_ONE,
+		  GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
+		  GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT);
+	if (!check_state_all_buffers()) {
+		printf("Setting one buffer state failed.\n");
+		pass = false;
+	}
+
+	/* set all buffer state again */
+	set_state_all_buffers(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
+			      GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
+			      GL_FUNC_ADD, GL_FUNC_ADD);
+	if (!check_state_all_buffers()) {
+		printf("Resetting all buffer state failed.\n");
+		pass = false;
+	}
+
+	/* set last buffer's state */
+	set_state(num_buffers - 1,
+		  GL_ZERO, GL_SRC_ALPHA,
+		  GL_SRC_ALPHA, GL_ONE,
+		  GL_FUNC_ADD, GL_FUNC_SUBTRACT);
+	if (!check_state_all_buffers()) {
+		printf("Setting last buffer state failed.\n");
+		pass = false;
+	}
+
+	/* set first buffer's state */
+	set_state(0,
+		  GL_ONE, GL_ZERO,
+		  GL_ZERO, GL_ONE,
+		  GL_FUNC_SUBTRACT, GL_FUNC_ADD);
+	if (!check_state_all_buffers()) {
+		printf("Setting first buffer state failed.\n");
+		pass = false;
+	}
+
+	return pass;
+}
+
+
+
+enum piglit_result
+piglit_display(void)
+{
+	/* never get here */
+	return PIGLIT_PASS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ARB_draw_buffers_blend");
+
+	glGetIntegerv(GL_MAX_DRAW_BUFFERS, &num_buffers);
+
+	num_buffers = MIN2(num_buffers, MAX_BUFFERS);
+
+	if (num_buffers < 2) {
+		printf("Need at least two draw buffers.\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+
+	printf("Testing %d buffers\n", num_buffers);
+
+	piglit_report_result(test_modes() ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
1.9.1



More information about the Piglit mailing list