2 * Copyright (c) 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
24 /** @file clear-max-level.c
26 * Exercise an nvidia driver bug where clearing a texture mipmap level
27 * fails if the level is >= GL_TEXTURE_MAX_LEVEL.
29 * BTW, glCopyImageSubData() seems to also fail if the src/dest mipmap level
30 * is >= GL_TEXTURE_MAX_LEVEL.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 14;
37 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
38 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
39 PIGLIT_GL_TEST_CONFIG_END
43 test_clear(GLint maxLevel
)
45 const GLenum target
= GL_TEXTURE_2D
;
46 const int width
= 32, height
= 32, numLevels
= 3;
47 const GLenum texInternalFormat
= GL_RGBA8
;
54 glGenTextures(1, &tex
);
55 glBindTexture(target
, tex
);
56 glTexStorage2D(target
,
61 if (!piglit_check_gl_error(GL_NO_ERROR
))
64 glTexParameteri(target
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
65 glTexParameteri(target
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
66 glTexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, 0);
67 glTexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, maxLevel
);
69 /* clear levels to unique values */
70 for (l
= 0; l
< numLevels
; ++l
) {
72 value
[0] = value
[1] = value
[2] = value
[3] = l
* 0.125;
73 glClearTexImage(tex
, l
, GL_RGBA
, GL_FLOAT
, value
);
74 if (!piglit_check_gl_error(GL_NO_ERROR
))
79 texData
= malloc(width
* height
* 4 * sizeof(GLfloat
));
81 for (l
= 0; l
< numLevels
; l
++) {
82 float expected
= l
* 0.125;
83 float w
= MAX2(1, width
>> l
);
84 float h
= MAX2(1, width
>> l
);
85 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
86 glGetTexImage(target
, l
, GL_RGBA
, GL_FLOAT
, texData
);
87 if (!piglit_check_gl_error(GL_NO_ERROR
))
89 for (i
= 0; i
< 4 * w
* h
; i
++) {
90 if (fabsf(texData
[i
] - expected
) > 0.01) {
92 printf("\tmipmap level %d, pixel %d\n",
94 printf("\tGL_TEXTURE_MAX_LEVEL %d\n", maxLevel
);
95 printf("\texpected value %g, found %g\n",
96 expected
, texData
[i
]);
104 glDeleteTextures(1, &tex
);
111 piglit_init(int argc
, char **argv
)
115 piglit_require_extension("GL_ARB_texture_storage");
116 piglit_require_extension("GL_ARB_clear_texture");
118 pass
= test_clear(0) && pass
;
119 pass
= test_clear(1) && pass
;
120 pass
= test_clear(2) && pass
;
122 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);