ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_blend_func_extended / api / getfragdataindex.c
blob3c0efd005774696f5e9ddd3222f830b7a6740c94
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
12 * Software.
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
20 * IN THE SOFTWARE.
23 /**
24 * \file getfragdataindex.c
26 * \author Dave Airlie
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;
37 #endif
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 =
45 "#version 130\n"
46 "in vec4 vertex;\n"
47 "void main() { gl_Position = vertex; }\n"
50 static const char *fs_text =
51 "#version 130\n"
52 "out vec4 v;\n"
53 "out vec4 a[2];\n"
54 "void main() {\n"
55 " v = vec4(0.0);\n"
56 " a[0] = vec4(1.0);\n"
57 " a[1] = vec4(2.0);\n"
58 "}\n"
60 #else // PIGLIT_USE_OPENGL_ES3
61 static const char *vs_text =
62 "#version 300 es\n"
63 "in vec4 vertex;\n"
64 "void main() { gl_Position = vertex; }\n"
67 static const char *fs_text =
68 "#version 300 es\n"
69 "#extension GL_EXT_blend_func_extended : enable\n"
70 "out highp vec4 v;\n"
71 "out highp vec4 a[2];\n"
72 "void main() {\n"
73 " v = vec4(0.0);\n"
74 " a[0] = vec4(1.0);\n"
75 " a[1] = vec4(2.0);\n"
76 "}\n"
78 #endif
80 enum piglit_result
81 piglit_display(void)
83 return PIGLIT_FAIL;
86 void piglit_init(int argc, char **argv)
88 GLint max_draw_buffers, max_dual_source;
89 GLuint prog;
90 GLuint vs;
91 GLuint fs;
92 GLint idx;
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");
99 #endif
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) {
107 fprintf(stderr,
108 "OpenGL 3.0 requires GL_MAX_DRAW_BUFFERS >= 8. "
109 "Only got %d!\n",
110 max_draw_buffers);
111 piglit_report_result(PIGLIT_FAIL);
113 glGetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, &max_dual_source);
114 if (max_dual_source < 1) {
115 fprintf(stderr,
116 "blend_func_extended requires GL_MAX_DUAL_SOURCE_DRAW_BUFFERS >= 1. "
117 "Only got %d!\n",
118 max_dual_source);
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");
142 #endif
143 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
144 piglit_report_result(PIGLIT_FAIL);
146 if (idx != -1) {
147 fprintf(stderr, "Expected index = -1, got %d\n", idx);
148 piglit_report_result(PIGLIT_FAIL);
152 glLinkProgram(prog);
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");
165 #endif
166 if (!piglit_check_gl_error(GL_NO_ERROR))
167 piglit_report_result(PIGLIT_FAIL);
169 if (idx != -1) {
170 fprintf(stderr, "Expected index = -1, got %d\n", idx);
171 piglit_report_result(PIGLIT_FAIL);
173 piglit_report_result(PIGLIT_PASS);