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
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
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
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
58 const char *vs_source
=
61 " gl_Position = gl_Vertex;\n"
63 const char *fs_source
=
66 " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\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
);
77 test_delete_active(void)
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();
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);
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
,
99 piglit_present_results();
101 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
105 test_delete_duplicate(void)
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
);
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
,
132 piglit_present_results();
134 glDeleteProgram(prog
);
136 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
143 case TEST_DELETE_DUPLICATE
:
144 return test_delete_duplicate();
145 case TEST_DELETE_ACTIVE
:
147 return test_delete_active();
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);