2 * Copyright 2015 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 DEALINGS
25 * Test glGetTextureSubImage with cube maps.
28 #include "piglit-util-gl.h"
30 PIGLIT_GL_TEST_CONFIG_BEGIN
31 config
.supports_gl_compat_version
= 20;
32 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
;
33 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
34 PIGLIT_GL_TEST_CONFIG_END
38 memset_series(unsigned *buffer
, unsigned baseValue
, unsigned size
)
41 for (i
= 0; i
< size
; i
++)
42 buffer
[i
] = baseValue
+ i
;
47 compare_series(const unsigned *buffer
, unsigned baseValue
, unsigned size
)
50 for (i
= 0; i
< size
; i
++) {
51 if (buffer
[i
] != baseValue
+ i
) {
52 printf("Expected 0x%08x found 0x%08x\n",
53 baseValue
+ i
, buffer
[i
]);
67 GLuint results
[6*8*8];
68 int level
, face
, imgStart
;
70 piglit_require_extension("GL_ARB_get_texture_sub_image");
72 /* setup 8x8 mipmapped cube texture */
73 glGenTextures(1, &tex
);
74 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
);
75 glTexStorage2D(GL_TEXTURE_CUBE_MAP
, 4, GL_RGBA8
, 8, 8);
77 for (level
= 0; level
< 4; level
++) {
78 for (face
= 0; face
< 6; face
++) {
79 memset_series(buffer
, face
*10000+level
*100,
81 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ face
,
82 level
, 0, 0, 8 >> level
, 8 >> level
,
83 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
,
88 /* test getting all six faces */
89 for (level
= 0; level
< 4; level
++) {
90 /* get all six faces */
91 memset(results
, 0, sizeof(results
));
92 glGetTextureSubImage(tex
, level
,
94 8 >> level
, 8 >> level
, 6, /* size */
95 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
,
96 sizeof(results
), results
);
100 for (face
= 0; face
< 6; face
++) {
101 GLuint expected
= face
* 10000 + level
* 100;
102 int numTexels
= (8 >> level
) * (8 >> level
);
103 if (!compare_series(results
+ imgStart
, expected
,
105 printf("Incorrect cubemap texel at "
106 "level %u, face %u\n",
110 imgStart
+= numTexels
;
114 /* Test getting face sub images (skip last 1x1 mipmap level)
115 * using four glGetTextureSubImage calls, one per quadrant.
116 * Note that each call retrieves the quadrant for all six faces
119 for (level
= 0; level
< 3; level
++) {
120 const int w
= 4 >> level
, h
= 4 >> level
;
123 memset(results
, 0, sizeof(results
));
125 glPixelStorei(GL_PACK_ROW_LENGTH
, w
* 2);
126 glPixelStorei(GL_PACK_IMAGE_HEIGHT
, h
* 2);
130 glPixelStorei(GL_PACK_SKIP_PIXELS
, x
);
131 glPixelStorei(GL_PACK_SKIP_ROWS
, y
);
132 glGetTextureSubImage(tex
, level
,
135 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
,
136 sizeof(results
), results
);
141 glPixelStorei(GL_PACK_SKIP_PIXELS
, x
);
142 glPixelStorei(GL_PACK_SKIP_ROWS
, y
);
143 glGetTextureSubImage(tex
, level
,
146 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
,
147 sizeof(results
), results
);
152 glPixelStorei(GL_PACK_SKIP_PIXELS
, x
);
153 glPixelStorei(GL_PACK_SKIP_ROWS
, y
);
154 glGetTextureSubImage(tex
, level
,
157 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
,
158 sizeof(results
), results
);
163 glPixelStorei(GL_PACK_SKIP_PIXELS
, x
);
164 glPixelStorei(GL_PACK_SKIP_ROWS
, y
);
165 glGetTextureSubImage(tex
, level
,
168 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
,
169 sizeof(results
), results
);
173 for (face
= 0; face
< 6; face
++) {
174 GLuint expected
= face
* 10000 + level
* 100;
175 int numTexels
= (8 >> level
) * (8 >> level
);
176 if (!compare_series(results
+ imgStart
, expected
,
178 printf("Incorrect cubemap texel at "
179 "level %u, face %u\n",
183 imgStart
+= numTexels
;
192 piglit_init(int argc
, char **argv
)
194 bool pass
= test_cubemap();
195 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);