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.h"
37 int piglit_width
= 50;
38 int piglit_height
= 20;
39 int piglit_window_mode
= GLUT_DOUBLE
| GLUT_DEPTH
;
47 glGenTextures(1, &tex
);
48 glBindTexture(GL_TEXTURE_1D
, tex
);
50 glTexImage1D(GL_TEXTURE_1D
, 0, GL_RGBA
,
53 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
54 assert(glGetError() == 0);
56 glGenFramebuffersEXT(1, &fb
);
57 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
59 glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT
,
60 GL_COLOR_ATTACHMENT0_EXT
,
65 assert(glGetError() == 0);
67 status
= glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
68 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
69 fprintf(stderr
, "FBO incomplete\n");
73 glViewport(0, 0, BUF_WIDTH
, 1);
74 piglit_ortho_projection(BUF_WIDTH
, 1, GL_FALSE
);
77 glColor4f(1.0, 0.0, 0.0, 0.0);
78 piglit_draw_rect(0, 0, BUF_WIDTH
/ 2, 1);
80 /* right side: green */
81 glColor4f(0.0, 1.0, 0.0, 0.0);
82 piglit_draw_rect(BUF_WIDTH
/ 2, 0, BUF_WIDTH
, 1);
85 glDeleteFramebuffersEXT(1, &fb
);
91 draw_fbo_1d(int x
, int y
)
93 glViewport(0, 0, piglit_width
, piglit_height
);
94 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
96 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
98 glEnable(GL_TEXTURE_1D
);
99 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
100 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
101 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
102 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
103 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
104 glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
106 piglit_draw_rect_tex(x
, y
, BUF_WIDTH
, 1,
113 GLboolean pass
= GL_TRUE
;
114 float red
[] = {1,0,0,0};
115 float green
[] = {0,1,0,0};
120 glClearColor(1.0, 1.0, 1.0, 1.0);
121 glClear(GL_COLOR_BUFFER_BIT
);
123 tex
= create_1d_fbo();
127 for (x
= 0; x
< BUF_WIDTH
; x
++) {
128 if (x
< BUF_WIDTH
/ 2)
133 pass
&= piglit_probe_pixel_rgb(10 + x
, 10, expected
);
136 glDeleteTextures(1, &tex
);
140 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
143 void piglit_init(int argc
, char **argv
)
145 piglit_require_extension("GL_EXT_framebuffer_object");