cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / createshaderprogram-bad-type.c
blob2f540f01bfe990036e8ddfff60592d8650fa5daa
1 /*
2 * Copyright © 2010 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
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file createshaderprogram-bad-type.c
26 * Call glCreateShaderProgramEXT with various program types, verify results
28 * \author Ian Romanick <ian.d.romanick@intel.com>
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 10;
36 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
38 PIGLIT_GL_TEST_CONFIG_END
40 static const char vs_text[] =
41 "void main() { gl_Position = gl_Vertex; }";
43 static const char gs_text[] =
44 "#extension GL_EXT_geometry_shader4: enable\n"
45 "#extension GL_ARB_geometry_shader4: enable\n"
46 "void main() {\n"
47 " for(int i = 0; i < gl_VerticesIn; i++) {\n"
48 " gl_Position = gl_PositionIn[i];\n"
49 " EmitVertex();\n"
50 " }\n"
51 " EndPrimitive();\n"
52 "}\n"
55 static const char fs_text[] =
56 "void main() { gl_FragColor = vec4(0.0); }";
58 enum piglit_result
59 piglit_display(void)
61 return PIGLIT_FAIL;
64 GLboolean
65 try_CreateShaderProgram(GLenum type, const char *source, GLenum expect)
67 GLboolean pass = GL_TRUE;
68 GLenum err;
69 GLuint prog;
71 /* There shouldn't be any GL errors, but clear them all just to be
72 * sure.
74 while (glGetError() != 0)
75 /* empty */ ;
77 /* Type is not one of the known shader types. This should generate
78 * the error GL_INVALID_ENUM.
80 prog = glCreateShaderProgramEXT(type, source);
82 err = glGetError();
83 if (err != expect) {
84 printf("Unexpected OpenGL error state 0x%04x for "
85 "glCreateShaderProgramEXT called with\n"
86 "the %sshader target 0x%04x (expected 0x%04x).\n",
87 err, (expect == 0) ? "" : "invalid ", type, expect);
88 pass = GL_FALSE;
91 while (glGetError() != 0)
92 /* empty */ ;
94 /* Exactly one of expect or prog should be zero. If the caller expected
95 * an error (expect != 0), a program should not have been created. If
96 * the caller expected success, a program should have been created.
98 if ((expect == 0) != (prog != 0)) {
99 printf("Expected that a program would %sbe created, "
100 "but instead one was %screated.\n",
101 (expect == 0) ? "not " : "",
102 (prog == 0) ? "not " : "");
103 pass = GL_FALSE;
106 return pass;
109 void
110 piglit_init(int argc, char **argv)
112 const GLenum expect = (piglit_is_extension_supported("GL_ARB_geometry_shader4")
113 || piglit_is_extension_supported("GL_EXT_geometry_shader4")
114 || piglit_is_extension_supported("GL_NV_geometry_shader4"))
115 ? 0 : GL_INVALID_ENUM;
116 GLboolean pass;
118 piglit_require_gl_version(20);
120 piglit_require_extension("GL_EXT_separate_shader_objects");
122 pass = try_CreateShaderProgram(GL_PROXY_TEXTURE_3D, vs_text,
123 GL_INVALID_ENUM);
124 pass = try_CreateShaderProgram(GL_VERTEX_SHADER, vs_text, 0)
125 && pass;
126 pass = try_CreateShaderProgram(GL_FRAGMENT_SHADER, fs_text, 0)
127 && pass;
128 pass = try_CreateShaderProgram(GL_GEOMETRY_SHADER_ARB, gs_text, expect)
129 && pass;
131 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);