Add more structure constructor tests.
[piglit/hramrach.git] / tests / bugs / point-sprite.c
blob8e3c65be2b327597447c472743f9ae1904070624
1 /*
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
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
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * This test draws a point sprite with a checkerboard texture and tests whether
26 * the correct colors were drawn using piglit_probe_pixel_rgb.
28 * \author Ben Holmes
31 #include "piglit-util.h"
32 #include "piglit-framework.h"
34 #define BOX_SIZE 64
35 #define TEST_COLS 6
36 #define TEST_ROWS 2
38 int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
39 int piglit_width = 1 + ((BOX_SIZE + 1) * TEST_COLS);
40 int piglit_height = 1 + ((BOX_SIZE + 1) * TEST_ROWS);
42 static float maxSize = 0.0f;
43 static GLuint tex;
44 static const GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
45 static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
47 void
48 piglit_init(int argc, char **argv)
50 GLfloat realMaxSize;
52 (void) argc;
53 (void) argv;
55 piglit_require_extension("GL_ARB_point_sprite");
57 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
59 glEnable(GL_TEXTURE_2D);
60 glEnable(GL_POINT_SPRITE_ARB);
62 glGetFloatv(GL_POINT_SIZE_MAX, &realMaxSize);
63 maxSize = (realMaxSize > BOX_SIZE) ? BOX_SIZE : realMaxSize;
65 glClearColor(0.2, 0.2, 0.2, 1.0);
66 glColor3f(1.0, 1.0, 1.0);
68 tex = piglit_checkerboard_texture(0, 0, 2, 2, 1, 1, black, white);
69 glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
71 if (!piglit_automatic)
72 printf("Maximum point size is %f, using %f\n",
73 realMaxSize, maxSize);
76 enum piglit_result
77 piglit_display(void)
79 static const GLenum origins[2] = { GL_UPPER_LEFT, GL_LOWER_LEFT };
80 const unsigned num_rows = (GLEW_VERSION_2_0) ? 2 : 1;
81 GLboolean pass = GL_TRUE;
82 unsigned i;
83 unsigned j;
85 glClear(GL_COLOR_BUFFER_BIT);
86 glBindTexture(GL_TEXTURE_2D, tex);
88 for (i = 0; i < num_rows; i++) {
89 const float y = 1 + (BOX_SIZE / 2) + (i * (BOX_SIZE + 1));
90 const float *const upper_left = (origins[i] == GL_UPPER_LEFT)
91 ? black : white;
92 const float *const lower_left = (origins[i] == GL_UPPER_LEFT)
93 ? white : black;
95 /* OpenGL version must be at least 2.0 to support modifying
96 * GL_POINT_SPRITE_COORD_ORIGIN.
98 if (GLEW_VERSION_2_0)
99 glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,
100 origins[i]);
102 for (j = 0; j < TEST_COLS; j++) {
103 const float x = 1 + (BOX_SIZE / 2)
104 + (j * (BOX_SIZE + 1));
105 const float size = maxSize / (float) (1 << j);
107 /* If the point size is too small, there won't be
108 * enough pixels drawn for the tests (below).
110 if (size < 2.0)
111 continue;
113 glPointSize(size - 0.2);
114 glBegin(GL_POINTS);
115 glTexCoord2f(1.5, 1.5);
116 glVertex2f(x, y);
117 glEnd();
119 if (!piglit_probe_pixel_rgb(x - (size / 4),
120 y + (size / 4),
121 upper_left)
122 || !piglit_probe_pixel_rgb(x - (size / 4),
123 y - (size / 4),
124 lower_left)
125 || !piglit_probe_pixel_rgb(x + (size / 4),
126 y + (size / 4),
127 lower_left)
128 || !piglit_probe_pixel_rgb(x + (size / 4),
129 y - (size / 4),
130 upper_left)) {
131 if (!piglit_automatic)
132 printf(" size = %.3f, "
133 "origin = %s left\n",
134 size,
135 (origins[i] == GL_UPPER_LEFT)
136 ? "upper" : "lower");
137 pass = GL_FALSE;
142 glutSwapBuffers();
144 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;