VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texdiff.c@ 21308

Last change on this file since 21308 was 16969, checked in by vboxsync, 16 years ago

crOpenGL: don't allocate memory for textures on host side (#3461)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 59.7 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "state.h"
8#include "state/cr_statetypes.h"
9#include "state/cr_texture.h"
10#include "cr_hash.h"
11#include "cr_string.h"
12#include "cr_mem.h"
13#include "cr_version.h"
14#include "state_internals.h"
15
16
17#define UNIMPLEMENTED() crStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented something or other" )
18
19
20#if 0 /* NOT USED??? */
21void crStateTextureObjSwitchCallback( unsigned long key, void *data1, void *data2 )
22{
23 CRTextureObj *tobj = (CRTextureObj *) data1;
24 CRContext *fromCtx = (CRContext *) data2;
25 unsigned int i = 0;
26 unsigned int j = 0;
27 CRbitvalue *bitID = fromCtx->bitid;
28 CRbitvalue nbitID[CR_MAX_BITARRAY];
29
30 for (j=0;j<CR_MAX_BITARRAY;j++)
31 nbitID[j] = ~bitID[j];
32
33 if (!tobj) return;
34
35 FILLDIRTY(tobj->dirty);
36 FILLDIRTY(tobj->imageBit);
37
38 for (i = 0; i < fromCtx->limits.maxTextureUnits; i++)
39 {
40 int j;
41
42 FILLDIRTY(tobj->paramsBit[i]);
43
44 switch (tobj->target)
45 {
46 case GL_TEXTURE_1D:
47 case GL_TEXTURE_2D:
48 for (j = 0; j <= fromCtx->texture.maxLevel; j++)
49 {
50 CRTextureLevel *tl = &(tobj->level[j]);
51 FILLDIRTY(tl->dirty);
52 }
53 break;
54#ifdef CR_OPENGL_VERSION_1_2
55 case GL_TEXTURE_3D:
56#endif
57 for (j = 0; j <= fromCtx->texture.max3DLevel; j++)
58 {
59 CRTextureLevel *tl = &(tobj->level[j]);
60 FILLDIRTY(tl->dirty);
61 }
62 break;
63#ifdef CR_ARB_texture_cube_map
64 case GL_TEXTURE_CUBE_MAP_ARB:
65 for (j = 0; j <= fromCtx->texture.maxCubeMapLevel; j++)
66 {
67 CRTextureLevel *tl;
68 /* Positive X */
69 tl = &(tobj->level[j]);
70 FILLDIRTY(tl->dirty);
71 /* Negative X */
72 tl = &(tobj->negativeXlevel[j]);
73 FILLDIRTY(tl->dirty);
74 /* Positive Y */
75 tl = &(tobj->positiveYlevel[j]);
76 FILLDIRTY(tl->dirty);
77 /* Negative Y */
78 tl = &(tobj->negativeYlevel[j]);
79 FILLDIRTY(tl->dirty);
80 /* Positive Z */
81 tl = &(tobj->positiveZlevel[j]);
82 FILLDIRTY(tl->dirty);
83 /* Negative Z */
84 tl = &(tobj->negativeZlevel[j]);
85 FILLDIRTY(tl->dirty);
86 }
87 break;
88#endif
89 default:
90 UNIMPLEMENTED();
91 }
92 }
93}
94#endif
95
96
97void crStateTextureSwitch( CRTextureBits *tb, CRbitvalue *bitID,
98 CRContext *fromCtx, CRContext *toCtx )
99{
100 CRTextureState *from = &(fromCtx->texture);
101 const CRTextureState *to = &(toCtx->texture);
102 unsigned int i,j;
103 glAble able[2];
104 CRbitvalue nbitID[CR_MAX_BITARRAY];
105 unsigned int activeUnit = (unsigned int) -1;
106
107 for (j=0;j<CR_MAX_BITARRAY;j++)
108 nbitID[j] = ~bitID[j];
109 able[0] = diff_api.Disable;
110 able[1] = diff_api.Enable;
111
112 for (i = 0; i < fromCtx->limits.maxTextureUnits; i++)
113 {
114 if (CHECKDIRTY(tb->enable[i], bitID))
115 {
116 if (activeUnit != i) {
117 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
118 activeUnit = i;
119 }
120 if (from->unit[i].enabled1D != to->unit[i].enabled1D)
121 {
122 able[to->unit[i].enabled1D](GL_TEXTURE_1D);
123 FILLDIRTY(tb->enable[i]);
124 FILLDIRTY(tb->dirty);
125 }
126 if (from->unit[i].enabled2D != to->unit[i].enabled2D)
127 {
128 able[to->unit[i].enabled2D](GL_TEXTURE_2D);
129 FILLDIRTY(tb->enable[i]);
130 FILLDIRTY(tb->dirty);
131 }
132#ifdef CR_OPENGL_VERSION_1_2
133 if (from->unit[i].enabled3D != to->unit[i].enabled3D)
134 {
135 able[to->unit[i].enabled3D](GL_TEXTURE_3D);
136 FILLDIRTY(tb->enable[i]);
137 FILLDIRTY(tb->dirty);
138 }
139#endif
140#ifdef CR_ARB_texture_cube_map
141 if (fromCtx->extensions.ARB_texture_cube_map &&
142 from->unit[i].enabledCubeMap != to->unit[i].enabledCubeMap)
143 {
144 able[to->unit[i].enabledCubeMap](GL_TEXTURE_CUBE_MAP_ARB);
145 FILLDIRTY(tb->enable[i]);
146 FILLDIRTY(tb->dirty);
147 }
148#endif
149#ifdef CR_NV_texture_rectangle
150 if (fromCtx->extensions.NV_texture_rectangle &&
151 from->unit[i].enabledRect != to->unit[i].enabledRect)
152 {
153 able[to->unit[i].enabledRect](GL_TEXTURE_RECTANGLE_NV);
154 FILLDIRTY(tb->enable[i]);
155 FILLDIRTY(tb->dirty);
156 }
157#endif
158 if (from->unit[i].textureGen.s != to->unit[i].textureGen.s ||
159 from->unit[i].textureGen.t != to->unit[i].textureGen.t ||
160 from->unit[i].textureGen.r != to->unit[i].textureGen.r ||
161 from->unit[i].textureGen.q != to->unit[i].textureGen.q)
162 {
163 able[to->unit[i].textureGen.s](GL_TEXTURE_GEN_S);
164 able[to->unit[i].textureGen.t](GL_TEXTURE_GEN_T);
165 able[to->unit[i].textureGen.r](GL_TEXTURE_GEN_R);
166 able[to->unit[i].textureGen.q](GL_TEXTURE_GEN_Q);
167 FILLDIRTY(tb->enable[i]);
168 FILLDIRTY(tb->dirty);
169 }
170 CLEARDIRTY(tb->enable[i], nbitID);
171 }
172
173 /*
174 ** A thought on switching with textures:
175 ** Since we are only performing a switch
176 ** and not a sync, we won't need to
177 ** update individual textures, just
178 ** the bindings....
179 */
180
181 if (CHECKDIRTY(tb->current[i], bitID))
182 {
183 if (activeUnit != i) {
184 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
185 activeUnit = i;
186 }
187 if (from->unit[i].currentTexture1D->name != to->unit[i].currentTexture1D->name)
188 {
189 diff_api.BindTexture(GL_TEXTURE_1D, to->unit[i].currentTexture1D->name);
190 FILLDIRTY(tb->current[i]);
191 FILLDIRTY(tb->dirty);
192 }
193 if (from->unit[i].currentTexture2D->name != to->unit[i].currentTexture2D->name)
194 {
195 diff_api.BindTexture(GL_TEXTURE_2D, to->unit[i].currentTexture2D->name);
196 FILLDIRTY(tb->current[i]);
197 FILLDIRTY(tb->dirty);
198 }
199#ifdef CR_OPENGL_VERSION_1_2
200 if (from->unit[i].currentTexture3D->name != to->unit[i].currentTexture3D->name) {
201 diff_api.BindTexture(GL_TEXTURE_3D, to->unit[i].currentTexture3D->name);
202 FILLDIRTY(tb->current[i]);
203 FILLDIRTY(tb->dirty);
204 }
205#endif
206#ifdef CR_ARB_texture_cube_map
207 if (fromCtx->extensions.ARB_texture_cube_map &&
208 from->unit[i].currentTextureCubeMap->name != to->unit[i].currentTextureCubeMap->name) {
209 diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, to->unit[i].currentTextureCubeMap->name);
210 FILLDIRTY(tb->current[i]);
211 FILLDIRTY(tb->dirty);
212 }
213#endif
214#ifdef CR_NV_texture_rectangle
215 if (fromCtx->extensions.NV_texture_rectangle &&
216 from->unit[i].currentTextureRect->name != to->unit[i].currentTextureRect->name) {
217 diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, to->unit[i].currentTextureRect->name);
218 FILLDIRTY(tb->current[i]);
219 FILLDIRTY(tb->dirty);
220 }
221#endif
222 }
223
224 if (CHECKDIRTY(tb->objGen[i], bitID))
225 {
226 if (activeUnit != i) {
227 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
228 activeUnit = i;
229 }
230 if (from->unit[i].objSCoeff.x != to->unit[i].objSCoeff.x ||
231 from->unit[i].objSCoeff.y != to->unit[i].objSCoeff.y ||
232 from->unit[i].objSCoeff.z != to->unit[i].objSCoeff.z ||
233 from->unit[i].objSCoeff.w != to->unit[i].objSCoeff.w)
234 {
235 GLfloat f[4];
236 f[0] = to->unit[i].objSCoeff.x;
237 f[1] = to->unit[i].objSCoeff.y;
238 f[2] = to->unit[i].objSCoeff.z;
239 f[3] = to->unit[i].objSCoeff.w;
240 diff_api.TexGenfv (GL_S, GL_OBJECT_PLANE, (const GLfloat *) f);
241 FILLDIRTY(tb->objGen[i]);
242 FILLDIRTY(tb->dirty);
243 }
244 if (from->unit[i].objTCoeff.x != to->unit[i].objTCoeff.x ||
245 from->unit[i].objTCoeff.y != to->unit[i].objTCoeff.y ||
246 from->unit[i].objTCoeff.z != to->unit[i].objTCoeff.z ||
247 from->unit[i].objTCoeff.w != to->unit[i].objTCoeff.w) {
248 GLfloat f[4];
249 f[0] = to->unit[i].objTCoeff.x;
250 f[1] = to->unit[i].objTCoeff.y;
251 f[2] = to->unit[i].objTCoeff.z;
252 f[3] = to->unit[i].objTCoeff.w;
253 diff_api.TexGenfv (GL_T, GL_OBJECT_PLANE, (const GLfloat *) f);
254 FILLDIRTY(tb->objGen[i]);
255 FILLDIRTY(tb->dirty);
256 }
257 if (from->unit[i].objRCoeff.x != to->unit[i].objRCoeff.x ||
258 from->unit[i].objRCoeff.y != to->unit[i].objRCoeff.y ||
259 from->unit[i].objRCoeff.z != to->unit[i].objRCoeff.z ||
260 from->unit[i].objRCoeff.w != to->unit[i].objRCoeff.w) {
261 GLfloat f[4];
262 f[0] = to->unit[i].objRCoeff.x;
263 f[1] = to->unit[i].objRCoeff.y;
264 f[2] = to->unit[i].objRCoeff.z;
265 f[3] = to->unit[i].objRCoeff.w;
266 diff_api.TexGenfv (GL_R, GL_OBJECT_PLANE, (const GLfloat *) f);
267 FILLDIRTY(tb->objGen[i]);
268 FILLDIRTY(tb->dirty);
269 }
270 if (from->unit[i].objQCoeff.x != to->unit[i].objQCoeff.x ||
271 from->unit[i].objQCoeff.y != to->unit[i].objQCoeff.y ||
272 from->unit[i].objQCoeff.z != to->unit[i].objQCoeff.z ||
273 from->unit[i].objQCoeff.w != to->unit[i].objQCoeff.w) {
274 GLfloat f[4];
275 f[0] = to->unit[i].objQCoeff.x;
276 f[1] = to->unit[i].objQCoeff.y;
277 f[2] = to->unit[i].objQCoeff.z;
278 f[3] = to->unit[i].objQCoeff.w;
279 diff_api.TexGenfv (GL_Q, GL_OBJECT_PLANE, (const GLfloat *) f);
280 FILLDIRTY(tb->objGen[i]);
281 FILLDIRTY(tb->dirty);
282 }
283 CLEARDIRTY(tb->objGen[i], nbitID);
284 }
285 if (CHECKDIRTY(tb->eyeGen[i], bitID))
286 {
287 if (activeUnit != i) {
288 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
289 activeUnit = i;
290 }
291 diff_api.MatrixMode(GL_MODELVIEW);
292 diff_api.PushMatrix();
293 diff_api.LoadIdentity();
294 if (from->unit[i].eyeSCoeff.x != to->unit[i].eyeSCoeff.x ||
295 from->unit[i].eyeSCoeff.y != to->unit[i].eyeSCoeff.y ||
296 from->unit[i].eyeSCoeff.z != to->unit[i].eyeSCoeff.z ||
297 from->unit[i].eyeSCoeff.w != to->unit[i].eyeSCoeff.w) {
298 GLfloat f[4];
299 f[0] = to->unit[i].eyeSCoeff.x;
300 f[1] = to->unit[i].eyeSCoeff.y;
301 f[2] = to->unit[i].eyeSCoeff.z;
302 f[3] = to->unit[i].eyeSCoeff.w;
303 diff_api.TexGenfv (GL_S, GL_EYE_PLANE, (const GLfloat *) f);
304 FILLDIRTY(tb->eyeGen[i]);
305 FILLDIRTY(tb->dirty);
306 }
307 if (from->unit[i].eyeTCoeff.x != to->unit[i].eyeTCoeff.x ||
308 from->unit[i].eyeTCoeff.y != to->unit[i].eyeTCoeff.y ||
309 from->unit[i].eyeTCoeff.z != to->unit[i].eyeTCoeff.z ||
310 from->unit[i].eyeTCoeff.w != to->unit[i].eyeTCoeff.w) {
311 GLfloat f[4];
312 f[0] = to->unit[i].eyeTCoeff.x;
313 f[1] = to->unit[i].eyeTCoeff.y;
314 f[2] = to->unit[i].eyeTCoeff.z;
315 f[3] = to->unit[i].eyeTCoeff.w;
316 diff_api.TexGenfv (GL_T, GL_EYE_PLANE, (const GLfloat *) f);
317 FILLDIRTY(tb->eyeGen[i]);
318 FILLDIRTY(tb->dirty);
319 }
320 if (from->unit[i].eyeRCoeff.x != to->unit[i].eyeRCoeff.x ||
321 from->unit[i].eyeRCoeff.y != to->unit[i].eyeRCoeff.y ||
322 from->unit[i].eyeRCoeff.z != to->unit[i].eyeRCoeff.z ||
323 from->unit[i].eyeRCoeff.w != to->unit[i].eyeRCoeff.w) {
324 GLfloat f[4];
325 f[0] = to->unit[i].eyeRCoeff.x;
326 f[1] = to->unit[i].eyeRCoeff.y;
327 f[2] = to->unit[i].eyeRCoeff.z;
328 f[3] = to->unit[i].eyeRCoeff.w;
329 diff_api.TexGenfv (GL_R, GL_EYE_PLANE, (const GLfloat *) f);
330 FILLDIRTY(tb->eyeGen[i]);
331 FILLDIRTY(tb->dirty);
332 }
333 if (from->unit[i].eyeQCoeff.x != to->unit[i].eyeQCoeff.x ||
334 from->unit[i].eyeQCoeff.y != to->unit[i].eyeQCoeff.y ||
335 from->unit[i].eyeQCoeff.z != to->unit[i].eyeQCoeff.z ||
336 from->unit[i].eyeQCoeff.w != to->unit[i].eyeQCoeff.w) {
337 GLfloat f[4];
338 f[0] = to->unit[i].eyeQCoeff.x;
339 f[1] = to->unit[i].eyeQCoeff.y;
340 f[2] = to->unit[i].eyeQCoeff.z;
341 f[3] = to->unit[i].eyeQCoeff.w;
342 diff_api.TexGenfv (GL_Q, GL_EYE_PLANE, (const GLfloat *) f);
343 FILLDIRTY(tb->eyeGen[i]);
344 FILLDIRTY(tb->dirty);
345 }
346 diff_api.PopMatrix();
347 CLEARDIRTY(tb->eyeGen[i], nbitID);
348 }
349 if (CHECKDIRTY(tb->genMode[i], bitID))
350 {
351 if (activeUnit != i) {
352 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
353 activeUnit = i;
354 }
355 if (from->unit[i].gen.s != to->unit[i].gen.s ||
356 from->unit[i].gen.t != to->unit[i].gen.t ||
357 from->unit[i].gen.r != to->unit[i].gen.r ||
358 from->unit[i].gen.q != to->unit[i].gen.q)
359 {
360 diff_api.TexGeni (GL_S, GL_TEXTURE_GEN_MODE, to->unit[i].gen.s);
361 diff_api.TexGeni (GL_T, GL_TEXTURE_GEN_MODE, to->unit[i].gen.t);
362 diff_api.TexGeni (GL_R, GL_TEXTURE_GEN_MODE, to->unit[i].gen.r);
363 diff_api.TexGeni (GL_Q, GL_TEXTURE_GEN_MODE, to->unit[i].gen.q);
364 FILLDIRTY(tb->genMode[i]);
365 FILLDIRTY(tb->dirty);
366 }
367 CLEARDIRTY(tb->genMode[i], nbitID);
368 }
369 CLEARDIRTY(tb->dirty, nbitID);
370
371 /* Texture enviroment */
372 if (CHECKDIRTY(tb->envBit[i], bitID))
373 {
374 if (activeUnit != i) {
375 diff_api.ActiveTextureARB( i + GL_TEXTURE0_ARB );
376 activeUnit = i;
377 }
378 if (from->unit[i].envMode != to->unit[i].envMode)
379 {
380 diff_api.TexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, to->unit[i].envMode);
381 FILLDIRTY(tb->envBit[i]);
382 FILLDIRTY(tb->dirty);
383 }
384 if (from->unit[i].envColor.r != to->unit[i].envColor.r ||
385 from->unit[i].envColor.g != to->unit[i].envColor.g ||
386 from->unit[i].envColor.b != to->unit[i].envColor.b ||
387 from->unit[i].envColor.a != to->unit[i].envColor.a)
388 {
389 GLfloat f[4];
390 f[0] = to->unit[i].envColor.r;
391 f[1] = to->unit[i].envColor.g;
392 f[2] = to->unit[i].envColor.b;
393 f[3] = to->unit[i].envColor.a;
394 diff_api.TexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, (const GLfloat *) f);
395 FILLDIRTY(tb->envBit[i]);
396 FILLDIRTY(tb->dirty);
397 }
398 if (from->unit[i].combineModeRGB != to->unit[i].combineModeRGB)
399 {
400 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, to->unit[i].combineModeRGB);
401 FILLDIRTY(tb->envBit[i]);
402 FILLDIRTY(tb->dirty);
403 }
404 if (from->unit[i].combineModeA != to->unit[i].combineModeA)
405 {
406 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, to->unit[i].combineModeA);
407 FILLDIRTY(tb->envBit[i]);
408 FILLDIRTY(tb->dirty);
409 }
410 if (from->unit[i].combineSourceRGB[0] != to->unit[i].combineSourceRGB[0])
411 {
412 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, to->unit[i].combineSourceRGB[0]);
413 FILLDIRTY(tb->envBit[i]);
414 FILLDIRTY(tb->dirty);
415 }
416 if (from->unit[i].combineSourceRGB[1] != to->unit[i].combineSourceRGB[1])
417 {
418 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, to->unit[i].combineSourceRGB[1]);
419 FILLDIRTY(tb->envBit[i]);
420 FILLDIRTY(tb->dirty);
421 }
422 if (from->unit[i].combineSourceRGB[2] != to->unit[i].combineSourceRGB[2])
423 {
424 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, to->unit[i].combineSourceRGB[2]);
425 FILLDIRTY(tb->envBit[i]);
426 FILLDIRTY(tb->dirty);
427 }
428 if (from->unit[i].combineSourceA[0] != to->unit[i].combineSourceA[0])
429 {
430 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, to->unit[i].combineSourceA[0]);
431 FILLDIRTY(tb->envBit[i]);
432 FILLDIRTY(tb->dirty);
433 }
434 if (from->unit[i].combineSourceA[1] != to->unit[i].combineSourceA[1])
435 {
436 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, to->unit[i].combineSourceA[1]);
437 FILLDIRTY(tb->envBit[i]);
438 FILLDIRTY(tb->dirty);
439 }
440 if (from->unit[i].combineSourceA[2] != to->unit[i].combineSourceA[2])
441 {
442 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, to->unit[i].combineSourceA[2]);
443 FILLDIRTY(tb->envBit[i]);
444 FILLDIRTY(tb->dirty);
445 }
446 if (from->unit[i].combineOperandRGB[0] != to->unit[i].combineOperandRGB[0])
447 {
448 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, to->unit[i].combineOperandRGB[0]);
449 FILLDIRTY(tb->envBit[i]);
450 FILLDIRTY(tb->dirty);
451 }
452 if (from->unit[i].combineOperandRGB[1] != to->unit[i].combineOperandRGB[1])
453 {
454 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, to->unit[i].combineOperandRGB[1]);
455 FILLDIRTY(tb->envBit[i]);
456 FILLDIRTY(tb->dirty);
457 }
458 if (from->unit[i].combineOperandRGB[2] != to->unit[i].combineOperandRGB[2])
459 {
460 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, to->unit[i].combineOperandRGB[2]);
461 FILLDIRTY(tb->envBit[i]);
462 FILLDIRTY(tb->dirty);
463 }
464 if (from->unit[i].combineOperandA[0] != to->unit[i].combineOperandA[0])
465 {
466 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, to->unit[i].combineOperandA[0]);
467 FILLDIRTY(tb->envBit[i]);
468 FILLDIRTY(tb->dirty);
469 }
470 if (from->unit[i].combineOperandA[1] != to->unit[i].combineOperandA[1])
471 {
472 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, to->unit[i].combineOperandA[1]);
473 FILLDIRTY(tb->envBit[i]);
474 FILLDIRTY(tb->dirty);
475 }
476 if (from->unit[i].combineOperandA[2] != to->unit[i].combineOperandA[2])
477 {
478 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, to->unit[i].combineOperandA[2]);
479 FILLDIRTY(tb->envBit[i]);
480 FILLDIRTY(tb->dirty);
481 }
482 if (from->unit[i].combineScaleRGB != to->unit[i].combineScaleRGB)
483 {
484 diff_api.TexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, to->unit[i].combineScaleRGB);
485 FILLDIRTY(tb->envBit[i]);
486 FILLDIRTY(tb->dirty);
487 }
488 if (from->unit[i].combineScaleA != to->unit[i].combineScaleA)
489 {
490 diff_api.TexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, to->unit[i].combineScaleA);
491 FILLDIRTY(tb->envBit[i]);
492 FILLDIRTY(tb->dirty);
493 }
494 CLEARDIRTY(tb->envBit[i], nbitID);
495 }
496 }
497
498 /* Resend texture images */
499 if (toCtx->texture.bResyncNeeded)
500 {
501 toCtx->texture.bResyncNeeded = GL_FALSE;
502
503 crStateDiffAllTextureObjects(toCtx, bitID, GL_TRUE);
504 }
505
506 /* After possible fiddling put them back now */
507 if (activeUnit != toCtx->texture.curTextureUnit) {
508 diff_api.ActiveTextureARB( toCtx->texture.curTextureUnit + GL_TEXTURE0_ARB );
509 }
510 diff_api.MatrixMode(toCtx->transform.matrixMode);
511}
512
513
514/*
515 * Check the dirty bits for the specified texture on a given unit to
516 * determine if any of its images are dirty.
517 * Return: 1 -- dirty, 0 -- clean
518 */
519int crStateTextureCheckDirtyImages(CRContext *from, CRContext *to, GLenum target, int textureUnit)
520{
521 CRContext *g = GetCurrentContext();
522 CRTextureState *tsto;
523 CRbitvalue *bitID;
524 CRTextureObj *tobj = NULL;
525 int maxLevel = 0, i;
526 int face, numFaces;
527
528 CRASSERT(to);
529 CRASSERT(from);
530
531 tsto = &(to->texture);
532 bitID = from->bitid;
533
534 CRASSERT(tsto);
535
536 switch(target)
537 {
538 case GL_TEXTURE_1D:
539 tobj = tsto->unit[textureUnit].currentTexture1D;
540 maxLevel = tsto->maxLevel;
541 break;
542 case GL_TEXTURE_2D:
543 tobj = tsto->unit[textureUnit].currentTexture2D;
544 maxLevel = tsto->maxLevel;
545 break;
546#ifdef CR_OPENGL_VERSION_1_2
547 case GL_TEXTURE_3D:
548 tobj = tsto->unit[textureUnit].currentTexture3D;
549 maxLevel = tsto->max3DLevel;
550 break;
551#endif
552#ifdef CR_ARB_texture_cube_map
553 case GL_TEXTURE_CUBE_MAP:
554 if (g->extensions.ARB_texture_cube_map) {
555 tobj = tsto->unit[textureUnit].currentTextureCubeMap;
556 maxLevel = tsto->maxCubeMapLevel;
557 }
558 break;
559#endif
560#ifdef CR_NV_texture_rectangle
561 case GL_TEXTURE_RECTANGLE_NV:
562 if (g->extensions.NV_texture_rectangle) {
563 tobj = tsto->unit[textureUnit].currentTextureRect;
564 maxLevel = 1;
565 }
566 break;
567#endif
568 default:
569 crError("Bad texture target in crStateTextureCheckDirtyImages()");
570 return 0;
571 }
572
573 if (!tobj)
574 {
575 return 0;
576 }
577
578 numFaces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
579
580 for (face = 0; face < numFaces; face++) {
581 for (i = 0; i < maxLevel; i++) {
582 if (CHECKDIRTY(tobj->level[face][i].dirty, bitID))
583 return 1;
584 }
585 }
586
587 return 0;
588}
589
590
591/*
592 * Do texture state differencing for the given texture object.
593 */
594void
595crStateTextureObjectDiff(CRContext *fromCtx,
596 const CRbitvalue *bitID, const CRbitvalue *nbitID,
597 CRTextureObj *tobj, GLboolean alwaysDirty)
598{
599 CRTextureState *from = &(fromCtx->texture);
600 glAble able[2];
601 int u = 0; /* always use texture unit 0 for diff'ing */
602
603 able[0] = diff_api.Disable;
604 able[1] = diff_api.Enable;
605
606#if 0
607 /* XXX disabling this code fixed Wes Bethel's problem with missing/white
608 * textures. Setting the active texture unit here can screw up the
609 * current texture object bindings.
610 */
611 /* Set active texture unit, and bind this texture object */
612 if (from->curTextureUnit != u) {
613 diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
614 from->curTextureUnit = u;
615 }
616#endif
617
618 diff_api.BindTexture( tobj->target, tobj->name );
619
620 if (alwaysDirty || CHECKDIRTY(tobj->paramsBit[u], bitID))
621 {
622 GLfloat f[4];
623 f[0] = tobj->borderColor.r;
624 f[1] = tobj->borderColor.g;
625 f[2] = tobj->borderColor.b;
626 f[3] = tobj->borderColor.a;
627 diff_api.TexParameteri(tobj->target, GL_TEXTURE_BASE_LEVEL, tobj->baseLevel);
628 diff_api.TexParameteri(tobj->target, GL_TEXTURE_MAX_LEVEL, tobj->maxLevel);
629 diff_api.TexParameteri(tobj->target, GL_TEXTURE_MIN_FILTER, tobj->minFilter);
630 diff_api.TexParameteri(tobj->target, GL_TEXTURE_MAG_FILTER, tobj->magFilter);
631 diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_S, tobj->wrapS);
632 diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_T, tobj->wrapT);
633#ifdef CR_OPENGL_VERSION_1_2
634 diff_api.TexParameteri(tobj->target, GL_TEXTURE_WRAP_R, tobj->wrapR);
635 diff_api.TexParameterf(tobj->target, GL_TEXTURE_PRIORITY, tobj->priority);
636#endif
637 diff_api.TexParameterfv(tobj->target, GL_TEXTURE_BORDER_COLOR, (const GLfloat *) f);
638#ifdef CR_EXT_texture_filter_anisotropic
639 if (fromCtx->extensions.EXT_texture_filter_anisotropic) {
640 diff_api.TexParameterf(tobj->target, GL_TEXTURE_MAX_ANISOTROPY_EXT, tobj->maxAnisotropy);
641 }
642#endif
643#ifdef CR_ARB_depth_texture
644 if (fromCtx->extensions.ARB_depth_texture)
645 diff_api.TexParameteri(tobj->target, GL_DEPTH_TEXTURE_MODE_ARB, tobj->depthMode);
646#endif
647#ifdef CR_ARB_shadow
648 if (fromCtx->extensions.ARB_shadow) {
649 diff_api.TexParameteri(tobj->target, GL_TEXTURE_COMPARE_MODE_ARB, tobj->compareMode);
650 diff_api.TexParameteri(tobj->target, GL_TEXTURE_COMPARE_FUNC_ARB, tobj->compareFunc);
651 }
652#endif
653#ifdef CR_ARB_shadow_ambient
654 if (fromCtx->extensions.ARB_shadow_ambient) {
655 diff_api.TexParameterf(tobj->target, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, tobj->compareFailValue);
656 }
657#endif
658#ifdef CR_SGIS_generate_mipmap
659 if (fromCtx->extensions.SGIS_generate_mipmap) {
660 diff_api.TexParameteri(tobj->target, GL_GENERATE_MIPMAP_SGIS, tobj->generateMipmap);
661 }
662#endif
663 if (!alwaysDirty)
664 CLEARDIRTY(tobj->paramsBit[u], nbitID);
665 }
666
667 /* now, if the texture images are dirty */
668 if (alwaysDirty || CHECKDIRTY(tobj->imageBit, bitID))
669 {
670 int lvl;
671 int face;
672
673 switch (tobj->target)
674 {
675 case GL_TEXTURE_1D:
676 for (lvl = 0; lvl <= from->maxLevel; lvl++)
677 {
678 CRTextureLevel *tl = &(tobj->level[0][lvl]);
679 if (alwaysDirty || CHECKDIRTY(tl->dirty, bitID))
680 {
681 if (tl->generateMipmap) {
682 diff_api.TexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, 1);
683 }
684 if (tl->compressed) {
685 diff_api.CompressedTexImage1DARB(GL_TEXTURE_1D, lvl,
686 tl->internalFormat, tl->width,
687 tl->border, tl->bytes, tl->img);
688 }
689 else {
690 /* alignment must be one */
691 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
692 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
693 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
694 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
695 if (tl->generateMipmap) {
696 diff_api.TexParameteri(GL_TEXTURE_1D, GL_GENERATE_MIPMAP_SGIS, 1);
697 }
698 diff_api.TexImage1D(GL_TEXTURE_1D, lvl,
699 tl->internalFormat,
700 tl->width, tl->border,
701 tl->format, tl->type, tl->img);
702 }
703 if (!alwaysDirty)
704 {
705 CLEARDIRTY(tl->dirty, nbitID);
706 }
707#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
708 else
709 {
710 crFree(tl->img);
711 tl->img = NULL;
712 }
713#endif
714 }
715 }
716 break;
717 case GL_TEXTURE_2D:
718 for (lvl = 0; lvl <= from->maxLevel; lvl++)
719 {
720 CRTextureLevel *tl = &(tobj->level[0][lvl]);
721 if (alwaysDirty || CHECKDIRTY(tl->dirty, bitID))
722 {
723 if (tl->generateMipmap) {
724 diff_api.TexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, 1);
725 }
726
727 if (tl->compressed) {
728 diff_api.CompressedTexImage2DARB(GL_TEXTURE_2D, lvl,
729 tl->internalFormat, tl->width,
730 tl->height, tl->border,
731 tl->bytes, tl->img);
732 }
733 else {
734 /* alignment must be one */
735 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
736 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
737 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
738 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
739 diff_api.TexImage2D(GL_TEXTURE_2D, lvl,
740 tl->internalFormat,
741 tl->width, tl->height, tl->border,
742 tl->format, tl->type, tl->img);
743 }
744
745 if (!alwaysDirty)
746 {
747 CLEARDIRTY(tl->dirty, nbitID);
748 }
749#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
750 else
751 {
752 crFree(tl->img);
753 tl->img = NULL;
754 }
755#endif
756 }
757 }
758 break;
759#ifdef CR_OPENGL_VERSION_1_2
760 case GL_TEXTURE_3D:
761 for (lvl = 0; lvl <= from->max3DLevel; lvl++)
762 {
763 CRTextureLevel *tl = &(tobj->level[0][lvl]);
764 if (alwaysDirty || CHECKDIRTY(tl->dirty, bitID))
765 {
766 if (tl->generateMipmap) {
767 diff_api.TexParameteri(GL_TEXTURE_3D, GL_GENERATE_MIPMAP_SGIS, 1);
768 }
769 if (tl->compressed) {
770 diff_api.CompressedTexImage3DARB(GL_TEXTURE_3D, lvl,
771 tl->internalFormat, tl->width,
772 tl->height, tl->depth,
773 tl->border, tl->bytes, tl->img);
774 }
775 else {
776 /* alignment must be one */
777 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
778 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
779 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
780 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
781 diff_api.TexImage3D(GL_TEXTURE_3D, lvl,
782 tl->internalFormat,
783 tl->width, tl->height, tl->depth,
784 tl->border, tl->format,
785 tl->type, tl->img);
786 }
787 if (!alwaysDirty)
788 {
789 CLEARDIRTY(tl->dirty, nbitID);
790 }
791#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
792 else
793 {
794 crFree(tl->img);
795 tl->img = NULL;
796 }
797#endif
798 }
799 }
800 break;
801#endif
802#ifdef CR_NV_texture_rectangle
803 case GL_TEXTURE_RECTANGLE_NV:
804 /* only one level */
805 for (lvl = 0; lvl <= from->maxRectLevel; lvl++)
806 {
807 CRTextureLevel *tl = &(tobj->level[0][lvl]);
808 if (alwaysDirty || CHECKDIRTY(tl->dirty, bitID))
809 {
810 if (tl->compressed) {
811 diff_api.CompressedTexImage2DARB(GL_TEXTURE_RECTANGLE_NV, lvl,
812 tl->internalFormat, tl->width,
813 tl->height, tl->border,
814 tl->bytes, tl->img);
815 }
816 else {
817 /* alignment must be one */
818 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
819 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
820 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
821 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
822 diff_api.TexImage2D(GL_TEXTURE_RECTANGLE_NV, lvl,
823 tl->internalFormat,
824 tl->width, tl->height, tl->border,
825 tl->format, tl->type, tl->img);
826 }
827 if (!alwaysDirty)
828 {
829 CLEARDIRTY(tl->dirty, nbitID);
830 }
831#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
832 else
833 {
834 crFree(tl->img);
835 tl->img = NULL;
836 }
837#endif
838 }
839 }
840 break;
841#endif
842#ifdef CR_ARB_texture_cube_map
843 case GL_TEXTURE_CUBE_MAP_ARB:
844 for (face = 0; face < 6; face++)
845 {
846 const GLenum target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
847 for (lvl = 0; lvl <= from->maxCubeMapLevel; lvl++)
848 {
849 CRTextureLevel *tl = &(tobj->level[face][lvl]);
850 if (alwaysDirty || CHECKDIRTY(tl->dirty, bitID))
851 {
852 if (tl->generateMipmap) {
853 diff_api.TexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
854 GL_GENERATE_MIPMAP_SGIS, 1);
855 }
856 if (tl->compressed) {
857 diff_api.CompressedTexImage2DARB(target,
858 lvl, tl->internalFormat,
859 tl->width, tl->height,
860 tl->border, tl->bytes, tl->img);
861 }
862 else {
863 /* alignment must be one */
864 diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
865 diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
866 diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
867 diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
868 diff_api.TexImage2D(target, lvl,
869 tl->internalFormat,
870 tl->width, tl->height, tl->border,
871 tl->format, tl->type, tl->img);
872 }
873 if (!alwaysDirty)
874 {
875 CLEARDIRTY(tl->dirty, nbitID);
876 }
877#ifdef CR_STATE_NO_TEXTURE_IMAGE_STORE
878 else
879 {
880 crFree(tl->img);
881 tl->img = NULL;
882 }
883#endif
884 }
885 } /* for lvl */
886 } /* for face */
887 break;
888#endif
889 default:
890 UNIMPLEMENTED();
891
892 } /* switch */
893 } /* if (CHECKDIRTY(tobj->imageBit, bitID)) */
894}
895
896
897
898void
899crStateTextureDiff( CRTextureBits *tb, CRbitvalue *bitID,
900 CRContext *fromCtx, CRContext *toCtx )
901{
902 CRTextureState *from = &(fromCtx->texture);
903 CRTextureState *to = &(toCtx->texture);
904 unsigned int u, t, j;
905 glAble able[2];
906 CRbitvalue nbitID[CR_MAX_BITARRAY];
907 const GLboolean haveFragProg = fromCtx->extensions.ARB_fragment_program || fromCtx->extensions.NV_fragment_program;
908
909 for (j=0;j<CR_MAX_BITARRAY;j++)
910 nbitID[j] = ~bitID[j];
911
912 able[0] = diff_api.Disable;
913 able[1] = diff_api.Enable;
914
915 /* loop over texture units */
916 for (u = 0; u < fromCtx->limits.maxTextureUnits; u++)
917 {
918 CRTextureObj **fromBinding = NULL;
919 CRTextureObj *tobj;
920
921 /* take care of enables/disables */
922 if (CHECKDIRTY(tb->enable[u], bitID))
923 {
924
925 /* Activate texture unit u if needed */
926 if (fromCtx->texture.curTextureUnit != u) {
927 diff_api.ActiveTextureARB( GL_TEXTURE0_ARB + u);
928 fromCtx->texture.curTextureUnit = u;
929 }
930
931 if (from->unit[u].enabled1D != to->unit[u].enabled1D)
932 {
933 able[to->unit[u].enabled1D](GL_TEXTURE_1D);
934 from->unit[u].enabled1D = to->unit[u].enabled1D;
935 }
936 if (from->unit[u].enabled2D != to->unit[u].enabled2D)
937 {
938 able[to->unit[u].enabled2D](GL_TEXTURE_2D);
939 from->unit[u].enabled2D = to->unit[u].enabled2D;
940 }
941#ifdef CR_OPENGL_VERSION_1_2
942 if (from->unit[u].enabled3D != to->unit[u].enabled3D)
943 {
944 able[to->unit[u].enabled3D](GL_TEXTURE_3D);
945 from->unit[u].enabled3D = to->unit[u].enabled3D;
946 }
947#endif
948#ifdef CR_ARB_texture_cube_map
949 if (fromCtx->extensions.ARB_texture_cube_map &&
950 from->unit[u].enabledCubeMap != to->unit[u].enabledCubeMap)
951 {
952 able[to->unit[u].enabledCubeMap](GL_TEXTURE_CUBE_MAP_ARB);
953 from->unit[u].enabledCubeMap = to->unit[u].enabledCubeMap;
954 }
955#endif
956#ifdef CR_NV_texture_rectangle
957 if (fromCtx->extensions.NV_texture_rectangle &&
958 from->unit[u].enabledRect != to->unit[u].enabledRect)
959 {
960 able[to->unit[u].enabledRect](GL_TEXTURE_RECTANGLE_NV);
961 from->unit[u].enabledRect = to->unit[u].enabledRect;
962 }
963#endif
964
965 /* texgen enables */
966 if (from->unit[u].textureGen.s != to->unit[u].textureGen.s ||
967 from->unit[u].textureGen.t != to->unit[u].textureGen.t ||
968 from->unit[u].textureGen.r != to->unit[u].textureGen.r ||
969 from->unit[u].textureGen.q != to->unit[u].textureGen.q)
970 {
971 able[to->unit[u].textureGen.s](GL_TEXTURE_GEN_S);
972 able[to->unit[u].textureGen.t](GL_TEXTURE_GEN_T);
973 able[to->unit[u].textureGen.r](GL_TEXTURE_GEN_R);
974 able[to->unit[u].textureGen.q](GL_TEXTURE_GEN_Q);
975 from->unit[u].textureGen = to->unit[u].textureGen;
976 }
977 CLEARDIRTY(tb->enable[u], nbitID);
978 }
979
980
981 /* Texgen coefficients */
982 if (CHECKDIRTY(tb->objGen[u], bitID))
983 {
984 if (fromCtx->texture.curTextureUnit != u) {
985 diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
986 fromCtx->texture.curTextureUnit = u;
987 }
988 if (from->unit[u].objSCoeff.x != to->unit[u].objSCoeff.x ||
989 from->unit[u].objSCoeff.y != to->unit[u].objSCoeff.y ||
990 from->unit[u].objSCoeff.z != to->unit[u].objSCoeff.z ||
991 from->unit[u].objSCoeff.w != to->unit[u].objSCoeff.w)
992 {
993 GLfloat f[4];
994 f[0] = to->unit[u].objSCoeff.x;
995 f[1] = to->unit[u].objSCoeff.y;
996 f[2] = to->unit[u].objSCoeff.z;
997 f[3] = to->unit[u].objSCoeff.w;
998 diff_api.TexGenfv (GL_S, GL_OBJECT_PLANE, (const GLfloat *) f);
999 from->unit[u].objSCoeff = to->unit[u].objSCoeff;
1000 }
1001 if (from->unit[u].objTCoeff.x != to->unit[u].objTCoeff.x ||
1002 from->unit[u].objTCoeff.y != to->unit[u].objTCoeff.y ||
1003 from->unit[u].objTCoeff.z != to->unit[u].objTCoeff.z ||
1004 from->unit[u].objTCoeff.w != to->unit[u].objTCoeff.w)
1005 {
1006 GLfloat f[4];
1007 f[0] = to->unit[u].objTCoeff.x;
1008 f[1] = to->unit[u].objTCoeff.y;
1009 f[2] = to->unit[u].objTCoeff.z;
1010 f[3] = to->unit[u].objTCoeff.w;
1011 diff_api.TexGenfv (GL_T, GL_OBJECT_PLANE, (const GLfloat *) f);
1012 from->unit[u].objTCoeff = to->unit[u].objTCoeff;
1013 }
1014 if (from->unit[u].objRCoeff.x != to->unit[u].objRCoeff.x ||
1015 from->unit[u].objRCoeff.y != to->unit[u].objRCoeff.y ||
1016 from->unit[u].objRCoeff.z != to->unit[u].objRCoeff.z ||
1017 from->unit[u].objRCoeff.w != to->unit[u].objRCoeff.w)
1018 {
1019 GLfloat f[4];
1020 f[0] = to->unit[u].objRCoeff.x;
1021 f[1] = to->unit[u].objRCoeff.y;
1022 f[2] = to->unit[u].objRCoeff.z;
1023 f[3] = to->unit[u].objRCoeff.w;
1024 diff_api.TexGenfv (GL_R, GL_OBJECT_PLANE, (const GLfloat *) f);
1025 from->unit[u].objRCoeff = to->unit[u].objRCoeff;
1026 }
1027 if (from->unit[u].objQCoeff.x != to->unit[u].objQCoeff.x ||
1028 from->unit[u].objQCoeff.y != to->unit[u].objQCoeff.y ||
1029 from->unit[u].objQCoeff.z != to->unit[u].objQCoeff.z ||
1030 from->unit[u].objQCoeff.w != to->unit[u].objQCoeff.w)
1031 {
1032 GLfloat f[4];
1033 f[0] = to->unit[u].objQCoeff.x;
1034 f[1] = to->unit[u].objQCoeff.y;
1035 f[2] = to->unit[u].objQCoeff.z;
1036 f[3] = to->unit[u].objQCoeff.w;
1037 diff_api.TexGenfv (GL_Q, GL_OBJECT_PLANE, (const GLfloat *) f);
1038 from->unit[u].objQCoeff = to->unit[u].objQCoeff;
1039 }
1040 CLEARDIRTY(tb->objGen[u], nbitID);
1041 }
1042 if (CHECKDIRTY(tb->eyeGen[u], bitID))
1043 {
1044 if (fromCtx->texture.curTextureUnit != u) {
1045 diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
1046 fromCtx->texture.curTextureUnit = u;
1047 }
1048 if (fromCtx->transform.matrixMode != GL_MODELVIEW) {
1049 diff_api.MatrixMode(GL_MODELVIEW);
1050 fromCtx->transform.matrixMode = GL_MODELVIEW;
1051 }
1052 diff_api.PushMatrix();
1053 diff_api.LoadIdentity();
1054 if (from->unit[u].eyeSCoeff.x != to->unit[u].eyeSCoeff.x ||
1055 from->unit[u].eyeSCoeff.y != to->unit[u].eyeSCoeff.y ||
1056 from->unit[u].eyeSCoeff.z != to->unit[u].eyeSCoeff.z ||
1057 from->unit[u].eyeSCoeff.w != to->unit[u].eyeSCoeff.w)
1058 {
1059 GLfloat f[4];
1060 f[0] = to->unit[u].eyeSCoeff.x;
1061 f[1] = to->unit[u].eyeSCoeff.y;
1062 f[2] = to->unit[u].eyeSCoeff.z;
1063 f[3] = to->unit[u].eyeSCoeff.w;
1064 diff_api.TexGenfv (GL_S, GL_EYE_PLANE, (const GLfloat *) f);
1065 from->unit[u].eyeSCoeff = to->unit[u].eyeSCoeff;
1066 }
1067 if (from->unit[u].eyeTCoeff.x != to->unit[u].eyeTCoeff.x ||
1068 from->unit[u].eyeTCoeff.y != to->unit[u].eyeTCoeff.y ||
1069 from->unit[u].eyeTCoeff.z != to->unit[u].eyeTCoeff.z ||
1070 from->unit[u].eyeTCoeff.w != to->unit[u].eyeTCoeff.w)
1071 {
1072 GLfloat f[4];
1073 f[0] = to->unit[u].eyeTCoeff.x;
1074 f[1] = to->unit[u].eyeTCoeff.y;
1075 f[2] = to->unit[u].eyeTCoeff.z;
1076 f[3] = to->unit[u].eyeTCoeff.w;
1077 diff_api.TexGenfv (GL_T, GL_EYE_PLANE, (const GLfloat *) f);
1078 from->unit[u].eyeTCoeff = to->unit[u].eyeTCoeff;
1079 }
1080 if (from->unit[u].eyeRCoeff.x != to->unit[u].eyeRCoeff.x ||
1081 from->unit[u].eyeRCoeff.y != to->unit[u].eyeRCoeff.y ||
1082 from->unit[u].eyeRCoeff.z != to->unit[u].eyeRCoeff.z ||
1083 from->unit[u].eyeRCoeff.w != to->unit[u].eyeRCoeff.w)
1084 {
1085 GLfloat f[4];
1086 f[0] = to->unit[u].eyeRCoeff.x;
1087 f[1] = to->unit[u].eyeRCoeff.y;
1088 f[2] = to->unit[u].eyeRCoeff.z;
1089 f[3] = to->unit[u].eyeRCoeff.w;
1090 diff_api.TexGenfv (GL_R, GL_EYE_PLANE, (const GLfloat *) f);
1091 from->unit[u].eyeRCoeff = to->unit[u].eyeRCoeff;
1092 }
1093 if (from->unit[u].eyeQCoeff.x != to->unit[u].eyeQCoeff.x ||
1094 from->unit[u].eyeQCoeff.y != to->unit[u].eyeQCoeff.y ||
1095 from->unit[u].eyeQCoeff.z != to->unit[u].eyeQCoeff.z ||
1096 from->unit[u].eyeQCoeff.w != to->unit[u].eyeQCoeff.w)
1097 {
1098 GLfloat f[4];
1099 f[0] = to->unit[u].eyeQCoeff.x;
1100 f[1] = to->unit[u].eyeQCoeff.y;
1101 f[2] = to->unit[u].eyeQCoeff.z;
1102 f[3] = to->unit[u].eyeQCoeff.w;
1103 diff_api.TexGenfv (GL_Q, GL_EYE_PLANE, (const GLfloat *) f);
1104 from->unit[u].eyeQCoeff = to->unit[u].eyeQCoeff;
1105 }
1106 diff_api.PopMatrix();
1107 CLEARDIRTY(tb->eyeGen[u], nbitID);
1108 }
1109 if (CHECKDIRTY(tb->genMode[u], bitID))
1110 {
1111 if (fromCtx->texture.curTextureUnit != u) {
1112 diff_api.ActiveTextureARB( u + GL_TEXTURE0_ARB );
1113 fromCtx->texture.curTextureUnit = u;
1114 }
1115 if (from->unit[u].gen.s != to->unit[u].gen.s ||
1116 from->unit[u].gen.t != to->unit[u].gen.t ||
1117 from->unit[u].gen.r != to->unit[u].gen.r ||
1118 from->unit[u].gen.q != to->unit[u].gen.q)
1119 {
1120 diff_api.TexGeni (GL_S, GL_TEXTURE_GEN_MODE, to->unit[u].gen.s);
1121 diff_api.TexGeni (GL_T, GL_TEXTURE_GEN_MODE, to->unit[u].gen.t);
1122 diff_api.TexGeni (GL_R, GL_TEXTURE_GEN_MODE, to->unit[u].gen.r);
1123 diff_api.TexGeni (GL_Q, GL_TEXTURE_GEN_MODE, to->unit[u].gen.q);
1124 from->unit[u].gen = to->unit[u].gen;
1125 }
1126 CLEARDIRTY(tb->genMode[u], nbitID);
1127 }
1128
1129 /* Texture enviroment */
1130 if (CHECKDIRTY(tb->envBit[u], bitID))
1131 {
1132 if (from->unit[u].envMode != to->unit[u].envMode)
1133 {
1134 diff_api.TexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, to->unit[u].envMode);
1135 from->unit[u].envMode = to->unit[u].envMode;
1136 }
1137 if (from->unit[u].envColor.r != to->unit[u].envColor.r ||
1138 from->unit[u].envColor.g != to->unit[u].envColor.g ||
1139 from->unit[u].envColor.b != to->unit[u].envColor.b ||
1140 from->unit[u].envColor.a != to->unit[u].envColor.a)
1141 {
1142 GLfloat f[4];
1143 f[0] = to->unit[u].envColor.r;
1144 f[1] = to->unit[u].envColor.g;
1145 f[2] = to->unit[u].envColor.b;
1146 f[3] = to->unit[u].envColor.a;
1147 diff_api.TexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, (const GLfloat *) f);
1148 from->unit[u].envColor = to->unit[u].envColor;
1149 }
1150#ifdef CR_ARB_texture_env_combine
1151 if (from->unit[u].combineModeRGB != to->unit[u].combineModeRGB)
1152 {
1153 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, to->unit[u].combineModeRGB);
1154 from->unit[u].combineModeRGB = to->unit[u].combineModeRGB;
1155 }
1156 if (from->unit[u].combineModeA != to->unit[u].combineModeA)
1157 {
1158 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, to->unit[u].combineModeA);
1159 from->unit[u].combineModeA = to->unit[u].combineModeA;
1160 }
1161 if (from->unit[u].combineSourceRGB[0] != to->unit[u].combineSourceRGB[0])
1162 {
1163 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, to->unit[u].combineSourceRGB[0]);
1164 from->unit[u].combineSourceRGB[0] = to->unit[u].combineSourceRGB[0];
1165 }
1166 if (from->unit[u].combineSourceRGB[1] != to->unit[u].combineSourceRGB[1])
1167 {
1168 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, to->unit[u].combineSourceRGB[1]);
1169 from->unit[u].combineSourceRGB[1] = to->unit[u].combineSourceRGB[1];
1170 }
1171 if (from->unit[u].combineSourceRGB[2] != to->unit[u].combineSourceRGB[2])
1172 {
1173 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, to->unit[u].combineSourceRGB[2]);
1174 from->unit[u].combineSourceRGB[2] = to->unit[u].combineSourceRGB[2];
1175 }
1176 if (from->unit[u].combineSourceA[0] != to->unit[u].combineSourceA[0])
1177 {
1178 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, to->unit[u].combineSourceA[0]);
1179 from->unit[u].combineSourceA[0] = to->unit[u].combineSourceA[0];
1180 }
1181 if (from->unit[u].combineSourceA[1] != to->unit[u].combineSourceA[1])
1182 {
1183 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, to->unit[u].combineSourceA[1]);
1184 from->unit[u].combineSourceA[1] = to->unit[u].combineSourceA[1];
1185 }
1186 if (from->unit[u].combineSourceA[2] != to->unit[u].combineSourceA[2])
1187 {
1188 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, to->unit[u].combineSourceA[2]);
1189 from->unit[u].combineSourceA[2] = to->unit[u].combineSourceA[2];
1190 }
1191 if (from->unit[u].combineOperandRGB[0] != to->unit[u].combineOperandRGB[0])
1192 {
1193 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, to->unit[u].combineOperandRGB[0]);
1194 from->unit[u].combineOperandRGB[0] = to->unit[u].combineOperandRGB[0];
1195 }
1196 if (from->unit[u].combineOperandRGB[1] != to->unit[u].combineOperandRGB[1])
1197 {
1198 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, to->unit[u].combineOperandRGB[1]);
1199 from->unit[u].combineOperandRGB[1] = to->unit[u].combineOperandRGB[1];
1200 }
1201 if (from->unit[u].combineOperandRGB[2] != to->unit[u].combineOperandRGB[2])
1202 {
1203 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, to->unit[u].combineOperandRGB[2]);
1204 from->unit[u].combineOperandRGB[2] = to->unit[u].combineOperandRGB[2];
1205 }
1206 if (from->unit[u].combineOperandA[0] != to->unit[u].combineOperandA[0])
1207 {
1208 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, to->unit[u].combineOperandA[0]);
1209 from->unit[u].combineOperandA[0] = to->unit[u].combineOperandA[0];
1210 }
1211 if (from->unit[u].combineOperandA[1] != to->unit[u].combineOperandA[1])
1212 {
1213 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, to->unit[u].combineOperandA[1]);
1214 from->unit[u].combineOperandA[1] = to->unit[u].combineOperandA[1];
1215 }
1216 if (from->unit[u].combineOperandA[2] != to->unit[u].combineOperandA[2])
1217 {
1218 diff_api.TexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, to->unit[u].combineOperandA[2]);
1219 from->unit[u].combineOperandA[2] = to->unit[u].combineOperandA[2];
1220 }
1221 if (from->unit[u].combineScaleRGB != to->unit[u].combineScaleRGB)
1222 {
1223 diff_api.TexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, to->unit[u].combineScaleRGB);
1224 from->unit[u].combineScaleRGB = to->unit[u].combineScaleRGB;
1225 }
1226 if (from->unit[u].combineScaleA != to->unit[u].combineScaleA)
1227 {
1228 diff_api.TexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, to->unit[u].combineScaleA);
1229 from->unit[u].combineScaleA = to->unit[u].combineScaleA;
1230 }
1231#endif
1232#if CR_EXT_texture_lod_bias
1233 if (from->unit[u].lodBias != to->unit[u].lodBias)
1234 {
1235 diff_api.TexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, to->unit[u].lodBias);
1236 from->unit[u].lodBias = to->unit[u].lodBias;
1237 }
1238#endif
1239 CLEARDIRTY(tb->envBit[u], nbitID);
1240 }
1241
1242 /* loop over texture targets */
1243 for (t = 0; t < 5; t++)
1244 {
1245 tobj = NULL;
1246
1247 switch (t) {
1248 case 0:
1249 if (to->unit[u].enabled1D || haveFragProg) {
1250 tobj = to->unit[u].currentTexture1D;
1251 fromBinding = &(from->unit[u].currentTexture1D);
1252 }
1253 break;
1254 case 1:
1255 if (to->unit[u].enabled2D || haveFragProg) {
1256 tobj = to->unit[u].currentTexture2D;
1257 fromBinding = &(from->unit[u].currentTexture2D);
1258 }
1259 break;
1260#ifdef CR_OPENGL_VERSION_1_2
1261 case 2:
1262 if (to->unit[u].enabled3D || haveFragProg) {
1263 tobj = to->unit[u].currentTexture3D;
1264 fromBinding = &(from->unit[u].currentTexture3D);
1265 }
1266 break;
1267#endif
1268#ifdef CR_ARB_texture_cube_map
1269 case 3:
1270 if (fromCtx->extensions.ARB_texture_cube_map &&
1271 (to->unit[u].enabledCubeMap || haveFragProg)) {
1272 tobj = to->unit[u].currentTextureCubeMap;
1273 fromBinding = &(from->unit[u].currentTextureCubeMap);
1274 }
1275 break;
1276#endif
1277#ifdef CR_NV_texture_rectangle
1278 case 4:
1279 if (fromCtx->extensions.NV_texture_rectangle &&
1280 (to->unit[u].enabledRect || haveFragProg)) {
1281 tobj = to->unit[u].currentTextureRect;
1282 fromBinding = &(from->unit[u].currentTextureRect);
1283 }
1284 break;
1285#endif
1286 default:
1287 /* maybe don't support cube maps or rects */
1288 continue;
1289 }
1290
1291 if (!tobj) {
1292 continue; /* with next target */
1293 }
1294
1295 /* Activate texture unit u if needed */
1296 if (fromCtx->texture.curTextureUnit != u) {
1297 diff_api.ActiveTextureARB( GL_TEXTURE0_ARB + u);
1298 fromCtx->texture.curTextureUnit = u;
1299 }
1300
1301 /* bind this texture if needed */
1302 if (CHECKDIRTY(tb->current[u], bitID))
1303 {
1304 if (*fromBinding != tobj)
1305 {
1306 diff_api.BindTexture(tobj->target, tobj->name);
1307 *fromBinding = tobj;
1308 }
1309 }
1310
1311 /* now, if the texture object is dirty */
1312 if (CHECKDIRTY(tobj->dirty, bitID))
1313 {
1314 crStateTextureObjectDiff(fromCtx, bitID, nbitID, tobj, GL_FALSE);
1315 }
1316 CLEARDIRTY(tobj->dirty, nbitID);
1317
1318 } /* loop over targets */
1319
1320 CLEARDIRTY(tb->current[u], nbitID);
1321
1322 } /* loop over units */
1323
1324 /* After possible fiddling with the active unit, put it back now */
1325 if (fromCtx->texture.curTextureUnit != toCtx->texture.curTextureUnit) {
1326 diff_api.ActiveTextureARB( toCtx->texture.curTextureUnit + GL_TEXTURE0_ARB );
1327 fromCtx->texture.curTextureUnit = toCtx->texture.curTextureUnit;
1328 }
1329 if (fromCtx->transform.matrixMode != toCtx->transform.matrixMode) {
1330 diff_api.MatrixMode(toCtx->transform.matrixMode);
1331 fromCtx->transform.matrixMode = toCtx->transform.matrixMode;
1332 }
1333
1334 CLEARDIRTY(tb->dirty, nbitID);
1335}
1336
1337
1338
1339struct callback_info
1340{
1341 CRbitvalue *bitID, *nbitID;
1342 CRContext *g;
1343 GLboolean bForceUpdate;
1344};
1345
1346
1347/* Called by crHashtableWalk() below */
1348static void
1349DiffTextureObjectCallback( unsigned long key, void *texObj , void *cbData)
1350{
1351 struct callback_info *info = (struct callback_info *) cbData;
1352 CRTextureObj *tobj = (CRTextureObj *) texObj;
1353 /*
1354 printf(" Checking %d 0x%x bitid=0x%x\n",tobj->name, tobj->dirty[0], info->bitID[0]);
1355 */
1356 if (info->bForceUpdate || CHECKDIRTY(tobj->dirty, info->bitID)) {
1357 /*
1358 printf(" Found Dirty! %d\n", tobj->name);
1359 */
1360 crStateTextureObjectDiff(info->g, info->bitID, info->nbitID, tobj, info->bForceUpdate);
1361 CLEARDIRTY(tobj->dirty, info->nbitID);
1362 }
1363}
1364
1365
1366/*
1367 * This isn't used right now, but will be used in the future to fix some
1368 * potential display list problems. Specifically, if glBindTexture is
1369 * in a display list, we have to be sure that all outstanding texture object
1370 * updates are resolved before the list is called. If we don't, we may
1371 * wind up binding texture objects that are stale.
1372 */
1373void
1374crStateDiffAllTextureObjects( CRContext *g, CRbitvalue *bitID, GLboolean bForceUpdate )
1375{
1376 CRbitvalue nbitID[CR_MAX_BITARRAY];
1377 struct callback_info info;
1378 int j;
1379 int origUnit, orig1D, orig2D, orig3D, origCube, origRect;
1380
1381 for (j = 0; j < CR_MAX_BITARRAY; j++)
1382 nbitID[j] = ~bitID[j];
1383
1384 info.bitID = bitID;
1385 info.nbitID = nbitID;
1386 info.g = g;
1387 info.bForceUpdate = bForceUpdate;
1388
1389 /* save current texture bindings */
1390 origUnit = g->texture.curTextureUnit;
1391 orig1D = g->texture.unit[0].currentTexture1D->name;
1392 orig2D = g->texture.unit[0].currentTexture2D->name;
1393 orig3D = g->texture.unit[0].currentTexture3D->name;
1394#ifdef CR_ARB_texture_cube_map
1395 origCube = g->texture.unit[0].currentTextureCubeMap->name;
1396#endif
1397#ifdef CR_NV_texture_rectangle
1398 origRect = g->texture.unit[0].currentTextureRect->name;
1399#endif
1400
1401 /* use texture unit 0 for updates */
1402 diff_api.ActiveTextureARB(GL_TEXTURE0_ARB);
1403
1404 /* diff all the textures */
1405 crHashtableWalk(g->shared->textureTable, DiffTextureObjectCallback, (void *) &info);
1406
1407 /* default ones */
1408 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.base1D, GL_TRUE);
1409 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.base2D, GL_TRUE);
1410 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.base3D, GL_TRUE);
1411 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.proxy1D, GL_TRUE);
1412 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.proxy2D, GL_TRUE);
1413 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.proxy3D, GL_TRUE);
1414#ifdef CR_ARB_texture_cube_map
1415 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.baseCubeMap, GL_TRUE);
1416 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.proxyCubeMap, GL_TRUE);
1417#endif
1418#ifdef CR_NV_texture_rectangle
1419 if (g->extensions.NV_texture_rectangle)
1420 {
1421 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.baseRect, GL_TRUE);
1422 crStateTextureObjectDiff(g, bitID, nbitID, &g->texture.proxyRect, GL_TRUE);
1423 }
1424#endif
1425
1426 /* restore bindings */
1427 diff_api.ActiveTextureARB(GL_TEXTURE0_ARB + origUnit);
1428 diff_api.BindTexture(GL_TEXTURE_1D, orig1D);
1429 diff_api.BindTexture(GL_TEXTURE_2D, orig2D);
1430 diff_api.BindTexture(GL_TEXTURE_3D, orig3D);
1431#ifdef CR_ARB_texture_cube_map
1432 diff_api.BindTexture(GL_TEXTURE_CUBE_MAP_ARB, origCube);
1433#endif
1434#ifdef CR_NV_texture_rectangle
1435 diff_api.BindTexture(GL_TEXTURE_RECTANGLE_NV, origRect);
1436#endif
1437}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette