cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / glsl-invalid-asm-01.c
bloba1e784f7663200dc210398d2448ead84649f11cf
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 DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * \file glsl-invalid-asm-01.c
26 * Attempting to render with an invalid ARB_fp shader should generate an error.
28 * Based on code inspection it was found that Mesa does not correctly generate
29 * the draw-time error if a GLSL shader is used with an invalid assembly
30 * (GL_ARB_vertex_program or GL_ARB_fragment_program) program. This test
31 * attempts to reproduce this failure using an assembly fragment program.
33 #include "piglit-util-gl.h"
35 static const char vs_text[] =
36 "void main() { gl_Position = gl_Vertex;"
37 "gl_FrontColor = vec4(1.0, 0.0, 0.0, 1.0); }";
39 static const char fp_text[] =
40 "this won't compile";
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 10;
46 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
48 PIGLIT_GL_TEST_CONFIG_END
50 enum piglit_result
51 piglit_display(void)
53 static GLboolean logged = GL_FALSE;
54 GLboolean pass = GL_TRUE;
55 GLenum err;
57 glClearColor(0.5, 0.5, 0.5, 0.0);
58 glClear(GL_COLOR_BUFFER_BIT);
60 piglit_draw_rect(-1.0, -1.0, 2.0, 2.0);
62 err = glGetError();
63 if (err != GL_INVALID_OPERATION) {
64 if (!logged) {
65 printf("Unexpected OpenGL error state 0x%04x with bad "
66 "fragment program at draw (expected 0x%04x).\n",
67 err, GL_INVALID_OPERATION);
68 logged = GL_TRUE;
71 pass = GL_FALSE;
73 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
76 void
77 piglit_init(int argc, char **argv)
79 GLuint vs;
80 GLuint fp;
81 GLuint prog;
82 GLenum err;
84 piglit_require_gl_version(20);
86 piglit_require_extension("GL_ARB_fragment_program");
88 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
89 prog = piglit_link_simple_program(vs, 0);
90 glUseProgram(prog);
92 glGenProgramsARB(1, &fp);
93 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fp);
94 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,
95 GL_PROGRAM_FORMAT_ASCII_ARB,
96 strlen(fp_text),
97 (const GLubyte *) fp_text);
99 err = glGetError();
100 if (err != GL_INVALID_OPERATION) {
101 printf("Unexpected OpenGL error state 0x%04x with bad "
102 "fragment program (expected 0x%04x).\n",
103 err, GL_INVALID_OPERATION);
104 piglit_report_result(PIGLIT_FAIL);
107 glEnable(GL_FRAGMENT_PROGRAM_ARB);
109 /* Clear all GL error state.
111 while (glGetError() != 0)
112 /* empty */ ;