blob: 80483900cb7d077bb80aed85de9c9438533546f4 [file] [log] [blame]
Gareth Hughes9f568e52000-11-01 03:14:12 +00001
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>
Eric Anholt9bb0d622007-09-24 10:22:31 -070013#include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
Karl Schultz40fac752002-01-16 01:03:25 +000014#ifdef _WIN32
15#include <windows.h>
16#endif
Gareth Hughes9f568e52000-11-01 03:14:12 +000017#define GL_GLEXT_LEGACY
Keith Whitwella58065d2009-03-10 13:11:23 +000018#include <GL/glew.h>
Gareth Hughes9f568e52000-11-01 03:14:12 +000019#include <GL/glut.h>
Eric Anholt745df742008-02-03 01:04:46 -080020#include <GL/glext.h>
Gareth Hughes9f568e52000-11-01 03:14:12 +000021
22GLfloat verts[][4] = {
Gareth Hughes5f5632c2000-11-03 00:09:31 +000023 { -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 },
Gareth Hughes78539012000-11-30 03:06:56 +000026 { 0.5, 0.5, -2.0, 0.0 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000027};
28
29GLubyte color[][4] = {
30 { 0xff, 0x00, 0x00, 0x00 },
31 { 0x00, 0xff, 0x00, 0x00 },
32 { 0x00, 0x00, 0xff, 0x00 },
Gareth Hughes78539012000-11-30 03:06:56 +000033 { 0xff, 0xff, 0xff, 0x00 },
Gareth Hughes9f568e52000-11-01 03:14:12 +000034};
35
Gareth Hughes78539012000-11-30 03:06:56 +000036GLuint indices[] = { 0, 1, 2, 3 };
Gareth Hughes9f568e52000-11-01 03:14:12 +000037
38GLboolean compiled = GL_TRUE;
Gareth Hughes78539012000-11-30 03:06:56 +000039GLboolean doubleBuffer = GL_TRUE;
Gareth Hughes9f568e52000-11-01 03:14:12 +000040
41
42void init( void )
43{
44 glClearColor( 0.0, 0.0, 0.0, 0.0 );
45 glShadeModel( GL_SMOOTH );
46
Gareth Hughes78539012000-11-30 03:06:56 +000047 glFrontFace( GL_CCW );
48 glCullFace( GL_BACK );
49 glEnable( GL_CULL_FACE );
50
Gareth Hughes9f568e52000-11-01 03:14:12 +000051 glEnable( GL_DEPTH_TEST );
52
53 glEnableClientState( GL_VERTEX_ARRAY );
54 glEnableClientState( GL_COLOR_ARRAY );
55
56 glMatrixMode( GL_PROJECTION );
57 glLoadIdentity();
Gareth Hughes5f5632c2000-11-03 00:09:31 +000058 glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000059 glMatrixMode( GL_MODELVIEW );
Gareth Hughes5f5632c2000-11-03 00:09:31 +000060 glLoadIdentity();
Gareth Hughes9f568e52000-11-01 03:14:12 +000061
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 ) {
Gareth Hughes78539012000-11-30 03:06:56 +000067 glLockArraysEXT( 0, 4 );
Gareth Hughes9f568e52000-11-01 03:14:12 +000068 }
69#endif
70}
71
72void 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();
Gareth Hughes78539012000-11-30 03:06:56 +000079 if ( doubleBuffer ) {
80 glutSwapBuffers();
81 }
Gareth Hughes9f568e52000-11-01 03:14:12 +000082}
83
84void keyboard( unsigned char key, int x, int y )
85{
86 switch ( key ) {
87 case 27:
88 exit( 0 );
89 break;
90 }
Gareth Hughes78539012000-11-30 03:06:56 +000091
92 glutPostRedisplay();
93}
94
95GLboolean 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;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000112}
113
114int main( int argc, char **argv )
115{
Gareth Hughes78539012000-11-30 03:06:56 +0000116 GLenum type;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000117 char *string;
Roland Scheidegger22b74ff2006-11-22 19:37:21 +0000118 double version;
Gareth Hughes9f568e52000-11-01 03:14:12 +0000119
120 glutInit( &argc, argv );
Gareth Hughes78539012000-11-30 03:06:56 +0000121
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 );
Gareth Hughes9f568e52000-11-01 03:14:12 +0000130 glutInitWindowSize( 250, 250 );
131 glutInitWindowPosition( 100, 100 );
132 glutCreateWindow( "CVA Test" );
Keith Whitwella58065d2009-03-10 13:11:23 +0000133 glewInit();
Gareth Hughes9f568e52000-11-01 03:14:12 +0000134
135 /* Make sure the server supports GL 1.2 vertex arrays.
136 */
137 string = (char *) glGetString( GL_VERSION );
138
Roland Scheidegger22b74ff2006-11-22 19:37:21 +0000139 version = atof(string);
140 if ( version < 1.2 ) {
Gareth Hughes9f568e52000-11-01 03:14:12 +0000141 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}