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
26 * A test of using glClearTexSubImage to clear sub-regions of integer
27 * tetures with a range of formats. Each format is created as a 4x4
28 * texture where the first four texels are cleared to known values
29 * using separate calls to glClearTexSubImage. The values are chosen
30 * to potentially trigger problems with signed conversions. The rest
31 * of the texture is initialised to zeroes. The textures are then read
32 * back with glGetTexImage and compared with the expected values.
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config
.supports_gl_compat_version
= 13;
44 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
46 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
48 PIGLIT_GL_TEST_CONFIG_END
50 /* Values to try clearing the texture to. The number of bytes used
51 * will depend on the component size for the format. The actual value
52 * used will depend on the endianness of the architecture but this
53 * shouldn't really matter for the test */
57 { 0xffffffffU
, 0x00000000U
, 0x12345678U
, 0x78274827U
},
58 { 0x00000000U
, 0xffffffffU
, 0x12345678U
, 0x78274827U
},
59 { 0x12345678U
, 0x00000000U
, 0xffffffffU
, 0x78274827U
},
60 { 0xa82748b7U
, 0x12345678U
, 0x00000000U
, 0xffffffffU
},
64 GLenum internal_format
;
71 static const struct format
73 { GL_RGBA32UI
, GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 4, 4 },
74 { GL_RGB32UI
, GL_RGB_INTEGER
, GL_UNSIGNED_INT
, 4, 3 },
75 { GL_RGBA16UI
, GL_RGBA_INTEGER
, GL_UNSIGNED_SHORT
, 2, 4 },
76 { GL_RGB16UI
, GL_RGB_INTEGER
, GL_UNSIGNED_SHORT
, 2, 3 },
77 { GL_RGBA8UI
, GL_RGBA_INTEGER
, GL_UNSIGNED_BYTE
, 1, 4 },
78 { GL_RGB8UI
, GL_RGB_INTEGER
, GL_UNSIGNED_BYTE
, 1, 3 },
79 { GL_RGBA32I
, GL_RGBA_INTEGER
, GL_INT
, 4, 4 },
80 { GL_RGB32I
, GL_RGB_INTEGER
, GL_INT
, 4, 3 },
81 { GL_RGBA16I
, GL_RGBA_INTEGER
, GL_SHORT
, 2, 4 },
82 { GL_RGB16I
, GL_RGB_INTEGER
, GL_SHORT
, 2, 3 },
83 { GL_RGBA8I
, GL_RGBA_INTEGER
, GL_BYTE
, 1, 4 },
84 { GL_RGB8I
, GL_RGB_INTEGER
, GL_BYTE
, 1, 3 },
88 create_texture(const struct format
*format
)
94 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
96 texel_size
= format
->component_size
* format
->n_components
;
97 tex_data
= malloc(texel_size
* TEX_WIDTH
* TEX_HEIGHT
);
99 memset(tex_data
, 0, texel_size
* TEX_WIDTH
* TEX_HEIGHT
);
101 glGenTextures(1, &tex
);
102 glBindTexture(GL_TEXTURE_2D
, tex
);
103 glTexImage2D(GL_TEXTURE_2D
,
105 format
->internal_format
,
106 TEX_WIDTH
, TEX_HEIGHT
,
111 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
112 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
120 clear_texture(GLuint tex
,
121 const struct format
*format
)
125 for (i
= 0; i
< ARRAY_SIZE(clear_values
); i
++) {
126 glClearTexSubImage(tex
,
128 i
% TEX_WIDTH
, /* x */
129 i
/ TEX_WIDTH
, /* y */
131 1, 1, 1, /* width/height/depth */
136 if (!piglit_check_gl_error(GL_NO_ERROR
))
144 check_texture(GLuint tex
,
145 const struct format
*format
)
147 GLubyte
*tex_data
, *p
;
152 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
154 texel_size
= format
->component_size
* format
->n_components
;
155 p
= tex_data
= malloc(texel_size
* TEX_WIDTH
* TEX_HEIGHT
);
157 glGetTexImage(GL_TEXTURE_2D
, 0, format
->format
, format
->type
, tex_data
);
159 for (i
= 0; i
< ARRAY_SIZE(clear_values
); i
++) {
160 if (memcmp(p
, clear_values
[i
], texel_size
)) {
167 /* The rest of the values should be zeroes */
168 for (i
= ARRAY_SIZE(clear_values
); i
< TEX_WIDTH
* TEX_HEIGHT
; i
++)
169 for (j
= 0; j
< texel_size
; j
++)
181 piglit_init(int argc
, char **argv
)
187 /* glClearTexture is either in the GL_ARB_clear_texture
188 * extension or in core in GL 4.4
190 if (piglit_get_gl_version() < 44 &&
191 !piglit_is_extension_supported("GL_ARB_clear_texture")) {
192 printf("OpenGL 4.4 or GL_ARB_clear_texture is required.\n");
193 piglit_report_result(PIGLIT_SKIP
);
196 /* Integer textures are either in GL 3.0 or GL_EXT_texture_integer
198 if (piglit_get_gl_version() < 30 &&
199 !piglit_is_extension_supported("GL_EXT_texture_integer")) {
200 printf("OpenGL 3.0 or GL_EXT_texture_integer is required.\n");
201 piglit_report_result(PIGLIT_SKIP
);
204 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
205 tex
= create_texture(formats
+ i
);
206 pass
&= clear_texture(tex
, formats
+ i
);
207 pass
&= check_texture(tex
, formats
+ i
);
208 glBindTexture(GL_TEXTURE_2D
, 0);
209 glDeleteTextures(1, &tex
);
212 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);