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