summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2018-01-24 08:37:34 -0700
committerBrian Paul <brianp@vmware.com>2018-02-14 08:51:20 -0700
commite7eacdcd3e05f2edea47259d70d1582ce571e0ef (patch)
tree6d1c61f077fd5a69c84e1020ae62a51db6a18ed1 /tests
parent32d1460fb084ce720e5f22d2589392d9f4961a1e (diff)
gl-2.0-shader-materials: test vertex shader with material attributes
Both with and without display lists.
Diffstat (limited to 'tests')
-rw-r--r--tests/all.py1
-rw-r--r--tests/spec/gl-2.0/CMakeLists.gl.txt1
-rw-r--r--tests/spec/gl-2.0/shader-materials.c141
3 files changed, 143 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py
index d2961f7cd..61d5faa23 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -973,6 +973,7 @@ with profile.test_list.group_manager(
g(['gl-2.0-vertex-attr-0'])
g(['gl-2.0-vertex-const-attr'])
g(['gl-2.0-reuse_fragment_shader'])
+ g(['gl-2.0-shader-materials'])
g(['attrib-assignments'])
g(['getattriblocation-conventional'])
g(['clip-flag-behavior'])
diff --git a/tests/spec/gl-2.0/CMakeLists.gl.txt b/tests/spec/gl-2.0/CMakeLists.gl.txt
index ce627998f..71aa7aa73 100644
--- a/tests/spec/gl-2.0/CMakeLists.gl.txt
+++ b/tests/spec/gl-2.0/CMakeLists.gl.txt
@@ -14,6 +14,7 @@ piglit_add_executable (gl-2.0-edgeflag edgeflag.c)
piglit_add_executable (gl-2.0-edgeflag-immediate edgeflag-immediate.c)
piglit_add_executable (gl-2.0-large-point-fs large-point-fs.c)
piglit_add_executable (gl-2.0-link-empty-prog glsl-link-empty-prog.c)
+piglit_add_executable (gl-2.0-shader-materials shader-materials.c)
piglit_add_executable (gl-2.0-two-sided-stencil two-sided-stencil.c)
piglit_add_executable (gl-2.0-vertexattribpointer vertexattribpointer.c)
piglit_add_executable (gl-2.0-vertexattribpointer-size-3 vertexattribpointer-size-3.c)
diff --git a/tests/spec/gl-2.0/shader-materials.c b/tests/spec/gl-2.0/shader-materials.c
new file mode 100644
index 000000000..e1f807499
--- /dev/null
+++ b/tests/spec/gl-2.0/shader-materials.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2018 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 vertex shader with gl_FrontMaterial and per-vertex materials.
+ *
+ * When using a VS, per-vertex materials are not used. Instead, the global
+ * material coefficients are the ones accessed via the gl_Front/BackMaterial
+ * built-in uniforms.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.supports_gl_compat_version = 20;
+ config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+ config.khr_no_error_support = PIGLIT_NO_ERRORS;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+/* VS: color = front ambient + front diffuse + two generic attributes */
+static const char *vs =
+ "attribute vec4 generic1, generic2; \n"
+ "void main()\n"
+ "{\n"
+ " gl_FrontColor = gl_FrontMaterial.ambient + \n"
+ " gl_FrontMaterial.diffuse + \n"
+ " generic1 + generic2; \n"
+ " gl_Position = ftransform(); \n"
+ "}\n";
+
+static const char *fs =
+ "uniform bool draw_secondary;\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = gl_Color;\n"
+ "}\n";
+
+
+static int generic1_attr, generic2_attr;
+
+
+static bool
+test(bool use_dlist)
+{
+ static const float red[] = {1.0, 0.0, 0.0, 1.0};
+ static const float green[] = {0.0, 1.0, 0.0, 1.0};
+ static const float ambient[] = {0.0, 0.3, 0.5, 1.0};
+ static const float diffuse[] = {0.0, 0.2, 0.3, 1.0};
+ static const float generic1[] = { 0.2, 0.3, -0.4, 0.0};
+ static const float generic2[] = {-0.2, 0.2, -0.4, 0.0};
+ static const float pos[4][2] = {
+ { -1, -1 },
+ { 1, -1 },
+ { 1, 1 },
+ { -1, 1 }
+ };
+ GLuint list = 0;
+ bool pass = true;
+
+ glClearColor(0.5, 0.5, 0.5, 0.5);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ if (use_dlist) {
+ list = glGenLists(1);
+ glNewList(1, GL_COMPILE);
+ }
+
+ /* These are the values picked up by gl_FrontMaterial.ambient, diffuse
+ */
+ glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
+
+ glBegin(GL_TRIANGLE_FAN);
+ for (int i = 0; i < 4; i++) {
+ /* These material values should be ignored */
+ glMaterialfv(GL_FRONT, GL_AMBIENT, red);
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, red);
+ glVertexAttrib4fv(generic1_attr, generic1);
+ glVertexAttrib4fv(generic2_attr, generic2);
+ glVertex2fv(pos[i]);
+ }
+ glEnd();
+
+ if (use_dlist) {
+ glEndList();
+ glCallList(list);
+ glDeleteLists(list, 1);
+ }
+
+ pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
+ green);
+ piglit_present_results();
+
+ if (!pass) {
+ printf("Fail while testing %s\n",
+ use_dlist ? "display list" : "immediate mode");
+ }
+
+ return pass;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ bool pass = test(false);
+ pass = test(true) && pass;
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLint prog = piglit_build_simple_program(vs, fs);
+ glUseProgram(prog);
+
+ generic1_attr = glGetAttribLocation(prog, "generic1");
+ generic2_attr = glGetAttribLocation(prog, "generic2");
+}