cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / useprogram-refcount-1.c
blob2fa73a8c6209b622c4fe0eec8c6a3b213ba86257
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.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Neil Roberts <neil@linux.intel.com>
29 /** @file useprogram-refcount-1.c
31 * test_delete_active: tests that a metaops call (glDrawPixels()) doesn't lose the last
32 * reference on an active, deleted shader prorgam (Bug #31194)
34 * test_delete_duplicate: tests for shader cache errors (issue #2596) by creating 2
35 * identical program, deleting one of them, and using the other
36 * to draw something.
39 #include "piglit-util-gl.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config.supports_gl_compat_version = 10;
45 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
47 PIGLIT_GL_TEST_CONFIG_END
49 static enum {
50 TEST_DELETE_ACTIVE,
51 TEST_DELETE_DUPLICATE
52 } test_mode;
54 static GLint
55 build_program(void)
57 GLint vs, fs;
58 const char *vs_source =
59 "void main()\n"
60 "{\n"
61 " gl_Position = gl_Vertex;\n"
62 "}\n";
63 const char *fs_source =
64 "void main()\n"
65 "{\n"
66 " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\n"
67 "}\n";
69 piglit_require_gl_version(20);
71 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
72 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
73 return piglit_link_simple_program(vs, fs);
76 enum piglit_result
77 test_delete_active(void)
79 bool pass = true;
80 float green[4] = {0.0, 1.0, 0.0, 0.0};
81 uint8_t pixel[4] = {0x00, 0xff, 0x00, 0xff};
83 GLint prog = build_program();
84 glUseProgram(prog);
85 glDeleteProgram(prog);
87 /* Set up fixed function to draw red if we lose our shader. */
88 glColor4f(1.0, 0.0, 0.0, 0.0);
90 /* Tiny drawpixels */
91 glDrawPixels(1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
93 /* Draw over the whole screen with the shader. */
94 piglit_draw_rect(-1, -1, 2, 2);
96 pass &= piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
97 green);
99 piglit_present_results();
101 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
104 enum piglit_result
105 test_delete_duplicate(void)
107 bool pass = true;
108 float green[4] = {0.0, 1.0, 0.0, 0.0};
109 uint8_t pixel[4] = {0x00, 0xff, 0x00, 0xff};
111 GLint prog = build_program();
112 /* Build a second program, using the same shaders */
113 GLint prog_dup = build_program();
115 /* Set up fixed function to draw red if we lose our shader. */
116 glColor4f(1.0, 0.0, 0.0, 0.0);
118 glDrawPixels(1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
120 glUseProgram(prog);
121 piglit_draw_rect(-1, -1, 2, 2);
123 /* Delete the duplicate */
124 glDeleteProgram(prog_dup);
126 /* Re-draw over the whole screen with the shader. */
127 piglit_draw_rect(-1, -1, 2, 2);
129 pass &= piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
130 green);
132 piglit_present_results();
134 glDeleteProgram(prog);
136 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
139 enum piglit_result
140 piglit_display(void)
142 switch (test_mode) {
143 case TEST_DELETE_DUPLICATE:
144 return test_delete_duplicate();
145 case TEST_DELETE_ACTIVE:
146 default:
147 return test_delete_active();
151 void
152 piglit_init(int argc, char **argv)
154 test_mode = TEST_DELETE_ACTIVE;
155 if (argc == 2 && strcmp(argv[1], "delete_dup") == 0)
156 test_mode = TEST_DELETE_DUPLICATE;
157 piglit_require_gl_version(20);