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
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
24 * Eric Anholt <eric@anholt.net>
30 * Tests that rendering to a 1D texture and then drawing it to the framebuffer
34 #include "piglit-util-gl.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config
.supports_gl_compat_version
= 10;
42 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
;
43 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
45 PIGLIT_GL_TEST_CONFIG_END
53 glGenTextures(1, &tex
);
54 glBindTexture(GL_TEXTURE_1D
, tex
);
56 glTexImage1D(GL_TEXTURE_1D
, 0, GL_RGBA
,
59 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
60 if (!piglit_check_gl_error(GL_NO_ERROR
))
61 piglit_report_result(PIGLIT_FAIL
);
63 glGenFramebuffersEXT(1, &fb
);
64 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
66 glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT
,
67 GL_COLOR_ATTACHMENT0_EXT
,
72 if (!piglit_check_gl_error(GL_NO_ERROR
))
73 piglit_report_result(PIGLIT_FAIL
);
75 status
= glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
76 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
77 fprintf(stderr
, "FBO incomplete\n");
81 glViewport(0, 0, BUF_WIDTH
, 1);
82 piglit_ortho_projection(BUF_WIDTH
, 1, GL_FALSE
);
85 glColor4f(1.0, 0.0, 0.0, 0.0);
86 piglit_draw_rect(0, 0, BUF_WIDTH
/ 2, 1);
88 /* right side: green */
89 glColor4f(0.0, 1.0, 0.0, 0.0);
90 piglit_draw_rect(BUF_WIDTH
/ 2, 0, BUF_WIDTH
, 1);
93 glBindFramebufferEXT(GL_FRAMEBUFFER
, piglit_winsys_fbo
);
94 glDeleteFramebuffersEXT(1, &fb
);
100 draw_fbo_1d(int x
, int y
)
102 glViewport(0, 0, piglit_width
, piglit_height
);
103 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
105 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
107 glEnable(GL_TEXTURE_1D
);
108 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
109 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
110 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
111 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
112 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
113 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
115 piglit_draw_rect_tex(x
, y
, BUF_WIDTH
, 1,
122 GLboolean pass
= GL_TRUE
;
123 float red
[] = {1,0,0,0};
124 float green
[] = {0,1,0,0};
129 glClearColor(1.0, 1.0, 1.0, 1.0);
130 glClear(GL_COLOR_BUFFER_BIT
);
132 tex
= create_1d_fbo();
136 for (x
= 0; x
< BUF_WIDTH
; x
++) {
137 if (x
< BUF_WIDTH
/ 2)
142 pass
&= piglit_probe_pixel_rgb(10 + x
, 10, expected
);
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");