ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_point_sprite / mipmap.c
blobd545b75bbefda5619377b5906a67f2b13397ab67
1 /*
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
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following
12 * conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the
16 * Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
29 /**
30 * @file mipmap.c: Test the GL_ARB_point_sprite extension
32 * Create mipmap textures which size varies from 32x32 to 1x1, every texture
33 * has different two colors: the upper half is one color and the lower half is
34 * another color.
35 * Draw point and polygon which mode is GL_POINT, and check that the point is
36 * rendered correctly.
39 #include "piglit-util-gl.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config.supports_gl_compat_version = 14;
44 config.window_visual = PIGLIT_GL_VISUAL_RGBA;
45 config.khr_no_error_support = PIGLIT_NO_ERRORS;
47 PIGLIT_GL_TEST_CONFIG_END
49 /* For the 1x1 LOD, only lower part (second color in the table) is used. */
50 static const float tex_color[6][2][4] = {
51 {{1.0, 0.0, 0.0, 1.0}, {0.0, 1.0, 0.0, 1.0}}, /* 32x32 */
52 {{0.0, 0.0, 1.0, 1.0}, {1.0, 1.0, 0.0, 1.0}}, /* 16x16 */
53 {{1.0, 0.0, 1.0, 1.0}, {0.0, 1.0, 1.0, 1.0}}, /* 8x8 */
54 {{1.0, 1.0, 1.0, 1.0}, {1.0, 0.0, 0.0, 1.0}}, /* 4x4 */
55 {{0.0, 1.0, 0.0, 1.0}, {0.0, 0.0, 1.0, 1.0}}, /* 2x2 */
56 {{1.0, 1.0, 0.0, 1.0}, {1.0, 1.0, 1.0, 1.0}}, /* 1x1 */
59 static int
60 level(int point_size)
62 /* Note: we use GL_NEAREST_MIPMAP_NEAREST for GL_TEXTURE_MIN_FILTER
64 if (point_size <= 1)
65 return 5;
66 if (point_size < 3)
67 return 4;
68 if (point_size < 6)
69 return 3;
70 if (point_size < 12)
71 return 2;
72 if (point_size < 24)
73 return 1;
74 return 0;
77 bool
78 draw_and_probe(int point_size, int coord_origin, int prim_type)
80 glPointSize((float)point_size);
81 glClear(GL_COLOR_BUFFER_BIT);
83 /* Draw GL_POINTS primitives, and draw GL_POLYGON primitives with the
84 * polygon mode set to GL_POINT.
86 if (prim_type == 0) {
87 glBegin(GL_POINTS);
88 glVertex2i(piglit_width / 4, piglit_height / 4);
89 glEnd();
90 } else {
91 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
92 glBegin(GL_POLYGON);
93 glVertex2i(piglit_width / 4, piglit_height / 4);
94 glVertex2i(piglit_width, piglit_height / 4);
95 glVertex2i(piglit_width, piglit_height);
96 glVertex2i(piglit_width / 4, piglit_height);
97 glEnd();
100 /* bottom, left, right, top, width and height of sprite */
101 const int b = piglit_width / 4 - point_size / 2;
102 const int l = piglit_height / 4 - point_size / 2;
103 const int r = piglit_height / 4 + point_size / 2;
104 const int t = piglit_width / 4 + point_size / 2;
105 const int w = point_size;
106 const int h = point_size / 2;
107 /* vertical middle of sprite */
108 const int m = piglit_height / 4;
110 /* width of total area to probe */
111 const int W = piglit_width / 2;
113 const float bk[] = {0.0, 0.0, 0.0, 0.0};
115 const float *cb = tex_color[level(point_size)][coord_origin];
116 const float *ct = tex_color[level(point_size)][1 - coord_origin];
117 if (piglit_probe_rect_rgba(0, 0, W, b, bk) &&
118 piglit_probe_rect_rgba(0, b, l, w, bk) &&
119 piglit_probe_rect_rgba(l, b, w, h, cb) &&
120 piglit_probe_rect_rgba(l, m, w, h, ct) &&
121 piglit_probe_rect_rgba(r, b, l, w, bk) &&
122 piglit_probe_rect_rgba(0, t, W, b, bk))
123 return true;
125 printf("Primitive type: %s, Coord Origin at: %s\n",
126 prim_type ? "polygon" : "points",
127 coord_origin ? "bottom" : "top");
128 return false;
131 enum piglit_result
132 piglit_display(void)
134 float max_point_size;
135 int point_size;
136 float point_size_range[2], point_size_granularity;
137 float n;
138 const float epsilon = 1e-5;
140 glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, point_size_range);
141 glGetFloatv(GL_SMOOTH_POINT_SIZE_GRANULARITY,
142 &point_size_granularity);
144 /* check that point size 2.0 is supported */
145 n = (2.0 - point_size_range[0]) / point_size_granularity;
146 if (!(roundf(n) - n < epsilon))
147 piglit_report_result(PIGLIT_SKIP);
148 /* check that other even integer point sizes are supported */
149 n = 2.0 / point_size_granularity;
150 if (!(roundf(n) - n < epsilon))
151 piglit_report_result(PIGLIT_SKIP);
153 max_point_size = MIN3(point_size_range[1], piglit_width / 2,
154 piglit_height / 2);
156 for (int prim_type = 0; prim_type < 2; prim_type++) {
157 if (piglit_get_gl_version() >= 20)
158 glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,
159 GL_UPPER_LEFT);
160 for (int coord_origin = 0; coord_origin < 2; coord_origin++) {
161 for (point_size = 2;
162 (float)point_size <= max_point_size;
163 point_size += 2) {
164 if (!draw_and_probe(point_size, coord_origin,
165 prim_type))
166 return PIGLIT_FAIL;
169 /* OpenGL 2.0 adds the ability to set the texture
170 * coordinate origin to the bottom left */
171 if (piglit_get_gl_version() < 20)
172 break;
173 glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,
174 GL_LOWER_LEFT);
178 return PIGLIT_PASS;
181 void
182 piglit_init(int argc, char **argv)
184 GLboolean enable;
185 GLint coordReplace;
186 GLint coordOrigin;
187 GLuint tex;
189 piglit_require_extension("GL_ARB_point_sprite");
191 /* check point sprite status, default is GL_FALSE */
192 enable = glIsEnabled(GL_POINT_SPRITE);
193 if (enable != GL_FALSE) {
194 printf("PointSprite should be disabled by default\n");
195 piglit_report_result(PIGLIT_FAIL);
198 /* check coordinate replacement, default is GL_FALSE */
199 glGetTexEnviv(GL_POINT_SPRITE, GL_COORD_REPLACE, &coordReplace);
201 if (coordReplace != GL_FALSE) {
202 printf("default value of COORD_REPLACE should be GL_FALSE\n");
203 piglit_report_result(PIGLIT_FAIL);
206 /* check coordinate origin, default is UPPER_LEFT */
207 glEnable(GL_POINT_SPRITE);
208 if (piglit_get_gl_version() >= 20) {
209 glGetIntegerv(GL_POINT_SPRITE_COORD_ORIGIN, &coordOrigin);
210 if (coordOrigin != GL_UPPER_LEFT) {
211 printf("default value of COORD_ORIGIN should be "
212 "GL_UPPER_LEFT\n");
213 piglit_report_result(PIGLIT_FAIL);
217 glMatrixMode(GL_PROJECTION);
218 glOrtho(0, piglit_width, 0, piglit_height, -1, 1);
220 glEnable(GL_TEXTURE_2D);
221 glGenTextures(1, &tex);
222 glBindTexture(GL_TEXTURE_2D, tex);
223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
224 GL_NEAREST_MIPMAP_NEAREST);
225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
227 int lvl = 0;
228 for (int size = 32; size; size /= 2) {
229 int mid = MAX2(size / 2, 1);
230 piglit_quads_texture(tex, lvl, size, size, size, mid,
231 tex_color[lvl][1], NULL,
232 tex_color[lvl][0], NULL);
233 lvl++;
236 glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);