Source code of Windows XP (NT5)
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.

263 lines
6.7 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <GL/gl.h>
  5. #include <GL/glu.h>
  6. #include "glaux.h"
  7. #define WWIDTH (2*TWIDTH+GAP)
  8. #define WHEIGHT (4*THEIGHT+3*GAP)
  9. #define TWIDTH 128
  10. #define THEIGHT 128
  11. #define GAP 16
  12. int wwidth = WWIDTH;
  13. int wheight = WHEIGHT;
  14. int twidth = TWIDTH;
  15. int theight = THEIGHT;
  16. int gap = GAP;
  17. char *tex1_file = "1.rgb";
  18. char *tex2_file = "2.rgb";
  19. AUX_RGBImageRec *tex1, *tex2;
  20. BYTE tex1d1[TWIDTH*3], tex1d2[TWIDTH*3];
  21. #define NTEXID 3
  22. GLuint texids[NTEXID+1];
  23. GLboolean texres[NTEXID];
  24. GLfloat texpri[NTEXID];
  25. void TexPoly(int x, int y)
  26. {
  27. glBegin(GL_POLYGON);
  28. glTexCoord2i(0, 0);
  29. glVertex2i(x, y);
  30. glTexCoord2i(1, 0);
  31. glVertex2i(x+twidth-1, y);
  32. glTexCoord2i(1, 1);
  33. glVertex2i(x+twidth-1, y+theight-1);
  34. glTexCoord2i(0, 1);
  35. glVertex2i(x, y+theight-1);
  36. glEnd();
  37. }
  38. void Test(void)
  39. {
  40. int i;
  41. GLint res;
  42. GLfloat pri;
  43. GLboolean retval;
  44. int x1, x2, y;
  45. x2 = 0;
  46. x1 = x2+twidth+gap;
  47. y = 0;
  48. glGenTextures(NTEXID, texids);
  49. for (i = 0; i < NTEXID; i++)
  50. {
  51. printf("Texture id %d is %d\n", i, texids[i]);
  52. }
  53. // Should fail for all because none have been bound and last is invalid
  54. for (i = 0; i < NTEXID+1; i++)
  55. {
  56. printf("IsTexture %d is %d\n", i, glIsTexture(texids[i]));
  57. }
  58. // Should fail because these are all unbound right now
  59. retval = glAreTexturesResident(NTEXID, texids, texres);
  60. printf("AreTexturesResident %d\n", retval);
  61. glBindTexture(GL_TEXTURE_2D, texids[0]);
  62. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  63. glTexImage2D(GL_TEXTURE_2D, 0, 3, tex1->sizeX, tex1->sizeY, 0, GL_RGB,
  64. GL_UNSIGNED_BYTE, tex1->data);
  65. glEnable(GL_TEXTURE_2D);
  66. glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, &pri);
  67. printf("2D Priority is %f\n", pri);
  68. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.5f);
  69. glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, &pri);
  70. printf("2D Priority is %f\n", pri);
  71. glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_RESIDENT, &res);
  72. printf("2D Residency is %d\n", res);
  73. retval = glAreTexturesResident(1, texids, texres);
  74. printf("AreTexturesResident %d\n", retval);
  75. for (i = 0; i < 1; i++)
  76. {
  77. printf("Residency %d is %d\n", i, texres[i]);
  78. }
  79. glClear(GL_COLOR_BUFFER_BIT);
  80. TexPoly(x2, y);
  81. glDisable(GL_TEXTURE_2D);
  82. glBindTexture(GL_TEXTURE_1D, texids[1]);
  83. glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  84. glTexImage1D(GL_TEXTURE_1D, 0, 3, TWIDTH, 0, GL_RGB,
  85. GL_UNSIGNED_BYTE, tex1d1);
  86. glEnable(GL_TEXTURE_1D);
  87. glGetTexParameterfv(GL_TEXTURE_1D, GL_TEXTURE_PRIORITY, &pri);
  88. printf("1D Priority is %f\n", pri);
  89. glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_PRIORITY, 0.5f);
  90. glGetTexParameterfv(GL_TEXTURE_1D, GL_TEXTURE_PRIORITY, &pri);
  91. printf("1D Priority is %f\n", pri);
  92. glGetTexParameteriv(GL_TEXTURE_1D, GL_TEXTURE_RESIDENT, &res);
  93. printf("1D Residency is %d\n", res);
  94. TexPoly(x1, y);
  95. retval = glAreTexturesResident(2, texids, texres);
  96. printf("AreTexturesResident %d\n", retval);
  97. for (i = 0; i < 2; i++)
  98. {
  99. printf("Residency %d is %d\n", i, texres[i]);
  100. }
  101. texpri[0] = 0.25f;
  102. texpri[1] = 0.4f;
  103. texpri[2] = 0.7f;
  104. glPrioritizeTextures(NTEXID, texids, texpri);
  105. glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, &pri);
  106. printf("2D Priority is %f\n", pri);
  107. glGetTexParameterfv(GL_TEXTURE_1D, GL_TEXTURE_PRIORITY, &pri);
  108. printf("1D Priority is %f\n", pri);
  109. retval = glAreTexturesResident(NTEXID, texids, texres);
  110. printf("AreTexturesResident %d\n", retval);
  111. for (i = 0; i < NTEXID; i++)
  112. {
  113. printf("Residency %d is %d\n", i, texres[i]);
  114. }
  115. glBindTexture(GL_TEXTURE_2D, texids[NTEXID-1]);
  116. // Should succeed for all
  117. for (i = 0; i < NTEXID; i++)
  118. {
  119. printf("IsTexture %d is %d\n", i, glIsTexture(texids[i]));
  120. }
  121. glDeleteTextures(1, &texids[NTEXID-1]);
  122. // Should fail for last
  123. for (i = 0; i < NTEXID; i++)
  124. {
  125. printf("IsTexture %d is %d\n", i, glIsTexture(texids[i]));
  126. }
  127. glBindTexture(GL_TEXTURE_2D, texids[0]);
  128. y += theight+gap;
  129. glPixelStorei(GL_UNPACK_ROW_LENGTH, tex2->sizeX);
  130. glDisable(GL_TEXTURE_1D);
  131. glEnable(GL_TEXTURE_2D);
  132. glTexSubImage2D(GL_TEXTURE_2D, 0, tex1->sizeX/4, tex1->sizeY/4,
  133. tex1->sizeX/2, tex1->sizeY/2, GL_RGB, GL_UNSIGNED_BYTE,
  134. tex2->data);
  135. TexPoly(x2, y);
  136. glDisable(GL_TEXTURE_2D);
  137. glEnable(GL_TEXTURE_1D);
  138. glTexSubImage1D(GL_TEXTURE_1D, 0, TWIDTH/4, TWIDTH/2,
  139. GL_RGB, GL_UNSIGNED_BYTE, tex1d2);
  140. TexPoly(x1, y);
  141. y += theight+gap;
  142. glDisable(GL_TEXTURE_1D);
  143. glEnable(GL_TEXTURE_2D);
  144. glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, x2, 0,
  145. tex1->sizeX, tex1->sizeY, 0);
  146. TexPoly(x2, y);
  147. glDisable(GL_TEXTURE_2D);
  148. glEnable(GL_TEXTURE_1D);
  149. glCopyTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, x1, 0,
  150. TWIDTH, 0);
  151. TexPoly(x1, y);
  152. y += theight+gap;
  153. glDisable(GL_TEXTURE_1D);
  154. glEnable(GL_TEXTURE_2D);
  155. glCopyTexSubImage2D(GL_TEXTURE_2D, 0, tex1->sizeX/4, tex1->sizeY/4,
  156. x2+twidth/4, theight+theight/4+gap,
  157. tex1->sizeX/2, tex1->sizeY/2);
  158. TexPoly(x2, y);
  159. glDisable(GL_TEXTURE_2D);
  160. glEnable(GL_TEXTURE_1D);
  161. glCopyTexSubImage1D(GL_TEXTURE_1D, 0, TWIDTH/4,
  162. x1+TWIDTH/4, theight+gap,
  163. TWIDTH/2);
  164. TexPoly(x1, y);
  165. glFlush();
  166. glDeleteTextures(NTEXID-1, texids);
  167. }
  168. void Display(void)
  169. {
  170. }
  171. void Reshape(GLsizei w, GLsizei h)
  172. {
  173. glViewport(0, 0, w, h);
  174. glMatrixMode(GL_PROJECTION);
  175. glLoadIdentity();
  176. glOrtho(0, w, 0, h, -1, 1);
  177. glMatrixMode(GL_MODELVIEW);
  178. wwidth = w;
  179. wheight = h;
  180. }
  181. void __cdecl main(int argc, char** argv)
  182. {
  183. int i;
  184. auxInitDisplayMode(AUX_SINGLE | AUX_RGB);
  185. auxInitPosition(10, 10, wwidth, wheight);
  186. auxInitWindow("Texture Enhancements Test");
  187. tex1 = auxRGBImageLoad(tex1_file);
  188. if (tex1 == NULL)
  189. {
  190. printf("Unable to load '%s'\n", tex1_file);
  191. exit(1);
  192. }
  193. printf("tex1 %d,%d\n", tex1->sizeX, tex1->sizeY);
  194. tex2 = auxRGBImageLoad(tex2_file);
  195. if (tex2 == NULL)
  196. {
  197. printf("Unable to load '%s'\n", tex2_file);
  198. exit(1);
  199. }
  200. printf("tex2 %d,%d\n", tex2->sizeX, tex2->sizeY);
  201. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  202. for (i = 0; i < TWIDTH; i++)
  203. {
  204. tex1d1[i*3+2] = (i*256/TWIDTH);
  205. tex1d2[i*3] = (i*256/TWIDTH);
  206. }
  207. // glDisable(GL_DITHER);
  208. Reshape(wwidth, wheight);
  209. Test();
  210. auxMainLoop(Display);
  211. }