Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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-02.c
  26. *
  27. * Simple test of APPLE_vertex_array_object functionality. This test creates
  28. * a VAO, pushed it (via \c glPushClientAttrib), deletes 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. GLenum err;
  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 = glutGetProcAddress( "glBindVertexArrayAPPLE" );
  107. gen_vertex_arrays = glutGetProcAddress( "glGenVertexArraysAPPLE" );
  108. delete_vertex_arrays = glutGetProcAddress( "glDeleteVertexArraysAPPLE" );
  109. is_vertex_array = 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. (*delete_vertex_arrays)( 1, & obj );
  116. err = glGetError();
  117. if (err) {
  118. printf( "glGetError incorrectly returned 0x%04x.\n", err );
  119. pass = 0;
  120. }
  121. if ( (*is_vertex_array)( obj ) ) {
  122. printf( "Array object is incorrectly still valid.\n" );
  123. pass = 0;
  124. }
  125. err = glGetError();
  126. if (err) {
  127. printf( "glGetError incorrectly returned 0x%04x.\n", err );
  128. pass = 0;
  129. }
  130. glPopClientAttrib();
  131. err = glGetError();
  132. if (err) {
  133. printf( "glGetError incorrectly returned 0x%04x.\n", err );
  134. pass = 0;
  135. }
  136. if ( ! (*is_vertex_array)( obj ) ) {
  137. printf( "Array object is incorrectly invalid.\n" );
  138. pass = 0;
  139. }
  140. if ( ! glIsEnabled( GL_VERTEX_ARRAY ) ) {
  141. printf( "Array state is incorrectly disabled.\n" );
  142. pass = 0;
  143. }
  144. glGetPointerv( GL_VERTEX_ARRAY_POINTER, & ptr );
  145. if ( ptr != (void *) 0xDEADBEEF ) {
  146. printf( "Array pointer is incorrectly set to 0x%p.\n", ptr );
  147. pass = 0;
  148. }
  149. if ( ! pass ) {
  150. printf( "FAIL!\n" );
  151. exit(1);
  152. }
  153. }
  154. int main( int argc, char *argv[] )
  155. {
  156. glutInit( &argc, argv );
  157. glutInitWindowPosition( 0, 0 );
  158. glutInitWindowSize( Width, Height );
  159. glutInitDisplayMode( GLUT_RGB );
  160. glutCreateWindow( "GL_APPLE_vertex_array_object demo" );
  161. glutReshapeFunc( Reshape );
  162. glutKeyboardFunc( Key );
  163. glutDisplayFunc( Display );
  164. glutVisibilityFunc( Visible );
  165. Init();
  166. return 0;
  167. }