Remove dd_function_table::BlendFunc. All drivers now use
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_state.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_state.c,v 1.5 2002/11/05 17:46:07 tsi Exp $ */
2 /*
3 * Copyright 2001 by Alan Hourihane.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Alan Hourihane not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission. Alan Hourihane makes no representations
12 * about the suitability of this software for any purpose. It is provided
13 * "as is" without express or implied warranty.
14 *
15 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
24 *
25 * 3DLabs Gamma driver
26 */
27
28 #include "gamma_context.h"
29 #include "gamma_macros.h"
30 #include "macros.h"
31 #include "glint_dri.h"
32 #include "colormac.h"
33 #include "swrast/swrast.h"
34 #include "swrast_setup/swrast_setup.h"
35 #include "array_cache/acache.h"
36 #include "tnl/tnl.h"
37
38 #define ENABLELIGHTING 0
39
40 /* =============================================================
41 * Alpha blending
42 */
43
44 static void gammaUpdateAlphaMode( GLcontext *ctx )
45 {
46 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
47 CARD32 a = gmesa->AlphaTestMode;
48 CARD32 b = gmesa->AlphaBlendMode;
49 CARD32 f = gmesa->AB_FBReadMode_Save = 0;
50 GLubyte refByte = (GLint) (ctx->Color.AlphaRef * 255.0);
51
52 a &= ~(AT_CompareMask | AT_RefValueMask);
53 b &= ~(AB_SrcBlendMask | AB_DstBlendMask);
54
55 a |= refByte << 4;
56
57 switch ( ctx->Color.AlphaFunc ) {
58 case GL_NEVER:
59 a |= AT_Never;
60 break;
61 case GL_LESS:
62 a |= AT_Less;
63 break;
64 case GL_EQUAL:
65 a |= AT_Equal;
66 break;
67 case GL_LEQUAL:
68 a |= AT_LessEqual;
69 break;
70 case GL_GEQUAL:
71 a |= AT_GreaterEqual;
72 break;
73 case GL_GREATER:
74 a |= AT_Greater;
75 break;
76 case GL_NOTEQUAL:
77 a |= AT_NotEqual;
78 break;
79 case GL_ALWAYS:
80 a |= AT_Always;
81 break;
82 }
83
84 if ( ctx->Color.AlphaEnabled ) {
85 f |= FBReadDstEnable;
86 a |= AlphaTestModeEnable;
87 } else {
88 a &= ~AlphaTestModeEnable;
89 }
90
91 switch ( ctx->Color.BlendSrcRGB ) {
92 case GL_ZERO:
93 b |= AB_Src_Zero;
94 break;
95 case GL_ONE:
96 b |= AB_Src_One;
97 break;
98 case GL_DST_COLOR:
99 b |= AB_Src_DstColor;
100 break;
101 case GL_ONE_MINUS_DST_COLOR:
102 b |= AB_Src_OneMinusDstColor;
103 break;
104 case GL_SRC_ALPHA:
105 b |= AB_Src_SrcAlpha;
106 break;
107 case GL_ONE_MINUS_SRC_ALPHA:
108 b |= AB_Src_OneMinusSrcAlpha;
109 break;
110 case GL_DST_ALPHA:
111 b |= AB_Src_DstAlpha;
112 f |= FBReadSrcEnable;
113 break;
114 case GL_ONE_MINUS_DST_ALPHA:
115 b |= AB_Src_OneMinusDstAlpha;
116 f |= FBReadSrcEnable;
117 break;
118 case GL_SRC_ALPHA_SATURATE:
119 b |= AB_Src_SrcAlphaSaturate;
120 break;
121 }
122
123 switch ( ctx->Color.BlendDstRGB ) {
124 case GL_ZERO:
125 b |= AB_Dst_Zero;
126 break;
127 case GL_ONE:
128 b |= AB_Dst_One;
129 break;
130 case GL_SRC_COLOR:
131 b |= AB_Dst_SrcColor;
132 break;
133 case GL_ONE_MINUS_SRC_COLOR:
134 b |= AB_Dst_OneMinusSrcColor;
135 break;
136 case GL_SRC_ALPHA:
137 b |= AB_Dst_SrcAlpha;
138 break;
139 case GL_ONE_MINUS_SRC_ALPHA:
140 b |= AB_Dst_OneMinusSrcAlpha;
141 break;
142 case GL_DST_ALPHA:
143 b |= AB_Dst_DstAlpha;
144 f |= FBReadSrcEnable;
145 break;
146 case GL_ONE_MINUS_DST_ALPHA:
147 b |= AB_Dst_OneMinusDstAlpha;
148 f |= FBReadSrcEnable;
149 break;
150 }
151
152 if ( ctx->Color.BlendEnabled ) {
153 f |= FBReadDstEnable;
154 b |= AlphaBlendModeEnable;
155 } else {
156 b &= ~AlphaBlendModeEnable;
157 }
158
159 if ( gmesa->AlphaTestMode != a ) {
160 gmesa->AlphaTestMode = a;
161 gmesa->dirty |= GAMMA_UPLOAD_ALPHA;
162 }
163 if ( gmesa->AlphaBlendMode != b) {
164 gmesa->AlphaBlendMode = b;
165 gmesa->dirty |= GAMMA_UPLOAD_BLEND;
166 }
167 gmesa->AB_FBReadMode_Save = f;
168 }
169
170 static void gammaDDAlphaFunc( GLcontext *ctx, GLenum func, GLfloat ref )
171 {
172 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
173 (void) ref;
174
175 FLUSH_BATCH( gmesa );
176
177 gmesa->new_state |= GAMMA_NEW_ALPHA;
178 }
179
180 static void gammaDDBlendEquation( GLcontext *ctx, GLenum mode )
181 {
182 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
183
184 FLUSH_BATCH( gmesa );
185
186 gmesa->new_state |= GAMMA_NEW_ALPHA;
187 }
188
189 static void gammaDDBlendFuncSeparate( GLcontext *ctx,
190 GLenum sfactorRGB, GLenum dfactorRGB,
191 GLenum sfactorA, GLenum dfactorA )
192 {
193 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
194
195 FLUSH_BATCH( gmesa );
196
197 gmesa->new_state |= GAMMA_NEW_ALPHA;
198 }
199
200
201 /* ================================================================
202 * Buffer clear
203 */
204
205 static void gammaDDClear( GLcontext *ctx, GLbitfield mask, GLboolean all,
206 GLint cx, GLint cy, GLint cw, GLint ch )
207 {
208 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
209 GLINTDRIPtr gDRIPriv = (GLINTDRIPtr)gmesa->driScreen->pDevPriv;
210 GLuint temp = 0;
211
212 FLUSH_BATCH( gmesa );
213
214 /* Update and emit any new state. We need to do this here to catch
215 * changes to the masks.
216 * FIXME: Just update the masks?
217 */
218 if ( gmesa->new_state )
219 gammaDDUpdateHWState( ctx );
220
221 #ifdef DO_VALIDATE
222 /* Flush any partially filled buffers */
223 FLUSH_DMA_BUFFER(gmesa);
224
225 DRM_SPINLOCK(&gmesa->driScreen->pSAREA->drawable_lock,
226 gmesa->driScreen->drawLockID);
227 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa);
228 #endif
229
230 if (mask & DD_DEPTH_BIT) {
231 /* Turn off writes the FB */
232 CHECK_DMA_BUFFER(gmesa, 1);
233 WRITE(gmesa->buf, FBWriteMode, FBWriteModeDisable);
234
235 mask &= ~DD_DEPTH_BIT;
236
237 /*
238 * Turn Rectangle2DControl off when the window is not clipped
239 * (i.e., the GID tests are not necessary). This dramatically
240 * increases the performance of the depth clears.
241 */
242 if (!gmesa->NotClipped) {
243 CHECK_DMA_BUFFER(gmesa, 1);
244 WRITE(gmesa->buf, Rectangle2DControl, 1);
245 }
246
247 temp = (gmesa->LBReadMode & LBPartialProdMask) | LBWindowOriginBot;
248 if (gDRIPriv->numMultiDevices == 2) temp |= LBScanLineInt2;
249
250 CHECK_DMA_BUFFER(gmesa, 5);
251 WRITE(gmesa->buf, LBReadMode, temp);
252 WRITE(gmesa->buf, DeltaMode, DM_DepthEnable);
253 WRITE(gmesa->buf, DepthMode, (DepthModeEnable |
254 DM_Always |
255 DM_SourceDepthRegister |
256 DM_WriteMask));
257 WRITE(gmesa->buf, GLINTDepth, gmesa->ClearDepth);
258
259 /* Increment the frame count */
260 gmesa->FrameCount++;
261 #ifdef FAST_CLEAR_4
262 gmesa->FrameCount &= 0x0f;
263 #else
264 gmesa->FrameCount &= 0xff;
265 #endif
266
267 /* Force FCP to be written */
268 WRITE(gmesa->buf, GLINTWindow, (WindowEnable |
269 W_PassIfEqual |
270 (gmesa->Window & W_GIDMask) |
271 W_DepthFCP |
272 W_LBUpdateFromRegisters |
273 W_OverrideWriteFiltering |
274 (gmesa->FrameCount << 9)));
275
276 /* Clear part of the depth and FCP buffers */
277 {
278 int y = gmesa->driScreen->fbHeight - gmesa->driDrawable->y - gmesa->driDrawable->h;
279 int x = gmesa->driDrawable->x;
280 int w = gmesa->driDrawable->w;
281 int h = gmesa->driDrawable->h;
282 #ifndef TURN_OFF_FCP
283 float hsub = h;
284
285 if (gmesa->WindowChanged) {
286 gmesa->WindowChanged = GL_FALSE;
287 } else {
288 #ifdef FAST_CLEAR_4
289 hsub /= 16;
290 #else
291 hsub /= 256;
292 #endif
293
294 /* Handle the case where the height < # of FCPs */
295 if (hsub < 1.0) {
296 if (gmesa->FrameCount > h)
297 gmesa->FrameCount = 0;
298 h = 1;
299 y += gmesa->FrameCount;
300 } else {
301 h = (gmesa->FrameCount+1)*hsub;
302 h -= (int)(gmesa->FrameCount*hsub);
303 y += gmesa->FrameCount*hsub;
304 }
305 }
306 #endif
307 if (h && w) {
308 #if 0
309 CHECK_DMA_BUFFER(gmesa, 2);
310 WRITE(gmesa->buf, Rectangle2DMode, ((h & 0xfff)<<12) |
311 (w & 0xfff) );
312 WRITE(gmesa->buf, DrawRectangle2D, ((y & 0xffff)<<16) |
313 (x & 0xffff) );
314 #else
315 CHECK_DMA_BUFFER(gmesa, 8);
316 WRITE(gmesa->buf, StartXDom, x<<16);
317 WRITE(gmesa->buf, StartY, y<<16);
318 WRITE(gmesa->buf, StartXSub, (x+w)<<16);
319 WRITE(gmesa->buf, GLINTCount, h);
320 WRITE(gmesa->buf, dY, 1<<16);
321 WRITE(gmesa->buf, dXDom, 0<<16);
322 WRITE(gmesa->buf, dXSub, 0<<16);
323 WRITE(gmesa->buf, Render, 0x00000040); /* NOT_DONE */
324 #endif
325 }
326 }
327
328 CHECK_DMA_BUFFER(gmesa, 6);
329 WRITE(gmesa->buf, DepthMode, gmesa->DepthMode);
330 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode);
331 WRITE(gmesa->buf, LBReadMode, gmesa->LBReadMode);
332 WRITE(gmesa->buf, GLINTWindow, gmesa->Window);
333 WRITE(gmesa->buf, FastClearDepth, gmesa->ClearDepth);
334 WRITE(gmesa->buf, FBWriteMode, FBWriteModeEnable);
335
336 /* Turn on Depth FCP */
337 if (gmesa->Window & W_DepthFCP) {
338 CHECK_DMA_BUFFER(gmesa, 1);
339 WRITE(gmesa->buf, WindowOr, (gmesa->FrameCount << 9));
340 }
341
342 /* Turn off GID clipping if window is not clipped */
343 if (gmesa->NotClipped) {
344 CHECK_DMA_BUFFER(gmesa, 1);
345 WRITE(gmesa->buf, Rectangle2DControl, 0);
346 }
347 }
348
349 if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) {
350 int y = gmesa->driScreen->fbHeight - gmesa->driDrawable->y - gmesa->driDrawable->h;
351 int x = gmesa->driDrawable->x;
352 int w = gmesa->driDrawable->w;
353 int h = gmesa->driDrawable->h;
354
355 mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
356
357 if (x < 0) { w -= -x; x = 0; }
358
359 /* Turn on GID clipping if window is clipped */
360 if (!gmesa->NotClipped) {
361 CHECK_DMA_BUFFER(gmesa, 1);
362 WRITE(gmesa->buf, Rectangle2DControl, 1);
363 }
364
365 CHECK_DMA_BUFFER(gmesa, 18);
366 WRITE(gmesa->buf, FBBlockColor, gmesa->ClearColor);
367 WRITE(gmesa->buf, ColorDDAMode, ColorDDADisable);
368 WRITE(gmesa->buf, FBWriteMode, FBWriteModeEnable);
369 WRITE(gmesa->buf, DepthMode, 0);
370 WRITE(gmesa->buf, DeltaMode, 0);
371 WRITE(gmesa->buf, AlphaBlendMode, 0);
372 #if 1
373 WRITE(gmesa->buf, dY, 1<<16);
374 WRITE(gmesa->buf, dXDom, 0<<16);
375 WRITE(gmesa->buf, dXSub, 0<<16);
376 WRITE(gmesa->buf, StartXSub, (x+w)<<16);
377 WRITE(gmesa->buf, GLINTCount, h);
378 WRITE(gmesa->buf, StartXDom, x<<16);
379 WRITE(gmesa->buf, StartY, y<<16);
380 WRITE(gmesa->buf, Render, 0x00000048); /* NOT_DONE */
381 #else
382 WRITE(gmesa->buf, Rectangle2DMode, (((h & 0xfff)<<12) |
383 (w & 0xfff)));
384 WRITE(gmesa->buf, DrawRectangle2D, (((y & 0xffff)<<16) |
385 (x & 0xffff)));
386 #endif
387 WRITE(gmesa->buf, DepthMode, gmesa->DepthMode);
388 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode);
389 WRITE(gmesa->buf, AlphaBlendMode, gmesa->AlphaBlendMode);
390 WRITE(gmesa->buf, ColorDDAMode, gmesa->ColorDDAMode);
391
392 /* Turn off GID clipping if window is clipped */
393 if (gmesa->NotClipped) {
394 CHECK_DMA_BUFFER(gmesa, 1);
395 WRITE(gmesa->buf, Rectangle2DControl, 0);
396 }
397 }
398
399 #ifdef DO_VALIDATE
400 PROCESS_DMA_BUFFER_TOP_HALF(gmesa);
401
402 DRM_SPINUNLOCK(&gmesa->driScreen->pSAREA->drawable_lock,
403 gmesa->driScreen->drawLockID);
404 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa);
405
406 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa);
407 #endif
408
409 if ( mask )
410 _swrast_Clear( ctx, mask, all, cx, cy, cw, ch );
411 }
412
413 /* =============================================================
414 * Depth testing
415 */
416
417 static void gammaUpdateZMode( GLcontext *ctx )
418 {
419 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
420 CARD32 z = gmesa->DepthMode;
421 CARD32 delta = gmesa->DeltaMode;
422 CARD32 window = gmesa->Window;
423 CARD32 lbread = gmesa->LBReadMode;
424
425 z &= ~DM_CompareMask;
426
427 switch ( ctx->Depth.Func ) {
428 case GL_NEVER:
429 z |= DM_Never;
430 break;
431 case GL_ALWAYS:
432 z |= DM_Always;
433 break;
434 case GL_LESS:
435 z |= DM_Less;
436 break;
437 case GL_LEQUAL:
438 z |= DM_LessEqual;
439 break;
440 case GL_EQUAL:
441 z |= DM_Equal;
442 break;
443 case GL_GEQUAL:
444 z |= DM_GreaterEqual;
445 break;
446 case GL_GREATER:
447 z |= DM_Greater;
448 break;
449 case GL_NOTEQUAL:
450 z |= DM_NotEqual;
451 break;
452 }
453
454 if ( ctx->Depth.Test ) {
455 z |= DepthModeEnable;
456 delta |= DM_DepthEnable;
457 window |= W_DepthFCP;
458 lbread |= LBReadDstEnable;
459 } else {
460 z &= ~DepthModeEnable;
461 delta &= ~DM_DepthEnable;
462 window &= ~W_DepthFCP;
463 lbread &= ~LBReadDstEnable;
464 }
465
466 if ( ctx->Depth.Mask ) {
467 z |= DM_WriteMask;
468 } else {
469 z &= ~DM_WriteMask;
470 }
471
472 #if 0
473 if ( gmesa->DepthMode != z ){
474 #endif
475 gmesa->DepthMode = z;
476 gmesa->DeltaMode = delta;
477 gmesa->Window = window;
478 gmesa->LBReadMode = lbread;
479 gmesa->dirty |= GAMMA_UPLOAD_DEPTH;
480 #if 0
481 }
482 #endif
483 }
484
485 static void gammaDDDepthFunc( GLcontext *ctx, GLenum func )
486 {
487 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
488
489 FLUSH_BATCH( gmesa );
490 gmesa->new_state |= GAMMA_NEW_DEPTH;
491 }
492
493 static void gammaDDDepthMask( GLcontext *ctx, GLboolean flag )
494 {
495 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
496
497 FLUSH_BATCH( gmesa );
498 gmesa->new_state |= GAMMA_NEW_DEPTH;
499 }
500
501 static void gammaDDClearDepth( GLcontext *ctx, GLclampd d )
502 {
503 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
504
505 switch ( gmesa->DepthSize ) {
506 case 16:
507 gmesa->ClearDepth = d * 0x0000ffff;
508 break;
509 case 24:
510 gmesa->ClearDepth = d * 0x00ffffff;
511 break;
512 case 32:
513 gmesa->ClearDepth = d * 0xffffffff;
514 break;
515 }
516 }
517
518 static void gammaDDFinish( GLcontext *ctx )
519 {
520 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
521
522 FLUSH_DMA_BUFFER(gmesa);
523 }
524
525 static void gammaDDFlush( GLcontext *ctx )
526 {
527 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
528
529 FLUSH_DMA_BUFFER(gmesa);
530 }
531
532 /* =============================================================
533 * Fog
534 */
535
536 static void gammaUpdateFogAttrib( GLcontext *ctx )
537 {
538 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
539 CARD32 f = gmesa->FogMode;
540 CARD32 g = gmesa->GeometryMode;
541 CARD32 d = gmesa->DeltaMode;
542
543 if (ctx->Fog.Enabled) {
544 f |= FogModeEnable;
545 g |= GM_FogEnable;
546 d |= DM_FogEnable;
547 } else {
548 f &= ~FogModeEnable;
549 g &= ~GM_FogEnable;
550 d &= ~DM_FogEnable;
551 }
552
553 g &= ~GM_FogMask;
554
555 switch (ctx->Fog.Mode) {
556 case GL_LINEAR:
557 g |= GM_FogLinear;
558 break;
559 case GL_EXP:
560 g |= GM_FogExp;
561 break;
562 case GL_EXP2:
563 g |= GM_FogExpSquared;
564 break;
565 }
566
567 if ( gmesa->FogMode != f ) {
568 gmesa->FogMode = f;
569 gmesa->dirty |= GAMMA_UPLOAD_FOG;
570 }
571
572 if ( gmesa->GeometryMode != g ) {
573 gmesa->GeometryMode = g;
574 gmesa->dirty |= GAMMA_UPLOAD_GEOMETRY;
575 }
576
577 if ( gmesa->DeltaMode != d ) {
578 gmesa->DeltaMode = d;
579 gmesa->dirty |= GAMMA_UPLOAD_DEPTH;
580 }
581 }
582
583 static void gammaDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *param )
584 {
585 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
586
587 FLUSH_BATCH( gmesa );
588 gmesa->new_state |= GAMMA_NEW_FOG;
589 }
590
591 /* =============================================================
592 * Lines
593 */
594 static void gammaDDLineWidth( GLcontext *ctx, GLfloat width )
595 {
596 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
597
598 CHECK_DMA_BUFFER(gmesa, 3);
599 WRITE(gmesa->buf, LineWidth, (GLuint)width);
600 WRITEF(gmesa->buf, AAlineWidth, width);
601 WRITE(gmesa->buf, LineWidthOffset, (GLuint)(width-1)/2);
602 }
603
604 static void gammaDDLineStipple( GLcontext *ctx, GLint factor, GLushort pattern )
605 {
606 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
607
608 gmesa->LineMode &= ~(LM_StippleMask | LM_RepeatFactorMask);
609 gmesa->LineMode |= ((GLuint)(factor - 1) << 1) | ((GLuint)pattern << 10);
610
611 gmesa->dirty |= GAMMA_UPLOAD_LINEMODE;
612 }
613
614
615
616 /* =============================================================
617 * Points
618 */
619 static void gammaDDPointSize( GLcontext *ctx, GLfloat size )
620 {
621 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
622
623 CHECK_DMA_BUFFER(gmesa, 2);
624 WRITE(gmesa->buf, PointSize, (GLuint)size);
625 WRITEF(gmesa->buf, AApointSize, size);
626 }
627
628 /* =============================================================
629 * Polygon
630 */
631
632 static void gammaUpdatePolygon( GLcontext *ctx )
633 {
634 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
635 CARD32 g = gmesa->GeometryMode;
636
637 g &= ~(GM_PolyOffsetFillEnable | GM_PolyOffsetPointEnable |
638 GM_PolyOffsetLineEnable);
639
640 if (ctx->Polygon.OffsetFill) g |= GM_PolyOffsetFillEnable;
641 if (ctx->Polygon.OffsetPoint) g |= GM_PolyOffsetPointEnable;
642 if (ctx->Polygon.OffsetLine) g |= GM_PolyOffsetLineEnable;
643
644 g &= ~GM_FB_PolyMask;
645
646 switch (ctx->Polygon.FrontMode) {
647 case GL_FILL:
648 g |= GM_FrontPolyFill;
649 break;
650 case GL_LINE:
651 g |= GM_FrontPolyLine;
652 break;
653 case GL_POINT:
654 g |= GM_FrontPolyPoint;
655 break;
656 }
657
658 switch (ctx->Polygon.BackMode) {
659 case GL_FILL:
660 g |= GM_BackPolyFill;
661 break;
662 case GL_LINE:
663 g |= GM_BackPolyLine;
664 break;
665 case GL_POINT:
666 g |= GM_BackPolyPoint;
667 break;
668 }
669
670 if ( gmesa->GeometryMode != g ) {
671 gmesa->GeometryMode = g;
672 gmesa->dirty |= GAMMA_UPLOAD_GEOMETRY;
673 }
674
675 gmesa->dirty |= GAMMA_UPLOAD_POLYGON;
676 }
677
678 static void gammaDDPolygonMode( GLcontext *ctx, GLenum face, GLenum mode)
679 {
680 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
681
682 FLUSH_BATCH( gmesa );
683
684 gmesa->new_state |= GAMMA_NEW_POLYGON;
685 }
686
687 static void gammaUpdateStipple( GLcontext *ctx )
688 {
689 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
690
691 FLUSH_BATCH( gmesa );
692
693 if (ctx->Polygon.StippleFlag) {
694 gmesa->AreaStippleMode |= AreaStippleModeEnable/* | ASM_X32 | ASM_Y32*/;
695 } else {
696 gmesa->AreaStippleMode &= ~AreaStippleModeEnable;
697 }
698
699 gmesa->dirty |= GAMMA_UPLOAD_STIPPLE;
700 }
701
702 static void gammaDDPolygonStipple( GLcontext *ctx, const GLubyte *mask)
703 {
704 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
705 FLUSH_BATCH( gmesa );
706 gmesa->new_state |= GAMMA_NEW_STIPPLE;
707 }
708
709 /* =============================================================
710 * Clipping
711 */
712
713 static void gammaUpdateClipping( GLcontext *ctx )
714 {
715 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
716 GLint x1, y1, x2, y2;
717
718 if ( gmesa->driDrawable ) {
719 x1 = gmesa->driDrawable->x + ctx->Scissor.X;
720 y1 = gmesa->driScreen->fbHeight -
721 (gmesa->driDrawable->y +
722 gmesa->driDrawable->h) + ctx->Scissor.Y;
723 x2 = x1 + ctx->Scissor.Width;
724 y2 = y1 + ctx->Scissor.Height;
725
726 gmesa->ScissorMinXY = x1 | (y1 << 16);
727 gmesa->ScissorMaxXY = x2 | (y2 << 16);
728 if (ctx->Scissor.Enabled)
729 gmesa->ScissorMode |= UserScissorEnable;
730 else
731 gmesa->ScissorMode &= ~UserScissorEnable;
732
733 gmesa->dirty |= GAMMA_UPLOAD_CLIP;
734 }
735 }
736
737 static void gammaDDScissor( GLcontext *ctx,
738 GLint x, GLint y, GLsizei w, GLsizei h )
739 {
740 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
741
742 FLUSH_BATCH( gmesa );
743 gmesa->new_state |= GAMMA_NEW_CLIP;
744 }
745
746 /* =============================================================
747 * Culling
748 */
749
750 static void gammaUpdateCull( GLcontext *ctx )
751 {
752 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
753 CARD32 g = gmesa->GeometryMode;
754
755 g &= ~(GM_PolyCullMask | GM_FFMask);
756
757 if (ctx->Polygon.FrontFace == GL_CCW) {
758 g |= GM_FrontFaceCCW;
759 } else {
760 g |= GM_FrontFaceCW;
761 }
762
763 switch ( ctx->Polygon.CullFaceMode ) {
764 case GL_FRONT:
765 g |= GM_PolyCullFront;
766 break;
767 case GL_BACK:
768 g |= GM_PolyCullBack;
769 break;
770 case GL_FRONT_AND_BACK:
771 g |= GM_PolyCullBoth;
772 break;
773 }
774
775 if ( ctx->Polygon.CullFlag ) {
776 g |= GM_PolyCullEnable;
777 } else {
778 g &= ~GM_PolyCullEnable;
779 }
780
781 if ( gmesa->GeometryMode != g ) {
782 gmesa->GeometryMode = g;
783 gmesa->dirty |= GAMMA_UPLOAD_GEOMETRY;
784 }
785 }
786
787 static void gammaDDCullFace( GLcontext *ctx, GLenum mode )
788 {
789 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
790
791 FLUSH_BATCH( gmesa );
792 gmesa->new_state |= GAMMA_NEW_CULL;
793 }
794
795 static void gammaDDFrontFace( GLcontext *ctx, GLenum mode )
796 {
797 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
798
799 FLUSH_BATCH( gmesa );
800 gmesa->new_state |= GAMMA_NEW_CULL;
801 }
802
803 /* =============================================================
804 * Masks
805 */
806
807 static void gammaUpdateMasks( GLcontext *ctx )
808 {
809 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
810
811
812 GLuint mask = gammaPackColor( gmesa->gammaScreen->cpp,
813 ctx->Color.ColorMask[RCOMP],
814 ctx->Color.ColorMask[GCOMP],
815 ctx->Color.ColorMask[BCOMP],
816 ctx->Color.ColorMask[ACOMP] );
817
818 if (gmesa->gammaScreen->cpp == 2) mask |= mask << 16;
819
820 if ( gmesa->FBHardwareWriteMask != mask ) {
821 gmesa->FBHardwareWriteMask = mask;
822 gmesa->dirty |= GAMMA_UPLOAD_MASKS;
823 }
824 }
825
826 static void gammaDDColorMask( GLcontext *ctx, GLboolean r, GLboolean g,
827 GLboolean b, GLboolean a)
828 {
829 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
830
831 FLUSH_BATCH( gmesa );
832 gmesa->new_state |= GAMMA_NEW_MASKS;
833 }
834
835 /* =============================================================
836 * Rendering attributes
837 *
838 * We really don't want to recalculate all this every time we bind a
839 * texture. These things shouldn't change all that often, so it makes
840 * sense to break them out of the core texture state update routines.
841 */
842
843 #if ENABLELIGHTING
844 static void gammaDDLightfv(GLcontext *ctx, GLenum light, GLenum pname,
845 const GLfloat *params, GLint nParams)
846 {
847 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
848 GLfloat l,x,y,z,w;
849
850 switch(light) {
851 case GL_LIGHT0:
852 switch (pname) {
853 case GL_AMBIENT:
854 CHECK_DMA_BUFFER(gmesa, 3);
855 /* We don't do alpha */
856 WRITEF(gmesa->buf, Light0AmbientIntensityBlue, params[2]);
857 WRITEF(gmesa->buf, Light0AmbientIntensityGreen, params[1]);
858 WRITEF(gmesa->buf, Light0AmbientIntensityRed, params[0]);
859 break;
860 case GL_DIFFUSE:
861 CHECK_DMA_BUFFER(gmesa, 3);
862 /* We don't do alpha */
863 WRITEF(gmesa->buf, Light0DiffuseIntensityBlue, params[2]);
864 WRITEF(gmesa->buf, Light0DiffuseIntensityGreen, params[1]);
865 WRITEF(gmesa->buf, Light0DiffuseIntensityRed, params[0]);
866 break;
867 case GL_SPECULAR:
868 CHECK_DMA_BUFFER(gmesa, 3);
869 /* We don't do alpha */
870 WRITEF(gmesa->buf, Light0SpecularIntensityBlue, params[2]);
871 WRITEF(gmesa->buf, Light0SpecularIntensityGreen, params[1]);
872 WRITEF(gmesa->buf, Light0SpecularIntensityRed, params[0]);
873 break;
874 case GL_POSITION:
875 /* Normalize <x,y,z> */
876 x = params[0]; y = params[1]; z = params[2]; w = params[3];
877 l = sqrt(x*x + y*y + z*z + w*w);
878 w /= l;
879 x /= l;
880 y /= l;
881 z /= l;
882 if (params[3] != 0.0) {
883 gmesa->Light0Mode |= Light0ModeAttenuation;
884 gmesa->Light0Mode |= Light0ModeLocal;
885 } else {
886 gmesa->Light0Mode &= ~Light0ModeAttenuation;
887 gmesa->Light0Mode &= ~Light0ModeLocal;
888 }
889 CHECK_DMA_BUFFER(gmesa, 5);
890 WRITE(gmesa->buf, Light0Mode, gmesa->Light0Mode);
891 WRITEF(gmesa->buf, Light0PositionW, w);
892 WRITEF(gmesa->buf, Light0PositionZ, z);
893 WRITEF(gmesa->buf, Light0PositionY, y);
894 WRITEF(gmesa->buf, Light0PositionX, x);
895 break;
896 case GL_SPOT_DIRECTION:
897 CHECK_DMA_BUFFER(gmesa, 3);
898 /* WRITEF(gmesa->buf, Light0SpotlightDirectionW, params[3]); */
899 WRITEF(gmesa->buf, Light0SpotlightDirectionZ, params[2]);
900 WRITEF(gmesa->buf, Light0SpotlightDirectionY, params[1]);
901 WRITEF(gmesa->buf, Light0SpotlightDirectionX, params[0]);
902 break;
903 case GL_SPOT_EXPONENT:
904 CHECK_DMA_BUFFER(gmesa, 1);
905 WRITEF(gmesa->buf, Light0SpotlightExponent, params[0]);
906 break;
907 case GL_SPOT_CUTOFF:
908 if (params[0] != 180.0)
909 gmesa->Light0Mode |= Light0ModeSpotLight;
910 else
911 gmesa->Light0Mode &= ~Light0ModeSpotLight;
912 CHECK_DMA_BUFFER(gmesa, 2);
913 WRITE(gmesa->buf, Light0Mode, gmesa->Light0Mode);
914 WRITEF(gmesa->buf, Light0CosSpotlightCutoffAngle, cos(params[0]*DEG2RAD));
915 break;
916 case GL_CONSTANT_ATTENUATION:
917 CHECK_DMA_BUFFER(gmesa, 1);
918 WRITEF(gmesa->buf, Light0ConstantAttenuation, params[0]);
919 break;
920 case GL_LINEAR_ATTENUATION:
921 CHECK_DMA_BUFFER(gmesa, 1);
922 WRITEF(gmesa->buf, Light0LinearAttenuation, params[0]);
923 break;
924 case GL_QUADRATIC_ATTENUATION:
925 CHECK_DMA_BUFFER(gmesa, 1);
926 WRITEF(gmesa->buf, Light0QuadraticAttenuation, params[0]);
927 break;
928 }
929 break;
930 }
931 }
932
933 static void gammaDDLightModelfv( GLcontext *ctx, GLenum pname,
934 const GLfloat *params )
935 {
936 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
937
938 switch (pname) {
939 case GL_LIGHT_MODEL_AMBIENT:
940 CHECK_DMA_BUFFER(gmesa, 3);
941 /* We don't do alpha */
942 WRITEF(gmesa->buf, SceneAmbientColorBlue, params[2]);
943 WRITEF(gmesa->buf, SceneAmbientColorGreen, params[1]);
944 WRITEF(gmesa->buf, SceneAmbientColorRed, params[0]);
945 break;
946 case GL_LIGHT_MODEL_LOCAL_VIEWER:
947 if (params[0] != 0.0)
948 gmesa->LightingMode |= LightingModeLocalViewer;
949 else
950 gmesa->LightingMode &= ~LightingModeLocalViewer;
951 CHECK_DMA_BUFFER(gmesa, 1);
952 WRITE(gmesa->buf, LightingMode, gmesa->LightingMode);
953 break;
954 case GL_LIGHT_MODEL_TWO_SIDE:
955 if (params[0] == 1.0f) {
956 gmesa->LightingMode |= LightingModeTwoSides;
957 gmesa->MaterialMode |= MaterialModeTwoSides;
958 } else {
959 gmesa->LightingMode &= ~LightingModeTwoSides;
960 gmesa->MaterialMode &= ~MaterialModeTwoSides;
961 }
962 CHECK_DMA_BUFFER(gmesa, 2);
963 WRITE(gmesa->buf, LightingMode, gmesa->LightingMode);
964 WRITE(gmesa->buf, MaterialMode, gmesa->MaterialMode);
965 break;
966 }
967 }
968 #endif
969
970 static void gammaDDShadeModel( GLcontext *ctx, GLenum mode )
971 {
972 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
973 CARD32 g = gmesa->GeometryMode;
974 CARD32 c = gmesa->ColorDDAMode;
975
976 g &= ~GM_ShadingMask;
977 c &= ~ColorDDAShadingMask;
978
979 switch ( mode ) {
980 case GL_FLAT:
981 g |= GM_FlatShading;
982 c |= ColorDDAFlat;
983 break;
984 case GL_SMOOTH:
985 g |= GM_GouraudShading;
986 c |= ColorDDAGouraud;
987 break;
988 default:
989 return;
990 }
991
992 if ( gmesa->ColorDDAMode != c ) {
993 FLUSH_BATCH( gmesa );
994 gmesa->ColorDDAMode = c;
995
996 gmesa->dirty |= GAMMA_UPLOAD_SHADE;
997 }
998
999 if ( gmesa->GeometryMode != g ) {
1000 FLUSH_BATCH( gmesa );
1001 gmesa->GeometryMode = g;
1002
1003 gmesa->dirty |= GAMMA_UPLOAD_GEOMETRY;
1004 }
1005 }
1006
1007 /* =============================================================
1008 * Miscellaneous
1009 */
1010
1011 static void gammaDDClearColor( GLcontext *ctx, const GLfloat color[4])
1012 {
1013 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1014 GLubyte c[4];
1015 UNCLAMPED_FLOAT_TO_UBYTE(c[0], color[0]);
1016 UNCLAMPED_FLOAT_TO_UBYTE(c[1], color[1]);
1017 UNCLAMPED_FLOAT_TO_UBYTE(c[2], color[2]);
1018 UNCLAMPED_FLOAT_TO_UBYTE(c[3], color[3]);
1019
1020 gmesa->ClearColor = gammaPackColor( gmesa->gammaScreen->cpp,
1021 c[0], c[1], c[2], c[3] );
1022
1023 if (gmesa->gammaScreen->cpp == 2) gmesa->ClearColor |= gmesa->ClearColor<<16;
1024 }
1025
1026
1027 static void gammaDDLogicalOpcode( GLcontext *ctx, GLenum opcode )
1028 {
1029 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1030
1031 FLUSH_BATCH( gmesa );
1032
1033 if ( ctx->Color.ColorLogicOpEnabled ) {
1034 gmesa->LogicalOpMode = opcode << 1 | LogicalOpModeEnable;
1035 } else {
1036 gmesa->LogicalOpMode = LogicalOpModeDisable;
1037 }
1038
1039 gmesa->dirty |= GAMMA_UPLOAD_LOGICOP;
1040 }
1041
1042 static void gammaDDDrawBuffer( GLcontext *ctx, GLenum mode )
1043 {
1044 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1045
1046 FLUSH_BATCH( gmesa );
1047
1048 switch ( mode ) {
1049 case GL_FRONT_LEFT:
1050 gmesa->drawOffset = gmesa->readOffset = 0;
1051 break;
1052 case GL_BACK_LEFT:
1053 gmesa->drawOffset = gmesa->readOffset = gmesa->driScreen->fbHeight * gmesa->driScreen->fbWidth * gmesa->gammaScreen->cpp;
1054 break;
1055 }
1056 }
1057
1058 static void gammaDDReadBuffer( GLcontext *ctx, GLenum mode )
1059 {
1060 /* XXX anything? */
1061 }
1062
1063 /* =============================================================
1064 * Window position and viewport transformation
1065 */
1066
1067 void gammaUpdateWindow( GLcontext *ctx )
1068 {
1069 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1070 __DRIdrawablePrivate *dPriv = gmesa->driDrawable;
1071 GLfloat xoffset = (GLfloat)dPriv->x;
1072 GLfloat yoffset = gmesa->driScreen->fbHeight - (GLfloat)dPriv->y - dPriv->h;
1073 const GLfloat *v = ctx->Viewport._WindowMap.m;
1074
1075 GLfloat sx = v[MAT_SX];
1076 GLfloat tx = v[MAT_TX] + xoffset;
1077 GLfloat sy = v[MAT_SY];
1078 GLfloat ty = v[MAT_TY] + yoffset;
1079 GLfloat sz = v[MAT_SZ] * gmesa->depth_scale;
1080 GLfloat tz = v[MAT_TZ] * gmesa->depth_scale;
1081
1082 gmesa->dirty |= GAMMA_UPLOAD_VIEWPORT;
1083
1084 gmesa->ViewportScaleX = sx;
1085 gmesa->ViewportScaleY = sy;
1086 gmesa->ViewportScaleZ = sz;
1087 gmesa->ViewportOffsetX = tx;
1088 gmesa->ViewportOffsetY = ty;
1089 gmesa->ViewportOffsetZ = tz;
1090 }
1091
1092
1093
1094 static void gammaDDViewport( GLcontext *ctx, GLint x, GLint y,
1095 GLsizei width, GLsizei height )
1096 {
1097 gammaUpdateWindow( ctx );
1098 }
1099
1100 static void gammaDDDepthRange( GLcontext *ctx, GLclampd nearval,
1101 GLclampd farval )
1102 {
1103 gammaUpdateWindow( ctx );
1104 }
1105
1106 void gammaUpdateViewportOffset( GLcontext *ctx )
1107 {
1108 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1109 __DRIdrawablePrivate *dPriv = gmesa->driDrawable;
1110 GLfloat xoffset = (GLfloat)dPriv->x;
1111 GLfloat yoffset = gmesa->driScreen->fbHeight - (GLfloat)dPriv->y - dPriv->h;
1112 const GLfloat *v = ctx->Viewport._WindowMap.m;
1113
1114 GLfloat tx = v[MAT_TX] + xoffset;
1115 GLfloat ty = v[MAT_TY] + yoffset;
1116
1117 if ( gmesa->ViewportOffsetX != tx ||
1118 gmesa->ViewportOffsetY != ty )
1119 {
1120 gmesa->ViewportOffsetX = tx;
1121 gmesa->ViewportOffsetY = ty;
1122
1123 gmesa->new_state |= GAMMA_NEW_WINDOW;
1124 }
1125
1126 gmesa->new_state |= GAMMA_NEW_CLIP;
1127 }
1128
1129 #if 0
1130 /*
1131 * Matrix
1132 */
1133
1134 static void gammaLoadHWMatrix(GLcontext *ctx)
1135 {
1136 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1137 const GLfloat *m;
1138
1139 gmesa->TransformMode &= ~XM_XformTexture;
1140
1141 switch (ctx->Transform.MatrixMode) {
1142 case GL_MODELVIEW:
1143 gmesa->TransformMode |= XM_UseModelViewMatrix;
1144 m = ctx->ModelviewMatrixStack.Top->m;
1145 CHECK_DMA_BUFFER(gmesa, 16);
1146 WRITEF(gmesa->buf, ModelViewMatrix0, m[0]);
1147 WRITEF(gmesa->buf, ModelViewMatrix1, m[1]);
1148 WRITEF(gmesa->buf, ModelViewMatrix2, m[2]);
1149 WRITEF(gmesa->buf, ModelViewMatrix3, m[3]);
1150 WRITEF(gmesa->buf, ModelViewMatrix4, m[4]);
1151 WRITEF(gmesa->buf, ModelViewMatrix5, m[5]);
1152 WRITEF(gmesa->buf, ModelViewMatrix6, m[6]);
1153 WRITEF(gmesa->buf, ModelViewMatrix7, m[7]);
1154 WRITEF(gmesa->buf, ModelViewMatrix8, m[8]);
1155 WRITEF(gmesa->buf, ModelViewMatrix9, m[9]);
1156 WRITEF(gmesa->buf, ModelViewMatrix10, m[10]);
1157 WRITEF(gmesa->buf, ModelViewMatrix11, m[11]);
1158 WRITEF(gmesa->buf, ModelViewMatrix12, m[12]);
1159 WRITEF(gmesa->buf, ModelViewMatrix13, m[13]);
1160 WRITEF(gmesa->buf, ModelViewMatrix14, m[14]);
1161 WRITEF(gmesa->buf, ModelViewMatrix15, m[15]);
1162 break;
1163 case GL_PROJECTION:
1164 m = ctx->ProjectionMatrixStack.Top->m;
1165 CHECK_DMA_BUFFER(gmesa, 16);
1166 WRITEF(gmesa->buf, ModelViewProjectionMatrix0, m[0]);
1167 WRITEF(gmesa->buf, ModelViewProjectionMatrix1, m[1]);
1168 WRITEF(gmesa->buf, ModelViewProjectionMatrix2, m[2]);
1169 WRITEF(gmesa->buf, ModelViewProjectionMatrix3, m[3]);
1170 WRITEF(gmesa->buf, ModelViewProjectionMatrix4, m[4]);
1171 WRITEF(gmesa->buf, ModelViewProjectionMatrix5, m[5]);
1172 WRITEF(gmesa->buf, ModelViewProjectionMatrix6, m[6]);
1173 WRITEF(gmesa->buf, ModelViewProjectionMatrix7, m[7]);
1174 WRITEF(gmesa->buf, ModelViewProjectionMatrix8, m[8]);
1175 WRITEF(gmesa->buf, ModelViewProjectionMatrix9, m[9]);
1176 WRITEF(gmesa->buf, ModelViewProjectionMatrix10, m[10]);
1177 WRITEF(gmesa->buf, ModelViewProjectionMatrix11, m[11]);
1178 WRITEF(gmesa->buf, ModelViewProjectionMatrix12, m[12]);
1179 WRITEF(gmesa->buf, ModelViewProjectionMatrix13, m[13]);
1180 WRITEF(gmesa->buf, ModelViewProjectionMatrix14, m[14]);
1181 WRITEF(gmesa->buf, ModelViewProjectionMatrix15, m[15]);
1182 break;
1183 case GL_TEXTURE:
1184 m = ctx->TextureMatrixStack[0].Top->m;
1185 CHECK_DMA_BUFFER(gmesa, 16);
1186 gmesa->TransformMode |= XM_XformTexture;
1187 WRITEF(gmesa->buf, TextureMatrix0, m[0]);
1188 WRITEF(gmesa->buf, TextureMatrix1, m[1]);
1189 WRITEF(gmesa->buf, TextureMatrix2, m[2]);
1190 WRITEF(gmesa->buf, TextureMatrix3, m[3]);
1191 WRITEF(gmesa->buf, TextureMatrix4, m[4]);
1192 WRITEF(gmesa->buf, TextureMatrix5, m[5]);
1193 WRITEF(gmesa->buf, TextureMatrix6, m[6]);
1194 WRITEF(gmesa->buf, TextureMatrix7, m[7]);
1195 WRITEF(gmesa->buf, TextureMatrix8, m[8]);
1196 WRITEF(gmesa->buf, TextureMatrix9, m[9]);
1197 WRITEF(gmesa->buf, TextureMatrix10, m[10]);
1198 WRITEF(gmesa->buf, TextureMatrix11, m[11]);
1199 WRITEF(gmesa->buf, TextureMatrix12, m[12]);
1200 WRITEF(gmesa->buf, TextureMatrix13, m[13]);
1201 WRITEF(gmesa->buf, TextureMatrix14, m[14]);
1202 WRITEF(gmesa->buf, TextureMatrix15, m[15]);
1203 break;
1204
1205 default:
1206 /* ERROR!!! -- how did this happen? */
1207 break;
1208 }
1209
1210 gmesa->dirty |= GAMMA_UPLOAD_TRANSFORM;
1211 }
1212 #endif
1213
1214 /* =============================================================
1215 * State enable/disable
1216 */
1217
1218 static void gammaDDEnable( GLcontext *ctx, GLenum cap, GLboolean state )
1219 {
1220 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1221
1222 switch ( cap ) {
1223 case GL_ALPHA_TEST:
1224 case GL_BLEND:
1225 FLUSH_BATCH( gmesa );
1226 gmesa->new_state |= GAMMA_NEW_ALPHA;
1227 break;
1228
1229 case GL_CULL_FACE:
1230 FLUSH_BATCH( gmesa );
1231 gmesa->new_state |= GAMMA_NEW_CULL;
1232 break;
1233
1234 case GL_DEPTH_TEST:
1235 FLUSH_BATCH( gmesa );
1236 gmesa->new_state |= GAMMA_NEW_DEPTH;
1237 break;
1238
1239 case GL_DITHER:
1240 do {
1241 CARD32 d = gmesa->DitherMode;
1242 FLUSH_BATCH( gmesa );
1243
1244 if ( state ) {
1245 d |= DM_DitherEnable;
1246 } else {
1247 d &= ~DM_DitherEnable;
1248 }
1249
1250 if ( gmesa->DitherMode != d ) {
1251 gmesa->DitherMode = d;
1252 gmesa->dirty |= GAMMA_UPLOAD_DITHER;
1253 }
1254 } while (0);
1255 break;
1256
1257 #if 0
1258 case GL_FOG:
1259 FLUSH_BATCH( gmesa );
1260 gmesa->new_state |= GAMMA_NEW_FOG;
1261 break;
1262 #endif
1263
1264 case GL_INDEX_LOGIC_OP:
1265 case GL_COLOR_LOGIC_OP:
1266 FLUSH_BATCH( gmesa );
1267 gmesa->new_state |= GAMMA_NEW_LOGICOP;
1268 break;
1269
1270 #if ENABLELIGHTING
1271 case GL_LIGHTING:
1272 do {
1273 CARD32 l = gmesa->LightingMode;
1274 FLUSH_BATCH( gmesa );
1275
1276 if ( state ) {
1277 l |= LightingModeEnable;
1278 } else {
1279 l &= ~LightingModeEnable;
1280 }
1281
1282 if ( gmesa->LightingMode != l ) {
1283 gmesa->LightingMode = l;
1284 gmesa->dirty |= GAMMA_UPLOAD_LIGHT;
1285 }
1286 } while (0);
1287 break;
1288
1289 case GL_COLOR_MATERIAL:
1290 do {
1291 CARD32 m = gmesa->MaterialMode;
1292 FLUSH_BATCH( gmesa );
1293
1294 if ( state ) {
1295 m |= MaterialModeEnable;
1296 } else {
1297 m &= ~MaterialModeEnable;
1298 }
1299
1300 if ( gmesa->MaterialMode != m ) {
1301 gmesa->MaterialMode = m;
1302 gmesa->dirty |= GAMMA_UPLOAD_LIGHT;
1303 }
1304 } while (0);
1305 break;
1306 #endif
1307
1308 case GL_LINE_SMOOTH:
1309 FLUSH_BATCH( gmesa );
1310 if ( state ) {
1311 gmesa->AntialiasMode |= AntialiasModeEnable;
1312 gmesa->LineMode |= LM_AntialiasEnable;
1313 } else {
1314 gmesa->AntialiasMode &= ~AntialiasModeEnable;
1315 gmesa->LineMode &= ~LM_AntialiasEnable;
1316 }
1317 gmesa->dirty |= GAMMA_UPLOAD_LINEMODE;
1318 break;
1319
1320 case GL_POINT_SMOOTH:
1321 FLUSH_BATCH( gmesa );
1322 if ( state ) {
1323 gmesa->AntialiasMode |= AntialiasModeEnable;
1324 gmesa->PointMode |= PM_AntialiasEnable;
1325 } else {
1326 gmesa->AntialiasMode &= ~AntialiasModeEnable;
1327 gmesa->PointMode &= ~PM_AntialiasEnable;
1328 }
1329 gmesa->dirty |= GAMMA_UPLOAD_POINTMODE;
1330 break;
1331
1332 case GL_POLYGON_SMOOTH:
1333 FLUSH_BATCH( gmesa );
1334 if ( state ) {
1335 gmesa->AntialiasMode |= AntialiasModeEnable;
1336 gmesa->TriangleMode |= TM_AntialiasEnable;
1337 } else {
1338 gmesa->AntialiasMode &= ~AntialiasModeEnable;
1339 gmesa->TriangleMode &= ~TM_AntialiasEnable;
1340 }
1341 gmesa->dirty |= GAMMA_UPLOAD_TRIMODE;
1342 break;
1343
1344 case GL_SCISSOR_TEST:
1345 FLUSH_BATCH( gmesa );
1346 gmesa->new_state |= GAMMA_NEW_CLIP;
1347 break;
1348
1349 case GL_POLYGON_OFFSET_FILL:
1350 case GL_POLYGON_OFFSET_POINT:
1351 case GL_POLYGON_OFFSET_LINE:
1352 FLUSH_BATCH( gmesa );
1353 gmesa->new_state |= GAMMA_NEW_POLYGON;
1354 break;
1355
1356 case GL_LINE_STIPPLE:
1357 FLUSH_BATCH( gmesa );
1358 if ( state )
1359 gmesa->LineMode |= LM_StippleEnable;
1360 else
1361 gmesa->LineMode &= ~LM_StippleEnable;
1362 gmesa->dirty |= GAMMA_UPLOAD_LINEMODE;
1363 break;
1364
1365 case GL_POLYGON_STIPPLE:
1366 FLUSH_BATCH( gmesa );
1367 gmesa->new_state |= GAMMA_NEW_STIPPLE;
1368 break;
1369
1370 default:
1371 return;
1372 }
1373 }
1374
1375 /* =============================================================
1376 * State initialization, management
1377 */
1378
1379
1380 /*
1381 * Load the current context's state into the hardware.
1382 *
1383 * NOTE: Be VERY careful about ensuring the context state is marked for
1384 * upload, the only place it shouldn't be uploaded is when the setup
1385 * state has changed in ReducedPrimitiveChange as this comes right after
1386 * a state update.
1387 *
1388 * Blits of any type should always upload the context and masks after
1389 * they are done.
1390 */
1391 void gammaEmitHwState( gammaContextPtr gmesa )
1392 {
1393 if (!gmesa->driDrawable) return;
1394
1395 if (!gmesa->dirty) return;
1396
1397 #ifdef DO_VALIDATE
1398 /* Flush any partially filled buffers */
1399 FLUSH_DMA_BUFFER(gmesa);
1400
1401 DRM_SPINLOCK(&gmesa->driScreen->pSAREA->drawable_lock,
1402 gmesa->driScreen->drawLockID);
1403 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa);
1404 #endif
1405
1406 if (gmesa->dirty & GAMMA_UPLOAD_VIEWPORT) {
1407 gmesa->dirty &= ~GAMMA_UPLOAD_VIEWPORT;
1408 CHECK_DMA_BUFFER(gmesa, 6);
1409 WRITEF(gmesa->buf, ViewPortOffsetX, gmesa->ViewportOffsetX);
1410 WRITEF(gmesa->buf, ViewPortOffsetY, gmesa->ViewportOffsetY);
1411 WRITEF(gmesa->buf, ViewPortOffsetZ, gmesa->ViewportOffsetZ);
1412 WRITEF(gmesa->buf, ViewPortScaleX, gmesa->ViewportScaleX);
1413 WRITEF(gmesa->buf, ViewPortScaleY, gmesa->ViewportScaleY);
1414 WRITEF(gmesa->buf, ViewPortScaleZ, gmesa->ViewportScaleZ);
1415 }
1416 if ( (gmesa->dirty & GAMMA_UPLOAD_POINTMODE) ||
1417 (gmesa->dirty & GAMMA_UPLOAD_LINEMODE) ||
1418 (gmesa->dirty & GAMMA_UPLOAD_TRIMODE) ) {
1419 CHECK_DMA_BUFFER(gmesa, 1);
1420 WRITE(gmesa->buf, AntialiasMode, gmesa->AntialiasMode);
1421 }
1422 if (gmesa->dirty & GAMMA_UPLOAD_POINTMODE) {
1423 gmesa->dirty &= ~GAMMA_UPLOAD_POINTMODE;
1424 CHECK_DMA_BUFFER(gmesa, 1);
1425 WRITE(gmesa->buf, PointMode, gmesa->PointMode);
1426 }
1427 if (gmesa->dirty & GAMMA_UPLOAD_LINEMODE) {
1428 gmesa->dirty &= ~GAMMA_UPLOAD_LINEMODE;
1429 CHECK_DMA_BUFFER(gmesa, 2);
1430 WRITE(gmesa->buf, LineMode, gmesa->LineMode);
1431 WRITE(gmesa->buf, LineStippleMode, gmesa->LineMode);
1432 }
1433 if (gmesa->dirty & GAMMA_UPLOAD_TRIMODE) {
1434 gmesa->dirty &= ~GAMMA_UPLOAD_TRIMODE;
1435 CHECK_DMA_BUFFER(gmesa, 1);
1436 WRITE(gmesa->buf, TriangleMode, gmesa->TriangleMode);
1437 }
1438 if (gmesa->dirty & GAMMA_UPLOAD_FOG) {
1439 GLchan c[3], col;
1440 UNCLAMPED_FLOAT_TO_RGB_CHAN( c, gmesa->glCtx->Fog.Color );
1441 col = gammaPackColor(4, c[0], c[1], c[2], 0);
1442 gmesa->dirty &= ~GAMMA_UPLOAD_FOG;
1443 CHECK_DMA_BUFFER(gmesa, 5);
1444 #if 0
1445 WRITE(gmesa->buf, FogMode, gmesa->FogMode);
1446 WRITE(gmesa->buf, FogColor, col);
1447 WRITEF(gmesa->buf, FStart, gmesa->glCtx->Fog.Start);
1448 #endif
1449 WRITEF(gmesa->buf, FogEnd, gmesa->glCtx->Fog.End);
1450 WRITEF(gmesa->buf, FogDensity, gmesa->glCtx->Fog.Density);
1451 WRITEF(gmesa->buf, FogScale,
1452 1.0f/(gmesa->glCtx->Fog.End - gmesa->glCtx->Fog.Start));
1453 }
1454 if (gmesa->dirty & GAMMA_UPLOAD_DITHER) {
1455 gmesa->dirty &= ~GAMMA_UPLOAD_DITHER;
1456 CHECK_DMA_BUFFER(gmesa, 1);
1457 WRITE(gmesa->buf, DitherMode, gmesa->DitherMode);
1458 }
1459 if (gmesa->dirty & GAMMA_UPLOAD_LOGICOP) {
1460 gmesa->dirty &= ~GAMMA_UPLOAD_LOGICOP;
1461 CHECK_DMA_BUFFER(gmesa, 1);
1462 WRITE(gmesa->buf, LogicalOpMode, gmesa->LogicalOpMode);
1463 }
1464 if (gmesa->dirty & GAMMA_UPLOAD_CLIP) {
1465 gmesa->dirty &= ~GAMMA_UPLOAD_CLIP;
1466 CHECK_DMA_BUFFER(gmesa, 3);
1467 WRITE(gmesa->buf, ScissorMinXY, gmesa->ScissorMinXY);
1468 WRITE(gmesa->buf, ScissorMaxXY, gmesa->ScissorMaxXY);
1469 WRITE(gmesa->buf, ScissorMode, gmesa->ScissorMode);
1470 }
1471 if (gmesa->dirty & GAMMA_UPLOAD_MASKS) {
1472 gmesa->dirty &= ~GAMMA_UPLOAD_MASKS;
1473 CHECK_DMA_BUFFER(gmesa, 1);
1474 WRITE(gmesa->buf, FBHardwareWriteMask, gmesa->FBHardwareWriteMask);
1475 }
1476 if (gmesa->dirty & GAMMA_UPLOAD_ALPHA) {
1477 gmesa->dirty &= ~GAMMA_UPLOAD_ALPHA;
1478 CHECK_DMA_BUFFER(gmesa, 1);
1479 WRITE(gmesa->buf, AlphaTestMode, gmesa->AlphaTestMode);
1480 }
1481 if (gmesa->dirty & GAMMA_UPLOAD_BLEND) {
1482 gmesa->dirty &= ~GAMMA_UPLOAD_BLEND;
1483 CHECK_DMA_BUFFER(gmesa, 1);
1484 WRITE(gmesa->buf, AlphaBlendMode, gmesa->AlphaBlendMode);
1485 }
1486 CHECK_DMA_BUFFER(gmesa, 1);
1487 if (gmesa->glCtx->Color.BlendEnabled || gmesa->glCtx->Color.AlphaEnabled) {
1488 WRITE(gmesa->buf, FBReadMode, gmesa->FBReadMode | gmesa->AB_FBReadMode_Save);
1489 } else {
1490 WRITE(gmesa->buf, FBReadMode, gmesa->FBReadMode);
1491 }
1492 if (gmesa->dirty & GAMMA_UPLOAD_LIGHT) {
1493 gmesa->dirty &= ~GAMMA_UPLOAD_LIGHT;
1494 CHECK_DMA_BUFFER(gmesa, 2);
1495 WRITE(gmesa->buf, LightingMode, gmesa->LightingMode);
1496 WRITE(gmesa->buf, MaterialMode, gmesa->MaterialMode);
1497 }
1498 if (gmesa->dirty & GAMMA_UPLOAD_SHADE) {
1499 gmesa->dirty &= ~GAMMA_UPLOAD_SHADE;
1500 CHECK_DMA_BUFFER(gmesa, 1);
1501 WRITE(gmesa->buf, ColorDDAMode, gmesa->ColorDDAMode);
1502 }
1503 if (gmesa->dirty & GAMMA_UPLOAD_POLYGON) {
1504 gmesa->dirty &= ~GAMMA_UPLOAD_POLYGON;
1505 CHECK_DMA_BUFFER(gmesa, 2);
1506 WRITEF(gmesa->buf, PolygonOffsetBias, gmesa->glCtx->Polygon.OffsetUnits);
1507 WRITEF(gmesa->buf, PolygonOffsetFactor, gmesa->glCtx->Polygon.OffsetFactor);
1508 }
1509 if (gmesa->dirty & GAMMA_UPLOAD_STIPPLE) {
1510 gmesa->dirty &= ~GAMMA_UPLOAD_STIPPLE;
1511 CHECK_DMA_BUFFER(gmesa, 33);
1512 WRITE(gmesa->buf, AreaStippleMode, gmesa->AreaStippleMode);
1513 WRITE(gmesa->buf, AreaStipplePattern0, gmesa->glCtx->PolygonStipple[0]);
1514 WRITE(gmesa->buf, AreaStipplePattern1, gmesa->glCtx->PolygonStipple[1]);
1515 WRITE(gmesa->buf, AreaStipplePattern2, gmesa->glCtx->PolygonStipple[2]);
1516 WRITE(gmesa->buf, AreaStipplePattern3, gmesa->glCtx->PolygonStipple[3]);
1517 WRITE(gmesa->buf, AreaStipplePattern4, gmesa->glCtx->PolygonStipple[4]);
1518 WRITE(gmesa->buf, AreaStipplePattern5, gmesa->glCtx->PolygonStipple[5]);
1519 WRITE(gmesa->buf, AreaStipplePattern6, gmesa->glCtx->PolygonStipple[6]);
1520 WRITE(gmesa->buf, AreaStipplePattern7, gmesa->glCtx->PolygonStipple[7]);
1521 WRITE(gmesa->buf, AreaStipplePattern8, gmesa->glCtx->PolygonStipple[8]);
1522 WRITE(gmesa->buf, AreaStipplePattern9, gmesa->glCtx->PolygonStipple[9]);
1523 WRITE(gmesa->buf, AreaStipplePattern10, gmesa->glCtx->PolygonStipple[10]);
1524 WRITE(gmesa->buf, AreaStipplePattern11, gmesa->glCtx->PolygonStipple[11]);
1525 WRITE(gmesa->buf, AreaStipplePattern12, gmesa->glCtx->PolygonStipple[12]);
1526 WRITE(gmesa->buf, AreaStipplePattern13, gmesa->glCtx->PolygonStipple[13]);
1527 WRITE(gmesa->buf, AreaStipplePattern14, gmesa->glCtx->PolygonStipple[14]);
1528 WRITE(gmesa->buf, AreaStipplePattern15, gmesa->glCtx->PolygonStipple[15]);
1529 WRITE(gmesa->buf, AreaStipplePattern16, gmesa->glCtx->PolygonStipple[16]);
1530 WRITE(gmesa->buf, AreaStipplePattern17, gmesa->glCtx->PolygonStipple[17]);
1531 WRITE(gmesa->buf, AreaStipplePattern18, gmesa->glCtx->PolygonStipple[18]);
1532 WRITE(gmesa->buf, AreaStipplePattern19, gmesa->glCtx->PolygonStipple[19]);
1533 WRITE(gmesa->buf, AreaStipplePattern20, gmesa->glCtx->PolygonStipple[20]);
1534 WRITE(gmesa->buf, AreaStipplePattern21, gmesa->glCtx->PolygonStipple[21]);
1535 WRITE(gmesa->buf, AreaStipplePattern22, gmesa->glCtx->PolygonStipple[22]);
1536 WRITE(gmesa->buf, AreaStipplePattern23, gmesa->glCtx->PolygonStipple[23]);
1537 WRITE(gmesa->buf, AreaStipplePattern24, gmesa->glCtx->PolygonStipple[24]);
1538 WRITE(gmesa->buf, AreaStipplePattern25, gmesa->glCtx->PolygonStipple[25]);
1539 WRITE(gmesa->buf, AreaStipplePattern26, gmesa->glCtx->PolygonStipple[26]);
1540 WRITE(gmesa->buf, AreaStipplePattern27, gmesa->glCtx->PolygonStipple[27]);
1541 WRITE(gmesa->buf, AreaStipplePattern28, gmesa->glCtx->PolygonStipple[28]);
1542 WRITE(gmesa->buf, AreaStipplePattern29, gmesa->glCtx->PolygonStipple[29]);
1543 WRITE(gmesa->buf, AreaStipplePattern30, gmesa->glCtx->PolygonStipple[30]);
1544 WRITE(gmesa->buf, AreaStipplePattern31, gmesa->glCtx->PolygonStipple[31]);
1545 }
1546 if (gmesa->dirty & GAMMA_UPLOAD_DEPTH) {
1547 gmesa->dirty &= ~GAMMA_UPLOAD_DEPTH;
1548 CHECK_DMA_BUFFER(gmesa, 4);
1549 WRITE(gmesa->buf, DepthMode, gmesa->DepthMode);
1550 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode);
1551 WRITE(gmesa->buf, GLINTWindow,gmesa->Window | (gmesa->FrameCount << 9));
1552 WRITE(gmesa->buf, LBReadMode, gmesa->LBReadMode);
1553 }
1554 if (gmesa->dirty & GAMMA_UPLOAD_GEOMETRY) {
1555 gmesa->dirty &= ~GAMMA_UPLOAD_GEOMETRY;
1556 CHECK_DMA_BUFFER(gmesa, 1);
1557 WRITE(gmesa->buf, GeometryMode, gmesa->GeometryMode);
1558 }
1559 if (gmesa->dirty & GAMMA_UPLOAD_TRANSFORM) {
1560 gmesa->dirty &= ~GAMMA_UPLOAD_TRANSFORM;
1561 CHECK_DMA_BUFFER(gmesa, 1);
1562 WRITE(gmesa->buf, TransformMode, gmesa->TransformMode);
1563 }
1564 if (gmesa->dirty & GAMMA_UPLOAD_TEX0) {
1565 gammaTextureObjectPtr curTex = gmesa->CurrentTexObj[0];
1566 gmesa->dirty &= ~GAMMA_UPLOAD_TEX0;
1567 if (curTex) {
1568 CHECK_DMA_BUFFER(gmesa, 21);
1569 WRITE(gmesa->buf, GeometryMode, gmesa->GeometryMode | GM_TextureEnable);
1570 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode | DM_TextureEnable);
1571 WRITE(gmesa->buf, TextureAddressMode, curTex->TextureAddressMode);
1572 WRITE(gmesa->buf, TextureReadMode, curTex->TextureReadMode);
1573 WRITE(gmesa->buf, TextureColorMode, curTex->TextureColorMode);
1574 WRITE(gmesa->buf, TextureFilterMode, curTex->TextureFilterMode);
1575 WRITE(gmesa->buf, TextureFormat, curTex->TextureFormat);
1576 WRITE(gmesa->buf, GLINTBorderColor, curTex->TextureBorderColor);
1577 WRITE(gmesa->buf, TxBaseAddr0, curTex->TextureBaseAddr[0]);
1578 WRITE(gmesa->buf, TxBaseAddr1, curTex->TextureBaseAddr[1]);
1579 WRITE(gmesa->buf, TxBaseAddr2, curTex->TextureBaseAddr[2]);
1580 WRITE(gmesa->buf, TxBaseAddr3, curTex->TextureBaseAddr[3]);
1581 WRITE(gmesa->buf, TxBaseAddr4, curTex->TextureBaseAddr[4]);
1582 WRITE(gmesa->buf, TxBaseAddr5, curTex->TextureBaseAddr[5]);
1583 WRITE(gmesa->buf, TxBaseAddr6, curTex->TextureBaseAddr[6]);
1584 WRITE(gmesa->buf, TxBaseAddr7, curTex->TextureBaseAddr[7]);
1585 WRITE(gmesa->buf, TxBaseAddr8, curTex->TextureBaseAddr[8]);
1586 WRITE(gmesa->buf, TxBaseAddr9, curTex->TextureBaseAddr[9]);
1587 WRITE(gmesa->buf, TxBaseAddr10, curTex->TextureBaseAddr[10]);
1588 WRITE(gmesa->buf, TxBaseAddr11, curTex->TextureBaseAddr[11]);
1589 WRITE(gmesa->buf, TxBaseAddr12, curTex->TextureBaseAddr[12]);
1590 WRITE(gmesa->buf, TextureCacheControl, (TCC_Enable | TCC_Invalidate));
1591 } else {
1592 CHECK_DMA_BUFFER(gmesa, 6);
1593 WRITE(gmesa->buf, GeometryMode, gmesa->GeometryMode);
1594 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode);
1595 WRITE(gmesa->buf, TextureAddressMode, TextureAddressModeDisable);
1596 WRITE(gmesa->buf, TextureReadMode, TextureReadModeDisable);
1597 WRITE(gmesa->buf, TextureFilterMode, TextureFilterModeDisable);
1598 WRITE(gmesa->buf, TextureColorMode, TextureColorModeDisable);
1599 }
1600 }
1601 #ifdef DO_VALIDATE
1602 PROCESS_DMA_BUFFER_TOP_HALF(gmesa);
1603
1604 DRM_SPINUNLOCK(&gmesa->driScreen->pSAREA->drawable_lock,
1605 gmesa->driScreen->drawLockID);
1606 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa);
1607
1608 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa);
1609 #endif
1610 }
1611
1612 void gammaDDUpdateHWState( GLcontext *ctx )
1613 {
1614 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1615 int new_state = gmesa->new_state;
1616
1617 if ( new_state )
1618 {
1619 FLUSH_BATCH( gmesa );
1620
1621 gmesa->new_state = 0;
1622
1623 /* Update the various parts of the context's state.
1624 */
1625 if ( new_state & GAMMA_NEW_ALPHA )
1626 gammaUpdateAlphaMode( ctx );
1627
1628 if ( new_state & GAMMA_NEW_DEPTH )
1629 gammaUpdateZMode( ctx );
1630
1631 if ( new_state & GAMMA_NEW_FOG )
1632 gammaUpdateFogAttrib( ctx );
1633
1634 if ( new_state & GAMMA_NEW_CLIP )
1635 gammaUpdateClipping( ctx );
1636
1637 if ( new_state & GAMMA_NEW_POLYGON )
1638 gammaUpdatePolygon( ctx );
1639
1640 if ( new_state & GAMMA_NEW_CULL )
1641 gammaUpdateCull( ctx );
1642
1643 if ( new_state & GAMMA_NEW_MASKS )
1644 gammaUpdateMasks( ctx );
1645
1646 if ( new_state & GAMMA_NEW_WINDOW )
1647 gammaUpdateWindow( ctx );
1648
1649 if ( new_state & GAMMA_NEW_STIPPLE )
1650 gammaUpdateStipple( ctx );
1651 }
1652
1653 /* HACK ! */
1654
1655 gammaEmitHwState( gmesa );
1656 }
1657
1658
1659 static void gammaDDUpdateState( GLcontext *ctx, GLuint new_state )
1660 {
1661 _swrast_InvalidateState( ctx, new_state );
1662 _swsetup_InvalidateState( ctx, new_state );
1663 _ac_InvalidateState( ctx, new_state );
1664 _tnl_InvalidateState( ctx, new_state );
1665 GAMMA_CONTEXT(ctx)->new_gl_state |= new_state;
1666 }
1667
1668
1669 /* Initialize the context's hardware state.
1670 */
1671 void gammaDDInitState( gammaContextPtr gmesa )
1672 {
1673 gmesa->new_state = 0;
1674 }
1675
1676 /* Initialize the driver's state functions.
1677 */
1678 void gammaDDInitStateFuncs( GLcontext *ctx )
1679 {
1680 ctx->Driver.UpdateState = gammaDDUpdateState;
1681
1682 ctx->Driver.Clear = gammaDDClear;
1683 ctx->Driver.ClearIndex = NULL;
1684 ctx->Driver.ClearColor = gammaDDClearColor;
1685 ctx->Driver.DrawBuffer = gammaDDDrawBuffer;
1686 ctx->Driver.ReadBuffer = gammaDDReadBuffer;
1687
1688 ctx->Driver.IndexMask = NULL;
1689 ctx->Driver.ColorMask = gammaDDColorMask;
1690
1691 ctx->Driver.AlphaFunc = gammaDDAlphaFunc;
1692 ctx->Driver.BlendEquation = gammaDDBlendEquation;
1693 ctx->Driver.BlendFuncSeparate = gammaDDBlendFuncSeparate;
1694 ctx->Driver.ClearDepth = gammaDDClearDepth;
1695 ctx->Driver.CullFace = gammaDDCullFace;
1696 ctx->Driver.FrontFace = gammaDDFrontFace;
1697 ctx->Driver.DepthFunc = gammaDDDepthFunc;
1698 ctx->Driver.DepthMask = gammaDDDepthMask;
1699 ctx->Driver.DepthRange = gammaDDDepthRange;
1700 ctx->Driver.Enable = gammaDDEnable;
1701 ctx->Driver.Finish = gammaDDFinish;
1702 ctx->Driver.Flush = gammaDDFlush;
1703 #if 0
1704 ctx->Driver.Fogfv = gammaDDFogfv;
1705 #endif
1706 ctx->Driver.Hint = NULL;
1707 ctx->Driver.LineWidth = gammaDDLineWidth;
1708 ctx->Driver.LineStipple = gammaDDLineStipple;
1709 #if ENABLELIGHTING
1710 ctx->Driver.Lightfv = gammaDDLightfv;
1711 ctx->Driver.LightModelfv = gammaDDLightModelfv;
1712 #endif
1713 ctx->Driver.LogicOpcode = gammaDDLogicalOpcode;
1714 ctx->Driver.PointSize = gammaDDPointSize;
1715 ctx->Driver.PolygonMode = gammaDDPolygonMode;
1716 ctx->Driver.PolygonStipple = gammaDDPolygonStipple;
1717 ctx->Driver.Scissor = gammaDDScissor;
1718 ctx->Driver.ShadeModel = gammaDDShadeModel;
1719 ctx->Driver.ClearStencil = NULL;
1720 ctx->Driver.StencilFunc = NULL;
1721 ctx->Driver.StencilMask = NULL;
1722 ctx->Driver.StencilOp = NULL;
1723 ctx->Driver.Viewport = gammaDDViewport;
1724 }