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
21 * DEALINGS IN THE SOFTWARE.
25 * Test a texture construction / base level issue in Mesa/gallium state tracker.
26 * The texture images are defined for levels 2, 3, ... and the height of
28 * Mesa was asserting in this case.
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 12;
39 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
40 PIGLIT_GL_TEST_CONFIG_END
43 const GLubyte gray
= 220;
47 piglit_init(int argc
, char **argv
)
49 const int width0
= 512;
51 const int base_level
= 2;
57 glGenTextures(1, &tex
);
58 glBindTexture(GL_TEXTURE_2D
, tex
);
60 nr_bytes
= (width0
>> base_level
) * height
* 4 * sizeof(GLubyte
);
61 texdata
= malloc(nr_bytes
);
62 memset(texdata
, gray
, nr_bytes
);
64 for (level
= base_level
; ; level
++) {
65 int width
= width0
>> level
;
68 printf("level %d: %d x %d\n", level
, width
, height
);
69 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGBA
, width
, height
, 0,
70 GL_RGBA
, GL_UNSIGNED_BYTE
, texdata
);
75 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
76 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
78 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, base_level
);
80 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
87 const float exp_color
[4] = {gray
/ 255.0f
, gray
/ 255.0f
,
88 gray
/ 255.0f
, gray
/ 255.0f
};
91 glClearColor(1, 0, 0, 0);
92 glClear(GL_COLOR_BUFFER_BIT
);
94 glEnable(GL_TEXTURE_2D
);
96 piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1);
98 pass
= piglit_probe_pixel_rgba(piglit_width
/ 2, piglit_height
/ 2,
101 piglit_present_results();
103 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;