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.

copytex.c 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 glCopyTex[Sub]Image() rate.
  23. * Create a large, off-screen framebuffer object for rendering and
  24. * copying the texture data from it since we can't make really large
  25. * on-screen windows.
  26. *
  27. * Brian Paul
  28. * 22 Sep 2009
  29. */
  30. #include <string.h>
  31. #include "glmain.h"
  32. #include "common.h"
  33. int WinWidth = 100, WinHeight = 100;
  34. static GLuint VBO, FBO, RBO, Tex;
  35. const GLsizei MinSize = 16, MaxSize = 4096;
  36. static GLsizei TexSize;
  37. static const GLboolean DrawPoint = GL_TRUE;
  38. static const GLboolean TexSubImage4 = GL_FALSE;
  39. struct vertex
  40. {
  41. GLfloat x, y, s, t;
  42. };
  43. static const struct vertex vertices[1] = {
  44. { 0.0, 0.0, 0.5, 0.5 },
  45. };
  46. #define VOFFSET(F) ((void *) offsetof(struct vertex, F))
  47. /** Called from test harness/main */
  48. void
  49. PerfInit(void)
  50. {
  51. const GLenum filter = GL_LINEAR;
  52. GLenum stat;
  53. if (!PerfExtensionSupported("GL_EXT_framebuffer_object")) {
  54. perf_printf("copytex: GL_EXT_framebuffer_object not supported\n");
  55. exit(0);
  56. }
  57. /* setup VBO */
  58. glGenBuffersARB(1, &VBO);
  59. glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
  60. glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertices),
  61. vertices, GL_STATIC_DRAW_ARB);
  62. glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(x));
  63. glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(s));
  64. glEnableClientState(GL_VERTEX_ARRAY);
  65. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  66. /* setup texture */
  67. glGenTextures(1, &Tex);
  68. glBindTexture(GL_TEXTURE_2D, Tex);
  69. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
  70. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
  71. glEnable(GL_TEXTURE_2D);
  72. /* setup rbo */
  73. glGenRenderbuffersEXT(1, &RBO);
  74. glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBO);
  75. glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, MaxSize, MaxSize);
  76. /* setup fbo */
  77. glGenFramebuffersEXT(1, &FBO);
  78. glBindFramebufferEXT(GL_FRAMEBUFFER, FBO);
  79. glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
  80. GL_COLOR_ATTACHMENT0_EXT,
  81. GL_RENDERBUFFER_EXT, RBO);
  82. stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  83. if (stat != GL_FRAMEBUFFER_COMPLETE_EXT) {
  84. perf_printf("fboswitch: Error: incomplete FBO!\n");
  85. exit(1);
  86. }
  87. /* clear the FBO */
  88. glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
  89. glViewport(0, 0, MaxSize, MaxSize);
  90. glClear(GL_COLOR_BUFFER_BIT);
  91. }
  92. static void
  93. CopyTexImage(unsigned count)
  94. {
  95. unsigned i;
  96. for (i = 1; i < count; i++) {
  97. /* draw something */
  98. if (DrawPoint)
  99. glDrawArrays(GL_POINTS, 0, 1);
  100. /* copy whole texture */
  101. glCopyTexImage2D(GL_TEXTURE_2D, 0,
  102. GL_RGBA, 0, 0, TexSize, TexSize, 0);
  103. }
  104. glFinish();
  105. }
  106. static void
  107. CopyTexSubImage(unsigned count)
  108. {
  109. unsigned i;
  110. for (i = 1; i < count; i++) {
  111. /* draw something */
  112. if (DrawPoint)
  113. glDrawArrays(GL_POINTS, 0, 1);
  114. /* copy sub texture */
  115. if (TexSubImage4) {
  116. /* four sub-copies */
  117. GLsizei half = TexSize / 2;
  118. /* lower-left */
  119. glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
  120. 0, 0, 0, 0, half, half);
  121. /* lower-right */
  122. glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
  123. half, 0, half, 0, half, half);
  124. /* upper-left */
  125. glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
  126. 0, half, 0, half, half, half);
  127. /* upper-right */
  128. glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
  129. half, half, half, half, half, half);
  130. }
  131. else {
  132. /* one big copy */
  133. glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
  134. 0, 0, 0, 0, TexSize, TexSize);
  135. }
  136. }
  137. glFinish();
  138. }
  139. /** Called from test harness/main */
  140. void
  141. PerfNextRound(void)
  142. {
  143. }
  144. /** Called from test harness/main */
  145. void
  146. PerfDraw(void)
  147. {
  148. double rate, mbPerSec;
  149. GLint sub, maxTexSize;
  150. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
  151. /* loop over whole/sub tex copy */
  152. for (sub = 0; sub < 2; sub++) {
  153. /* loop over texture sizes */
  154. for (TexSize = MinSize; TexSize <= MaxSize; TexSize *= 4) {
  155. if (TexSize <= maxTexSize) {
  156. GLint bytesPerImage = 4 * TexSize * TexSize;
  157. if (sub == 0)
  158. rate = PerfMeasureRate(CopyTexImage);
  159. else {
  160. /* setup empty dest texture */
  161. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
  162. TexSize, TexSize, 0,
  163. GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  164. rate = PerfMeasureRate(CopyTexSubImage);
  165. }
  166. mbPerSec = rate * bytesPerImage / (1024.0 * 1024.0);
  167. }
  168. else {
  169. rate = 0.0;
  170. mbPerSec = 0.0;
  171. }
  172. perf_printf(" glCopyTex%sImage(%d x %d): %.1f copies/sec, %.1f Mpixels/sec\n",
  173. (sub ? "Sub" : ""), TexSize, TexSize, rate, mbPerSec);
  174. }
  175. }
  176. exit(0);
  177. }