Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vao-01.c 4.9KB

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