perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / spec / arb_vertex_program / unused-attributes.c
blob1feb8ea70f049e5a392fbef6f131ace4a2b11d19
1 /*
2 * Copyright © 2020 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * @file unused-attributes.c
26 * Tests that unused attributes in GL_ARB_vertex_program don't affect
27 * attributes that are actually used.
28 * See https://gitlab.freedesktop.org/mesa/mesa/issues/2758
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_compat_version = 10;
37 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
38 config.khr_no_error_support = PIGLIT_NO_ERRORS;
40 PIGLIT_GL_TEST_CONFIG_END
42 static GLfloat pos[4][3] =
44 { 1.0, -1.0, 0.0 },
45 { 1.0, 1.0, 0.0 },
46 { -1.0, 1.0, 0.0 },
47 { -1.0, -1.0, 0.0 }
50 static GLfloat norms[4][3] =
52 { 1, 0, 0},
53 { 1, 0, 0},
54 { 1, 0, 0},
55 { 1, 0, 0}
58 static GLfloat colors[4][4] =
60 { 1, 0, 0, 1},
61 { 1, 0, 0, 1},
62 { 1, 0, 0, 1},
63 { 1, 0, 0, 1}
66 static GLfloat texcoords[4][4] =
68 { 0, 1, 0, 1},
69 { 0, 1, 0, 1},
70 { 0, 1, 0, 1},
71 { 0, 1, 0, 1}
74 static enum piglit_result
75 test_conventional_attribs(void *data)
77 static const char *vertProgramText =
78 "!!ARBvp1.0 \n"
79 "TEMP temp1, temp2;\n"
80 "MOV temp1, vertex.normal;\n"
81 "MOV temp2, vertex.color;\n"
82 "MOV result.position, vertex.position;\n"
83 "MOV result.color, vertex.texcoord;\n"
84 "END";
86 static const char *fragProgramText =
87 "!!ARBfp1.0 \n"
88 "MOV result.color, fragment.color;\n"
89 "END";
91 static const GLfloat expected[4] = {0.0, 1.0, 0.0, 1.0};
92 bool pass = true;
93 GLuint vertProg, fragProg;
95 glEnable(GL_FRAGMENT_PROGRAM_ARB);
96 glEnable(GL_VERTEX_PROGRAM_ARB);
98 fragProg = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, fragProgramText);
99 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fragProg);
101 vertProg = piglit_compile_program(GL_VERTEX_PROGRAM_ARB, vertProgramText);
102 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertProg);
104 glVertexPointer(3, GL_FLOAT, 0, pos);
105 glNormalPointer(GL_FLOAT, 0, norms);
106 glColorPointer(4, GL_FLOAT, 0, colors);
107 glTexCoordPointer(4, GL_FLOAT, 0, texcoords);
109 glEnableClientState(GL_VERTEX_ARRAY);
110 glEnableClientState(GL_NORMAL_ARRAY);
111 glEnableClientState(GL_COLOR_ARRAY);
112 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
114 glClearColor(0.0, 0.0, 0.0, 1);
115 glClear(GL_COLOR_BUFFER_BIT);
117 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
119 pass = piglit_probe_pixel_rgba(piglit_width - 1, piglit_height - 1, expected);
120 piglit_present_results();
122 glDisableClientState(GL_VERTEX_ARRAY);
123 glDisableClientState(GL_NORMAL_ARRAY);
124 glDisableClientState(GL_COLOR_ARRAY);
125 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
127 glDeleteProgramsARB(1, &vertProg);
128 glDeleteProgramsARB(1, &fragProg);
130 glDisable(GL_FRAGMENT_PROGRAM_ARB);
131 glDisable(GL_VERTEX_PROGRAM_ARB);
133 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
136 static enum piglit_result
137 test_generic_attribs(void *data)
139 static const char *vertProgramText =
140 "!!ARBvp1.0 \n"
141 "TEMP temp1, temp2;\n"
142 "MOV temp1, vertex.attrib[1];\n"
143 "MOV temp2, vertex.attrib[2];\n"
144 "MOV result.position, vertex.attrib[0];\n"
145 "MOV result.color, vertex.attrib[7];\n"
146 "END";
148 static const char *fragProgramText =
149 "!!ARBfp1.0 \n"
150 "MOV result.color, fragment.color;\n"
151 "END";
153 static const GLfloat expected[4] = {0.0, 1.0, 0.0, 1.0};
154 bool pass = true;
155 GLuint vertProg, fragProg;
157 glEnable(GL_FRAGMENT_PROGRAM_ARB);
158 glEnable(GL_VERTEX_PROGRAM_ARB);
160 fragProg = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, fragProgramText);
161 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fragProg);
163 vertProg = piglit_compile_program(GL_VERTEX_PROGRAM_ARB, vertProgramText);
164 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertProg);
166 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
167 3 * sizeof(GLfloat), pos);
168 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
169 3 * sizeof(GLfloat), norms);
170 glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE,
171 4 * sizeof(GLfloat), colors);
172 glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE,
173 4 * sizeof(GLfloat), texcoords);
175 glEnableVertexAttribArray(0);
176 glEnableVertexAttribArray(1);
177 glEnableVertexAttribArray(2);
178 glEnableVertexAttribArray(7);
180 glClearColor(0.0, 0.0, 0.0, 1);
181 glClear(GL_COLOR_BUFFER_BIT);
183 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
185 pass = piglit_probe_pixel_rgba(piglit_width - 1, piglit_height - 1, expected);
186 piglit_present_results();
188 glDisableVertexAttribArray(0);
189 glDisableVertexAttribArray(1);
190 glDisableVertexAttribArray(2);
191 glDisableVertexAttribArray(7);
193 glDeleteProgramsARB(1, &vertProg);
194 glDeleteProgramsARB(1, &fragProg);
196 glDisable(GL_FRAGMENT_PROGRAM_ARB);
197 glDisable(GL_VERTEX_PROGRAM_ARB);
199 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
202 enum piglit_result
203 piglit_display(void)
205 return PIGLIT_FAIL;
208 void
209 piglit_init(int argc, char **argv)
211 piglit_require_extension("GL_ARB_vertex_program");
212 piglit_require_extension("GL_ARB_fragment_program");
214 struct piglit_subtest tests[] = {
216 "Unused conventional attributes",
217 "conventional-attribs",
218 &test_conventional_attribs,
219 NULL
222 "Unused generic attributes",
223 "generic-attribs",
224 &test_generic_attribs,
225 NULL
228 NULL
232 enum piglit_result result =
233 piglit_run_selected_subtests(tests, NULL, 0, PIGLIT_PASS);
235 piglit_report_result(result);