2 * Copyright © 2011 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 /** @file fbo-alphatest-nocolor.c
26 * Tests that rendering to a depth texture with no color buffer bound
27 * and alpha testing enabled does the alpha testing correctly.
30 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 10;
38 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_RGBA
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
45 static const char *vs_source
=
48 " gl_Position = gl_Vertex;\n"
51 static const char *fs_source
=
52 "uniform vec4 color;\n"
55 " gl_FragColor = color;\n"
57 static int color_location
;
59 static void create_fbo(GLuint
*out_tex
)
64 /* Create the depth-stencil buffer. */
65 glGenTextures(1, &tex
);
66 glBindTexture(GL_TEXTURE_2D
, tex
);
67 glTexImage2D(GL_TEXTURE_2D
, 0, GL_DEPTH_COMPONENT
,
68 BUF_WIDTH
, BUF_WIDTH
, 0,
69 GL_DEPTH_COMPONENT
, GL_FLOAT
, NULL
);
70 if (!piglit_check_gl_error(GL_NO_ERROR
))
71 piglit_report_result(PIGLIT_FAIL
);
74 glGenFramebuffersEXT(1, &fb
);
75 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
76 glDrawBuffer(GL_NONE
);
77 glReadBuffer(GL_NONE
);
79 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
80 GL_DEPTH_ATTACHMENT_EXT
,
85 status
= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT
);
86 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
87 piglit_report_result(PIGLIT_SKIP
);
90 glViewport(0, 0, BUF_WIDTH
, BUF_WIDTH
);
91 glEnable(GL_DEPTH_TEST
);
92 glDepthFunc(GL_ALWAYS
);
94 glClear(GL_DEPTH_BUFFER_BIT
);
96 if (!piglit_check_gl_error(GL_NO_ERROR
))
97 piglit_report_result(PIGLIT_FAIL
);
99 glEnable(GL_ALPHA_TEST
);
100 glAlphaFunc(GL_GREATER
, 0.5f
);
103 /* Does not draw (depth texture = 1.0) */
104 glUniform4f(color_location
, 0.0, 1.0, 0.0, 0.0);
105 piglit_draw_rect_z(1.0,
106 -1.0, -1.0, 1.0, 2.0);
108 /* Draws (depth texture = 0.0). */
109 glUniform4f(color_location
, 0.0, 1.0, 0.0, 1.0);
110 piglit_draw_rect_z(1.0,
111 0.0, -1.0, 1.0, 2.0);
113 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
114 glDeleteFramebuffersEXT(1, &fb
);
116 glDisable(GL_ALPHA_TEST
);
117 glDisable(GL_DEPTH_TEST
);
123 enum piglit_result
piglit_display(void)
125 GLboolean pass
= GL_TRUE
;
126 float black
[] = {0, 0, 0, 0};
127 float white
[] = {1, 1, 1, 1};
130 glClearColor(0.0, 1.0, 0.0, 0.0);
131 glClear(GL_COLOR_BUFFER_BIT
);
135 glBindTexture(GL_TEXTURE_2D
, tex
);
136 glViewport(0, 0, piglit_width
, piglit_height
);
138 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
140 glEnable(GL_TEXTURE_2D
);
141 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
142 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
143 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
144 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
145 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
146 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
147 glTexParameteri(GL_TEXTURE_2D
, GL_DEPTH_TEXTURE_MODE
, GL_INTENSITY
);
149 piglit_draw_rect_tex(-1, -1, 2, 2,
152 glDisable(GL_TEXTURE_2D
);
154 pass
= pass
&& piglit_probe_rect_rgba(0, 0,
155 piglit_width
/ 2, piglit_height
,
157 pass
= pass
&& piglit_probe_rect_rgba(piglit_width
/ 2, 0,
158 piglit_width
/ 2, piglit_height
,
161 glDeleteTextures(1, &tex
);
163 piglit_present_results();
165 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
168 void piglit_init(int argc
, char **argv
)
172 piglit_require_gl_version(20);
174 piglit_require_extension("GL_EXT_framebuffer_object");
176 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_source
);
177 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fs_source
);
178 prog
= piglit_link_simple_program(vs
, fs
);
181 piglit_report_result(PIGLIT_SKIP
);
184 color_location
= glGetUniformLocation(prog
, "color");
185 if (color_location
== -1) {
186 fprintf(stderr
, "Failed to get uniform location");
187 piglit_report_result(PIGLIT_FAIL
);