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
21 * DEALINGS IN THE SOFTWARE.
25 * This test draws a point sprite with a checkerboard texture and tests
26 * whether the correct colors were drawn using piglit_probe_pixel_rgb.
31 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 10;
40 config
.supports_gl_es_version
= 10;
42 config
.window_width
= 1+((BOX_SIZE
+1)*TEST_COLS
);
43 config
.window_height
= 1+((BOX_SIZE
+1)*TEST_ROWS
);
44 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
45 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
47 PIGLIT_GL_TEST_CONFIG_END
49 static float maxSize
= 0.0f
;
51 static const GLfloat black
[4] = {0.0, 0.0, 0.0, 1.0};
52 static const GLfloat white
[4] = {1.0, 1.0, 1.0, 1.0};
55 piglit_init(int argc
, char **argv
)
62 #ifdef PIGLIT_USE_OPENGL
63 piglit_require_extension("GL_ARB_point_sprite");
65 piglit_require_extension("GL_OES_point_sprite");
68 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
70 glEnable(GL_TEXTURE_2D
);
71 glEnable(GL_POINT_SPRITE
);
73 glGetFloatv(GL_POINT_SIZE_MAX
, &realMaxSize
);
74 maxSize
= (realMaxSize
> BOX_SIZE
) ? BOX_SIZE
: realMaxSize
;
76 glClearColor(0.2, 0.2, 0.2, 1.0);
77 glColor4f(1.0, 1.0, 1.0, 1.0);
79 tex
= piglit_checkerboard_texture(0, 0, 2, 2, 1, 1, black
, white
);
80 glTexEnvi(GL_POINT_SPRITE
, GL_COORD_REPLACE
, GL_TRUE
);
82 if (!piglit_automatic
)
83 printf("Maximum point size is %f, using %f\n",
84 realMaxSize
, maxSize
);
90 #ifdef PIGLIT_USE_OPENGL
91 const unsigned num_rows
= (piglit_get_gl_version() >= 20) ? 2 : 1;
93 const unsigned num_rows
= 1;
95 static const GLenum origins
[2] = { GL_UPPER_LEFT
, GL_LOWER_LEFT
};
96 GLboolean pass
= GL_TRUE
;
100 glClear(GL_COLOR_BUFFER_BIT
);
101 glBindTexture(GL_TEXTURE_2D
, tex
);
103 for (i
= 0; i
< num_rows
; i
++) {
104 const float y
= 1 + (BOX_SIZE
/ 2) + (i
* (BOX_SIZE
+ 1));
105 const float *const upper_left
= (origins
[i
] == GL_UPPER_LEFT
)
107 const float *const lower_left
= (origins
[i
] == GL_UPPER_LEFT
)
110 #ifdef PIGLIT_USE_OPENGL
111 /* OpenGL version must be at least 2.0 to support modifying
112 * GL_POINT_SPRITE_COORD_ORIGIN.
114 if (piglit_get_gl_version() >= 20)
115 glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN
,
119 for (j
= 0; j
< TEST_COLS
; j
++) {
120 const float x
= 1 + (BOX_SIZE
/ 2)
121 + (j
* (BOX_SIZE
+ 1));
122 const float size
= maxSize
/ (float) (1 << j
);
124 /* If the point size is too small, there won't be
125 * enough pixels drawn for the tests (below).
130 glPointSize(size
- 0.2);
132 /* Vertex arrays are overkill for this case,
133 * but they are necessary for OpenGL ES 1.x.
135 GLfloat tcp
[] = { 1.5, 1.5 };
136 GLfloat vp
[] = { x
, y
};
138 glEnableClientState(GL_VERTEX_ARRAY
);
139 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
141 glTexCoordPointer(2, GL_FLOAT
, 0, tcp
);
142 glVertexPointer(2, GL_FLOAT
, 0, vp
);
143 glDrawArrays(GL_POINTS
, 0, 1);
145 glDisableClientState(GL_VERTEX_ARRAY
);
146 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
148 if (!piglit_probe_pixel_rgb(x
- (size
/ 4),
151 || !piglit_probe_pixel_rgb(x
- (size
/ 4),
154 || !piglit_probe_pixel_rgb(x
+ (size
/ 4),
157 || !piglit_probe_pixel_rgb(x
+ (size
/ 4),
160 if (!piglit_automatic
)
161 printf(" size = %.3f, "
162 "origin = %s left\n",
164 (origins
[i
] == GL_UPPER_LEFT
)
165 ? "upper" : "lower");
171 piglit_present_results();
173 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;