2 * (C) Copyright IBM Corporation 2006
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
28 * Simple test of APPLE_vertex_array_object functionality. This test creates
29 * a VAO, pushed it (via \c glPushClientAttrib), deletes the VAO, then pops
30 * it (via \c glPopClientAttrib). After popping, the state of the VAO is
33 * According to the APPLE_vertex_array_object spec, the contents of the VAO
34 * should be restored to the values that they had when pushed.
36 * \author Ian Romanick <idr@us.ibm.com>
44 #include <GLUT/glut.h>
46 typedef void (* PFNGLBINDVERTEXARRAYAPPLEPROC
) (GLuint array
);
47 typedef void (* PFNGLDELETEVERTEXARRAYSAPPLEPROC
) (GLsizei n
, const GLuint
*arrays
);
48 typedef void (* PFNGLGENVERTEXARRAYSAPPLEPROC
) (GLsizei n
, GLuint
*arrays
);
49 typedef GLboolean (* PFNGLISVERTEXARRAYAPPLEPROC
) (GLuint array
);
56 static PFNGLBINDVERTEXARRAYAPPLEPROC bind_vertex_array
= NULL
;
57 static PFNGLGENVERTEXARRAYSAPPLEPROC gen_vertex_arrays
= NULL
;
58 static PFNGLDELETEVERTEXARRAYSAPPLEPROC delete_vertex_arrays
= NULL
;
59 static PFNGLISVERTEXARRAYAPPLEPROC is_vertex_array
= NULL
;
61 static int Width
= 400;
62 static int Height
= 200;
63 static const GLfloat Near
= 5.0, Far
= 25.0;
66 static void Display( void )
71 static void Idle( void )
76 static void Visible( int vis
)
78 if ( vis
== GLUT_VISIBLE
) {
85 static void Reshape( int width
, int height
)
87 GLfloat ar
= (float) width
/ (float) height
;
90 glViewport( 0, 0, width
, height
);
91 glMatrixMode( GL_PROJECTION
);
93 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
97 static void Key( unsigned char key
, int x
, int y
)
110 static void Init( void )
112 const char * const ver_string
= (const char * const)
113 glGetString( GL_VERSION
);
120 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
121 printf("GL_VERSION = %s\n\n", ver_string
);
123 if ( !glutExtensionSupported("GL_APPLE_vertex_array_object") ) {
124 printf("Sorry, this program requires GL_APPLE_vertex_array_object\n");
128 bind_vertex_array
= (PFNGLBINDVERTEXARRAYAPPLEPROC
) glutGetProcAddress( "glBindVertexArrayAPPLE" );
129 gen_vertex_arrays
= (PFNGLGENVERTEXARRAYSAPPLEPROC
) glutGetProcAddress( "glGenVertexArraysAPPLE" );
130 delete_vertex_arrays
= (PFNGLDELETEVERTEXARRAYSAPPLEPROC
) glutGetProcAddress( "glDeleteVertexArraysAPPLE" );
131 is_vertex_array
= (PFNGLISVERTEXARRAYAPPLEPROC
) glutGetProcAddress( "glIsVertexArrayAPPLE" );
134 (*gen_vertex_arrays
)( 1, & obj
);
135 (*bind_vertex_array
)( obj
);
136 glVertexPointer( 4, GL_FLOAT
, sizeof(GLfloat
) * 4, (void *) 0xDEADBEEF);
137 glEnableClientState( GL_VERTEX_ARRAY
);
139 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT
);
141 (*delete_vertex_arrays
)( 1, & obj
);
145 printf( "glGetError incorrectly returned 0x%04x.\n", err
);
149 if ( (*is_vertex_array
)( obj
) ) {
150 printf( "Array object is incorrectly still valid.\n" );
156 printf( "glGetError incorrectly returned 0x%04x.\n", err
);
164 printf( "glGetError incorrectly returned 0x%04x.\n", err
);
168 if ( ! (*is_vertex_array
)( obj
) ) {
169 printf( "Array object is incorrectly invalid.\n" );
173 if ( ! glIsEnabled( GL_VERTEX_ARRAY
) ) {
174 printf( "Array state is incorrectly disabled.\n" );
178 glGetPointerv( GL_VERTEX_ARRAY_POINTER
, & ptr
);
179 if ( ptr
!= (void *) 0xDEADBEEF ) {
180 printf( "Array pointer is incorrectly set to 0x%p.\n", ptr
);
191 int main( int argc
, char *argv
[] )
193 glutInit( &argc
, argv
);
194 glutInitWindowPosition( 0, 0 );
195 glutInitWindowSize( Width
, Height
);
196 glutInitDisplayMode( GLUT_RGB
);
197 glutCreateWindow( "GL_APPLE_vertex_array_object demo" );
199 glutReshapeFunc( Reshape
);
200 glutKeyboardFunc( Key
);
201 glutDisplayFunc( Display
);
202 glutVisibilityFunc( Visible
);