fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / spec / ext_transform_feedback / points.c
blobef7604bdf306c9d40fd9cf61ba9eac19d24a0e66
1 /*
2 * Copyright © 2014 VMware, Inc.
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 * Simple transform feedback test drawing GL_POINTS.
26 * If argv[1] == "large" draw large points (which may hit a point->quad
27 * conversion path.)
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config.supports_gl_compat_version = 10;
34 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
35 config.khr_no_error_support = PIGLIT_NO_ERRORS;
36 PIGLIT_GL_TEST_CONFIG_END
39 static GLuint prog;
40 static GLuint xfb_buf, vert_buf;
41 static const int xfb_buf_size = 500;
43 static const char *vstext = {
44 "void main() {"
45 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
46 " gl_FrontColor = vec4(0.9, 0.8, 0.7, 0.6);"
47 "}"
50 #define NUM_VERTS 3
51 static const GLfloat verts[NUM_VERTS][3] =
53 {-1, 0.2, 0},
54 {0, 0.2, 0},
55 {1, 0.2, 0}
59 void
60 piglit_init(int argc, char **argv)
62 static const char *varyings[] = { "gl_Position", "gl_FrontColor" };
63 GLuint vs;
65 glMatrixMode(GL_MODELVIEW);
66 glLoadIdentity();
67 glScalef(0.5, 0.5, 1.0);
69 /* Check the driver. */
70 piglit_require_gl_version(15);
71 piglit_require_vertex_shader();
72 piglit_require_transform_feedback();
74 /* Create shaders. */
75 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
76 prog = glCreateProgram();
77 glAttachShader(prog, vs);
78 glTransformFeedbackVaryings(prog, 2, varyings,
79 GL_INTERLEAVED_ATTRIBS_EXT);
80 glLinkProgram(prog);
81 if (!piglit_link_check_status(prog)) {
82 glDeleteProgram(prog);
83 piglit_report_result(PIGLIT_FAIL);
85 glUseProgram(prog);
87 /* Set up the vertex data buffer */
88 glGenBuffers(1, &vert_buf);
89 glBindBuffer(GL_ARRAY_BUFFER, vert_buf);
90 glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
92 /* Set up the transform feedback buffer. */
93 glGenBuffers(1, &xfb_buf);
94 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, xfb_buf);
95 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
96 xfb_buf_size, NULL, GL_STREAM_READ);
97 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0, xfb_buf);
99 glClearColor(0.2, 0.2, 0.2, 1.0);
101 if (argc > 1 && strcmp(argv[1], "large") == 0) {
102 GLint range[2];
103 glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, range);
104 if (range[1] == 1.0) {
105 printf("Max point size is %d, can't test large\n",
106 range[1]);
107 piglit_report_result(PIGLIT_WARN);
109 printf("Testing large points\n");
110 glPointSize(10.0);
115 static bool
116 equal(float a, float b)
118 return fabsf(a - b) < 0.0001;
122 enum piglit_result
123 piglit_display(void)
125 bool pass = true;
126 GLfloat *v;
127 int i;
128 GLuint q, num_prims;
130 glClear(GL_COLOR_BUFFER_BIT);
132 glGenQueries(1, &q);
133 glBeginQuery(GL_PRIMITIVES_GENERATED_EXT, q);
135 glBeginTransformFeedback(GL_POINTS);
136 glBindBuffer(GL_ARRAY_BUFFER, vert_buf);
137 glVertexPointer(3, GL_FLOAT, 0, 0);
138 glEnable(GL_VERTEX_ARRAY);
139 glDrawArrays(GL_POINTS, 0, 3);
140 glEndTransformFeedback();
142 glEndQuery(GL_PRIMITIVES_GENERATED);
144 glGetQueryObjectuiv(q, GL_QUERY_RESULT, &num_prims);
145 glDeleteQueries(1, &q);
146 printf("%u primitives generated:\n", num_prims);
148 if (num_prims != NUM_VERTS) {
149 printf("Incorrect number of prims generated.\n");
150 printf("Found %u, expected %u\n", num_prims, NUM_VERTS);
151 pass = false;
154 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, xfb_buf);
155 v = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, GL_READ_ONLY);
156 for (i = 0; i < num_prims; i++) {
157 printf("vertex %2d: pos %5.2g, %5.2g, %5.2g, %5.2g "
158 "color %5.2g, %5.2g, %5.2g, %5.2g\n", i,
159 v[i*8+0], v[i*8+1], v[i*8+2], v[i*8+3],
160 v[i*8+4], v[i*8+5], v[i*8+6], v[i*8+7]);
161 /* spot-check results */
162 if (!equal(v[i*8+1], 0.1)) {
163 printf("Incorrect Y coord for point %d: %f\n",
164 i, v[i*8+1]);
165 pass = false;
167 if (!equal(v[i*8+4], 0.9)) {
168 printf("Incorrect red value for point %d: %f\n",
169 i, v[i*8+4]);
170 pass = false;
173 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT);
175 piglit_present_results();
177 return pass ? PIGLIT_PASS : PIGLIT_FAIL;