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