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 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 to 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/glew.h>
  48. #include <GL/glut.h>
  49. #endif
  50. static PFNGLBINDVERTEXARRAYAPPLEPROC bind_vertex_array = NULL;
  51. static PFNGLGENVERTEXARRAYSAPPLEPROC gen_vertex_arrays = NULL;
  52. static PFNGLDELETEVERTEXARRAYSAPPLEPROC delete_vertex_arrays = NULL;
  53. static PFNGLISVERTEXARRAYAPPLEPROC is_vertex_array = NULL;
  54. static int Width = 400;
  55. static int Height = 200;
  56. static const GLfloat Near = 5.0, Far = 25.0;
  57. static void Display( void )
  58. {
  59. }
  60. static void Idle( void )
  61. {
  62. }
  63. static void Visible( int vis )
  64. {
  65. if ( vis == GLUT_VISIBLE ) {
  66. glutIdleFunc( Idle );
  67. }
  68. else {
  69. glutIdleFunc( NULL );
  70. }
  71. }
  72. static void Reshape( int width, int height )
  73. {
  74. GLfloat ar = (float) width / (float) height;
  75. Width = width;
  76. Height = height;
  77. glViewport( 0, 0, width, height );
  78. glMatrixMode( GL_PROJECTION );
  79. glLoadIdentity();
  80. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  81. }
  82. static void Key( unsigned char key, int x, int y )
  83. {
  84. (void) x;
  85. (void) y;
  86. switch (key) {
  87. case 27:
  88. exit(0);
  89. break;
  90. }
  91. glutPostRedisplay();
  92. }
  93. static void Init( void )
  94. {
  95. const char * const ver_string = (const char * const)
  96. glGetString( GL_VERSION );
  97. GLuint obj;
  98. int pass = 1;
  99. void * ptr;
  100. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  101. printf("GL_VERSION = %s\n\n", ver_string);
  102. if ( !glutExtensionSupported("GL_APPLE_vertex_array_object") ) {
  103. printf("Sorry, this program requires GL_APPLE_vertex_array_object\n");
  104. exit(2);
  105. }
  106. bind_vertex_array = (PFNGLBINDVERTEXARRAYAPPLEPROC) glutGetProcAddress( "glBindVertexArrayAPPLE" );
  107. gen_vertex_arrays = (PFNGLGENVERTEXARRAYSAPPLEPROC) glutGetProcAddress( "glGenVertexArraysAPPLE" );
  108. delete_vertex_arrays = (PFNGLDELETEVERTEXARRAYSAPPLEPROC) glutGetProcAddress( "glDeleteVertexArraysAPPLE" );
  109. is_vertex_array = (PFNGLISVERTEXARRAYAPPLEPROC) glutGetProcAddress( "glIsVertexArrayAPPLE" );
  110. (*gen_vertex_arrays)( 1, & obj );
  111. (*bind_vertex_array)( obj );
  112. glVertexPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, (void *) 0xDEADBEEF);
  113. glEnableClientState( GL_VERTEX_ARRAY );
  114. glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
  115. glVertexPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, (void *) 0xBADDC0DE);
  116. glDisableClientState( GL_VERTEX_ARRAY );
  117. glPopClientAttrib();
  118. if ( ! glIsEnabled( GL_VERTEX_ARRAY ) ) {
  119. printf( "Array state is incorrectly disabled.\n" );
  120. pass = 0;
  121. }
  122. glGetPointerv( GL_VERTEX_ARRAY_POINTER, & ptr );
  123. if ( ptr != (void *) 0xDEADBEEF ) {
  124. printf( "Array pointer is incorrectly set to 0x%p.\n", ptr );
  125. pass = 0;
  126. }
  127. if ( ! pass ) {
  128. printf( "FAIL!\n" );
  129. exit(1);
  130. }
  131. }
  132. int main( int argc, char *argv[] )
  133. {
  134. glutInit( &argc, argv );
  135. glutInitWindowPosition( 0, 0 );
  136. glutInitWindowSize( Width, Height );
  137. glutInitDisplayMode( GLUT_RGB );
  138. glutCreateWindow( "GL_APPLE_vertex_array_object demo" );
  139. glewInit();
  140. glutReshapeFunc( Reshape );
  141. glutKeyboardFunc( Key );
  142. glutDisplayFunc( Display );
  143. glutVisibilityFunc( Visible );
  144. Init();
  145. return 0;
  146. }