Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / glsl-fs-pointcoord.c
blobdb56a108360badfec120488cf8d448afc5973b91
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 DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /** @file glsl-fs-pointcoord.c
30 * Tests that gl_PointCoord produces the expected output in a fragment shader
31 * with point sprites enabled.
34 #include <assert.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <errno.h>
39 #include <sys/stat.h>
40 #define GL_GLEXT_PROTOTYPES
41 #include <GL/glew.h>
42 #if defined(__APPLE__)
43 #include <GLUT/glut.h>
44 #else
45 #include "GL/glut.h"
46 #endif
48 #include "piglit-util.h"
50 int piglit_width = 256;
51 int piglit_height = 256;
52 int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
54 static GLint prog;
55 static GLint point_size;
57 enum piglit_result
58 piglit_display(void)
60 GLboolean pass = GL_TRUE;
61 const float red[4] = {1, 0, 0, 0};
62 const float green[4] = {0, 1, 0, 0};
63 const float yellow[4] = {1, 1, 0, 0};
64 const float black[4] = {0, 0, 0, 0};
66 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
68 glClearColor(0.5, 0.5, 0.5, 0.5);
69 glClear(GL_COLOR_BUFFER_BIT);
71 glPointSize(point_size);
72 glBegin(GL_POINTS);
73 glVertex2f(point_size / 2, point_size / 2);
74 glEnd();
76 pass = pass && piglit_probe_pixel_rgb(0, 0, green);
77 pass = pass && piglit_probe_pixel_rgb(point_size - 1, 0, yellow);
78 pass = pass && piglit_probe_pixel_rgb(0, point_size - 1, black);
79 pass = pass && piglit_probe_pixel_rgb(point_size - 1, point_size - 1, red);
81 glutSwapBuffers();
83 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
86 void piglit_init(int argc, char**argv)
88 GLint vs, fs;
89 GLint point_size_limits[2];
91 if (!GLEW_VERSION_2_0) {
92 printf("Requires OpenGL 2.0\n");
93 piglit_report_result(PIGLIT_SKIP);
94 exit(1);
96 piglit_require_extension("GL_ARB_point_sprite");
98 glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, point_size_limits);
99 point_size = point_size_limits[1];
100 if (point_size > piglit_width)
101 point_size = piglit_width;
103 if (point_size > piglit_width)
104 point_size = piglit_width;
105 if (point_size > piglit_height)
106 point_size = piglit_height;
108 vs = piglit_compile_shader(GL_VERTEX_SHADER,
109 "shaders/glsl-fs-pointcoord.vert");
110 fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
111 "shaders/glsl-fs-pointcoord.frag");
113 prog = piglit_link_simple_program(vs, fs);
115 glEnable(GL_POINT_SPRITE);
117 glUseProgram(prog);