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 4.0KB

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