ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_transform_feedback3 / set_varyings_with_invalid_args.c
bloba9efccb1970adb5658283f4fee70083de3585310
1 /*
2 * Copyright © 2013 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 #include "piglit-util-gl.h"
25 #include "xfb3_common.h"
27 /**
28 * @file set_varyings_with_invalid_args.c
30 * Tests that TransformFeedbackVaryings() does not accept non-existing program
31 * and that the upper limit for the number of attributes is guarded. The spec:
33 * "The error INVALID_VALUE is generated by TransformFeedbackVaryings if
34 * <program> is not the name of a program object, or if <bufferMode> is
35 * SEPARATE_ATTRIBS and <count> is greater than the limit
36 * MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS."
38 * Additionally accept following common rule with shader object API, specified
39 * by the 'Shader Objects' section of OpenGL spec:
41 * "Commands that accept shader or program object names will generate the error
42 * INVALID VALUE if the provided name is not the name of either a shader or pro-
43 * gram object and INVALID OPERATION if the provided name identifies an object
44 * that is not the expected type."
47 PIGLIT_GL_TEST_CONFIG_BEGIN
49 config.supports_gl_compat_version = 32;
50 config.supports_gl_core_version = 32;
51 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
53 PIGLIT_GL_TEST_CONFIG_END
55 static const char gs_simple_text[] =
56 "#version 150\n"
57 "layout(points) in;\n"
58 "layout(points, max_vertices = 1) out;\n"
59 "out float x1_out;\n"
60 "void main() {\n"
61 " gl_Position = gl_in[0].gl_Position;\n"
62 " x1_out = 1.0;\n"
63 "}";
65 static const char *varyings[] = { "x1_out" };
67 /**
68 * Dynamically reserve space and setup an array of 'n' string pointers all
69 * referring to 'varyings'. For testing the upper bound of attributes expected
70 * the string values do not need to be mutually unique but in order to respect
71 * the API there should be as many strings available in the array as claimed.
73 static void
74 try_max_varyings(GLuint prog, unsigned n)
76 const char **var_array;
77 unsigned i;
79 var_array = (const char**)malloc(n * sizeof(const char *));
81 for (i = 0; i < n; ++i)
82 var_array[i] = varyings[0];
84 glTransformFeedbackVaryings(prog, n, var_array, GL_SEPARATE_ATTRIBS);
86 free(var_array);
89 void
90 piglit_init(int argc, char **argv)
92 GLuint vs, gs, prog;
93 GLint max_attrib_n;
95 piglit_require_extension("GL_ARB_transform_feedback3");
97 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
98 &max_attrib_n);
99 if (!max_attrib_n) {
100 printf("Maximum number of separete attributes is zero\n");
101 piglit_report_result(PIGLIT_FAIL);
104 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_pass_thru_text);
105 gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_simple_text);
107 if (!vs || !gs)
108 piglit_report_result(PIGLIT_FAIL);
110 prog = glCreateProgram();
111 glAttachShader(prog, vs);
112 glAttachShader(prog, gs);
113 glLinkProgram(prog);
115 if(!piglit_link_check_status(prog))
116 piglit_report_result(PIGLIT_FAIL);
118 /* Try invalid program */
119 glTransformFeedbackVaryings(42, ARRAY_SIZE(varyings), varyings,
120 GL_INTERLEAVED_ATTRIBS);
121 if (!piglit_check_gl_error(GL_INVALID_VALUE))
122 piglit_report_result(PIGLIT_FAIL);
124 /* Try shader in place of program. */
125 glTransformFeedbackVaryings(vs, ARRAY_SIZE(varyings), varyings,
126 GL_INTERLEAVED_ATTRIBS);
127 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
128 piglit_report_result(PIGLIT_FAIL);
130 /* Try too many attributes */
131 try_max_varyings(prog, max_attrib_n + 1);
132 if (!piglit_check_gl_error(GL_INVALID_VALUE))
133 piglit_report_result(PIGLIT_FAIL);
135 piglit_report_result(PIGLIT_PASS);
138 enum piglit_result
139 piglit_display(void)
141 /* Should never be reached */
142 return PIGLIT_FAIL;