2 * Copyright © 2011 Intel Corporation
3 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #include "piglit-util-gl.h"
28 * @file copytexsubimage.c
30 * Tests that conditional rendering does not affect glCopyTexSubImage2D().
32 * It's something that would be likely to be implemented through
33 * normal rendering inside of the driver, and thus easy to
34 * accidentally disable during conditional rendering.
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 10;
40 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
46 fill_tex(int level
, int w
, int h
, const GLfloat
*color
)
51 data
= malloc(w
* h
* 4 * sizeof(GLfloat
));
52 for (i
= 0; i
< 4 * w
* h
; i
+= 4) {
53 data
[i
+ 0] = color
[0];
54 data
[i
+ 1] = color
[1];
55 data
[i
+ 2] = color
[2];
56 data
[i
+ 3] = color
[3];
58 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGBA
, w
, h
, 0,
59 GL_RGBA
, GL_FLOAT
, data
);
67 float red
[4] = {1.0, 0.0, 0.0, 0.0};
68 float green
[4] = {0.0, 1.0, 0.0, 0.0};
71 glClearColor(0.5, 0.5, 0.5, 0.5);
72 glClear(GL_COLOR_BUFFER_BIT
);
74 /* Draw bottom half of window to green. */
76 piglit_draw_rect(-1, -1, 2, 1);
77 glColor4f(1, 1, 1, 1);
79 /* Set up a red texture. */
80 glGenTextures(1, &texture
);
81 glBindTexture(GL_TEXTURE_2D
, texture
);
83 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
84 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
85 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
86 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
87 GL_LINEAR_MIPMAP_NEAREST
);
88 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP
, GL_TRUE
);
90 fill_tex(0, piglit_width
*2, piglit_height
/ 2, red
);
94 /* Generate query fail. */
95 glBeginQuery(GL_SAMPLES_PASSED
, q
);
96 glEndQuery(GL_SAMPLES_PASSED
);
98 /* This should not be affected by conditional rendering. */
99 glBeginConditionalRenderNV(q
, GL_QUERY_WAIT_NV
);
100 glCopyTexSubImage2D(GL_TEXTURE_2D
, 0, piglit_width
, 0, 0, 0, piglit_width
, piglit_height
/ 2);
101 glEndConditionalRenderNV();
103 /* Draw the right half of the texture. */
104 glEnable(GL_TEXTURE_2D
);
105 piglit_draw_rect_tex(-1, 0, 2, 1,
107 glDisable(GL_TEXTURE_2D
);
109 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
,
112 piglit_present_results();
114 glDeleteQueries(1, &q
);
116 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
120 piglit_init(int argc
, char **argv
)
122 piglit_require_gl_version(20);
124 piglit_require_extension("GL_NV_conditional_render");