Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

mipmap_limits.c 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* Test GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL
  2. * Brian Paul
  3. * 10 May 2006
  4. */
  5. /* Copyright (c) Mark J. Kilgard, 1994. */
  6. /*
  7. * (c) Copyright 1993, Silicon Graphics, Inc.
  8. * ALL RIGHTS RESERVED
  9. * Permission to use, copy, modify, and distribute this software for
  10. * any purpose and without fee is hereby granted, provided that the above
  11. * copyright notice appear in all copies and that both the copyright notice
  12. * and this permission notice appear in supporting documentation, and that
  13. * the name of Silicon Graphics, Inc. not be used in advertising
  14. * or publicity pertaining to distribution of the software without specific,
  15. * written prior permission.
  16. *
  17. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  18. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  19. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  20. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  21. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  22. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  23. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  24. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  25. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  26. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  27. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  28. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  29. *
  30. * US Government Users Restricted Rights
  31. * Use, duplication, or disclosure by the Government is subject to
  32. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  33. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  34. * clause at DFARS 252.227-7013 and/or in similar or successor
  35. * clauses in the FAR or the DOD or NASA FAR Supplement.
  36. * Unpublished-- rights reserved under the copyright laws of the
  37. * United States. Contractor/manufacturer is Silicon Graphics,
  38. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  39. *
  40. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  41. */
  42. /* mipmap.c
  43. * This program demonstrates using mipmaps for texture maps.
  44. * To overtly show the effect of mipmaps, each mipmap reduction
  45. * level has a solidly colored, contrasting texture image.
  46. * Thus, the quadrilateral which is drawn is drawn with several
  47. * different colors.
  48. */
  49. #include <stdlib.h>
  50. #include <stdio.h>
  51. #include <GL/glut.h>
  52. static GLint BaseLevel = 0, MaxLevel = 8;
  53. static GLfloat MinLod = -1, MaxLod = 9;
  54. static GLfloat LodBias = 0.0;
  55. static GLboolean NearestFilter = GL_TRUE;
  56. static void
  57. InitValues(void)
  58. {
  59. BaseLevel = 0;
  60. MaxLevel = 8;
  61. MinLod = -1;
  62. MaxLod = 9;
  63. LodBias = 0.0;
  64. NearestFilter = GL_TRUE;
  65. }
  66. static void MakeImage(int level, int width, int height, const GLubyte color[4])
  67. {
  68. const int makeStripes = 0;
  69. GLubyte img[256*256*3];
  70. int i, j;
  71. for (i = 0; i < height; i++) {
  72. for (j = 0; j < width; j++) {
  73. int k = (i * width + j) * 3;
  74. int p = (i/8) & makeStripes;
  75. if (p == 0) {
  76. img[k + 0] = color[0];
  77. img[k + 1] = color[1];
  78. img[k + 2] = color[2];
  79. }
  80. else {
  81. img[k + 0] = 0;
  82. img[k + 1] = 0;
  83. img[k + 2] = 0;
  84. }
  85. }
  86. }
  87. glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, width, height, 0,
  88. GL_RGB, GL_UNSIGNED_BYTE, img);
  89. }
  90. static void makeImages(void)
  91. {
  92. static const GLubyte colors[8][3] = {
  93. {128, 128, 128 },
  94. { 0, 255, 255 },
  95. { 255, 255, 0 },
  96. { 255, 0, 255 },
  97. { 255, 0, 0 },
  98. { 0, 255, 0 },
  99. { 0, 0, 255 },
  100. { 255, 255, 255 }
  101. };
  102. int i, sz = 128;
  103. for (i = 0; i < 8; i++) {
  104. MakeImage(i, sz, sz, colors[i]);
  105. sz /= 2;
  106. }
  107. }
  108. static void myinit(void)
  109. {
  110. InitValues();
  111. glEnable(GL_DEPTH_TEST);
  112. glDepthFunc(GL_LESS);
  113. glShadeModel(GL_FLAT);
  114. glTranslatef(0.0, 0.0, -3.6);
  115. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  116. makeImages();
  117. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  118. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  119. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  120. glEnable(GL_TEXTURE_2D);
  121. }
  122. static void display(void)
  123. {
  124. GLfloat tcm = 4.0;
  125. printf("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n",
  126. BaseLevel, MaxLevel, MinLod, MaxLod, LodBias,
  127. NearestFilter ? "NEAREST" : "LINEAR");
  128. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel);
  129. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel);
  130. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, MinLod);
  131. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, MaxLod);
  132. if (NearestFilter) {
  133. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  134. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  135. GL_NEAREST_MIPMAP_NEAREST);
  136. }
  137. else {
  138. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  139. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  140. GL_LINEAR_MIPMAP_LINEAR);
  141. }
  142. glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias);
  143. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  144. glBegin(GL_QUADS);
  145. glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
  146. glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0);
  147. glTexCoord2f(tcm, tcm); glVertex3f(3000.0, 1.0, -6000.0);
  148. glTexCoord2f(tcm, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
  149. glEnd();
  150. glFlush();
  151. }
  152. static void myReshape(int w, int h)
  153. {
  154. glViewport(0, 0, w, h);
  155. glMatrixMode(GL_PROJECTION);
  156. glLoadIdentity();
  157. gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0);
  158. glMatrixMode(GL_MODELVIEW);
  159. glLoadIdentity();
  160. }
  161. static void
  162. key(unsigned char k, int x, int y)
  163. {
  164. (void) x;
  165. (void) y;
  166. switch (k) {
  167. case 'b':
  168. BaseLevel--;
  169. if (BaseLevel < 0)
  170. BaseLevel = 0;
  171. break;
  172. case 'B':
  173. BaseLevel++;
  174. if (BaseLevel > 10)
  175. BaseLevel = 10;
  176. break;
  177. case 'm':
  178. MaxLevel--;
  179. if (MaxLevel < 0)
  180. MaxLevel = 0;
  181. break;
  182. case 'M':
  183. MaxLevel++;
  184. if (MaxLevel > 10)
  185. MaxLevel = 10;
  186. break;
  187. case 'l':
  188. LodBias -= 0.25;
  189. break;
  190. case 'L':
  191. LodBias += 0.25;
  192. break;
  193. case 'n':
  194. MinLod -= 0.25;
  195. break;
  196. case 'N':
  197. MinLod += 0.25;
  198. break;
  199. case 'x':
  200. MaxLod -= 0.25;
  201. break;
  202. case 'X':
  203. MaxLod += 0.25;
  204. break;
  205. case 'f':
  206. NearestFilter = !NearestFilter;
  207. break;
  208. case ' ':
  209. InitValues();
  210. break;
  211. case 27: /* Escape */
  212. exit(0);
  213. break;
  214. default:
  215. return;
  216. }
  217. glutPostRedisplay();
  218. }
  219. static void usage(void)
  220. {
  221. printf("usage:\n");
  222. printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n");
  223. printf(" m/M decrease/increase GL_TEXTURE_MAX_LEVEL\n");
  224. printf(" n/N decrease/increase GL_TEXTURE_MIN_LOD\n");
  225. printf(" x/X decrease/increase GL_TEXTURE_MAX_LOD\n");
  226. printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n");
  227. printf(" f toggle nearest/linear filtering\n");
  228. printf(" SPACE reset values\n");
  229. }
  230. int main(int argc, char** argv)
  231. {
  232. glutInit(&argc, argv);
  233. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  234. glutInitWindowSize (600, 600);
  235. glutCreateWindow (argv[0]);
  236. myinit();
  237. glutReshapeFunc (myReshape);
  238. glutDisplayFunc(display);
  239. glutKeyboardFunc(key);
  240. usage();
  241. glutMainLoop();
  242. return 0; /* ANSI C requires main to return int. */
  243. }