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
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 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
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,
54 glGenTextures(1, &tex
);
55 glBindTexture(GL_TEXTURE_2D
, tex
);
56 glTexImage2D(GL_TEXTURE_2D
,
58 GL_DEPTH24_STENCIL8_EXT
,
59 2, 2, /* width/height */
62 GL_UNSIGNED_INT_24_8_EXT
,
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
,
80 1, 1, /* width/height */
82 GL_UNSIGNED_INT_24_8_EXT
,
84 glTexSubImage2D(GL_TEXTURE_2D
,
87 1, 1, /* width/height */
89 GL_UNSIGNED_INT_24_8_EXT
,
96 GLubyte texels
[2 * 2 * 4];
99 glGetTexImage(GL_TEXTURE_2D
,
101 GL_DEPTH_STENCIL_EXT
,
102 GL_UNSIGNED_INT_24_8_EXT
,
105 for (i
= 0; i
< sizeof texels
; i
++)
113 piglit_init(int argc
, char **argv
)
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
);
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
);