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