2 * Copyright (C) 2007 Intel Corporation
3 * Copyright (C) 1999 Allen Akin All Rights Reserved.
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
27 * Authors: Shuang He <shuang.he@intel.com>
29 * Draw solid colors to all levels of a 2D texture. Then draw rectangles to
30 * the framebuffer sampling from the texture.
33 #include "piglit-util-gl.h"
37 enum { BLACK
, RED
, GREEN
, BLUE
, WHITE
};
39 static const GLfloat colors
[][4] = {{0.0, 0.0, 0.0, 0.0},
43 {1.0, 1.0, 1.0, 1.0}};
45 PIGLIT_GL_TEST_CONFIG_BEGIN
47 config
.supports_gl_compat_version
= 11;
49 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
50 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
52 PIGLIT_GL_TEST_CONFIG_END
60 glGenFramebuffersEXT(1, &fbo
);
61 glGenTextures(1, &texture
);
63 glBindTexture(GL_TEXTURE_2D
, texture
);
64 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fbo
);
65 glDisable(GL_TEXTURE_2D
);
67 for (int i
= TEXSIZE
, level
= 0; i
> 0; i
/= 2, level
++) {
69 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, level
);
70 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGB
, i
, i
, 0, GL_RGB
,
73 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
74 GL_COLOR_ATTACHMENT0_EXT
,
75 GL_TEXTURE_2D
, texture
, level
);
78 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT
);
79 if (e
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
80 printf("FBO incomplete (%x): %s\n",
81 e
, piglit_get_gl_enum_name(e
));
85 glColor4fv(colors
[RED
+ (level
% (WHITE
- RED
))]);
86 glClear(GL_COLOR_BUFFER_BIT
);
88 piglit_draw_rect(0, 0, TEXSIZE
, TEXSIZE
);
91 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
92 glEnable(GL_TEXTURE_2D
);
94 /* Render to the window */
95 glClear(GL_COLOR_BUFFER_BIT
);
96 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
97 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
98 GL_NEAREST_MIPMAP_NEAREST
);
99 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
101 for (int i
= TEXSIZE
, x
= 0; i
> 0; i
/= 2) {
102 piglit_draw_rect_tex(x
, 0, i
, i
, 0, 0, 1, 1);
104 assert(x
< piglit_width
);
109 for (int i
= TEXSIZE
, x
= 0, level
= 0;
111 x
+= i
, i
/= 2, level
++) {
113 if (!piglit_probe_pixel_rgb(
114 x
, 0, colors
[RED
+ (level
% (WHITE
- RED
))])) {
115 printf("level = %d\n", level
);
120 piglit_present_results();
122 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
126 piglit_init(int argc
, char **argv
)
128 piglit_require_extension("GL_EXT_framebuffer_object");
129 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);