1 /*
2  * Copyright © 2010 Intel Corporation
3  *
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:
10  *
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.
14  *
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.
22  *
23  */
24 
25 /**
26  * \file glsl-max-vertex-attrib.c
27  * Test setting vertex attrib value of GL_MAX_VERTEX_ATTRIBS attrib
28  *
29  * Queries the value for GL_MAX_VERTEX_ATTRIBS and uses that as index
30  * to set a value. GL specification states that GL_INVALID_VALUE should
31  * occur if index >= GL_MAX_VERTEX_ATTRIBS.
32  *
33  * \author Sun Yi <yi.sun@intel.com>
34  * \author Tapani Pälli <tapani.palli@intel.com>
35  */
36 
37 #include "piglit-util-gl.h"
38 
39 PIGLIT_GL_TEST_CONFIG_BEGIN
40 
41 	config.supports_gl_compat_version = 10;
42 
43 	config.window_width = 250;
44 	config.window_height = 250;
45 	config.window_visual = PIGLIT_GL_VISUAL_RGB;
46 
47 PIGLIT_GL_TEST_CONFIG_END
48 
49 static int test = 0;
50 
51 #define CHECK_GL_INVALID_VALUE \
52 	if (glGetError() != GL_INVALID_VALUE) return PIGLIT_FAIL; \
53 	else printf("glsl-max-vertex-attrib test %d passed\n", ++test);
54 
55 static const char *vShaderString =
56 	"attribute float pos;\n"
57 	"void main()\n"
58 	"{\n"
59 	"	gl_Position = vec4(pos, 0.0, 0.0, 1.0);\n"
60 	"}\n";
61 
62 static const char *fShaderString =
63 	"void main()\n"
64 	"{\n"
65 	"	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
66 	"}\n";
67 
piglit_display(void)68 enum piglit_result piglit_display(void)
69 {
70 	GLvoid *datap;
71 	GLint intv[] = { 1, 1, 1, 1 };
72 	GLfloat floatv[] = { 1.0, 1.0, 1.0, 1.0 };
73 	GLfloat quad[] = { -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0 };
74 
75 	GLsizei length;
76 	GLint size;
77 	GLenum type;
78 	GLchar buffer[64];
79 
80 	GLuint program;
81 	int maxAttribCount;
82 
83 	/* --- valid program needed for some of the functions --- */
84 	program = piglit_build_simple_program(vShaderString, fShaderString);
85 	piglit_check_gl_error(GL_NO_ERROR);
86 
87 	glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttribCount);
88 
89 	/* --- tests begin here --- */
90 
91 	glVertexAttrib1f(maxAttribCount, floatv[0]);
92 	CHECK_GL_INVALID_VALUE;
93 
94 	glVertexAttrib2f(maxAttribCount, floatv[0], floatv[1]);
95 	CHECK_GL_INVALID_VALUE;
96 
97 	glVertexAttrib3f(maxAttribCount, floatv[0], floatv[1], floatv[2]);
98 	CHECK_GL_INVALID_VALUE;
99 
100 	glVertexAttrib4f(maxAttribCount, floatv[0], floatv[1], floatv[2],
101 			 floatv[3]);
102 	CHECK_GL_INVALID_VALUE;
103 
104 	glVertexAttrib1fv(maxAttribCount, floatv);
105 	CHECK_GL_INVALID_VALUE;
106 
107 	glVertexAttrib2fv(maxAttribCount, floatv);
108 	CHECK_GL_INVALID_VALUE;
109 
110 	glVertexAttrib3fv(maxAttribCount, floatv);
111 	CHECK_GL_INVALID_VALUE;
112 
113 	glVertexAttrib4fv(maxAttribCount, floatv);
114 	CHECK_GL_INVALID_VALUE;
115 
116 	glVertexAttribPointer(maxAttribCount, 2, GL_FLOAT, GL_FALSE, 0, quad);
117 	CHECK_GL_INVALID_VALUE;
118 
119 	glBindAttribLocation(program, maxAttribCount, "pos");
120 	CHECK_GL_INVALID_VALUE;
121 
122 	glEnableVertexAttribArray(maxAttribCount);
123 	CHECK_GL_INVALID_VALUE;
124 
125 	glDisableVertexAttribArray(maxAttribCount);
126 	CHECK_GL_INVALID_VALUE;
127 
128 	glGetVertexAttribfv(maxAttribCount, GL_CURRENT_VERTEX_ATTRIB, floatv);
129 	CHECK_GL_INVALID_VALUE;
130 
131 	glGetVertexAttribiv(maxAttribCount, GL_CURRENT_VERTEX_ATTRIB, intv);
132 	CHECK_GL_INVALID_VALUE;
133 
134 	glGetVertexAttribPointerv(maxAttribCount, GL_VERTEX_ATTRIB_ARRAY_POINTER, &datap);
135 	CHECK_GL_INVALID_VALUE;
136 
137 	glGetActiveAttrib(program, maxAttribCount, 64, &length, &size, &type, buffer);
138 	CHECK_GL_INVALID_VALUE;
139 
140 	return PIGLIT_PASS;
141 }
142 
piglit_init(int argc,char ** argv)143 void piglit_init(int argc, char **argv)
144 {
145 	piglit_require_gl_version(20);
146 }
147