ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / nv_conditional_render / generatemipmap.c
blob1953e3dbf48bf81d43e0c4970a25ca1060a07576
1 /*
2 * Copyright © 2011 Intel Corporation
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 #include "piglit-util-gl.h"
26 /**
27 * @file generatemipmap.c
29 * Tests that conditional rendering does not affect glGenerateMipmap().
31 * It's something that would be likely to be implemented through
32 * normal rendering inside of the driver, and thus easy to
33 * accidentally disable during conditional rendering.
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config.supports_gl_compat_version = 10;
39 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
40 config.khr_no_error_support = PIGLIT_NO_ERRORS;
41 /* Note that this must be half of the texture size,
42 * see comments in the test
44 config.window_width = 32;
45 config.window_height = 32;
47 PIGLIT_GL_TEST_CONFIG_END
49 static void
50 fill_level(int level, int size, const GLfloat *color)
52 GLfloat *data;
53 int i;
55 data = malloc(size * size * 4 * sizeof(GLfloat));
56 for (i = 0; i < 4 * size * size; i += 4) {
57 data[i + 0] = color[0];
58 data[i + 1] = color[1];
59 data[i + 2] = color[2];
60 data[i + 3] = color[3];
62 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0,
63 GL_RGBA, GL_FLOAT, data);
64 free(data);
67 enum piglit_result
68 piglit_display(void)
70 bool pass = true;
71 float red[4] = {1.0, 0.0, 0.0, 0.0};
72 float green[4] = {0.0, 1.0, 0.0, 0.0};
73 GLuint q, texture;
74 int tex_size = 64;
75 int i;
77 glClearColor(0.5, 0.5, 0.5, 0.5);
78 glClear(GL_COLOR_BUFFER_BIT);
80 /* Set up a texture object with green at level 0, red elsewhere */
81 glGenTextures(1, &texture);
82 glBindTexture(GL_TEXTURE_2D, texture);
84 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
85 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
88 GL_LINEAR_MIPMAP_NEAREST);
89 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
91 for (i = 0; tex_size / (1 << i) > 0; i++)
92 fill_level(i, tex_size / (1 << i), i == 0 ? green : red);
94 glGenQueries(1, &q);
96 /* Generate query fail. */
97 glBeginQuery(GL_SAMPLES_PASSED, q);
98 glEndQuery(GL_SAMPLES_PASSED);
100 /* Mipmap generation should not be affected by conditional rendering. */
101 glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV);
102 glGenerateMipmapEXT(GL_TEXTURE_2D);
103 glEndConditionalRenderNV();
105 /* This should draw level 1, since starting window size is 32
106 * and texture is 64.
108 glEnable(GL_TEXTURE_2D);
109 piglit_draw_rect_tex(-1, -1, 2, 2,
110 0, 0, 1, 1);
111 glDisable(GL_TEXTURE_2D);
113 pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
114 green);
116 piglit_present_results();
118 glDeleteQueries(1, &q);
120 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
123 void
124 piglit_init(int argc, char **argv)
126 piglit_require_gl_version(20);
128 piglit_require_extension("GL_NV_conditional_render");
129 piglit_require_extension("GL_EXT_framebuffer_object");