arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / fbo / fbo-copyteximage.c
blob38f0477dc7c2032d71b2c9e767b2a172eb69ac06
1 /*
2 * Copyright © 2009 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.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /** @file fbo-generatemipmap.c
30 * Tests that glCopyTexSubImage work to a mipmap level of a NPOT texture.
31 * This tries to catch a bug with the Intel driver and texture tiling.
34 #include "piglit-util-gl.h"
36 #define TEX_WIDTH 254
37 #define TEX_HEIGHT 254
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config.supports_gl_compat_version = 10;
43 config.window_width = 700;
44 config.window_height = 300;
45 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
46 config.khr_no_error_support = PIGLIT_NO_ERRORS;
48 PIGLIT_GL_TEST_CONFIG_END
50 static const float red[] = {1, 0, 0, 0};
51 static const float green[] = {0, 1, 0, 0};
52 static const float blue[] = {0, 0, 1, 0};
53 static const float white[] = {1, 1, 1, 1};
55 static int
56 create_fbo(void)
58 GLuint tex, copied_tex, fb;
59 GLenum status;
60 int i, dim;
61 int draw_w = TEX_WIDTH / 2, draw_h = TEX_HEIGHT / 2;
63 glGenTextures(1, &tex);
64 glBindTexture(GL_TEXTURE_2D, tex);
66 for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
67 glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA,
68 dim, dim,
70 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
72 if (!piglit_check_gl_error(GL_NO_ERROR))
73 piglit_report_result(PIGLIT_FAIL);
75 /* Draw into the second level. */
76 glGenFramebuffersEXT(1, &fb);
77 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
78 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
79 GL_COLOR_ATTACHMENT0_EXT,
80 GL_TEXTURE_2D,
81 tex,
82 1);
83 if (!piglit_check_gl_error(GL_NO_ERROR))
84 piglit_report_result(PIGLIT_FAIL);
86 status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
87 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
88 fprintf(stderr, "FBO incomplete\n");
89 piglit_report_result(PIGLIT_SKIP);
92 glViewport(0, 0, draw_w, draw_h);
93 piglit_ortho_projection(draw_w, draw_h, GL_FALSE);
95 glColor4fv(red);
96 piglit_draw_rect(0, 0, draw_w / 2, draw_h / 2);
97 glColor4fv(green);
98 piglit_draw_rect(draw_w / 2, 0, draw_w, draw_h / 2);
99 glColor4fv(blue);
100 piglit_draw_rect(0, draw_h / 2, draw_w/2, draw_h);
101 glColor4fv(white);
102 piglit_draw_rect(draw_w / 2, draw_h / 2, draw_w, draw_h);
104 glGenTextures(1, &copied_tex);
105 glBindTexture(GL_TEXTURE_2D, copied_tex);
106 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, draw_w, draw_h, 0);
108 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
109 glDeleteFramebuffersEXT(1, &fb);
110 glDeleteTextures(1, &tex);
112 return copied_tex;
115 enum piglit_result
116 piglit_display(void)
118 GLboolean pass = GL_TRUE;
119 GLuint tex;
120 int x1 = 10 + TEX_WIDTH / 4;
121 int x2 = 10 + TEX_WIDTH * 3 / 4;
122 int y1 = 10 + TEX_HEIGHT / 4;
123 int y2 = 10 + TEX_HEIGHT * 3 / 4;
125 glClearColor(0.5, 0.5, 0.5, 0.5);
126 glClear(GL_COLOR_BUFFER_BIT);
128 tex = create_fbo();
129 glViewport(0, 0, piglit_width, piglit_height);
130 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
132 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
134 glEnable(GL_TEXTURE_2D);
135 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
139 piglit_draw_rect_tex(10, 10, TEX_WIDTH, TEX_HEIGHT,
140 0, 0, 1, 1);
142 pass &= piglit_probe_pixel_rgb(x1, y1, red);
143 pass &= piglit_probe_pixel_rgb(x2, y1, green);
144 pass &= piglit_probe_pixel_rgb(x1, y2, blue);
145 pass &= piglit_probe_pixel_rgb(x2, y2, white);
147 glDeleteTextures(1, &tex);
148 glDisable(GL_TEXTURE_2D);
150 piglit_present_results();
152 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
155 void piglit_init(int argc, char **argv)
157 piglit_require_extension("GL_EXT_framebuffer_object");
158 piglit_require_extension("GL_ARB_texture_non_power_of_two");