1 /*
2 * Copyright (c) 2014 Intel Corporation
3 *
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:
10 *
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.
14 *
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
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 /**
25 * @file emitstreamvertex_stream_too_large.c
26 *
27 * Test that exceeding the implementation's maximum streams
28 * value (GL_MAX_VERTEX_STREAMS) when calling EmitStreamVertex
29 * results in a linking error.
30 *
31 * From ARB_gpu_shader5 spec:
32 *
33 * "If an implementation supports <N> vertex streams, the
34 * individual streams are numbered 0 through <N>-1"
35 *
36 */
37
38 #include "piglit-util-gl.h"
39
40 PIGLIT_GL_TEST_CONFIG_BEGIN
41
42 config.supports_gl_compat_version = 32;
43 config.supports_gl_core_version = 32;
44
45 PIGLIT_GL_TEST_CONFIG_END
46
47 enum piglit_result
piglit_display(void)48 piglit_display(void)
49 {
50 /* UNREACHED */
51 return PIGLIT_FAIL;
52 }
53
54 static const char *vs_source =
55 "#version 150\n"
56 "\n"
57 "void main()\n"
58 "{\n"
59 "gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
60 "}\n";
61
62 static const char *gs_template =
63 "#version 150\n"
64 "#extension GL_ARB_gpu_shader5: enable\n"
65 "\n"
66 "layout(points) in;\n"
67 "layout(points, max_vertices=1) out;\n"
68 "\n"
69 "void main()\n"
70 "{\n"
71 "gl_Position = vec4(1.0, 1.0, 1.0, 1.0);\n"
72 "EmitStreamVertex(%d);\n"
73 "EndStreamPrimitive(%d);\n"
74 "}\n";
75
76 static const char *fs_source =
77 "#version 150\n"
78 "out vec3 color;\n"
79 "\n"
80 "void main()\n"
81 "{\n"
82 "color = vec3(0.0, 0.0, 0.0);\n"
83 "}\n";
84
85 void
piglit_init(int argc,char ** argv)86 piglit_init(int argc, char **argv)
87 {
88 GLint max_streams;
89 GLint pass = 1;
90 GLint program;
91 GLint vs, fs, gs;
92 char *shader_text;
93
94 piglit_require_extension("GL_ARB_gpu_shader5");
95
96 glGetIntegerv(GL_MAX_VERTEX_STREAMS, &max_streams);
97
98 if (!piglit_check_gl_error(GL_NO_ERROR))
99 piglit_report_result(PIGLIT_FAIL);
100
101 vs = glCreateShader(GL_VERTEX_SHADER);
102 glShaderSource(vs, 1, (const GLchar **) &vs_source, NULL);
103 glCompileShader(vs);
104
105 fs = glCreateShader(GL_FRAGMENT_SHADER);
106 glShaderSource(fs, 1, (const GLchar **) &fs_source, NULL);
107 glCompileShader(fs);
108
109 (void)!asprintf(&shader_text, gs_template, max_streams, max_streams);
110 gs = glCreateShader(GL_GEOMETRY_SHADER);
111 glShaderSource(gs, 1, (const GLchar **) &shader_text, NULL);
112 glCompileShader(gs);
113
114 program = glCreateProgram();
115 glAttachShader(program, vs);
116 glAttachShader(program, gs);
117 glAttachShader(program, fs);
118
119 glLinkProgram(program);
120 glGetProgramiv(program, GL_LINK_STATUS, &pass);
121
122 glDetachShader(program, fs);
123 glDetachShader(program, gs);
124 glDetachShader(program, vs);
125
126 glDeleteProgram(program);
127
128 glDeleteShader(vs);
129 glDeleteShader(gs);
130 glDeleteShader(fs);
131 /* As an error is expected, pass should be 0. */
132 piglit_report_result(pass ? PIGLIT_FAIL : PIGLIT_PASS);
133 }
134