Remove CVS keywords.
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_texstate.c
1
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include "glheader.h"
6 #include "macros.h"
7 #include "mtypes.h"
8 #include "simple_list.h"
9 #include "enums.h"
10
11 #include "mm.h"
12 #include "gamma_context.h"
13
14 static void gammaSetTexImages( gammaContextPtr gmesa,
15 struct gl_texture_object *tObj )
16 {
17 GLuint height, width, pitch, i, log_pitch;
18 gammaTextureObjectPtr t = (gammaTextureObjectPtr) tObj->DriverData;
19 const struct gl_texture_image *baseImage = tObj->Image[0][tObj->BaseLevel];
20 GLint firstLevel, lastLevel, numLevels;
21 GLint log2Width, log2Height;
22
23 /* fprintf(stderr, "%s\n", __FUNCTION__); */
24
25 t->texelBytes = 2;
26
27 /* Compute which mipmap levels we really want to send to the hardware.
28 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
29 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
30 * Yes, this looks overly complicated, but it's all needed.
31 */
32 if (tObj->MinFilter == GL_LINEAR || tObj->MinFilter == GL_NEAREST) {
33 firstLevel = lastLevel = tObj->BaseLevel;
34 }
35 else {
36 firstLevel = tObj->BaseLevel + (GLint) (tObj->MinLod + 0.5);
37 firstLevel = MAX2(firstLevel, tObj->BaseLevel);
38 lastLevel = tObj->BaseLevel + (GLint) (tObj->MaxLod + 0.5);
39 lastLevel = MAX2(lastLevel, tObj->BaseLevel);
40 lastLevel = MIN2(lastLevel, tObj->BaseLevel + baseImage->MaxLog2);
41 lastLevel = MIN2(lastLevel, tObj->MaxLevel);
42 lastLevel = MAX2(firstLevel, lastLevel); /* need at least one level */
43 }
44
45 /* save these values */
46 t->firstLevel = firstLevel;
47 t->lastLevel = lastLevel;
48
49 numLevels = lastLevel - firstLevel + 1;
50
51 log2Width = tObj->Image[0][firstLevel]->WidthLog2;
52 log2Height = tObj->Image[0][firstLevel]->HeightLog2;
53
54
55 /* Figure out the amount of memory required to hold all the mipmap
56 * levels. Choose the smallest pitch to accomodate the largest
57 * mipmap:
58 */
59 width = tObj->Image[0][firstLevel]->Width * t->texelBytes;
60 for (pitch = 32, log_pitch=2 ; pitch < width ; pitch *= 2 )
61 log_pitch++;
62
63 /* All images must be loaded at this pitch. Count the number of
64 * lines required:
65 */
66 for ( height = i = 0 ; i < numLevels ; i++ ) {
67 t->image[i].image = tObj->Image[0][firstLevel + i];
68 t->image[i].offset = height * pitch;
69 t->image[i].internalFormat = baseImage->Format;
70 height += t->image[i].image->Height;
71 t->TextureBaseAddr[i] = /* ??? */
72 (unsigned long)(t->image[i].offset + t->BufAddr) << 5;
73
74 }
75
76 t->Pitch = pitch;
77 t->totalSize = height*pitch;
78 t->max_level = i-1;
79 gmesa->dirty |= GAMMA_UPLOAD_TEX0 /* | GAMMA_UPLOAD_TEX1*/;
80
81 gammaUploadTexImages( gmesa, t );
82 }
83
84 static void gammaUpdateTexEnv( GLcontext *ctx, GLuint unit )
85 {
86 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
87 const struct gl_texture_object *tObj = texUnit->_Current;
88 const GLuint format = tObj->Image[0][tObj->BaseLevel]->Format;
89 gammaTextureObjectPtr t = (gammaTextureObjectPtr)tObj->DriverData;
90 GLuint tc;
91
92 /* fprintf(stderr, "%s\n", __FUNCTION__); */
93
94 tc = t->TextureColorMode & ~(TCM_BaseFormatMask | TCM_ApplicationMask);
95
96 switch (format) {
97 case GL_RGB:
98 tc |= TCM_BaseFormat_RGB;
99 break;
100 case GL_LUMINANCE:
101 tc |= TCM_BaseFormat_Lum;
102 break;
103 case GL_ALPHA:
104 tc |= TCM_BaseFormat_Alpha;
105 break;
106 case GL_LUMINANCE_ALPHA:
107 tc |= TCM_BaseFormat_LumAlpha;
108 break;
109 case GL_INTENSITY:
110 tc |= TCM_BaseFormat_Intensity;
111 break;
112 case GL_RGBA:
113 tc |= TCM_BaseFormat_RGBA;
114 break;
115 case GL_COLOR_INDEX:
116 break;
117 }
118
119 switch (texUnit->EnvMode) {
120 case GL_REPLACE:
121 tc |= TCM_Replace;
122 break;
123 case GL_MODULATE:
124 tc |= TCM_Modulate;
125 break;
126 case GL_ADD:
127 /* do nothing ???*/
128 break;
129 case GL_DECAL:
130 tc |= TCM_Decal;
131 break;
132 case GL_BLEND:
133 tc |= TCM_Blend;
134 break;
135 default:
136 fprintf(stderr, "unknown tex env mode");
137 return;
138 }
139
140 t->TextureColorMode = tc;
141 }
142
143
144
145
146 static void gammaUpdateTexUnit( GLcontext *ctx, GLuint unit )
147 {
148 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
149 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
150
151 /* fprintf(stderr, "%s\n", __FUNCTION__); */
152
153 if (texUnit->_ReallyEnabled == TEXTURE_2D_BIT)
154 {
155 struct gl_texture_object *tObj = texUnit->_Current;
156 gammaTextureObjectPtr t = (gammaTextureObjectPtr)tObj->DriverData;
157
158 /* Upload teximages (not pipelined)
159 */
160 if (t->dirty_images) {
161 gammaSetTexImages( gmesa, tObj );
162 if (!t->MemBlock) {
163 FALLBACK( gmesa, GAMMA_FALLBACK_TEXTURE, GL_TRUE );
164 return;
165 }
166 }
167
168 #if 0
169 if (tObj->Image[0][tObj->BaseLevel]->Border > 0) {
170 FALLBACK( gmesa, GAMMA_FALLBACK_TEXTURE, GL_TRUE );
171 return;
172 }
173 #endif
174
175 /* Update state if this is a different texture object to last
176 * time.
177 */
178 if (gmesa->CurrentTexObj[unit] != t) {
179 gmesa->dirty |= GAMMA_UPLOAD_TEX0 /* << unit */;
180 gmesa->CurrentTexObj[unit] = t;
181 gammaUpdateTexLRU( gmesa, t ); /* done too often */
182 }
183
184 /* Update texture environment if texture object image format or
185 * texture environment state has changed.
186 */
187 if (tObj->Image[0][tObj->BaseLevel]->Format != gmesa->TexEnvImageFmt[unit]) {
188 gmesa->TexEnvImageFmt[unit] = tObj->Image[0][tObj->BaseLevel]->Format;
189 gammaUpdateTexEnv( ctx, unit );
190 }
191 }
192 else if (texUnit->_ReallyEnabled) {
193 FALLBACK( gmesa, GAMMA_FALLBACK_TEXTURE, GL_TRUE );
194 }
195 else /*if (gmesa->CurrentTexObj[unit])*/ {
196 gmesa->CurrentTexObj[unit] = 0;
197 gmesa->TexEnvImageFmt[unit] = 0;
198 gmesa->dirty &= ~(GAMMA_UPLOAD_TEX0<<unit);
199 }
200 }
201
202
203 void gammaUpdateTextureState( GLcontext *ctx )
204 {
205 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
206 /* fprintf(stderr, "%s\n", __FUNCTION__); */
207 FALLBACK( gmesa, GAMMA_FALLBACK_TEXTURE, GL_FALSE );
208 gammaUpdateTexUnit( ctx, 0 );
209 #if 0
210 gammaUpdateTexUnit( ctx, 1 );
211 #endif
212 }
213
214
215