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.

drawoverhead.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 drawing overhead
  23. *
  24. * This is the first in a series of simple performance benchmarks.
  25. * The code in this file should be as simple as possible to make it
  26. * easily portable to other APIs.
  27. *
  28. * All the window-system stuff should be contained in glmain.c (or TBDmain.c).
  29. *
  30. * Brian Paul
  31. * 15 Sep 2009
  32. */
  33. #include "glmain.h"
  34. #include "common.h"
  35. int WinWidth = 100, WinHeight = 100;
  36. static GLuint VBO;
  37. struct vertex
  38. {
  39. GLfloat x, y;
  40. };
  41. static const struct vertex vertices[4] = {
  42. { -1.0, -1.0 },
  43. { 1.0, -1.0 },
  44. { 1.0, 1.0 },
  45. { -1.0, 1.0 }
  46. };
  47. /** Called from test harness/main */
  48. void
  49. PerfInit(void)
  50. {
  51. /* setup VBO w/ vertex data */
  52. glGenBuffersARB(1, &VBO);
  53. glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
  54. glBufferDataARB(GL_ARRAY_BUFFER_ARB,
  55. sizeof(vertices), vertices, GL_STATIC_DRAW_ARB);
  56. glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), (void *) 0);
  57. glEnableClientState(GL_VERTEX_ARRAY);
  58. /* misc GL state */
  59. glAlphaFunc(GL_ALWAYS, 0.0);
  60. }
  61. static void
  62. DrawNoStateChange(unsigned count)
  63. {
  64. unsigned i;
  65. for (i = 0; i < count; i++) {
  66. glDrawArrays(GL_POINTS, 0, 4);
  67. }
  68. glFinish();
  69. }
  70. static void
  71. DrawNopStateChange(unsigned count)
  72. {
  73. unsigned i;
  74. for (i = 0; i < count; i++) {
  75. glDisable(GL_ALPHA_TEST);
  76. glDrawArrays(GL_POINTS, 0, 4);
  77. }
  78. glFinish();
  79. }
  80. static void
  81. DrawStateChange(unsigned count)
  82. {
  83. unsigned i;
  84. for (i = 0; i < count; i++) {
  85. if (i & 1)
  86. glEnable(GL_TEXTURE_GEN_S);
  87. else
  88. glDisable(GL_TEXTURE_GEN_S);
  89. glDrawArrays(GL_POINTS, 0, 4);
  90. }
  91. glFinish();
  92. }
  93. void
  94. PerfNextRound(void)
  95. {
  96. }
  97. /** Called from test harness/main */
  98. void
  99. PerfDraw(void)
  100. {
  101. double rate0, rate1, rate2, overhead;
  102. rate0 = PerfMeasureRate(DrawNoStateChange);
  103. perf_printf(" Draw only: %s draws/second\n",
  104. PerfHumanFloat(rate0));
  105. rate1 = PerfMeasureRate(DrawNopStateChange);
  106. overhead = 1000.0 * (1.0 / rate1 - 1.0 / rate0);
  107. perf_printf(" Draw w/ nop state change: %s draws/sec (overhead: %f ms/draw)\n",
  108. PerfHumanFloat(rate1), overhead);
  109. rate2 = PerfMeasureRate(DrawStateChange);
  110. overhead = 1000.0 * (1.0 / rate2 - 1.0 / rate0);
  111. perf_printf(" Draw w/ state change: %s draws/sec (overhead: %f ms/draw)\n",
  112. PerfHumanFloat(rate2), overhead);
  113. exit(0);
  114. }