2 * Copyright (c) 2013 VMware, Inc.
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
21 * DEALINGS IN THE SOFTWARE.
25 * The section 3.8.7 (page 160) of the GL 3.2 core specification says:
27 * "Depth textures and the depth components of depth/stencil textures can
28 * be treated as RED textures during texture filtering and application
29 * (see section 3.8.15). The initial state for depth and depth/stencil
30 * textures treats them as RED textures."
37 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config
.supports_gl_core_version
= 32;
41 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
42 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
48 static GLuint tex
, prog
, vao
;
52 make_depth_texture(void)
54 GLfloat texels
[TEX_SIZE
][TEX_SIZE
];
56 GLenum format
= GL_DEPTH_COMPONENT
;
58 /* Z = 0 at bottom, Z = 1 at top */
59 for (i
= 0; i
< TEX_SIZE
; i
++) {
60 for (j
= 0; j
< TEX_SIZE
; j
++) {
61 float z
= i
/ (float) (TEX_SIZE
- 1);
66 glGenTextures(1, &tex
);
67 glBindTexture(GL_TEXTURE_2D
, tex
);
68 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
69 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
70 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
71 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
73 glTexImage2D(GL_TEXTURE_2D
, 0, format
,
74 TEX_SIZE
, TEX_SIZE
, 0,
75 format
, GL_FLOAT
, texels
);
77 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
78 piglit_report_result(PIGLIT_FAIL
);
81 if (!piglit_khr_no_error
) {
82 /* this call should generate an error in the core profile */
83 glTexParameteri(GL_TEXTURE_2D
, GL_DEPTH_TEXTURE_MODE
, GL_INTENSITY
);
84 if (!piglit_check_gl_error(GL_INVALID_ENUM
)) {
85 piglit_report_result(PIGLIT_FAIL
);
94 make_shader_program(void)
96 static const char *vs_text
=
99 "in vec2 texcoord_in;\n"
100 "smooth out vec2 texcoord;\n"
103 " gl_Position = pos_in;\n"
104 " texcoord = texcoord_in;\n"
106 static const char *fs_text
=
108 "uniform sampler2D tex;\n"
109 "smooth in vec2 texcoord;\n"
113 " color = texture(tex, texcoord);\n"
114 " // enabling the next line fixes NVIDIA failure\n"
115 " // color = vec4(vec3(color.x), 1.0);\n"
121 prog
= piglit_build_simple_program(vs_text
, fs_text
);
124 u
= glGetUniformLocation(prog
, "tex");
125 glUniform1i(u
, 0); /* bind tex unit 0, just to be safe */
127 glBindAttribLocation(prog
, 0, "pos_in");
128 glBindAttribLocation(prog
, 1, "texcoord_in");
132 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
133 piglit_report_result(PIGLIT_FAIL
);
143 static const float pos_tc
[4][4] = {
144 { -1.0, -1.0, 0.0, 0.0 },
145 { 1.0, -1.0, 1.0, 0.0 },
146 { 1.0, 1.0, 1.0, 1.0 },
147 { -1.0, 1.0, 0.0, 1.0 }
149 const int stride
= sizeof(pos_tc
[0]);
152 glGenVertexArrays(1, &vao
);
153 glBindVertexArray(vao
);
155 glGenBuffers(1, &vbo
);
156 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
157 glBufferData(GL_ARRAY_BUFFER
, sizeof(pos_tc
), pos_tc
, GL_STATIC_DRAW
);
158 piglit_check_gl_error(GL_NO_ERROR
);
160 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
, stride
, (void *) 0);
161 glVertexAttribPointer(1, 2, GL_FLOAT
, GL_FALSE
, stride
, (void *) 8);
163 glEnableVertexAttribArray(0);
164 glEnableVertexAttribArray(1);
166 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
167 piglit_report_result(PIGLIT_FAIL
);
175 piglit_init(int argc
, char **argv
)
177 tex
= make_depth_texture();
178 prog
= make_shader_program();
186 static const float black
[4] = { 0.0, 0.0, 0.0, 1.0 };
187 static const float red50
[4] = { 0.5, 0.0, 0.0, 1.0 };
188 static const float red100
[4] = { 1.0, 0.0, 0.0, 1.0 };
191 glViewport(0, 0, piglit_width
, piglit_height
);
193 /* This should draw a red gradient ranging from black
194 * at the bottom of the window to full red at the top.
196 glClearColor(0.2, 0.2, 0.8, 1.0);
197 glClear(GL_COLOR_BUFFER_BIT
);
198 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
200 if (!piglit_probe_pixel_rgba(0, 0, black
))
203 if (!piglit_probe_pixel_rgba(0, piglit_height
/2, red50
))
206 if (!piglit_probe_pixel_rgba(0, piglit_height
-1, red100
))
209 piglit_present_results();
211 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
213 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;