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.

floattex.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Test floating point textures.
  3. * No actual rendering, yet.
  4. */
  5. #include <assert.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <math.h>
  9. #include <GL/glut.h>
  10. /* XXX - temporary */
  11. #ifndef GL_ARB_texture_float
  12. #define GL_ARB_texture_float 1
  13. #define GL_TEXTURE_RED_TYPE_ARB 0x9000
  14. #define GL_TEXTURE_GREEN_TYPE_ARB 0x9001
  15. #define GL_TEXTURE_BLUE_TYPE_ARB 0x9002
  16. #define GL_TEXTURE_ALPHA_TYPE_ARB 0x9003
  17. #define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x9004
  18. #define GL_TEXTURE_INTENSITY_TYPE_ARB 0x9005
  19. #define GL_TEXTURE_DEPTH_TYPE_ARB 0x9006
  20. #define GL_UNSIGNED_NORMALIZED_ARB 0x9007
  21. #define GL_RGBA32F_ARB 0x8814
  22. #define GL_RGB32F_ARB 0x8815
  23. #define GL_ALPHA32F_ARB 0x8816
  24. #define GL_INTENSITY32F_ARB 0x8817
  25. #define GL_LUMINANCE32F_ARB 0x8818
  26. #define GL_LUMINANCE_ALPHA32F_ARB 0x8819
  27. #define GL_RGBA16F_ARB 0x881A
  28. #define GL_RGB16F_ARB 0x881B
  29. #define GL_ALPHA16F_ARB 0x881C
  30. #define GL_INTENSITY16F_ARB 0x881D
  31. #define GL_LUMINANCE16F_ARB 0x881E
  32. #define GL_LUMINANCE_ALPHA16F_ARB 0x881F
  33. #endif
  34. static GLboolean
  35. CheckError( int line )
  36. {
  37. GLenum error = glGetError();
  38. if (error) {
  39. char *err = (char *) gluErrorString( error );
  40. fprintf( stderr, "GL Error: %s at line %d\n", err, line );
  41. return GL_TRUE;
  42. }
  43. return GL_FALSE;
  44. }
  45. static void
  46. Draw(void)
  47. {
  48. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  49. glPushMatrix();
  50. glutSolidCube(2.0);
  51. glPopMatrix();
  52. glutSwapBuffers();
  53. }
  54. static void
  55. Reshape(int width, int height)
  56. {
  57. glViewport(0, 0, width, height);
  58. glMatrixMode(GL_PROJECTION);
  59. glLoadIdentity();
  60. glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
  61. glMatrixMode(GL_MODELVIEW);
  62. glLoadIdentity();
  63. glTranslatef(0.0, 0.0, -15.0);
  64. }
  65. static void
  66. Key(unsigned char key, int x, int y)
  67. {
  68. (void) x;
  69. (void) y;
  70. switch (key) {
  71. case 27:
  72. exit(0);
  73. break;
  74. }
  75. glutPostRedisplay();
  76. }
  77. static void
  78. Init(void)
  79. {
  80. GLfloat tex[16][16][4];
  81. GLfloat tex2[16][16][4];
  82. GLint i, j, t;
  83. if (!glutExtensionSupported("GL_MESAX_texture_float")) {
  84. printf("Sorry, this test requires GL_MESAX_texture_float\n");
  85. exit(1);
  86. }
  87. for (i = 0; i < 16; i++) {
  88. for (j = 0; j < 16; j++) {
  89. GLfloat s = i / 15.0;
  90. tex[i][j][0] = s;
  91. tex[i][j][1] = 2.0 * s;
  92. tex[i][j][2] = -3.0 * s;
  93. tex[i][j][3] = 4.0 * s;
  94. }
  95. }
  96. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, 16, 16, 0, GL_RGBA,
  97. GL_FLOAT, tex);
  98. CheckError(__LINE__);
  99. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_TYPE_ARB, &t);
  100. assert(t == GL_FLOAT);
  101. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_TYPE_ARB, &t);
  102. assert(t == GL_FLOAT);
  103. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_TYPE_ARB, &t);
  104. assert(t == GL_FLOAT);
  105. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_TYPE_ARB, &t);
  106. assert(t == GL_FLOAT);
  107. CheckError(__LINE__);
  108. /* read back the texture and make sure values are correct */
  109. glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, tex2);
  110. CheckError(__LINE__);
  111. for (i = 0; i < 16; i++) {
  112. for (j = 0; j < 16; j++) {
  113. if (tex[i][j][0] != tex2[i][j][0] ||
  114. tex[i][j][1] != tex2[i][j][1] ||
  115. tex[i][j][2] != tex2[i][j][2] ||
  116. tex[i][j][3] != tex2[i][j][3]) {
  117. printf("tex[%d][%d] %g %g %g %g != tex2[%d][%d] %g %g %g %g\n",
  118. i, j,
  119. tex[i][j][0], tex[i][j][1], tex[i][j][2], tex[i][j][3],
  120. i, j,
  121. tex2[i][j][0], tex2[i][j][1], tex2[i][j][2], tex2[i][j][3]);
  122. }
  123. }
  124. }
  125. }
  126. int
  127. main(int argc, char *argv[])
  128. {
  129. glutInit(&argc, argv);
  130. glutInitWindowPosition(0, 0);
  131. glutInitWindowSize(400, 400);
  132. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  133. glutCreateWindow(argv[0]);
  134. glutReshapeFunc(Reshape);
  135. glutKeyboardFunc(Key);
  136. glutDisplayFunc(Draw);
  137. Init();
  138. glutMainLoop();
  139. return 0;
  140. }