Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

mipmap_limits.c 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 MakeImage(int level, int width, int height, const GLubyte color[4])
  57. {
  58. const int makeStripes = 0;
  59. GLubyte img[256*256*3];
  60. int i, j;
  61. for (i = 0; i < height; i++) {
  62. for (j = 0; j < width; j++) {
  63. int k = (i * width + j) * 3;
  64. int p = (i/8) & makeStripes;
  65. if (p == 0) {
  66. img[k + 0] = color[0];
  67. img[k + 1] = color[1];
  68. img[k + 2] = color[2];
  69. }
  70. else {
  71. img[k + 0] = 0;
  72. img[k + 1] = 0;
  73. img[k + 2] = 0;
  74. }
  75. }
  76. }
  77. glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, width, height, 0,
  78. GL_RGB, GL_UNSIGNED_BYTE, img);
  79. }
  80. static void makeImages(void)
  81. {
  82. static const GLubyte colors[8][3] = {
  83. {128, 128, 128 },
  84. { 0, 255, 255 },
  85. { 255, 255, 0 },
  86. { 255, 0, 255 },
  87. { 255, 0, 0 },
  88. { 0, 255, 0 },
  89. { 0, 0, 255 },
  90. { 255, 255, 255 }
  91. };
  92. int i, sz = 128;
  93. for (i = 0; i < 8; i++) {
  94. MakeImage(i, sz, sz, colors[i]);
  95. sz /= 2;
  96. }
  97. }
  98. static void myinit(void)
  99. {
  100. glEnable(GL_DEPTH_TEST);
  101. glDepthFunc(GL_LESS);
  102. glShadeModel(GL_FLAT);
  103. glTranslatef(0.0, 0.0, -3.6);
  104. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  105. makeImages();
  106. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  107. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  108. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  109. glEnable(GL_TEXTURE_2D);
  110. }
  111. static void display(void)
  112. {
  113. GLfloat tcm = 4.0;
  114. printf("BASE_LEVEL = %d MAX_LEVEL = %d MIN_LOD = %f MAX_LOD = %f Bias = %.2g filter = %s\n",
  115. BaseLevel, MaxLevel, MinLod, MaxLod, LodBias,
  116. NearestFilter ? "NEAREST" : "LINEAR");
  117. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel);
  118. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel);
  119. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, MinLod);
  120. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, MaxLod);
  121. if (NearestFilter) {
  122. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  123. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  124. GL_NEAREST_MIPMAP_NEAREST);
  125. }
  126. else {
  127. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  128. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  129. GL_LINEAR_MIPMAP_LINEAR);
  130. }
  131. glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias);
  132. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  133. glBegin(GL_QUADS);
  134. glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
  135. glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0);
  136. glTexCoord2f(tcm, tcm); glVertex3f(3000.0, 1.0, -6000.0);
  137. glTexCoord2f(tcm, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
  138. glEnd();
  139. glFlush();
  140. }
  141. static void myReshape(int w, int h)
  142. {
  143. glViewport(0, 0, w, h);
  144. glMatrixMode(GL_PROJECTION);
  145. glLoadIdentity();
  146. gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0);
  147. glMatrixMode(GL_MODELVIEW);
  148. glLoadIdentity();
  149. }
  150. static void
  151. key(unsigned char k, int x, int y)
  152. {
  153. (void) x;
  154. (void) y;
  155. switch (k) {
  156. case 'b':
  157. BaseLevel--;
  158. if (BaseLevel < 0)
  159. BaseLevel = 0;
  160. break;
  161. case 'B':
  162. BaseLevel++;
  163. if (BaseLevel > 10)
  164. BaseLevel = 10;
  165. break;
  166. case 'm':
  167. MaxLevel--;
  168. if (MaxLevel < 0)
  169. MaxLevel = 0;
  170. break;
  171. case 'M':
  172. MaxLevel++;
  173. if (MaxLevel > 10)
  174. MaxLevel = 10;
  175. break;
  176. case 'l':
  177. LodBias -= 0.02;
  178. break;
  179. case 'L':
  180. LodBias += 0.02;
  181. break;
  182. case 'n':
  183. MinLod -= 0.02;
  184. break;
  185. case 'N':
  186. MinLod += 0.02;
  187. break;
  188. case 'x':
  189. MaxLod -= 0.02;
  190. break;
  191. case 'X':
  192. MaxLod += 0.02;
  193. break;
  194. case 'f':
  195. NearestFilter = !NearestFilter;
  196. break;
  197. case 27: /* Escape */
  198. exit(0);
  199. break;
  200. default:
  201. return;
  202. }
  203. glutPostRedisplay();
  204. }
  205. static void usage(void)
  206. {
  207. printf("usage:\n");
  208. printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n");
  209. printf(" m/M decrease/increase GL_TEXTURE_MAX_LEVEL\n");
  210. printf(" n/N decrease/increase GL_TEXTURE_MIN_LOD\n");
  211. printf(" x/X decrease/increase GL_TEXTURE_MAX_LOD\n");
  212. printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n");
  213. printf(" f toggle nearest/linear filtering\n");
  214. }
  215. int main(int argc, char** argv)
  216. {
  217. glutInit(&argc, argv);
  218. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  219. glutInitWindowSize (600, 600);
  220. glutCreateWindow (argv[0]);
  221. myinit();
  222. glutReshapeFunc (myReshape);
  223. glutDisplayFunc(display);
  224. glutKeyboardFunc(key);
  225. usage();
  226. glutMainLoop();
  227. return 0; /* ANSI C requires main to return int. */
  228. }