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.

mapvbo.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Test glMapBuffer() call immediately after glDrawArrays().
  3. * See details below.
  4. *
  5. * NOTE: Do not use freeglut with this test! It calls the Display()
  6. * callback twice right away instead of just once.
  7. *
  8. * Brian Paul
  9. * 27 Feb 2009
  10. */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <GL/glew.h>
  14. #include <GL/glut.h>
  15. static GLuint BufferID;
  16. static GLuint Win;
  17. /*
  18. * Create VBO (position and color) and load with data.
  19. */
  20. static void
  21. SetupBuffers(void)
  22. {
  23. static const GLfloat data[] = {
  24. /* vertex */ /* color */
  25. 0, -1, 0, 1, 1, 0,
  26. 1, 0, 0, 1, 1, 0,
  27. 0, 1, 0, 1, 1, 0,
  28. -1, 0, 0, 1, 1, 0
  29. };
  30. glGenBuffersARB(1, &BufferID);
  31. glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID);
  32. glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(data), data,
  33. GL_STATIC_DRAW_ARB);
  34. }
  35. static void
  36. Draw(void)
  37. {
  38. static int count = 1;
  39. printf("Draw Frame %d\n", count);
  40. count++;
  41. glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID);
  42. glVertexPointer(3, GL_FLOAT, 24, 0);
  43. glEnableClientState(GL_VERTEX_ARRAY);
  44. glColorPointer(3, GL_FLOAT, 24, (void*) 12);
  45. glEnableClientState(GL_COLOR_ARRAY);
  46. glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  47. if (0)
  48. glFinish();
  49. /* Immediately map the color buffer and change something.
  50. * This should not effect the first glDrawArrays above, but the
  51. * next time we draw we should see a black vertex.
  52. */
  53. if (1) {
  54. GLfloat *m = (GLfloat *) glMapBufferARB(GL_ARRAY_BUFFER_ARB,
  55. GL_WRITE_ONLY_ARB);
  56. m[3] = m[4] = m[5] = 0.0f; /* black vertex */
  57. glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
  58. }
  59. }
  60. static void Display( void )
  61. {
  62. glClear( GL_COLOR_BUFFER_BIT );
  63. Draw();
  64. glutSwapBuffers();
  65. }
  66. static void Reshape( int width, int height )
  67. {
  68. float ar = (float) width / (float) height;
  69. glViewport( 0, 0, width, height );
  70. glMatrixMode( GL_PROJECTION );
  71. glLoadIdentity();
  72. glFrustum( -ar, ar, -1.0, 1.0, 5.0, 25.0 );
  73. glMatrixMode( GL_MODELVIEW );
  74. glLoadIdentity();
  75. glTranslatef( 0.0, 0.0, -15.0 );
  76. }
  77. static void Key( unsigned char key, int x, int y )
  78. {
  79. (void) x;
  80. (void) y;
  81. if (key == 27) {
  82. glutDestroyWindow(Win);
  83. exit(0);
  84. }
  85. glutPostRedisplay();
  86. }
  87. static void Init( void )
  88. {
  89. if (!glutExtensionSupported("GL_ARB_vertex_buffer_object")) {
  90. printf("GL_ARB_vertex_buffer_object not found!\n");
  91. exit(0);
  92. }
  93. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  94. SetupBuffers();
  95. }
  96. int main( int argc, char *argv[] )
  97. {
  98. glutInit( &argc, argv );
  99. glutInitWindowPosition( 0, 0 );
  100. glutInitWindowSize( 300, 300 );
  101. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  102. Win = glutCreateWindow(argv[0]);
  103. glewInit();
  104. glutReshapeFunc( Reshape );
  105. glutKeyboardFunc( Key );
  106. glutDisplayFunc( Display );
  107. Init();
  108. glutMainLoop();
  109. return 0;
  110. }