2 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
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
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
25 * EXT_transform_feedback test.
27 * Test writing interleaved vertex attribs into a buffer object.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 10;
35 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
36 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
38 PIGLIT_GL_TEST_CONFIG_END
40 static const char *vstext
= {
44 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
45 " gl_FrontColor = vec4(1.0, 0.9, 0.8, 0.7);"
46 " gl_TexCoord[0] = vec4(0.5);"
47 " gl_TexCoord[1] = vec4(0.6, 0.0, 0.1, 0.6);"
48 " v2 = vec2(0.2, 0.7);"
49 " v3 = vec3(0.55, 0.66, 0.77);"
53 static const char *varyings
[] = {"v3", "gl_FrontColor", "v2", "gl_Position", "gl_TexCoord[1]"};
57 #define BUF_FLOATS (17*6)
59 void piglit_init(int argc
, char **argv
)
65 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
67 /* Check the driver. */
68 piglit_require_gl_version(15);
69 piglit_require_vertex_shader();
70 piglit_require_transform_feedback();
72 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT
, &maxcomps
);
74 fprintf(stderr
, "Not enough interleaved components supported by transform feedback.\n");
75 piglit_report_result(PIGLIT_SKIP
);
79 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vstext
);
80 prog
= glCreateProgram();
81 glAttachShader(prog
, vs
);
82 glTransformFeedbackVaryings(prog
, sizeof(varyings
)/sizeof(varyings
[0]),
83 varyings
, GL_INTERLEAVED_ATTRIBS_EXT
);
85 if (!piglit_link_check_status(prog
)) {
86 glDeleteProgram(prog
);
87 piglit_report_result(PIGLIT_FAIL
);
90 /* Set up the transform feedback buffer. */
91 glGenBuffers(1, &buf
);
92 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
, buf
);
93 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
,
94 BUF_FLOATS
*sizeof(float), NULL
, GL_STREAM_READ
);
95 ptr
= glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
, GL_WRITE_ONLY
);
96 for (i
= 0; i
< BUF_FLOATS
; i
++) {
99 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
);
100 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
, 0, buf
);
102 if (!piglit_check_gl_error(GL_NO_ERROR
))
103 piglit_report_result(PIGLIT_FAIL
);
105 glClearColor(0.2, 0.2, 0.2, 1.0);
106 glEnableClientState(GL_VERTEX_ARRAY
);
109 enum piglit_result
piglit_display(void)
111 GLboolean pass
= GL_TRUE
;
114 static const float verts
[] = {
120 static const unsigned indices
[] = {
123 static const float expected
[] = {
124 0.550000, 0.660000, 0.770000,
125 1.000000, 0.900000, 0.800000, 0.700000,
127 -0.687500, -0.375000, 0.000000, 1.000000,
128 0.600000, 0.000000, 0.100000, 0.600000,
130 0.550000, 0.660000, 0.770000,
131 1.000000, 0.900000, 0.800000, 0.700000,
133 -0.687500, 0.250000, 0.000000, 1.000000,
134 0.600000, 0.000000, 0.100000, 0.600000,
136 0.550000, 0.660000, 0.770000,
137 1.000000, 0.900000, 0.800000, 0.700000,
139 -0.375000, -0.375000, 0.000000, 1.000000,
140 0.600000, 0.000000, 0.100000, 0.600000,
142 0.550000, 0.660000, 0.770000,
143 1.000000, 0.900000, 0.800000, 0.700000,
145 -0.687500, 0.250000, 0.000000, 1.000000,
146 0.600000, 0.000000, 0.100000, 0.600000,
148 0.550000, 0.660000, 0.770000,
149 1.000000, 0.900000, 0.800000, 0.700000,
151 -0.375000, 0.250000, 0.000000, 1.000000,
152 0.600000, 0.000000, 0.100000, 0.600000,
154 0.550000, 0.660000, 0.770000,
155 1.000000, 0.900000, 0.800000, 0.700000,
157 -0.375000, -0.375000, 0.000000, 1.000000,
158 0.600000, 0.000000, 0.100000, 0.600000
161 glClear(GL_COLOR_BUFFER_BIT
);
163 /* Setup projection for a 64 x 32 window region. That's what
164 * the expected coords above assume.
165 * XXX it would be better if the position coords in the above
166 * array were compute instead of fixed.
168 glMatrixMode(GL_PROJECTION
);
170 glOrtho(0, 64, 0, 32, -1, 1);
171 glMatrixMode(GL_MODELVIEW
);
174 /* Render into TFBO. */
176 glEnable(GL_RASTERIZER_DISCARD
);
177 glBeginTransformFeedback(GL_TRIANGLES
);
178 glVertexPointer(2, GL_FLOAT
, 0, verts
);
179 glDrawElements(GL_TRIANGLES
, 6, GL_UNSIGNED_INT
, indices
);
180 glEndTransformFeedback();
181 glDisable(GL_RASTERIZER_DISCARD
);
183 if (!piglit_check_gl_error(GL_NO_ERROR
))
184 piglit_report_result(PIGLIT_FAIL
);
186 ptr
= glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
, GL_READ_ONLY
);
187 for (i
= 0; i
< BUF_FLOATS
; i
++) {
188 //printf("%f, ", ptr[i]); continue;
189 if (fabs(ptr
[i
] - expected
[i
]) > 0.01) {
190 printf("Buffer[%i]: %f, Expected: %f\n", i
, ptr
[i
], expected
[i
]);
194 printf("Buffer[%i]: %f, Expected: %f -- OK\n", i
, ptr
[i
], expected
[i
]);
198 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
);
200 if (!piglit_check_gl_error(GL_NO_ERROR
))
201 piglit_report_result(PIGLIT_FAIL
);
203 piglit_present_results();
205 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;