2 * GL_ARB_vertex_shader test application. Feeds a vertex shader with attributes that
3 * that have magic values and check if the values received by the shader are the same.
5 * Requires specific support on the GL implementation side. A special function printMESA()
6 * must be supported in the language that prints variable's current value of generic type
7 * to the appropriate shader's info log, and optionally to the screen.
9 * Perfectly valid behaviour produces output that does not have a line
10 * beginning with three stars (***).
15 #include "framework.h"
17 #define EPSILON 0.0001f
19 static GLhandleARB vert
= 0;
20 static GLhandleARB prog
= 0;
31 static enum SUBMIT_MODE submit_method
= SM_IM
;
51 static struct ATTRIB_DATA attribs
[] = {
52 { "gl_Color", C
, -1, -1, 4, { 4.2f
, 0.56f
, -2.1f
, 0.29f
} },
53 { "gl_SecondaryColor", S
, -1, -1, 4, { 0.38f
, 2.0f
, 0.99f
, 1.0f
} },
54 { "gl_Normal", N
, -1, -1, 3, { 54.0f
, 77.0f
, 1.15f
, 0.0f
} },
55 { "gl_MultiTexCoord0", T
, 0, -1, 4, { 11.1f
, 11.2f
, 11.3f
, 11.4f
} },
56 { "gl_MultiTexCoord1", T
, 1, -1, 4, { 22.1f
, 22.2f
, 22.3f
, 22.4f
} },
57 { "gl_MultiTexCoord2", T
, 2, -1, 4, { 33.1f
, 33.2f
, 33.3f
, 33.4f
} },
58 { "gl_MultiTexCoord3", T
, 3, -1, 4, { 44.1f
, 44.2f
, 44.3f
, 44.4f
} },
59 { "gl_MultiTexCoord4", T
, 4, -1, 4, { 55.1f
, 55.2f
, 55.3f
, 55.4f
} },
60 { "gl_MultiTexCoord5", T
, 5, -1, 4, { 66.1f
, 66.2f
, 66.3f
, 66.4f
} },
61 { "gl_MultiTexCoord6", T
, 6, -1, 4, { 77.1f
, 77.2f
, 77.3f
, 77.4f
} },
62 { "gl_MultiTexCoord7", T
, 7, -1, 4, { 88.1f
, 88.2f
, 88.3f
, 88.4f
} },
63 { "gl_FogCoord", F
, -1, -1, 1, { 0.63f
, 0.0f
, 0.0f
, 0.0f
} },
64 { "Attribute1", A
, 1, 1, 4, { 1.11f
, 1.22f
, 1.33f
, 1.44f
} },
65 { "Attribute2", A
, 2, 2, 4, { 2.11f
, 2.22f
, 2.33f
, 2.44f
} },
66 { "Attribute3", A
, 3, 3, 4, { 3.11f
, 3.22f
, 3.33f
, 3.44f
} },
67 { "Attribute4", A
, 4, 4, 1, { 4.11f
, 0.0f
, 0.0f
, 0.0f
} },
68 { "Attribute5", A
, 5, 5, 2, { 5.11f
, 5.22f
, 0.0f
, 0.0f
} },
69 { "Attribute6", A
, 6, 6, 3, { 6.11f
, 6.22f
, 6.33f
, 0.0f
} },
70 { "Attribute7", A
, 7, 7, 2, { 7.11f
, 7.22f
, 0.0f
, 0.0f
} },
71 { "Attribute7", A
, 8, -1, 2, { 8.11f
, 8.22f
, 0.0f
, 0.0f
} },
72 { "Attribute9", A
, 9, 9, 3, { 9.11f
, 9.22f
, 9.33f
, 0.0f
} },
73 { "Attribute9", A
, 10, -1, 3, { 10.11f
, 10.22f
, 10.33f
, 0.0f
} },
74 { "Attribute9", A
, 11, -1, 3, { 11.11f
, 11.22f
, 11.33f
, 0.0f
} },
75 { "Attribute12", A
, 12, 12, 4, { 12.11f
, 12.22f
, 12.33f
, 12.44f
} },
76 { "Attribute12", A
, 13, -1, 4, { 13.11f
, 13.22f
, 13.33f
, 13.44f
} },
77 { "Attribute12", A
, 14, -1, 4, { 14.11f
, 14.22f
, 14.33f
, 14.44f
} },
78 { "Attribute12", A
, 15, -1, 4, { 15.11f
, 15.22f
, 15.33f
, 15.44f
} },
79 { "gl_Vertex", V
, 16, -1, 4, { 0.25f
, -0.14f
, 0.01f
, 1.0f
} }
82 static void im_render ()
87 for (i
= 0; i
< sizeof (attribs
) / sizeof (*attribs
); i
++) {
88 struct ATTRIB_DATA
*att
= &attribs
[i
];
89 switch (att
->dispatch
)
92 glColor4fv (att
->data
);
95 glSecondaryColor3fvEXT (att
->data
);
98 glNormal3fv (att
->data
);
101 glVertex4fv (att
->data
);
104 assert (att
->index
>= 0 && att
->index
< 8);
105 glMultiTexCoord4fvARB (GL_TEXTURE0_ARB
+ att
->index
, att
->data
);
108 glFogCoordfvEXT (att
->data
);
111 assert (att
->index
> 0 && att
->index
< 16);
112 glVertexAttrib4fvARB (att
->index
, att
->data
);
121 static void va_render ()
125 for (i
= 0; i
< sizeof (attribs
) / sizeof (*attribs
); i
++) {
126 struct ATTRIB_DATA
*att
= &attribs
[i
];
127 switch (att
->dispatch
)
130 glColorPointer (4, GL_FLOAT
, 0, att
->data
);
131 glEnableClientState (GL_COLOR_ARRAY
);
134 glSecondaryColorPointerEXT (4, GL_FLOAT
, 0, att
->data
);
135 glEnableClientState (GL_SECONDARY_COLOR_ARRAY_EXT
);
138 glNormalPointer (GL_FLOAT
, 0, att
->data
);
139 glEnableClientState (GL_NORMAL_ARRAY
);
142 glVertexPointer (4, GL_FLOAT
, 0, att
->data
);
143 glEnableClientState (GL_VERTEX_ARRAY
);
146 assert (att
->index
>= 0 && att
->index
< 8);
147 glClientActiveTextureARB (GL_TEXTURE0_ARB
+ att
->index
);
148 glTexCoordPointer (4, GL_FLOAT
, 0, att
->data
);
149 glEnableClientState (GL_TEXTURE_COORD_ARRAY
);
152 glFogCoordPointerEXT (GL_FLOAT
, 0, att
->data
);
153 glEnableClientState (GL_FOG_COORDINATE_ARRAY_EXT
);
156 assert (att
->index
> 0 && att
->index
< 16);
157 glVertexAttribPointerARB (att
->index
, 4, GL_FLOAT
, GL_FALSE
, 0, att
->data
);
158 glEnableVertexAttribArrayARB (att
->index
);
165 glDrawArrays (GL_POINTS
, 0, 1);
167 for (i
= 0; i
< sizeof (attribs
) / sizeof (*attribs
); i
++) {
168 struct ATTRIB_DATA
*att
= &attribs
[i
];
169 switch (att
->dispatch
)
172 glDisableClientState (GL_COLOR_ARRAY
);
175 glDisableClientState (GL_SECONDARY_COLOR_ARRAY_EXT
);
178 glDisableClientState (GL_NORMAL_ARRAY
);
181 glDisableClientState (GL_VERTEX_ARRAY
);
184 glClientActiveTextureARB (GL_TEXTURE0_ARB
+ att
->index
);
185 glDisableClientState (GL_TEXTURE_COORD_ARRAY
);
188 glDisableClientState (GL_FOG_COORDINATE_ARRAY_EXT
);
191 glDisableVertexAttribArrayARB (att
->index
);
199 static void dl_start ()
201 glNewList (GL_COMPILE
, 1);
204 static void dl_end ()
210 static void load_test_file (const char *filename
)
217 f
= fopen (filename
, "r");
221 fseek (f
, 0, SEEK_END
);
229 fseek (f
, 0, SEEK_SET
);
231 code
= (char *) (malloc (size
));
236 size
= fread (code
, 1, size
, f
);
239 glShaderSourceARB (vert
, 1, (const GLcharARB
**) (&code
), &size
);
240 glCompileShaderARB (vert
);
241 if (!CheckObjectStatus (vert
))
244 for (i
= 0; i
< sizeof (attribs
) / sizeof (*attribs
); i
++)
245 if (attribs
[i
].dispatch
== A
&& attribs
[i
].bind
!= -1)
246 glBindAttribLocationARB (prog
, attribs
[i
].bind
, attribs
[i
].name
);
249 void InitScene (void)
251 prog
= glCreateProgramObjectARB ();
252 vert
= glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB
);
253 glAttachObjectARB (prog
, vert
);
254 glDeleteObjectARB (vert
);
255 load_test_file ("vstest.txt");
256 glLinkProgramARB (prog
);
257 if (!CheckObjectStatus (prog
))
259 glUseProgramObjectARB (prog
);
262 void RenderScene (void)
264 GLint info_length
, length
;
265 char output
[65000], *p
;
268 if (submit_method
== SM_MAX
)
272 * Get the current size of the info log. Any text output produced by executed
273 * shader will be appended to the end of log.
275 glGetObjectParameterivARB (vert
, GL_OBJECT_INFO_LOG_LENGTH_ARB
, &info_length
);
277 switch (submit_method
)
280 printf ("\n--- TESTING IMMEDIATE MODE\n");
284 printf ("\n--- TESTING VERTEX ARRAY MODE\n");
288 printf ("\n--- TESTING IMMEDIATE + DISPLAY LIST MODE\n");
294 printf ("\n--- TESTING VERTEX ARRAY + DISPLAY LIST MODE\n");
306 * Get the info log and set the pointer to the beginning of the output.
308 glGetInfoLogARB (vert
, sizeof (output
), &length
, output
);
309 p
= output
+ info_length
- 1;
311 for (i
= 0; i
< sizeof (attribs
) / sizeof (*attribs
); i
++) {
313 for (j
= 0; j
< attribs
[i
].size
; j
++) {
316 printf ("*** %s\n", "I/O error");
319 if (strncmp (p
, "true", 4) == 0)
321 else if (strncmp (p
, "false", 5) == 0)
323 else if (sscanf (p
, "%f", &value
) != 1) {
324 printf ("*** %s\n", "I/O error");
328 if (fabs (value
- attribs
[i
].data
[j
]) > EPSILON
)
329 printf ("*** %s, is %f, should be %f\n", "Values are different", value
, attribs
[i
].data
[j
]);
330 p
= strchr (p
, '\n');
341 int main (int argc
, char *argv
[])
343 InitFramework (&argc
, argv
);