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.

genmipmap.c 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 glGenerateMipmap() speed.
  23. *
  24. * Brian Paul
  25. * 24 Sep 2009
  26. */
  27. #include <string.h>
  28. #include "glmain.h"
  29. #include "common.h"
  30. int WinWidth = 100, WinHeight = 100;
  31. static GLboolean DrawPoint = GL_TRUE;
  32. static GLuint VBO;
  33. static GLuint TexObj = 0;
  34. static GLint BaseLevel, MaxLevel;
  35. struct vertex
  36. {
  37. GLfloat x, y, s, t;
  38. };
  39. static const struct vertex vertices[1] = {
  40. { 0.0, 0.0, 0.5, 0.5 },
  41. };
  42. #define VOFFSET(F) ((void *) offsetof(struct vertex, F))
  43. /** Called from test harness/main */
  44. void
  45. PerfInit(void)
  46. {
  47. /* setup VBO w/ vertex data */
  48. glGenBuffersARB(1, &VBO);
  49. glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
  50. glBufferDataARB(GL_ARRAY_BUFFER_ARB,
  51. sizeof(vertices), vertices, GL_STATIC_DRAW_ARB);
  52. glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(x));
  53. glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(s));
  54. glEnableClientState(GL_VERTEX_ARRAY);
  55. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  56. glGenTextures(1, &TexObj);
  57. glBindTexture(GL_TEXTURE_2D, TexObj);
  58. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  59. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  60. glEnable(GL_TEXTURE_2D);
  61. }
  62. static void
  63. GenMipmap(unsigned count)
  64. {
  65. unsigned i;
  66. for (i = 0; i < count; i++) {
  67. GLubyte texel[4];
  68. texel[0] = texel[1] = texel[2] = texel[3] = i & 0xff;
  69. /* dirty the base image */
  70. glTexSubImage2D(GL_TEXTURE_2D, BaseLevel,
  71. 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texel);
  72. glGenerateMipmap(GL_TEXTURE_2D);
  73. if (DrawPoint)
  74. glDrawArrays(GL_POINTS, 0, 1);
  75. }
  76. glFinish();
  77. }
  78. /** Called from test harness/main */
  79. void
  80. PerfNextRound(void)
  81. {
  82. }
  83. /** Called from test harness/main */
  84. void
  85. PerfDraw(void)
  86. {
  87. const GLint NumLevels = 12;
  88. const GLint TexWidth = 2048, TexHeight = 2048;
  89. GLubyte *img;
  90. double rate;
  91. /* Make 2K x 2K texture */
  92. img = (GLubyte *) malloc(TexWidth * TexHeight * 4);
  93. memset(img, 128, TexWidth * TexHeight * 4);
  94. glTexImage2D(GL_TEXTURE_2D, 0,
  95. GL_RGBA, TexWidth, TexHeight, 0,
  96. GL_RGBA, GL_UNSIGNED_BYTE, img);
  97. free(img);
  98. perf_printf("Texture level[0] size: %d x %d, %d levels\n",
  99. TexWidth, TexHeight, NumLevels);
  100. /* loop over base levels 0, 2, 4 */
  101. for (BaseLevel = 0; BaseLevel <= 4; BaseLevel += 2) {
  102. /* loop over max level */
  103. for (MaxLevel = NumLevels; MaxLevel > BaseLevel; MaxLevel--) {
  104. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel);
  105. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel);
  106. rate = PerfMeasureRate(GenMipmap);
  107. perf_printf(" glGenerateMipmap(levels %d..%d): %.2f gens/sec\n",
  108. BaseLevel + 1, MaxLevel, rate);
  109. }
  110. }
  111. exit(0);
  112. }