ext_framebuffer_object: setup max mipmap level to make fbo complete
[piglit.git] / tests / spec / arb_get_texture_sub_image / cubemap.c
blobec94670b721e1b740708f761bbbb43d0ec290b86
1 /*
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
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 /**
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
37 static void
38 memset_series(unsigned *buffer, unsigned baseValue, unsigned size)
40 unsigned i;
41 for (i = 0; i < size; i++)
42 buffer[i] = baseValue + i;
46 static bool
47 compare_series(const unsigned *buffer, unsigned baseValue, unsigned size)
49 unsigned i;
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]);
54 return false;
58 return true;
62 static bool
63 test_cubemap(void)
65 GLuint tex;
66 GLuint buffer[8*8];
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,
80 sizeof(buffer)/4);
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,
84 buffer);
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,
93 0, 0, 0, /* offset */
94 8 >> level, 8 >> level, 6, /* size */
95 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
96 sizeof(results), results);
98 /* check results */
99 imgStart = 0;
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,
104 numTexels)) {
105 printf("Incorrect cubemap texel at "
106 "level %u, face %u\n",
107 level, face);
108 return false;
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
117 * at once.
119 for (level = 0; level < 3; level++) {
120 const int w = 4 >> level, h = 4 >> level;
121 int x, y;
123 memset(results, 0, sizeof(results));
125 glPixelStorei(GL_PACK_ROW_LENGTH, w * 2);
126 glPixelStorei(GL_PACK_IMAGE_HEIGHT, h * 2);
128 /* lower-left */
129 x = y = 0;
130 glPixelStorei(GL_PACK_SKIP_PIXELS, x);
131 glPixelStorei(GL_PACK_SKIP_ROWS, y);
132 glGetTextureSubImage(tex, level,
133 x, y, 0,
134 w, h, 6,
135 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
136 sizeof(results), results);
138 /* lower-right */
139 x = w;
140 y = 0;
141 glPixelStorei(GL_PACK_SKIP_PIXELS, x);
142 glPixelStorei(GL_PACK_SKIP_ROWS, y);
143 glGetTextureSubImage(tex, level,
144 x, y, 0,
145 w, h, 6,
146 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
147 sizeof(results), results);
149 /* upper-left */
150 x = 0;
151 y = h;
152 glPixelStorei(GL_PACK_SKIP_PIXELS, x);
153 glPixelStorei(GL_PACK_SKIP_ROWS, y);
154 glGetTextureSubImage(tex, level,
155 x, y, 0,
156 w, h, 6,
157 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
158 sizeof(results), results);
160 /* upper-right */
161 x = w;
162 y = h;
163 glPixelStorei(GL_PACK_SKIP_PIXELS, x);
164 glPixelStorei(GL_PACK_SKIP_ROWS, y);
165 glGetTextureSubImage(tex, level,
166 x, y, 0,
167 w, h, 6,
168 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
169 sizeof(results), results);
171 /* check results */
172 imgStart = 0;
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,
177 numTexels)) {
178 printf("Incorrect cubemap texel at "
179 "level %u, face %u\n",
180 level, face);
181 return false;
183 imgStart += numTexels;
187 return true;
191 void
192 piglit_init(int argc, char **argv)
194 bool pass = test_cubemap();
195 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
199 enum piglit_result
200 piglit_display(void)
202 /* never called */
203 return PIGLIT_PASS;