Replace ctx->Driver.StencilOp/Func/Mask() functions with
[mesa.git] / src / mesa / drivers / dri / s3v / s3v_state.c
1 /*
2 * Author: Max Lingua <sunmax@libero.it>
3 */
4
5 #include <X11/Xlibint.h>
6 #include "s3v_context.h"
7 #include "s3v_macros.h"
8 #include "macros.h"
9 #include "s3v_dri.h"
10 #include "colormac.h"
11 #include "swrast/swrast.h"
12 #include "swrast_setup/swrast_setup.h"
13 #include "array_cache/acache.h"
14 #include "tnl/tnl.h"
15
16 /* #define DEBUG(str) printf str */
17 #define ENABLELIGHTING 0
18
19
20 /* =============================================================
21 * Alpha blending
22 */
23
24 static void s3vUpdateAlphaMode( GLcontext *ctx )
25 {
26 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
27 CARD32 cmd = vmesa->CMD;
28 cmd &= ~ALPHA_BLEND_MASK;
29
30 if ( ctx->Color.BlendEnabled ) {
31 DEBUG(("ctx->Color.AlphaEnabled = 1"));
32 vmesa->_alpha[0] = ALPHA_SRC;
33 vmesa->_alpha[1] = vmesa->_alpha_tex; /* FIXME: not all tex modes
34 support alpha */
35 } else {
36 DEBUG(("ctx->Color.AlphaEnabled = 0"));
37 vmesa->_alpha[0] = vmesa->_alpha[1] = ALPHA_OFF;
38 }
39 #if 1
40 if ((cmd & DO_MASK) & DO_3D_LINE) { /* we are drawing 3d lines */
41 /* which don't support tex */
42 cmd |= vmesa->_alpha[0];
43 } else {
44 cmd |= vmesa->_alpha[vmesa->_3d_mode];
45 }
46
47 vmesa->CMD = cmd; /* FIXME: enough? */
48 #else
49 vmesa->restore_primitive = -1;
50 #endif
51
52 }
53
54 static void s3vDDAlphaFunc( GLcontext *ctx, GLenum func, GLfloat ref )
55 {
56 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
57
58 DEBUG(("s3vDDAlphaFunc\n"));
59
60 vmesa->new_state |= S3V_NEW_ALPHA;
61 }
62
63 static void s3vDDBlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor )
64 {
65 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
66
67 DEBUG(("s3vDDBlendFunc\n"));
68
69 vmesa->new_state |= S3V_NEW_ALPHA;
70 }
71
72 /* ================================================================
73 * Buffer clear
74 */
75
76 static void s3vDDClear( GLcontext *ctx, GLbitfield mask, GLboolean all,
77 GLint cx, GLint cy, GLint cw, GLint ch )
78 {
79 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
80 unsigned int _stride;
81
82 vmesa->restore_primitive = -1;
83
84 /* Update and emit any new state. We need to do this here to catch
85 * changes to the masks.
86 * FIXME: Just update the masks?
87 */
88
89 if ( vmesa->new_state )
90 s3vDDUpdateHWState( ctx );
91
92 /* s3vUpdateMasks( ctx ); */
93 /* s3vUpdateClipping( ctx ); */
94 /* s3vEmitHwState( vmesa ); */
95
96
97 #if 1 /* soft (0)/hw (1)*/
98
99 DEBUG(("*** s3vDDClear ***\n"));
100
101 DMAOUT_CHECK(BITBLT_SRC_BASE, 15);
102 DMAOUT(vmesa->SrcBase);
103 DMAOUT(vmesa->DestBlit);
104 DMAOUT( vmesa->ScissorLR );
105 DMAOUT( vmesa->ScissorTB );
106 DMAOUT( (vmesa->SrcStride << 16) | vmesa->SrcStride ); /* FIXME: unify */
107 DMAOUT( (~(0)) ); /* masks */
108 DMAOUT( (~(0)) );
109 DMAOUT(0);
110 DMAOUT(vmesa->ClearColor);
111 DMAOUT(0);
112 DMAOUT(0);
113 /* FIXME */
114 DMAOUT(0x16000122 | 0x5 | (0xF0 << 17)); /* black magic to me */
115 DMAOUT(vmesa->ScissorWH);
116 DMAOUT(vmesa->SrcXY);
117 DMAOUT(vmesa->DestXY);
118 DMAFINISH();
119
120 if (mask & BUFFER_BIT_DEPTH) { /* depth */
121 DEBUG(("BUFFER_BIT_DEPTH\n"));
122
123 _stride = ((cw+31)&~31) * 2;
124
125 DMAOUT_CHECK(BITBLT_SRC_BASE, 15);
126 DMAOUT(0);
127 DMAOUT(vmesa->s3vScreen->depthOffset);
128 DMAOUT( (0 << 16) | cw );
129 DMAOUT( (0 << 16) | ch );
130 DMAOUT( (vmesa->SrcStride << 16) | vmesa->DestStride );
131 DMAOUT( (~(0)) ); /* masks */
132 DMAOUT( (~(0)) );
133 DMAOUT(0);
134 DMAOUT(vmesa->ClearDepth); /* 0x7FFF */
135 /* FIXME */
136 DMAOUT(0);
137 DMAOUT(0);
138 DMAOUT(0x16000122 | 0x5 | (0xF0 << 17));
139 DMAOUT( ((cw-1) << 16) | (ch-1) );
140 DMAOUT(0);
141 DMAOUT( (0 << 16) | 0 );
142 DMAFINISH();
143
144 DEBUG(("vmesa->ClearDepth = 0x%x\n", vmesa->ClearDepth));
145 mask &= ~BUFFER_BIT_DEPTH;
146 }
147
148 if (!vmesa->NotClipped) {
149 DEBUG(("vmesa->NotClipped\n")); /* yes */
150 }
151
152 if (!(vmesa->EnabledFlags & S3V_BACK_BUFFER)) {
153 DEBUG(("!S3V_BACK_BUFFER -> flush\n"));
154 DMAFLUSH();
155 }
156 /*
157 if ( mask )
158 DEBUG(("still masked ;3(\n")); */ /* yes */
159 #else
160 _swrast_Clear( ctx, mask, all, cx, cy, cw, ch );
161 #endif
162 }
163
164 /* =============================================================
165 * Depth testing
166 */
167
168 static void s3vUpdateZMode( GLcontext *ctx )
169 {
170 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
171 CARD32 cmd = vmesa->CMD;
172
173 DEBUG(("Depth.Test = %i\n", ctx->Depth.Test));
174 DEBUG(("CMD was = 0x%x ", cmd));
175
176 /* printf("depth --- CMD was = 0x%x \n", cmd); */
177
178 cmd &= ~Z_MASK; /* 0xfc0fffff; */
179 /* Z_BUFFER */ /* 000 mode */ /* Z_UPDATE_OFF */
180
181 if (!ctx->Depth.Test)
182 cmd |= Z_OFF;
183
184 if ( ctx->Depth.Mask )
185 cmd |= Z_UPDATE_ON;
186
187 switch ( ctx->Depth.Func ) {
188 case GL_NEVER:
189 cmd |= Z_NEVER;
190 break;
191 case GL_ALWAYS:
192 cmd |= Z_ALWAYS;
193 break;
194 case GL_LESS:
195 cmd |= Z_LESS;
196 break;
197 case GL_LEQUAL:
198 cmd |= Z_LEQUAL;
199 break;
200 case GL_EQUAL:
201 cmd |= Z_EQUAL;
202 break;
203 case GL_GEQUAL:
204 cmd |= Z_GEQUAL;
205 break;
206 case GL_GREATER:
207 cmd |= Z_GREATER;
208 break;
209 case GL_NOTEQUAL:
210 cmd |= Z_NOTEQUAL;
211 break;
212 }
213
214 DEBUG(("CMD is 0x%x\n", cmd));
215
216 vmesa->dirty |= S3V_UPLOAD_DEPTH;
217 vmesa->CMD = cmd;
218 }
219
220 static void s3vDDDepthFunc( GLcontext *ctx, GLenum func )
221 {
222 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
223
224 /* FLUSH_BATCH( vmesa ); */
225 DEBUG(("s3vDDDepthFunc\n"));
226 vmesa->new_state |= S3V_NEW_DEPTH;
227 }
228
229 static void s3vDDDepthMask( GLcontext *ctx, GLboolean flag )
230 {
231 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
232
233 /* FLUSH_BATCH( vmesa ); */
234 DEBUG(("s3vDDDepthMask\n"));
235 vmesa->new_state |= S3V_NEW_DEPTH;
236 }
237
238 static void s3vDDClearDepth( GLcontext *ctx, GLclampd d )
239 {
240 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
241
242 switch ( vmesa->DepthSize ) {
243 case 15:
244 case 16:
245 vmesa->ClearDepth = d * 0x0000ffff; /* 65536 */
246 DEBUG(("GLclampd d = %f\n", d));
247 DEBUG(("ctx->Depth.Clear = %f\n", ctx->Depth.Clear));
248 DEBUG(("(They should be the same)\n"));
249 break;
250 case 24:
251 vmesa->ClearDepth = d * 0x00ffffff;
252 break;
253 case 32:
254 vmesa->ClearDepth = d * 0xffffffff;
255 break;
256 }
257 }
258
259 static void s3vDDFinish( GLcontext *ctx )
260 {
261 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
262 DMAFLUSH();
263 }
264
265 static void s3vDDFlush( GLcontext *ctx )
266 {
267 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
268 DMAFLUSH();
269 }
270
271 /* =============================================================
272 * Fog
273 */
274
275 static void s3vUpdateFogAttrib( GLcontext *ctx )
276 {
277 /* s3vContextPtr vmesa = S3V_CONTEXT(ctx); */
278
279 if (ctx->Fog.Enabled) {
280 } else {
281 }
282
283 switch (ctx->Fog.Mode) {
284 case GL_LINEAR:
285 break;
286 case GL_EXP:
287 break;
288 case GL_EXP2:
289 break;
290 }
291 }
292
293 static void s3vDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *param )
294 {
295 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
296 vmesa->new_state |= S3V_NEW_FOG;
297 }
298
299 /* =============================================================
300 * Lines
301 */
302 static void s3vDDLineWidth( GLcontext *ctx, GLfloat width )
303 {
304 /* FIXME: on virge you only have one size of 3d lines *
305 * if we wanted more, we should start using tris instead *
306 * but virge has problem with some tris when all of the *
307 * vertices stay on a line */
308 }
309
310 /* =============================================================
311 * Points
312 */
313 static void s3vDDPointSize( GLcontext *ctx, GLfloat size )
314 {
315 /* FIXME: we use 3d line to fake points. So same limitations
316 * as above apply */
317 }
318
319 /* =============================================================
320 * Polygon
321 */
322
323 static void s3vUpdatePolygon( GLcontext *ctx )
324 {
325 /* FIXME: I don't think we could do much here */
326
327 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
328 vmesa->dirty |= S3V_UPLOAD_POLYGON;
329 }
330
331 /* =============================================================
332 * Clipping
333 */
334
335 static void s3vUpdateClipping( GLcontext *ctx )
336 {
337 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
338 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
339
340 int x0,y0,x1,y1;
341
342 DEBUG((">>> s3vUpdateClipping <<<\n"));
343 /*
344 if ( vmesa->driDrawable ) {
345 DEBUG(("s3vUpdateClipping\n"));
346 */
347 if (vmesa->EnabledFlags & S3V_BACK_BUFFER) {
348 DEBUG(("S3V_BACK_BUFFER\n"));
349
350 x0 = 0;
351 y0 = 0;
352 x1 = dPriv->w - 1;
353 y1 = dPriv->h - 1;
354
355 vmesa->SrcBase = 0;
356 vmesa->DestBase = vmesa->s3vScreen->backOffset;
357 vmesa->DestBlit = vmesa->DestBase;
358 vmesa->ScissorLR = ( (0 << 16) | (dPriv->w-1) );
359 vmesa->ScissorTB = ( (0 << 16) | (dPriv->h-1) );
360 /*
361 vmesa->ScissorLR = ( (x0 << 16) | x1 );
362 vmesa->ScissorTB = ( (y0 << 16) | y1 );
363 */
364 vmesa->SrcStride = ( ((dPriv->w+31)&~31) * vmesa->s3vScreen->cpp );
365 vmesa->DestStride = vmesa->driScreen->fbWidth*vmesa->s3vScreen->cpp;
366 vmesa->ScissorWH = ( (dPriv->w << 16) | dPriv->h );
367 vmesa->SrcXY = 0;
368 /* vmesa->DestXY = ( (dPriv->x << 16) | dPriv->y ); */
369 vmesa->DestXY = ( (0 << 16) | 0 );
370 } else {
371 DEBUG(("S3V_FRONT_BUFFER\n"));
372
373 x0 = dPriv->x;
374 y0 = dPriv->y;
375 x1 = x0 + dPriv->w - 1;
376 y1 = y0 + dPriv->h - 1;
377
378 vmesa->SrcBase = 0;
379 vmesa->DestBase = 0;
380 vmesa->ScissorLR = ( (x0 << 16) | x1 );
381 vmesa->ScissorTB = ( (y0 << 16) | y1 );
382 vmesa->DestStride = vmesa->driScreen->fbWidth*vmesa->s3vScreen->cpp;
383 vmesa->SrcStride = vmesa->DestStride;
384 vmesa->DestBase = (y0 * vmesa->DestStride)
385 + x0*vmesa->s3vScreen->cpp;
386 vmesa->DestBlit = 0;
387 vmesa->ScissorWH = ( (x1 << 16) | y1 );
388 vmesa->SrcXY = 0;
389 vmesa->DestXY = ( (0 << 16) | 0 );
390 /* vmesa->DestXY = ( (dPriv->x << 16) | dPriv->y ); */
391 }
392
393 DEBUG(("x0=%i y0=%i x1=%i y1=%i\n", x0, y0, x1, y1));
394 DEBUG(("stride=%i rectWH=0x%x\n\n", vmesa->DestStride, vmesa->ScissorWH));
395
396 /* FIXME: how could we use the following info? */
397 /* if (ctx->Scissor.Enabled) {} */
398
399 vmesa->dirty |= S3V_UPLOAD_CLIP;
400 /* } */
401 }
402
403 static void s3vDDScissor( GLcontext *ctx,
404 GLint x, GLint y, GLsizei w, GLsizei h )
405 {
406 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
407
408 DEBUG((">>> s3vDDScissor <<<"));
409 /* FLUSH_BATCH( vmesa ); */
410 vmesa->new_state |= S3V_NEW_CLIP;
411 }
412
413 /* =============================================================
414 * Culling
415 */
416
417 static void s3vUpdateCull( GLcontext *ctx )
418 {
419 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
420 GLfloat backface_sign = 1;
421
422 DEBUG(("s3vUpdateCull\n"));
423 /* FIXME: GL_FRONT_AND_BACK */
424
425 switch ( ctx->Polygon.CullFaceMode ) {
426 case GL_BACK:
427 if (ctx->Polygon.FrontFace == GL_CCW)
428 backface_sign = -1;
429 break;
430
431 case GL_FRONT:
432 if (ctx->Polygon.FrontFace != GL_CCW)
433 backface_sign = -1;
434 break;
435
436 default:
437 break;
438 }
439
440 vmesa->backface_sign = backface_sign;
441 vmesa->dirty |= S3V_UPLOAD_GEOMETRY;
442 }
443
444
445 static void s3vDDCullFace( GLcontext *ctx, GLenum mode )
446 {
447 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
448 /* FLUSH_BATCH( vmesa ); */
449 vmesa->new_state |= S3V_NEW_CULL;
450 }
451
452 static void s3vDDFrontFace( GLcontext *ctx, GLenum mode )
453 {
454 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
455 /* FLUSH_BATCH( vmesa ); */
456 vmesa->new_state |= S3V_NEW_CULL;
457 }
458
459 /* =============================================================
460 * Masks
461 */
462
463 static void s3vUpdateMasks( GLcontext *ctx )
464 {
465 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
466
467 GLuint mask = s3vPackColor( vmesa->s3vScreen->cpp,
468 ctx->Color.ColorMask[RCOMP],
469 ctx->Color.ColorMask[GCOMP],
470 ctx->Color.ColorMask[BCOMP],
471 ctx->Color.ColorMask[ACOMP] );
472
473 if (vmesa->s3vScreen->cpp == 2) mask |= mask << 16;
474
475 /* FIXME: can we do something in virge? */
476 }
477 /*
478 static void s3vDDColorMask( GLcontext *ctx, GLboolean r, GLboolean g,
479 GLboolean b, GLboolean a)
480 {
481 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
482
483 FLUSH_BATCH( vmesa );
484 vmesa->new_state |= S3V_NEW_MASKS;
485 }
486 */
487 /* =============================================================
488 * Rendering attributes
489 */
490
491 /* =============================================================
492 * Miscellaneous
493 */
494
495 static void s3vDDClearColor( GLcontext *ctx, const GLfloat color[4])
496 {
497 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
498
499 DEBUG(("*** s3vDDClearColor\n"));
500
501 vmesa->ClearColor = s3vPackColor( 2, /* vmesa->s3vScreen->cpp, */
502 color[0], color[1], color[2], color[3] );
503
504 #if 0
505 if (vmesa->s3vScreen->cpp == 2) vmesa->ClearColor |= vmesa->ClearColor<<16;
506 #endif
507 }
508
509 static void s3vDDSetDrawBuffer( GLcontext *ctx, GLenum mode )
510 {
511 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
512 int found = GL_TRUE;
513
514 DEBUG(("*** s3vDDSetDrawBuffer ***\n"));
515
516 /* FLUSH_BATCH( vmesa ); */
517
518 switch ( mode ) {
519 case GL_FRONT_LEFT:
520 vmesa->drawOffset = vmesa->s3vScreen->frontOffset;
521 break;
522 case GL_BACK_LEFT:
523 vmesa->drawOffset = vmesa->s3vScreen->backOffset;
524 /* vmesa->driScreen->fbHeight *
525 * vmesa->driScreen->fbWidth *
526 * vmesa->s3vScreen->cpp; */
527 break;
528 default:
529 found = GL_FALSE;
530 break;
531 }
532
533 DEBUG(("vmesa->drawOffset = 0x%x\n", vmesa->drawOffset));
534 /* return GL_TRUE; */
535 }
536
537 /* =============================================================
538 * Window position and viewport transformation
539 */
540
541 void s3vUpdateWindow( GLcontext *ctx )
542 {
543 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
544 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
545 GLfloat xoffset = (GLfloat)dPriv->x;
546 GLfloat yoffset =
547 vmesa->driScreen->fbHeight - (GLfloat)dPriv->y - dPriv->h;
548 const GLfloat *v = ctx->Viewport._WindowMap.m;
549
550 GLfloat sx = v[MAT_SX];
551 GLfloat tx = v[MAT_TX] + xoffset;
552 GLfloat sy = v[MAT_SY];
553 GLfloat ty = v[MAT_TY] + yoffset;
554 GLfloat sz = v[MAT_SZ] * vmesa->depth_scale;
555 GLfloat tz = v[MAT_TZ] * vmesa->depth_scale;
556
557 vmesa->dirty |= S3V_UPLOAD_VIEWPORT;
558
559 vmesa->ViewportScaleX = sx;
560 vmesa->ViewportScaleY = sy;
561 vmesa->ViewportScaleZ = sz;
562 vmesa->ViewportOffsetX = tx;
563 vmesa->ViewportOffsetY = ty;
564 vmesa->ViewportOffsetZ = tz;
565 }
566
567
568 /*
569 static void s3vDDViewport( GLcontext *ctx, GLint x, GLint y,
570 GLsizei width, GLsizei height )
571 {
572 s3vUpdateWindow( ctx );
573 }
574
575 static void s3vDDDepthRange( GLcontext *ctx, GLclampd nearval,
576 GLclampd farval )
577 {
578 s3vUpdateWindow( ctx );
579 }
580 */
581 void s3vUpdateViewportOffset( GLcontext *ctx )
582 {
583 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
584 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
585 GLfloat xoffset = (GLfloat)dPriv->x;
586 GLfloat yoffset =
587 vmesa->driScreen->fbHeight - (GLfloat)dPriv->y - dPriv->h;
588 const GLfloat *v = ctx->Viewport._WindowMap.m;
589
590 GLfloat tx = v[MAT_TX] + xoffset;
591 GLfloat ty = v[MAT_TY] + yoffset;
592
593 DEBUG(("*** s3vUpdateViewportOffset ***\n"));
594
595 if ( vmesa->ViewportOffsetX != tx ||
596 vmesa->ViewportOffsetY != ty )
597 {
598 vmesa->ViewportOffsetX = tx;
599 vmesa->ViewportOffsetY = ty;
600
601 vmesa->new_state |= S3V_NEW_WINDOW;
602 }
603
604 /* vmesa->new_state |= S3V_NEW_CLIP; */
605 }
606
607 /* =============================================================
608 * State enable/disable
609 */
610
611 static void s3vDDEnable( GLcontext *ctx, GLenum cap, GLboolean state )
612 {
613 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
614
615 switch ( cap ) {
616 case GL_ALPHA_TEST:
617 case GL_BLEND:
618 vmesa->new_state |= S3V_NEW_ALPHA;
619 DEBUG(("s3vDDEnable: GL_BLEND\n"));
620 break;
621
622 case GL_CULL_FACE:
623 vmesa->new_state |= S3V_NEW_CULL;
624 DEBUG(("s3vDDEnable: GL_CULL_FACE\n"));
625 break;
626
627 case GL_DEPTH_TEST:
628 vmesa->new_state |= S3V_NEW_DEPTH;
629 DEBUG(("s3vDDEnable: GL_DEPTH\n"));
630 break;
631 #if 0
632 case GL_FOG:
633 vmesa->new_state |= S3V_NEW_FOG;
634 break;
635 #endif
636
637 case GL_SCISSOR_TEST:
638 vmesa->new_state |= S3V_NEW_CLIP;
639 break;
640
641 case GL_TEXTURE_2D:
642 DEBUG(("*** GL_TEXTURE_2D: %i\n", state));
643 vmesa->_3d_mode = state;
644 vmesa->restore_primitive = -1;
645 break;
646
647 default:
648 return;
649 }
650 }
651
652 /* =============================================================
653 * State initialization, management
654 */
655
656
657 /*
658 * Load the current context's state into the hardware.
659 *
660 * NOTE: Be VERY careful about ensuring the context state is marked for
661 * upload, the only place it shouldn't be uploaded is when the setup
662 * state has changed in ReducedPrimitiveChange as this comes right after
663 * a state update.
664 *
665 * Blits of any type should always upload the context and masks after
666 * they are done.
667 */
668 void s3vEmitHwState( s3vContextPtr vmesa )
669 {
670 if (!vmesa->driDrawable) return;
671 if (!vmesa->dirty) return;
672
673 DEBUG(("**********************\n"));
674 DEBUG(("*** s3vEmitHwState ***\n"));
675 DEBUG(("**********************\n"));
676
677 if (vmesa->dirty & S3V_UPLOAD_VIEWPORT) {
678 vmesa->dirty &= ~S3V_UPLOAD_VIEWPORT;
679 DEBUG(("S3V_UPLOAD_VIEWPORT\n"));
680 }
681
682 if ( (vmesa->dirty & S3V_UPLOAD_POINTMODE) ||
683 (vmesa->dirty & S3V_UPLOAD_LINEMODE) ||
684 (vmesa->dirty & S3V_UPLOAD_TRIMODE) ) {
685
686 }
687
688 if (vmesa->dirty & S3V_UPLOAD_POINTMODE) {
689 vmesa->dirty &= ~S3V_UPLOAD_POINTMODE;
690 }
691
692 if (vmesa->dirty & S3V_UPLOAD_LINEMODE) {
693 vmesa->dirty &= ~S3V_UPLOAD_LINEMODE;
694 }
695
696 if (vmesa->dirty & S3V_UPLOAD_TRIMODE) {
697 vmesa->dirty &= ~S3V_UPLOAD_TRIMODE;
698 }
699
700 if (vmesa->dirty & S3V_UPLOAD_FOG) {
701 GLchan c[3], col;
702 UNCLAMPED_FLOAT_TO_RGB_CHAN( c, vmesa->glCtx->Fog.Color );
703 DEBUG(("uploading ** FOG **\n"));
704 col = s3vPackColor(2, c[0], c[1], c[2], 0);
705 vmesa->dirty &= ~S3V_UPLOAD_FOG;
706 }
707
708 if (vmesa->dirty & S3V_UPLOAD_DITHER) {
709 vmesa->dirty &= ~S3V_UPLOAD_DITHER;
710 }
711
712 if (vmesa->dirty & S3V_UPLOAD_LOGICOP) {
713 vmesa->dirty &= ~S3V_UPLOAD_LOGICOP;
714 }
715
716 if (vmesa->dirty & S3V_UPLOAD_CLIP) {
717 vmesa->dirty &= ~S3V_UPLOAD_CLIP;
718 DEBUG(("S3V_UPLOAD_CLIP\n"));
719 DEBUG(("vmesa->ScissorLR: %i\n", vmesa->ScissorLR));
720 DEBUG(("vmesa->ScissorTB: %i\n", vmesa->ScissorTB));
721 }
722
723 if (vmesa->dirty & S3V_UPLOAD_MASKS) {
724 vmesa->dirty &= ~S3V_UPLOAD_MASKS;
725 DEBUG(("S3V_UPLOAD_BLEND\n"));
726 }
727
728 if (vmesa->dirty & S3V_UPLOAD_ALPHA) {
729 vmesa->dirty &= ~S3V_UPLOAD_ALPHA;
730 DEBUG(("S3V_UPLOAD_ALPHA\n"));
731 }
732
733 if (vmesa->dirty & S3V_UPLOAD_SHADE) {
734 vmesa->dirty &= ~S3V_UPLOAD_SHADE;
735 }
736
737 if (vmesa->dirty & S3V_UPLOAD_POLYGON) {
738 vmesa->dirty &= ~S3V_UPLOAD_POLYGON;
739 }
740
741 if (vmesa->dirty & S3V_UPLOAD_DEPTH) {
742 vmesa->dirty &= ~S3V_UPLOAD_DEPTH;
743 DEBUG(("S3V_UPLOAD_DEPTH: DepthMode = 0x%x08\n", vmesa->DepthMode));
744 }
745
746 if (vmesa->dirty & S3V_UPLOAD_GEOMETRY) {
747 vmesa->dirty &= ~S3V_UPLOAD_GEOMETRY;
748 }
749
750 if (vmesa->dirty & S3V_UPLOAD_TRANSFORM) {
751 vmesa->dirty &= ~S3V_UPLOAD_TRANSFORM;
752 }
753
754 if (vmesa->dirty & S3V_UPLOAD_TEX0) {
755 s3vTextureObjectPtr curTex = vmesa->CurrentTexObj[0];
756 vmesa->dirty &= ~S3V_UPLOAD_TEX0;
757 DEBUG(("S3V_UPLOAD_TEX0\n"));
758 if (curTex) {
759 DEBUG(("S3V_UPLOAD_TEX0: curTex\n"));
760 } else {
761 DEBUG(("S3V_UPLOAD_TEX0: !curTex\n"));
762 }
763 }
764 }
765
766 void s3vDDUpdateHWState( GLcontext *ctx )
767 {
768 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
769
770 int new_state = vmesa->new_state;
771
772 /* s3vUpdateClipping( ctx ); */
773
774 if ( new_state )
775 {
776
777 vmesa->new_state = 0;
778
779 /* Update the various parts of the context's state.
780 */
781 if ( new_state & S3V_NEW_ALPHA )
782 s3vUpdateAlphaMode( ctx );
783
784 if ( new_state & S3V_NEW_DEPTH )
785 s3vUpdateZMode( ctx );
786
787 if ( new_state & S3V_NEW_FOG )
788 s3vUpdateFogAttrib( ctx );
789
790 if ( new_state & S3V_NEW_CLIP )
791 {
792 DEBUG(("---> going to s3vUpdateClipping\n"));
793 s3vUpdateClipping( ctx );
794 }
795
796 if ( new_state & S3V_NEW_POLYGON )
797 s3vUpdatePolygon( ctx );
798
799 if ( new_state & S3V_NEW_CULL )
800 s3vUpdateCull( ctx );
801
802 if ( new_state & S3V_NEW_MASKS )
803 s3vUpdateMasks( ctx );
804
805 if ( new_state & S3V_NEW_WINDOW )
806 s3vUpdateWindow( ctx );
807 /*
808 if ( new_state & S3_NEW_TEXTURE )
809 s3vUpdateTextureState( ctx );
810 */
811 CMDCHANGE();
812 }
813
814 /* HACK ! */
815 s3vEmitHwState( vmesa );
816 }
817
818
819 static void s3vDDUpdateState( GLcontext *ctx, GLuint new_state )
820 {
821 _swrast_InvalidateState( ctx, new_state );
822 _swsetup_InvalidateState( ctx, new_state );
823 _ac_InvalidateState( ctx, new_state );
824 _tnl_InvalidateState( ctx, new_state );
825 S3V_CONTEXT(ctx)->new_gl_state |= new_state;
826 }
827
828
829 /* Initialize the context's hardware state.
830 */
831 void s3vInitState( s3vContextPtr vmesa )
832 {
833 vmesa->new_state = 0;
834 }
835
836 /* Initialize the driver's state functions.
837 */
838 void s3vInitStateFuncs( GLcontext *ctx )
839 {
840 ctx->Driver.UpdateState = s3vDDUpdateState;
841
842 ctx->Driver.Clear = s3vDDClear;
843 ctx->Driver.ClearIndex = NULL;
844 ctx->Driver.ClearColor = s3vDDClearColor;
845 ctx->Driver.DrawBuffer = s3vDDSetDrawBuffer;
846 ctx->Driver.ReadBuffer = NULL; /* XXX */
847
848 ctx->Driver.IndexMask = NULL;
849 ctx->Driver.ColorMask = NULL; /* s3vDDColorMask; */ /* FIXME */
850
851 ctx->Driver.AlphaFunc = s3vDDAlphaFunc; /* FIXME */
852 #if 0
853 ctx->Driver.BlendEquation = NULL; /* s3vDDBlendEquation; */
854 ctx->Driver.BlendFunc = s3vDDBlendFunc; /* FIXME */
855 #endif
856 ctx->Driver.BlendFuncSeparate = NULL; /* s3vDDBlendFuncSeparate; */
857 ctx->Driver.ClearDepth = s3vDDClearDepth;
858 ctx->Driver.CullFace = s3vDDCullFace;
859 ctx->Driver.FrontFace = s3vDDFrontFace;
860 ctx->Driver.DepthFunc = s3vDDDepthFunc; /* FIXME */
861 ctx->Driver.DepthMask = s3vDDDepthMask; /* FIXME */
862 ctx->Driver.DepthRange = NULL; /* s3vDDDepthRange; */
863 ctx->Driver.Enable = s3vDDEnable; /* FIXME */
864 ctx->Driver.Finish = s3vDDFinish;
865 ctx->Driver.Flush = s3vDDFlush;
866 #if 1
867 ctx->Driver.Fogfv = NULL; /* s3vDDFogfv; */
868 #endif
869 ctx->Driver.Hint = NULL;
870 ctx->Driver.LineWidth = NULL; /* s3vDDLineWidth; */
871 ctx->Driver.LineStipple = NULL; /* s3vDDLineStipple; */
872 #if ENABLELIGHTING
873 ctx->Driver.Lightfv = NULL; /* s3vDDLightfv; */
874
875 ctx->Driver.LightModelfv = NULL; /* s3vDDLightModelfv; */
876 #endif
877 ctx->Driver.LogicOpcode = NULL; /* s3vDDLogicalOpcode; */
878 ctx->Driver.PointSize = NULL; /* s3vDDPointSize; */
879 ctx->Driver.PolygonMode = NULL; /* s3vDDPolygonMode; */
880 ctx->Driver.PolygonStipple = NULL; /* s3vDDPolygonStipple; */
881 ctx->Driver.Scissor = s3vDDScissor; /* ScissorLR / ScissorTB */
882 ctx->Driver.ShadeModel = NULL; /* s3vDDShadeModel; */
883 ctx->Driver.Viewport = NULL; /* s3vDDViewport; */
884 }