framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / ext_packed_depth_stencil / texsubimage.c
blob999d2e0bc00d1f70292119cb03b744a001dc0462
1 /*
2 * Copyright (c) 2014 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 /** @file texsubimage.c
26 * A test of using glTexSubImage2D to update a region of a
27 * depth-stencil texture. A 4x4 depth-stencil is created and then two
28 * of the texels are set using different values. The whole texture is
29 * read back using glGetTexImage and compared to the expected values.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 13;
38 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
39 config.khr_no_error_support = PIGLIT_NO_ERRORS;
41 PIGLIT_GL_TEST_CONFIG_END
43 static GLuint
44 create_texture(void)
46 static const GLubyte data[] = {
47 0xff, 0xff, 0xff, 0xff,
48 0x04, 0x05, 0x06, 0x07,
49 0xff, 0xff, 0xff, 0xff,
50 0x0c, 0x0d, 0x0e, 0x0f,
52 GLuint tex;
54 glGenTextures(1, &tex);
55 glBindTexture(GL_TEXTURE_2D, tex);
56 glTexImage2D(GL_TEXTURE_2D,
57 0, /* level */
58 GL_DEPTH24_STENCIL8_EXT,
59 2, 2, /* width/height */
60 0, /* border */
61 GL_DEPTH_STENCIL_EXT,
62 GL_UNSIGNED_INT_24_8_EXT,
63 data);
65 return tex;
68 static void
69 update_texture(void)
71 static const GLubyte bottom_left_pixel[] = {
72 0x00, 0x01, 0x02, 0x03
74 static const GLubyte top_left_pixel[] = {
75 0x08, 0x09, 0x0a, 0x0b
77 glTexSubImage2D(GL_TEXTURE_2D,
78 0, /* level */
79 0, 0, /* x/y */
80 1, 1, /* width/height */
81 GL_DEPTH_STENCIL_EXT,
82 GL_UNSIGNED_INT_24_8_EXT,
83 bottom_left_pixel);
84 glTexSubImage2D(GL_TEXTURE_2D,
85 0, /* level */
86 0, 1, /* x/y */
87 1, 1, /* width/height */
88 GL_DEPTH_STENCIL_EXT,
89 GL_UNSIGNED_INT_24_8_EXT,
90 top_left_pixel);
93 static bool
94 check_texels(void)
96 GLubyte texels[2 * 2 * 4];
97 int i;
99 glGetTexImage(GL_TEXTURE_2D,
100 0, /* level */
101 GL_DEPTH_STENCIL_EXT,
102 GL_UNSIGNED_INT_24_8_EXT,
103 texels);
105 for (i = 0; i < sizeof texels; i++)
106 if (texels[i] != i)
107 return false;
109 return true;
112 void
113 piglit_init(int argc, char **argv)
115 GLuint tex;
116 bool pass;
118 /* We can create depth/stencil textures if either:
119 * 1. We have GL 3.0 or later
120 * 2. We have GL_EXT_packed_depth_stencil and GL_ARB_depth_texture
122 if (piglit_get_gl_version() < 30
123 && !(piglit_is_extension_supported("GL_EXT_packed_depth_stencil") &&
124 piglit_is_extension_supported("GL_ARB_depth_texture"))) {
125 printf("OpenGL 3.0 or GL_EXT_packed_depth_stencil + "
126 "GL_ARB_depth_texture is required.\n");
127 piglit_report_result(PIGLIT_SKIP);
130 tex = create_texture();
132 if (!piglit_check_gl_error(GL_NO_ERROR))
133 piglit_report_result(PIGLIT_FAIL);
135 update_texture();
137 if (!piglit_check_gl_error(GL_NO_ERROR))
138 piglit_report_result(PIGLIT_FAIL);
140 glBindTexture(GL_TEXTURE_2D, tex);
142 pass = check_texels();
144 glBindTexture(GL_TEXTURE_2D, 0);
146 glDeleteTextures(1, &tex);
148 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
151 enum piglit_result
152 piglit_display(void)
154 /* unused */
155 return PIGLIT_FAIL;