Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / glsl-novertexdata.c
blob96570fa37dcd440a4f3ba322c69ca79952b547cb
1 /*
2 * Copyright © 2009 Intel Corporation
3 * Copyright © 2010 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 /**
26 * \file glsl-novertexdata.c
28 * Test if we can draw something without specifying/enabling any vertex
29 * arrays. The vertex shader simply sets gl_Position=(0,0,0,1) and we
30 * try to draw a GL_POINT.
32 * This is an obscure case, but it works with NVIDIA's OpenGL driver,
33 * works with Mesa/swrast, but Mesa/gallium fails (at the time of
34 * writing this).
36 * This test is based on the glsl-dlist-getattriblocation.c test written
37 * by Ian.
39 * \author Ian Romanick <ian.d.romanick@intel.com>
40 * \author Brian Paul
43 #include "piglit-util.h"
44 #include "piglit-framework.h"
46 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
47 int piglit_width = 100;
48 int piglit_height = 100;
50 static const GLchar *vertShaderText =
51 "attribute vec4 attrib;\n"
52 "void main()\n"
53 "{\n"
54 " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
55 " gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
56 "} \n";
59 enum piglit_result
60 piglit_display(void)
62 static const GLfloat expColor[4] = {0, 1, 0, 1};
63 GLint vs;
64 GLint prog;
65 GLint stat;
66 enum piglit_result result;
68 vs = glCreateShader(GL_VERTEX_SHADER);
69 glShaderSource(vs, 1, &vertShaderText, NULL);
71 glCompileShader(vs);
72 glGetShaderiv(vs, GL_COMPILE_STATUS, &stat);
73 if (!stat) {
74 printf("glsl-novertexdata: error compiling vertex shader!\n");
75 exit(1);
78 prog = glCreateProgram();
79 glAttachShader(prog, vs);
80 glLinkProgram(prog);
81 glUseProgram(prog);
83 glMatrixMode(GL_PROJECTION);
84 glLoadIdentity();
85 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
87 glClear(GL_COLOR_BUFFER_BIT);
89 glPointSize(20.0);
90 glDrawArrays(GL_POINTS, 0, 1);
92 result = piglit_probe_pixel_rgba(piglit_width /2, piglit_height / 2,
93 expColor)
94 ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
96 glutSwapBuffers();
98 return result;
102 void
103 piglit_init(int argc, char **argv)
105 if (!GLEW_VERSION_2_0) {
106 printf("Requires OpenGL 2.0\n");
107 piglit_report_result(PIGLIT_SKIP);
108 exit(1);