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.

swapbuffers.c 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 SwapBuffers.
  23. *
  24. * Keith Whitwell
  25. * 22 Sep 2009
  26. */
  27. #include "glmain.h"
  28. #include "common.h"
  29. int WinWidth = 100, WinHeight = 100;
  30. int real_WinWidth, real_WinHeight; /* don't know whats going on here */
  31. static GLuint VBO;
  32. struct vertex
  33. {
  34. GLfloat x, y;
  35. };
  36. static const struct vertex vertices[4] = {
  37. { -1.0, -1.0 },
  38. { 1.0, -1.0 },
  39. { 1.0, 1.0 },
  40. { -1.0, 1.0 }
  41. };
  42. /** Called from test harness/main */
  43. void
  44. PerfInit(void)
  45. {
  46. /* setup VBO w/ vertex data */
  47. glGenBuffersARB(1, &VBO);
  48. glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
  49. glBufferDataARB(GL_ARRAY_BUFFER_ARB,
  50. sizeof(vertices), vertices, GL_STATIC_DRAW_ARB);
  51. glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), (void *) 0);
  52. glEnableClientState(GL_VERTEX_ARRAY);
  53. /* misc GL state */
  54. glAlphaFunc(GL_ALWAYS, 0.0);
  55. }
  56. static void
  57. SwapNaked(unsigned count)
  58. {
  59. unsigned i;
  60. for (i = 0; i < count; i++) {
  61. PerfSwapBuffers();
  62. }
  63. }
  64. static void
  65. SwapClear(unsigned count)
  66. {
  67. unsigned i;
  68. for (i = 0; i < count; i++) {
  69. glClear(GL_COLOR_BUFFER_BIT);
  70. PerfSwapBuffers();
  71. }
  72. }
  73. static void
  74. SwapClearPoint(unsigned count)
  75. {
  76. unsigned i;
  77. for (i = 0; i < count; i++) {
  78. glClear(GL_COLOR_BUFFER_BIT);
  79. glDrawArrays(GL_POINTS, 0, 4);
  80. PerfSwapBuffers();
  81. }
  82. }
  83. static const struct {
  84. unsigned w;
  85. unsigned h;
  86. } sizes[] = {
  87. { 320, 240 },
  88. { 640, 480 },
  89. { 1024, 768 },
  90. { 1200, 1024 },
  91. { 1600, 1200 }
  92. };
  93. void
  94. PerfNextRound(void)
  95. {
  96. static unsigned i;
  97. if (i < sizeof(sizes) / sizeof(sizes[0]) &&
  98. PerfReshapeWindow( sizes[i].w, sizes[i].h ))
  99. {
  100. perf_printf("Reshape %dx%d\n", sizes[i].w, sizes[i].h);
  101. real_WinWidth = sizes[i].w;
  102. real_WinHeight = sizes[i].h;
  103. i++;
  104. }
  105. else {
  106. exit(0);
  107. }
  108. }
  109. /** Called from test harness/main */
  110. void
  111. PerfDraw(void)
  112. {
  113. double rate0;
  114. rate0 = PerfMeasureRate(SwapNaked);
  115. perf_printf(" Swapbuffers %dx%d: %s swaps/second",
  116. real_WinWidth, real_WinHeight,
  117. PerfHumanFloat(rate0));
  118. perf_printf(" %s pixels/second\n",
  119. PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight));
  120. rate0 = PerfMeasureRate(SwapClear);
  121. perf_printf(" Swap/Clear %dx%d: %s swaps/second",
  122. real_WinWidth, real_WinHeight,
  123. PerfHumanFloat(rate0));
  124. perf_printf(" %s pixels/second\n",
  125. PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight));
  126. rate0 = PerfMeasureRate(SwapClearPoint);
  127. perf_printf(" Swap/Clear/Draw %dx%d: %s swaps/second",
  128. real_WinWidth, real_WinHeight,
  129. PerfHumanFloat(rate0));
  130. perf_printf(" %s pixels/second\n",
  131. PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight));
  132. }