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.

mipmap_comp_tests.c 7.7KB

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