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