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