Ian Romanick | ee34e6e | 2006-06-12 16:26:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright IBM Corporation 2006 |
| 3 | * All Rights Reserved. |
| 4 | * |
| 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: |
| 11 | * |
| 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 |
| 14 | * Software. |
| 15 | * |
| 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. |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * \file vao-01.c |
| 27 | * |
| 28 | * Simple test of APPLE_vertex_array_object functionality. This test creates |
| 29 | * a VAO, pushed it (via \c glPushClientAttrib), modifies the VAO, then pops |
| 30 | * it (via \c glPopClientAttrib). After popping, the state of the VAO is |
| 31 | * examined. |
| 32 | * |
| 33 | * According the the APPLE_vertex_array_object spec, the contents of the VAO |
| 34 | * should be restored to the values that they had when pushed. |
| 35 | * |
| 36 | * \author Ian Romanick <idr@us.ibm.com> |
| 37 | */ |
| 38 | |
| 39 | #include <stdio.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <math.h> |
| 42 | |
| 43 | #ifdef __darwin__ |
| 44 | #include <GLUT/glut.h> |
| 45 | |
| 46 | typedef void (* PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); |
| 47 | typedef void (* PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); |
Brian Paul | 18d0efb | 2006-06-13 01:14:48 +0000 | [diff] [blame] | 48 | typedef void (* PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays); |
Ian Romanick | ee34e6e | 2006-06-12 16:26:29 +0000 | [diff] [blame] | 49 | typedef GLboolean (* PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); |
| 50 | |
| 51 | #else |
Keith Whitwell | a58065d | 2009-03-10 13:11:23 +0000 | [diff] [blame] | 52 | #include <GL/glew.h> |
Ian Romanick | ee34e6e | 2006-06-12 16:26:29 +0000 | [diff] [blame] | 53 | #include <GL/glut.h> |
| 54 | #endif |
| 55 | |
| 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; |
| 60 | |
| 61 | static int Width = 400; |
| 62 | static int Height = 200; |
| 63 | static const GLfloat Near = 5.0, Far = 25.0; |
| 64 | |
| 65 | |
| 66 | static void Display( void ) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | |
| 71 | static void Idle( void ) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | |
| 76 | static void Visible( int vis ) |
| 77 | { |
| 78 | if ( vis == GLUT_VISIBLE ) { |
| 79 | glutIdleFunc( Idle ); |
| 80 | } |
| 81 | else { |
| 82 | glutIdleFunc( NULL ); |
| 83 | } |
| 84 | } |
| 85 | static void Reshape( int width, int height ) |
| 86 | { |
| 87 | GLfloat ar = (float) width / (float) height; |
| 88 | Width = width; |
| 89 | Height = height; |
| 90 | glViewport( 0, 0, width, height ); |
| 91 | glMatrixMode( GL_PROJECTION ); |
| 92 | glLoadIdentity(); |
| 93 | glFrustum( -ar, ar, -1.0, 1.0, Near, Far ); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | static void Key( unsigned char key, int x, int y ) |
| 98 | { |
| 99 | (void) x; |
| 100 | (void) y; |
| 101 | switch (key) { |
| 102 | case 27: |
| 103 | exit(0); |
| 104 | break; |
| 105 | } |
| 106 | glutPostRedisplay(); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | static void Init( void ) |
| 111 | { |
| 112 | const char * const ver_string = (const char * const) |
| 113 | glGetString( GL_VERSION ); |
| 114 | GLuint obj; |
| 115 | int pass = 1; |
| 116 | void * ptr; |
| 117 | |
| 118 | |
| 119 | printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); |
| 120 | printf("GL_VERSION = %s\n\n", ver_string); |
| 121 | |
| 122 | if ( !glutExtensionSupported("GL_APPLE_vertex_array_object") ) { |
| 123 | printf("Sorry, this program requires GL_APPLE_vertex_array_object\n"); |
| 124 | exit(2); |
| 125 | } |
| 126 | |
| 127 | bind_vertex_array = glutGetProcAddress( "glBindVertexArrayAPPLE" ); |
| 128 | gen_vertex_arrays = glutGetProcAddress( "glGenVertexArraysAPPLE" ); |
| 129 | delete_vertex_arrays = glutGetProcAddress( "glDeleteVertexArraysAPPLE" ); |
| 130 | is_vertex_array = glutGetProcAddress( "glIsVertexArrayAPPLE" ); |
| 131 | |
| 132 | |
| 133 | (*gen_vertex_arrays)( 1, & obj ); |
| 134 | (*bind_vertex_array)( obj ); |
| 135 | glVertexPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, (void *) 0xDEADBEEF); |
| 136 | glEnableClientState( GL_VERTEX_ARRAY ); |
| 137 | |
| 138 | glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); |
| 139 | |
| 140 | glVertexPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, (void *) 0xBADDC0DE); |
| 141 | glDisableClientState( GL_VERTEX_ARRAY ); |
| 142 | |
| 143 | glPopClientAttrib(); |
| 144 | |
| 145 | if ( ! glIsEnabled( GL_VERTEX_ARRAY ) ) { |
| 146 | printf( "Array state is incorrectly disabled.\n" ); |
| 147 | pass = 0; |
| 148 | } |
| 149 | |
| 150 | glGetPointerv( GL_VERTEX_ARRAY_POINTER, & ptr ); |
| 151 | if ( ptr != (void *) 0xDEADBEEF ) { |
| 152 | printf( "Array pointer is incorrectly set to 0x%p.\n", ptr ); |
| 153 | pass = 0; |
| 154 | } |
| 155 | |
| 156 | if ( ! pass ) { |
| 157 | printf( "FAIL!\n" ); |
| 158 | exit(1); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | |
| 163 | int main( int argc, char *argv[] ) |
| 164 | { |
| 165 | glutInit( &argc, argv ); |
| 166 | glutInitWindowPosition( 0, 0 ); |
| 167 | glutInitWindowSize( Width, Height ); |
| 168 | glutInitDisplayMode( GLUT_RGB ); |
| 169 | glutCreateWindow( "GL_APPLE_vertex_array_object demo" ); |
Keith Whitwell | a58065d | 2009-03-10 13:11:23 +0000 | [diff] [blame] | 170 | glewInit(); |
Ian Romanick | ee34e6e | 2006-06-12 16:26:29 +0000 | [diff] [blame] | 171 | glutReshapeFunc( Reshape ); |
| 172 | glutKeyboardFunc( Key ); |
| 173 | glutDisplayFunc( Display ); |
| 174 | glutVisibilityFunc( Visible ); |
| 175 | |
| 176 | Init(); |
| 177 | |
| 178 | return 0; |
| 179 | } |