~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to progs/tests/floattex.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

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