Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

vao-02.c 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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/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. GLenum err;
  101. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  102. printf("GL_VERSION = %s\n\n", ver_string);
  103. if ( !glutExtensionSupported("GL_APPLE_vertex_array_object") ) {
  104. printf("Sorry, this program requires GL_APPLE_vertex_array_object\n");
  105. exit(2);
  106. }
  107. bind_vertex_array = (PFNGLBINDVERTEXARRAYAPPLEPROC) glutGetProcAddress( "glBindVertexArrayAPPLE" );
  108. gen_vertex_arrays = (PFNGLGENVERTEXARRAYSAPPLEPROC) glutGetProcAddress( "glGenVertexArraysAPPLE" );
  109. delete_vertex_arrays = (PFNGLDELETEVERTEXARRAYSAPPLEPROC) glutGetProcAddress( "glDeleteVertexArraysAPPLE" );
  110. is_vertex_array = (PFNGLISVERTEXARRAYAPPLEPROC) glutGetProcAddress( "glIsVertexArrayAPPLE" );
  111. (*gen_vertex_arrays)( 1, & obj );
  112. (*bind_vertex_array)( obj );
  113. glVertexPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, (void *) 0xDEADBEEF);
  114. glEnableClientState( GL_VERTEX_ARRAY );
  115. glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
  116. (*delete_vertex_arrays)( 1, & obj );
  117. err = glGetError();
  118. if (err) {
  119. printf( "glGetError incorrectly returned 0x%04x.\n", err );
  120. pass = 0;
  121. }
  122. if ( (*is_vertex_array)( obj ) ) {
  123. printf( "Array object is incorrectly still valid.\n" );
  124. pass = 0;
  125. }
  126. err = glGetError();
  127. if (err) {
  128. printf( "glGetError incorrectly returned 0x%04x.\n", err );
  129. pass = 0;
  130. }
  131. glPopClientAttrib();
  132. err = glGetError();
  133. if (err) {
  134. printf( "glGetError incorrectly returned 0x%04x.\n", err );
  135. pass = 0;
  136. }
  137. if ( ! (*is_vertex_array)( obj ) ) {
  138. printf( "Array object is incorrectly invalid.\n" );
  139. pass = 0;
  140. }
  141. if ( ! glIsEnabled( GL_VERTEX_ARRAY ) ) {
  142. printf( "Array state is incorrectly disabled.\n" );
  143. pass = 0;
  144. }
  145. glGetPointerv( GL_VERTEX_ARRAY_POINTER, & ptr );
  146. if ( ptr != (void *) 0xDEADBEEF ) {
  147. printf( "Array pointer is incorrectly set to 0x%p.\n", ptr );
  148. pass = 0;
  149. }
  150. if ( ! pass ) {
  151. printf( "FAIL!\n" );
  152. exit(1);
  153. }
  154. }
  155. int main( int argc, char *argv[] )
  156. {
  157. glutInit( &argc, argv );
  158. glutInitWindowPosition( 0, 0 );
  159. glutInitWindowSize( Width, Height );
  160. glutInitDisplayMode( GLUT_RGB );
  161. glutCreateWindow( "GL_APPLE_vertex_array_object demo" );
  162. glewInit();
  163. glutReshapeFunc( Reshape );
  164. glutKeyboardFunc( Key );
  165. glutDisplayFunc( Display );
  166. glutVisibilityFunc( Visible );
  167. Init();
  168. return 0;
  169. }