add pbobench: a benchmark for pbo functions
[piglit.git] / tests / texturing / generatemipmap-base-change.c
blobe550a754a367eabb272a50cd31f623c98489bc0d
1 /*
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
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 that glGenerateMipmap works properly (doesn't crash) when called a
26 * second time on a texture after we change the base image's size or format.
28 * The command line takes two parameters:
29 * size - test base level size change
30 * format - test base level format change
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 10;
38 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
39 config.khr_no_error_support = PIGLIT_NO_ERRORS;
40 PIGLIT_GL_TEST_CONFIG_END
43 void
44 piglit_init(int argc, char **argv)
46 #define MAX_SIZE 8
47 GLubyte img[MAX_SIZE * MAX_SIZE * 4];
48 bool change_size = false, change_format = false;
49 int i;
50 GLuint tex;
51 GLsizei base_size, w0 = 0, h0 = 0;
52 bool pass = true;
54 /* We require GL 3.0 or GL_EXT_framebuffer_object */
55 if (piglit_get_gl_version() < 30 &&
56 !piglit_is_extension_supported("GL_EXT_framebuffer_object")) {
57 piglit_report_result(PIGLIT_SKIP);
60 /* parse args */
61 for (i = 1; i < argc; i++) {
62 if (strcmp(argv[i], "size") == 0) {
63 change_size = true;
64 } else if (strcmp(argv[i], "format") == 0) {
65 change_format = true;
69 if (!change_size && !change_format) {
70 printf("Missing required argument: 'size' or 'format'\n");
71 piglit_report_result(PIGLIT_SKIP);
74 /* init image data */
75 for (i = 0; i < sizeof(img); i++)
76 img[i] = 128;
79 glGenTextures(1, &tex);
80 glBindTexture(GL_TEXTURE_2D, tex);
82 // Create initial texture mipmap (base_size x base_size)
83 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
84 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
85 base_size = change_size ? MAX_SIZE / 2 : MAX_SIZE;
86 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, base_size, base_size, 0,
87 GL_RGBA, GL_UNSIGNED_BYTE, img);
88 glGenerateMipmap(GL_TEXTURE_2D);
90 if (change_format) {
91 /* Change format of first level */
92 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, base_size, base_size,
93 0, GL_RGBA, GL_UNSIGNED_BYTE, img);
95 else if (change_size) {
96 /* Change base level to be larger */
97 assert(base_size * 2 == MAX_SIZE);
98 base_size = MAX_SIZE;
99 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, base_size, base_size,
100 0, GL_RGBA, GL_UNSIGNED_BYTE, img);
103 /* See if mipmap generation works (may crash/assert in Mesa) */
104 glGenerateMipmap(GL_TEXTURE_2D);
106 /* check level sizes */
107 for (i = 0; i < 3; i++) {
108 GLint w, h;
109 glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w);
110 glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h);
111 if (i == 0) {
112 w0 = w;
113 h0 = h;
115 else {
116 if (w != w0 >> i || h != h0 >> i) {
117 printf("Incorrect mipmap level size: level %d", i);
118 printf(" Found %d x %d, expected %d x %d\n", w, h,
119 w0 >> i , h0 >> i);
120 pass = false;
125 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
129 enum piglit_result
130 piglit_display(void)
132 // no-op
133 return PIGLIT_PASS;