2 * Copyright © 2009 Intel Corporation
3 * Copyright © 2010 Red Hat, Inc.
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 * Eric Anholt <eric@anholt.net>
26 * Owen Taylor <otaylor@fishsoup.net>
30 /** @file fbo-generatemipmap.c
32 * Tests that glCopyTexImage2D can be used to copy from a texture
33 * into another texture.
36 #include "piglit-util-gl.h"
39 #define TEX_HEIGHT 256
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config
.supports_gl_compat_version
= 10;
45 config
.window_width
= TEX_WIDTH
;
46 config
.window_height
= TEX_HEIGHT
;
47 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
48 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
50 PIGLIT_GL_TEST_CONFIG_END
52 static const float red
[] = {1, 0, 0, 0};
53 static const float green
[] = {0, 1, 0, 0};
54 static const float blue
[] = {0, 0, 1, 0};
55 static const float white
[] = {1, 1, 1, 1};
60 GLuint tex
, copied_tex
, fb
;
63 glGenTextures(1, &tex
);
64 glBindTexture(GL_TEXTURE_2D
, tex
);
66 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
,
67 TEX_WIDTH
, TEX_HEIGHT
,
69 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
71 if (!piglit_check_gl_error(GL_NO_ERROR
))
72 piglit_report_result(PIGLIT_FAIL
);
74 glGenFramebuffersEXT(1, &fb
);
75 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
76 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
77 GL_COLOR_ATTACHMENT0_EXT
,
81 if (!piglit_check_gl_error(GL_NO_ERROR
))
82 piglit_report_result(PIGLIT_FAIL
);
84 status
= glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
85 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
86 fprintf(stderr
, "FBO incomplete\n");
87 piglit_report_result(PIGLIT_SKIP
);
90 glViewport(0, 0, TEX_WIDTH
, TEX_HEIGHT
);
91 piglit_ortho_projection(TEX_WIDTH
, TEX_HEIGHT
, GL_FALSE
);
94 piglit_draw_rect(0, 0, TEX_WIDTH
/ 2, TEX_HEIGHT
/ 2);
96 piglit_draw_rect(TEX_WIDTH
/ 2, 0, TEX_WIDTH
, TEX_HEIGHT
/ 2);
98 piglit_draw_rect(0, TEX_HEIGHT
/ 2, TEX_WIDTH
/2, TEX_HEIGHT
);
100 piglit_draw_rect(TEX_WIDTH
/ 2, TEX_HEIGHT
/ 2, TEX_WIDTH
, TEX_HEIGHT
);
102 glGenTextures(1, &copied_tex
);
103 glBindTexture(GL_TEXTURE_2D
, copied_tex
);
104 glCopyTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, TEX_WIDTH
, TEX_HEIGHT
, 0);
106 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
107 glDeleteFramebuffersEXT(1, &fb
);
108 glDeleteTextures(1, &tex
);
116 GLboolean pass
= GL_TRUE
;
118 int x1
= TEX_WIDTH
/ 4;
119 int x2
= TEX_WIDTH
* 3 / 4;
120 int y1
= TEX_HEIGHT
/ 4;
121 int y2
= TEX_HEIGHT
* 3 / 4;
123 glClearColor(0.5, 0.5, 0.5, 0.5);
124 glClear(GL_COLOR_BUFFER_BIT
);
127 glViewport(0, 0, piglit_width
, piglit_height
);
128 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
130 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
132 glEnable(GL_TEXTURE_2D
);
133 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
134 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
135 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
137 piglit_draw_rect_tex(0, 0, TEX_WIDTH
, TEX_HEIGHT
,
140 pass
&= piglit_probe_pixel_rgb(x1
, y1
, red
);
141 pass
&= piglit_probe_pixel_rgb(x2
, y1
, green
);
142 pass
&= piglit_probe_pixel_rgb(x1
, y2
, blue
);
143 pass
&= piglit_probe_pixel_rgb(x2
, y2
, white
);
145 glDeleteTextures(1, &tex
);
147 piglit_present_results();
149 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
152 void piglit_init(int argc
, char **argv
)
154 piglit_require_extension("GL_EXT_framebuffer_object");