glsl-1.30: add more loop unroll tests
[piglit.git] / tests / spec / oes_draw_texture / oes_draw_texture.c
blob27d24d908cdbbd3cfbb8942c0a86b2cb4edf7c67
1 /*
2 * Copyright © 2011 LunarG, Inc.
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 * Author: Chia-I Wu <olv@lunarg.com>
26 /** @file draw-tex.c
28 * Test GL_OES_draw_texture.
31 #include <EGL/egl.h>
33 #include "piglit-util-gl.h"
35 #define TEXTURE_SIZE 2
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_es_version = 10;
41 config.window_width = 100;
42 config.window_height = 100;
43 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DEPTH | PIGLIT_GL_VISUAL_DOUBLE;
45 PIGLIT_GL_TEST_CONFIG_END
47 /* see piglit_rgbw_texture */
48 static const float red[4] = { 1.0f, 0.0f, 0.0f, 0.0f };
49 static const float green[4] = { 0.0f, 1.0f, 0.0f, 0.25f };
50 static const float blue[4] = { 0.0f, 0.0f, 1.0f, 0.50f };
51 static const float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
53 static PFNGLDRAWTEXIOESPROC piglit_glDrawTexiOES;
55 /**
56 * Test the basic use of glDrawTex
58 static int
59 test_basic(void)
61 const GLint crop[4] = {
62 0, 0, TEXTURE_SIZE, TEXTURE_SIZE
64 const int x = piglit_width / 2 - 2;
65 const int y = piglit_height / 2 - 2;
66 int pass;
68 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
70 /* draw the RGBW texture */
71 piglit_glDrawTexiOES(0, 0, 0, piglit_width, piglit_height);
73 pass = piglit_probe_pixel_rgb(x, y, red);
74 pass = piglit_probe_pixel_rgb(x + 5, y, green) && pass;
75 pass = piglit_probe_pixel_rgb(x, y + 5, blue) && pass;
76 pass = piglit_probe_pixel_rgb(x + 5, y + 5, white) && pass;
78 if (!pass)
79 fprintf(stderr, "glDrawTexiOES() failed\n");
81 return pass;
84 /**
85 * Test glDrawTex with a crop rectangle with negative width/height.
87 static int
88 test_negative_crop(void)
90 const GLint crop[4] = {
91 TEXTURE_SIZE, TEXTURE_SIZE, -TEXTURE_SIZE, -TEXTURE_SIZE
93 const int x = piglit_width / 2 - 2;
94 const int y = piglit_height / 2 - 2;
95 int pass;
97 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
99 /* draw the RGBW texture with negative crop */
100 piglit_glDrawTexiOES(0, 0, 0, piglit_width, piglit_height);
102 pass = piglit_probe_pixel_rgb(x, y, white);
103 pass = piglit_probe_pixel_rgb(x + 5, y, blue) && pass;
104 pass = piglit_probe_pixel_rgb(x, y + 5, green) && pass;
105 pass = piglit_probe_pixel_rgb(x + 5, y + 5, red) && pass;
107 if (!pass)
108 fprintf(stderr, "negative crop width/height failed\n");
110 return pass;
114 * Test glDrawTex with a small crop rectangle covering only the right-top of
115 * the texture.
117 static int
118 test_right_top_crop(void)
120 const GLint crop[4] = {
121 TEXTURE_SIZE / 2, TEXTURE_SIZE / 2,
122 TEXTURE_SIZE / 2, TEXTURE_SIZE / 2
124 const int x = piglit_width / 2 - 2;
125 const int y = piglit_height / 2 - 2;
126 int pass;
128 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
130 /* draw the right top quarter of RGBW texture */
131 piglit_glDrawTexiOES(0, 0, 0, piglit_width, piglit_height);
133 pass = piglit_probe_pixel_rgb(x, y, white);
134 pass = piglit_probe_pixel_rgb(x + 5, y, white) && pass;
135 pass = piglit_probe_pixel_rgb(x, y + 5, white) && pass;
136 pass = piglit_probe_pixel_rgb(x + 5, y + 5, white) && pass;
138 if (!pass)
139 fprintf(stderr, "sub crop rect failed\n");
141 return pass;
145 * Test glDrawTex with non-zero x and y.
147 static int
148 test_right_top_win(void)
150 const GLint crop[4] = {
151 0, 0, TEXTURE_SIZE, TEXTURE_SIZE
153 const int half_width = piglit_width / 2;
154 const int half_height = piglit_height / 2;
155 const int x = half_width + half_width / 2 - 2;
156 const int y = half_height + half_height / 2 - 2;
157 int pass;
159 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
161 /* draw the RGBW texture at the right top */
162 piglit_glDrawTexiOES(half_width, half_height, 0, half_width, half_height);
164 pass = piglit_probe_pixel_rgb(x, y, red);
165 pass = piglit_probe_pixel_rgb(x + 5, y, green) && pass;
166 pass = piglit_probe_pixel_rgb(x, y + 5, blue) && pass;
167 pass = piglit_probe_pixel_rgb(x + 5, y + 5, white) && pass;
169 if (!pass)
170 fprintf(stderr, "non-zero (x, y) failed\n");
172 return pass;
176 * Test glDrawTex with non-zero z.
178 static int
179 test_depth(void)
181 const GLint crop[4] = {
182 0, 0, TEXTURE_SIZE, TEXTURE_SIZE
184 const int x = piglit_width / 2 - 2;
185 const int y = piglit_height / 2 - 2;
186 int pass;
188 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
190 glEnable(GL_DEPTH_TEST);
192 /* draw at near plane */
193 piglit_glDrawTexiOES(0, 0, 0, piglit_width, piglit_height);
194 /* draw at far plane: should be no-op */
195 piglit_glDrawTexiOES(0, 0, 1, piglit_width / 2, piglit_height / 2);
197 glDisable(GL_DEPTH_TEST);
199 pass = piglit_probe_pixel_rgb(x, y, red);
201 if (!pass)
202 fprintf(stderr, "non-zero depth failed\n");
204 return pass;
207 enum piglit_result
208 piglit_display(void)
210 GLboolean pass = GL_TRUE;
212 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
214 pass = test_basic();
215 pass = test_negative_crop() && pass;
216 pass = test_right_top_win() && pass;
217 pass = test_right_top_crop() && pass;
218 pass = test_depth() && pass;
220 glFinish();
221 piglit_present_results();
223 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
226 void
227 piglit_init(int argc, char **argv)
229 GLuint tex;
231 piglit_require_extension("GL_OES_draw_texture");
232 piglit_glDrawTexiOES = (PFNGLDRAWTEXIOESPROC)
233 eglGetProcAddress("glDrawTexiOES");
234 if (!piglit_glDrawTexiOES)
235 piglit_report_result(PIGLIT_FAIL);
237 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
239 tex = piglit_rgbw_texture(GL_RGBA,
240 TEXTURE_SIZE, TEXTURE_SIZE, GL_FALSE, GL_TRUE,
241 GL_UNSIGNED_BYTE);
243 glBindTexture(GL_TEXTURE_2D, tex);
244 glEnable(GL_TEXTURE_2D);