Convert libGL and DRI drivers to require libdrm.
[mesa-demos.git] / src / tests / cva.c
blob3f7960f53b6d1daee610178eda8d0e45f01388fe
1 /* $Id: cva.c,v 1.7 2003/12/08 09:03:35 joukj Exp $ */
3 /*
4 * Trivial CVA test, good for testing driver fastpaths (especially
5 * indexed vertex buffers if they are supported).
7 * Gareth Hughes
8 * November 2000
9 */
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #ifdef __VMS
15 # include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
16 #else
17 # include <malloc.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
18 #endif
19 #ifdef _WIN32
20 #include <windows.h>
21 #endif
22 #define GL_GLEXT_LEGACY
23 #include <GL/glut.h>
26 GLfloat verts[][4] = {
27 { -0.5, -0.5, -2.0, 0.0 },
28 { 0.5, -0.5, -2.0, 0.0 },
29 { -0.5, 0.5, -2.0, 0.0 },
30 { 0.5, 0.5, -2.0, 0.0 },
33 GLubyte color[][4] = {
34 { 0xff, 0x00, 0x00, 0x00 },
35 { 0x00, 0xff, 0x00, 0x00 },
36 { 0x00, 0x00, 0xff, 0x00 },
37 { 0xff, 0xff, 0xff, 0x00 },
40 GLuint indices[] = { 0, 1, 2, 3 };
42 GLboolean compiled = GL_TRUE;
43 GLboolean doubleBuffer = GL_TRUE;
46 void init( void )
48 glClearColor( 0.0, 0.0, 0.0, 0.0 );
49 glShadeModel( GL_SMOOTH );
51 glFrontFace( GL_CCW );
52 glCullFace( GL_BACK );
53 glEnable( GL_CULL_FACE );
55 glEnable( GL_DEPTH_TEST );
57 glEnableClientState( GL_VERTEX_ARRAY );
58 glEnableClientState( GL_COLOR_ARRAY );
60 glMatrixMode( GL_PROJECTION );
61 glLoadIdentity();
62 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
63 glMatrixMode( GL_MODELVIEW );
64 glLoadIdentity();
66 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
67 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
69 #ifdef GL_EXT_compiled_vertex_array
70 if ( compiled ) {
71 glLockArraysEXT( 0, 4 );
73 #endif
76 void display( void )
78 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
80 glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
82 glFlush();
83 if ( doubleBuffer ) {
84 glutSwapBuffers();
88 void keyboard( unsigned char key, int x, int y )
90 switch ( key ) {
91 case 27:
92 exit( 0 );
93 break;
96 glutPostRedisplay();
99 GLboolean args( int argc, char **argv )
101 GLint i;
103 doubleBuffer = GL_TRUE;
105 for ( i = 1 ; i < argc ; i++ ) {
106 if ( strcmp( argv[i], "-sb" ) == 0 ) {
107 doubleBuffer = GL_FALSE;
108 } else if ( strcmp( argv[i], "-db" ) == 0 ) {
109 doubleBuffer = GL_TRUE;
110 } else {
111 fprintf( stderr, "%s (Bad option).\n", argv[i] );
112 return GL_FALSE;
115 return GL_TRUE;
118 int main( int argc, char **argv )
120 GLenum type;
121 char *string;
123 glutInit( &argc, argv );
125 if ( args( argc, argv ) == GL_FALSE ) {
126 exit( 1 );
129 type = GLUT_RGB | GLUT_DEPTH;
130 type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE;
132 glutInitDisplayMode( type );
133 glutInitWindowSize( 250, 250 );
134 glutInitWindowPosition( 100, 100 );
135 glutCreateWindow( "CVA Test" );
137 /* Make sure the server supports GL 1.2 vertex arrays.
139 string = (char *) glGetString( GL_VERSION );
141 if ( !strstr(string, "1.2") &&
142 !strstr(string, "1.3") &&
143 !strstr(string, "1.4")) {
144 fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
145 exit( -1 );
148 /* See if the server supports compiled vertex arrays.
150 string = (char *) glGetString( GL_EXTENSIONS );
152 if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) {
153 fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
154 compiled = GL_FALSE;
157 init();
159 glutDisplayFunc( display );
160 glutKeyboardFunc( keyboard );
161 glutMainLoop();
163 return 0;