Fix PowerPC related typo in spantmp2.h
[mesa.git] / progs / tests / cva.c
1
2 /*
3 * Trivial CVA test, good for testing driver fastpaths (especially
4 * indexed vertex buffers if they are supported).
5 *
6 * Gareth Hughes
7 * November 2000
8 */
9
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
14 #ifdef _WIN32
15 #include <windows.h>
16 #endif
17 #define GL_GLEXT_LEGACY
18 #include <GL/glew.h>
19 #include <GL/glut.h>
20 #include <GL/glext.h>
21
22 GLfloat verts[][4] = {
23 { -0.5, -0.5, -2.0, 0.0 },
24 { 0.5, -0.5, -2.0, 0.0 },
25 { -0.5, 0.5, -2.0, 0.0 },
26 { 0.5, 0.5, -2.0, 0.0 },
27 };
28
29 GLubyte color[][4] = {
30 { 0xff, 0x00, 0x00, 0x00 },
31 { 0x00, 0xff, 0x00, 0x00 },
32 { 0x00, 0x00, 0xff, 0x00 },
33 { 0xff, 0xff, 0xff, 0x00 },
34 };
35
36 GLuint indices[] = { 0, 1, 2, 3 };
37
38 GLboolean compiled = GL_TRUE;
39 GLboolean doubleBuffer = GL_TRUE;
40
41
42 static void init( void )
43 {
44 glClearColor( 0.0, 0.0, 0.0, 0.0 );
45 glShadeModel( GL_SMOOTH );
46
47 glFrontFace( GL_CCW );
48 glCullFace( GL_BACK );
49 glEnable( GL_CULL_FACE );
50
51 glEnable( GL_DEPTH_TEST );
52
53 glEnableClientState( GL_VERTEX_ARRAY );
54 glEnableClientState( GL_COLOR_ARRAY );
55
56 glMatrixMode( GL_PROJECTION );
57 glLoadIdentity();
58 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
59 glMatrixMode( GL_MODELVIEW );
60 glLoadIdentity();
61
62 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
63 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
64
65 #ifdef GL_EXT_compiled_vertex_array
66 if ( compiled ) {
67 glLockArraysEXT( 0, 4 );
68 }
69 #endif
70 }
71
72 static void display( void )
73 {
74 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
75
76 glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
77
78 glFlush();
79 if ( doubleBuffer ) {
80 glutSwapBuffers();
81 }
82 }
83
84 static void keyboard( unsigned char key, int x, int y )
85 {
86 switch ( key ) {
87 case 27:
88 exit( 0 );
89 break;
90 }
91
92 glutPostRedisplay();
93 }
94
95 static GLboolean args( int argc, char **argv )
96 {
97 GLint i;
98
99 doubleBuffer = GL_TRUE;
100
101 for ( i = 1 ; i < argc ; i++ ) {
102 if ( strcmp( argv[i], "-sb" ) == 0 ) {
103 doubleBuffer = GL_FALSE;
104 } else if ( strcmp( argv[i], "-db" ) == 0 ) {
105 doubleBuffer = GL_TRUE;
106 } else {
107 fprintf( stderr, "%s (Bad option).\n", argv[i] );
108 return GL_FALSE;
109 }
110 }
111 return GL_TRUE;
112 }
113
114 int main( int argc, char **argv )
115 {
116 GLenum type;
117 char *string;
118 double version;
119
120 glutInit( &argc, argv );
121
122 if ( args( argc, argv ) == GL_FALSE ) {
123 exit( 1 );
124 }
125
126 type = GLUT_RGB | GLUT_DEPTH;
127 type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE;
128
129 glutInitDisplayMode( type );
130 glutInitWindowSize( 250, 250 );
131 glutInitWindowPosition( 100, 100 );
132 glutCreateWindow( "CVA Test" );
133 glewInit();
134
135 /* Make sure the server supports GL 1.2 vertex arrays.
136 */
137 string = (char *) glGetString( GL_VERSION );
138
139 version = atof(string);
140 if ( version < 1.2 ) {
141 fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
142 exit( -1 );
143 }
144
145 /* See if the server supports compiled vertex arrays.
146 */
147 string = (char *) glGetString( GL_EXTENSIONS );
148
149 if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) {
150 fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
151 compiled = GL_FALSE;
152 }
153
154 init();
155
156 glutDisplayFunc( display );
157 glutKeyboardFunc( keyboard );
158 glutMainLoop();
159
160 return 0;
161 }