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.

fbobind.c 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included
  12. * in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  18. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. /**
  22. * Measure rate of binding/switching between FBO targets.
  23. * Create two framebuffer objects for rendering to two textures.
  24. * Ping pong between texturing from one and drawing into the other.
  25. *
  26. * Brian Paul
  27. * 22 Sep 2009
  28. */
  29. #include <string.h>
  30. #include "glmain.h"
  31. #include "common.h"
  32. int WinWidth = 100, WinHeight = 100;
  33. static GLuint VBO;
  34. static GLuint FBO[2], Tex[2];
  35. static const GLsizei TexSize = 512;
  36. static const GLboolean DrawPoint = GL_TRUE;
  37. struct vertex
  38. {
  39. GLfloat x, y, s, t;
  40. };
  41. static const struct vertex vertices[1] = {
  42. { 0.0, 0.0, 0.5, 0.5 },
  43. };
  44. #define VOFFSET(F) ((void *) offsetof(struct vertex, F))
  45. /** Called from test harness/main */
  46. void
  47. PerfInit(void)
  48. {
  49. const GLenum filter = GL_LINEAR;
  50. GLenum stat;
  51. int i;
  52. if (!PerfExtensionSupported("GL_EXT_framebuffer_object")) {
  53. perf_printf("fboswitch: GL_EXT_framebuffer_object not supported\n");
  54. exit(0);
  55. }
  56. /* setup VBO */
  57. glGenBuffersARB(1, &VBO);
  58. glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
  59. glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertices),
  60. vertices, GL_STATIC_DRAW_ARB);
  61. glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(x));
  62. glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(s));
  63. glEnableClientState(GL_VERTEX_ARRAY);
  64. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  65. glGenFramebuffersEXT(2, FBO);
  66. glGenTextures(2, Tex);
  67. for (i = 0; i < 2; i++) {
  68. /* setup texture */
  69. glBindTexture(GL_TEXTURE_2D, Tex[i]);
  70. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
  71. TexSize, TexSize, 0,
  72. GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  73. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
  74. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
  75. /* setup fbo */
  76. glBindFramebufferEXT(GL_FRAMEBUFFER, FBO[i]);
  77. glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
  78. GL_COLOR_ATTACHMENT0_EXT,
  79. GL_TEXTURE_2D, Tex[i], 0/*level*/);
  80. stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  81. if (stat != GL_FRAMEBUFFER_COMPLETE_EXT) {
  82. perf_printf("fboswitch: Error: incomplete FBO!\n");
  83. exit(1);
  84. }
  85. /* clear the FBO */
  86. glClear(GL_COLOR_BUFFER_BIT);
  87. }
  88. glEnable(GL_TEXTURE_2D);
  89. }
  90. static void
  91. FBOBind(unsigned count)
  92. {
  93. unsigned i;
  94. for (i = 1; i < count; i++) {
  95. const GLuint dst = i & 1;
  96. const GLuint src = 1 - dst;
  97. /* bind src texture */
  98. glBindTexture(GL_TEXTURE_2D, Tex[src]);
  99. /* bind dst fbo */
  100. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO[dst]);
  101. glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
  102. /* draw something */
  103. if (DrawPoint)
  104. glDrawArrays(GL_POINTS, 0, 1);
  105. }
  106. glFinish();
  107. }
  108. /** Called from test harness/main */
  109. void
  110. PerfNextRound(void)
  111. {
  112. }
  113. /** Called from test harness/main */
  114. void
  115. PerfDraw(void)
  116. {
  117. double rate;
  118. rate = PerfMeasureRate(FBOBind);
  119. perf_printf(" FBO Binding: %1.f binds/sec\n", rate);
  120. exit(0);
  121. }