2 * Copyright © 2016 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 * Verifies that mipmap generation uses the right format (from view,
26 * not what was originally specified).
29 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 20;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
38 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
40 PIGLIT_GL_TEST_CONFIG_END
43 * Create view with different view format and generate mipmap.
49 GLint width
= 4, height
= 4, levels
= 2;
52 glGenTextures(1, &tex
);
53 glBindTexture(GL_TEXTURE_2D
, tex
);
55 glTexStorage2D(GL_TEXTURE_2D
, levels
, GL_R8
, width
, height
);
57 /* averaging these as snorm values should give 0 */
59 {{0xFF, 0x01, 0xFF, 0x01},
60 {0xFF, 0x01, 0xFF, 0x01},
61 {0xFF, 0x01, 0xFF, 0x01},
62 {0xFF, 0x01, 0xFF, 0x01}};
65 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, width
, height
,
66 GL_RED
, GL_UNSIGNED_BYTE
, buf
);
68 glGenTextures(1, &new_tex
);
70 glTextureView(new_tex
, GL_TEXTURE_2D
, tex
, GL_R8_SNORM
, 0, 2, 0, 1);
71 glBindTexture(GL_TEXTURE_2D
, new_tex
);
72 glGenerateMipmap(GL_TEXTURE_2D
);
73 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
74 glGetTexImage(GL_TEXTURE_2D
, 1, GL_RED
, GL_BYTE
, &res
);
75 pass
= !res
[0] && !res
[1] && !res
[2] && !res
[3];
78 printf("expected 0, got %d %d %d %d\n",
79 res
[0], res
[1], res
[2], res
[3]);
82 glDeleteTextures(1, &new_tex
);
83 glDeleteTextures(1, &tex
);
95 piglit_init(int argc
, char **argv
)
99 piglit_require_extension("GL_ARB_texture_storage");
100 piglit_require_extension("GL_ARB_texture_view");
102 pass
= test_mipgen() && piglit_check_gl_error(GL_NO_ERROR
);
103 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);