Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 simple vertex processing rate via:
  23. * - immediate mode
  24. * - vertex arrays
  25. * - VBO vertex arrays
  26. * - glDrawElements
  27. * - VBO glDrawElements
  28. * - glDrawRangeElements
  29. * - VBO glDrawRangeElements
  30. *
  31. * Brian Paul
  32. * 16 Sep 2009
  33. */
  34. #include <assert.h>
  35. #include <string.h>
  36. #include "glmain.h"
  37. #include "common.h"
  38. #define MAX_VERTS (100 * 100)
  39. /** glVertex2/3/4 size */
  40. #define VERT_SIZE 4
  41. int WinWidth = 500, WinHeight = 500;
  42. static GLuint VertexBO, ElementBO;
  43. static unsigned NumVerts = MAX_VERTS;
  44. static unsigned VertBytes = VERT_SIZE * sizeof(float);
  45. static float *VertexData = NULL;
  46. static unsigned NumElements = MAX_VERTS;
  47. static GLuint *Elements = NULL;
  48. /**
  49. * Load VertexData buffer with a 2-D grid of points in the range [-1,1]^2.
  50. */
  51. static void
  52. InitializeVertexData(void)
  53. {
  54. unsigned i;
  55. float x = -1.0, y = -1.0;
  56. float dx = 2.0 / 100;
  57. float dy = 2.0 / 100;
  58. VertexData = (float *) malloc(NumVerts * VertBytes);
  59. for (i = 0; i < NumVerts; i++) {
  60. VertexData[i * VERT_SIZE + 0] = x;
  61. VertexData[i * VERT_SIZE + 1] = y;
  62. VertexData[i * VERT_SIZE + 2] = 0.0;
  63. VertexData[i * VERT_SIZE + 3] = 1.0;
  64. x += dx;
  65. if (x > 1.0) {
  66. x = -1.0;
  67. y += dy;
  68. }
  69. }
  70. Elements = (GLuint *) malloc(NumVerts * sizeof(GLuint));
  71. for (i = 0; i < NumVerts; i++) {
  72. Elements[i] = NumVerts - i - 1;
  73. }
  74. }
  75. /** Called from test harness/main */
  76. void
  77. PerfInit(void)
  78. {
  79. InitializeVertexData();
  80. /* setup VertexBO */
  81. glGenBuffersARB(1, &VertexBO);
  82. glBindBufferARB(GL_ARRAY_BUFFER_ARB, VertexBO);
  83. glBufferDataARB(GL_ARRAY_BUFFER_ARB,
  84. NumVerts * VertBytes, VertexData, GL_STATIC_DRAW_ARB);
  85. glEnableClientState(GL_VERTEX_ARRAY);
  86. /* setup ElementBO */
  87. glGenBuffersARB(1, &ElementBO);
  88. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ElementBO);
  89. glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
  90. NumElements * sizeof(GLuint), Elements, GL_STATIC_DRAW_ARB);
  91. }
  92. static void
  93. DrawImmediate(unsigned count)
  94. {
  95. unsigned i;
  96. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
  97. glBindBufferARB(GL_ARRAY_BUFFER, 0);
  98. for (i = 0; i < count; i++) {
  99. unsigned j;
  100. glBegin(GL_POINTS);
  101. for (j = 0; j < NumVerts; j++) {
  102. #if VERT_SIZE == 4
  103. glVertex4fv(VertexData + j * 4);
  104. #elif VERT_SIZE == 3
  105. glVertex3fv(VertexData + j * 3);
  106. #elif VERT_SIZE == 2
  107. glVertex2fv(VertexData + j * 2);
  108. #else
  109. abort();
  110. #endif
  111. }
  112. glEnd();
  113. }
  114. glFinish();
  115. PerfSwapBuffers();
  116. }
  117. static void
  118. DrawArraysMem(unsigned count)
  119. {
  120. unsigned i;
  121. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
  122. glBindBufferARB(GL_ARRAY_BUFFER, 0);
  123. glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, VertexData);
  124. for (i = 0; i < count; i++) {
  125. glDrawArrays(GL_POINTS, 0, NumVerts);
  126. }
  127. glFinish();
  128. PerfSwapBuffers();
  129. }
  130. static void
  131. DrawArraysVBO(unsigned count)
  132. {
  133. unsigned i;
  134. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
  135. glBindBufferARB(GL_ARRAY_BUFFER, VertexBO);
  136. glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, (void *) 0);
  137. for (i = 0; i < count; i++) {
  138. glDrawArrays(GL_POINTS, 0, NumVerts);
  139. }
  140. glFinish();
  141. PerfSwapBuffers();
  142. }
  143. static void
  144. DrawElementsMem(unsigned count)
  145. {
  146. unsigned i;
  147. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
  148. glBindBufferARB(GL_ARRAY_BUFFER, 0);
  149. glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, VertexData);
  150. for (i = 0; i < count; i++) {
  151. glDrawElements(GL_POINTS, NumVerts, GL_UNSIGNED_INT, Elements);
  152. }
  153. glFinish();
  154. PerfSwapBuffers();
  155. }
  156. static void
  157. DrawElementsBO(unsigned count)
  158. {
  159. unsigned i;
  160. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, ElementBO);
  161. glBindBufferARB(GL_ARRAY_BUFFER, VertexBO);
  162. glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, (void *) 0);
  163. for (i = 0; i < count; i++) {
  164. glDrawElements(GL_POINTS, NumVerts, GL_UNSIGNED_INT, (void *) 0);
  165. }
  166. glFinish();
  167. PerfSwapBuffers();
  168. }
  169. static void
  170. DrawRangeElementsMem(unsigned count)
  171. {
  172. unsigned i;
  173. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
  174. glBindBufferARB(GL_ARRAY_BUFFER, 0);
  175. glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, VertexData);
  176. for (i = 0; i < count; i++) {
  177. glDrawRangeElements(GL_POINTS, 0, NumVerts - 1,
  178. NumVerts, GL_UNSIGNED_INT, Elements);
  179. }
  180. glFinish();
  181. PerfSwapBuffers();
  182. }
  183. static void
  184. DrawRangeElementsBO(unsigned count)
  185. {
  186. unsigned i;
  187. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, ElementBO);
  188. glBindBufferARB(GL_ARRAY_BUFFER, VertexBO);
  189. glVertexPointer(VERT_SIZE, GL_FLOAT, VertBytes, (void *) 0);
  190. for (i = 0; i < count; i++) {
  191. glDrawRangeElements(GL_POINTS, 0, NumVerts - 1,
  192. NumVerts, GL_UNSIGNED_INT, (void *) 0);
  193. }
  194. glFinish();
  195. PerfSwapBuffers();
  196. }
  197. void
  198. PerfNextRound(void)
  199. {
  200. }
  201. /** Called from test harness/main */
  202. void
  203. PerfDraw(void)
  204. {
  205. double rate;
  206. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  207. perf_printf("Vertex rate (%d x Vertex%df)\n", NumVerts, VERT_SIZE);
  208. rate = PerfMeasureRate(DrawImmediate);
  209. rate *= NumVerts;
  210. perf_printf(" Immediate mode: %s verts/sec\n", PerfHumanFloat(rate));
  211. rate = PerfMeasureRate(DrawArraysMem);
  212. rate *= NumVerts;
  213. perf_printf(" glDrawArrays: %s verts/sec\n", PerfHumanFloat(rate));
  214. rate = PerfMeasureRate(DrawArraysVBO);
  215. rate *= NumVerts;
  216. perf_printf(" VBO glDrawArrays: %s verts/sec\n", PerfHumanFloat(rate));
  217. rate = PerfMeasureRate(DrawElementsMem);
  218. rate *= NumVerts;
  219. perf_printf(" glDrawElements: %s verts/sec\n", PerfHumanFloat(rate));
  220. rate = PerfMeasureRate(DrawElementsBO);
  221. rate *= NumVerts;
  222. perf_printf(" VBO glDrawElements: %s verts/sec\n", PerfHumanFloat(rate));
  223. rate = PerfMeasureRate(DrawRangeElementsMem);
  224. rate *= NumVerts;
  225. perf_printf(" glDrawRangeElements: %s verts/sec\n", PerfHumanFloat(rate));
  226. rate = PerfMeasureRate(DrawRangeElementsBO);
  227. rate *= NumVerts;
  228. perf_printf(" VBO glDrawRangeElements: %s verts/sec\n", PerfHumanFloat(rate));
  229. exit(0);
  230. }