1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * \file getfragdataindex.c
27 * heavily inspired by getfragdatalocation.c from Ian Romanick
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 #ifdef PIGLIT_USE_OPENGL
34 config
.supports_gl_compat_version
= 10;
35 #else // PIGLIT_USE_OPENGL_ES3
36 config
.supports_gl_es_version
= 30;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
43 #ifdef PIGLIT_USE_OPENGL
44 static const char *vs_text
=
47 "void main() { gl_Position = vertex; }\n"
50 static const char *fs_text
=
56 " a[0] = vec4(1.0);\n"
57 " a[1] = vec4(2.0);\n"
60 #else // PIGLIT_USE_OPENGL_ES3
61 static const char *vs_text
=
64 "void main() { gl_Position = vertex; }\n"
67 static const char *fs_text
=
69 "#extension GL_EXT_blend_func_extended : enable\n"
71 "out highp vec4 a[2];\n"
74 " a[0] = vec4(1.0);\n"
75 " a[1] = vec4(2.0);\n"
86 void piglit_init(int argc
, char **argv
)
88 GLint max_draw_buffers
, max_dual_source
;
94 #ifdef PIGLIT_USE_OPENGL
95 piglit_require_gl_version(30);
96 piglit_require_extension("GL_ARB_blend_func_extended");
97 #else // PIGLIT_USE_OPENGL_ES3
98 piglit_require_extension("GL_EXT_blend_func_extended");
101 /* This test needs some number of draw buffers, so make sure the
102 * implementation isn't broken. This enables the test to generate a
103 * useful failure message.
105 glGetIntegerv(GL_MAX_DRAW_BUFFERS
, &max_draw_buffers
);
106 if (max_draw_buffers
< 8) {
108 "OpenGL 3.0 requires GL_MAX_DRAW_BUFFERS >= 8. "
111 piglit_report_result(PIGLIT_FAIL
);
113 glGetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS
, &max_dual_source
);
114 if (max_dual_source
< 1) {
116 "blend_func_extended requires GL_MAX_DUAL_SOURCE_DRAW_BUFFERS >= 1. "
119 piglit_report_result(PIGLIT_FAIL
);
122 prog
= glCreateProgram();
123 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_text
);
124 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fs_text
);
125 glAttachShader(prog
, vs
);
126 glAttachShader(prog
, fs
);
127 if (!piglit_check_gl_error(GL_NO_ERROR
))
128 piglit_report_result(PIGLIT_FAIL
);
130 /* Page 237 (page 253 of the PDF) of the OpenGL 3.0 spec says:
132 * "If program has not been successfully linked, the error INVALID
133 * OPERATION is generated. If name is not a varying out variable,
134 * or if an error occurs, -1 will be returned."
136 if (!piglit_khr_no_error
) {
137 printf("Querying index before linking...\n");
138 #ifdef PIGLIT_USE_OPENGL
139 idx
= glGetFragDataIndex(prog
, "v");
140 #else // PIGLIT_USE_OPENGLES3
141 idx
= glGetFragDataIndexEXT(prog
, "v");
143 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
144 piglit_report_result(PIGLIT_FAIL
);
147 fprintf(stderr
, "Expected index = -1, got %d\n", idx
);
148 piglit_report_result(PIGLIT_FAIL
);
153 if (!piglit_check_gl_error(GL_NO_ERROR
))
154 piglit_report_result(PIGLIT_FAIL
);
156 if (!piglit_link_check_status(prog
)) {
157 piglit_report_result(PIGLIT_FAIL
);
160 printf("Querying index of nonexistent variable...\n");
161 #ifdef PIGLIT_USE_OPENGL
162 idx
= glGetFragDataIndex(prog
, "waldo");
163 #else // PIGLIT_USE_OPENGLES3
164 idx
= glGetFragDataIndexEXT(prog
, "waldo");
166 if (!piglit_check_gl_error(GL_NO_ERROR
))
167 piglit_report_result(PIGLIT_FAIL
);
170 fprintf(stderr
, "Expected index = -1, got %d\n", idx
);
171 piglit_report_result(PIGLIT_FAIL
);
173 piglit_report_result(PIGLIT_PASS
);