1 /* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_state.c,v 1.5 2002/11/05 17:46:07 tsi Exp $ */
3 * Copyright 2001 by Alan Hourihane.
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.
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.
23 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
28 #include "gamma_context.h"
29 #include "gamma_macros.h"
31 #include "glint_dri.h"
33 #include "swrast/swrast.h"
34 #include "swrast_setup/swrast_setup.h"
35 #include "array_cache/acache.h"
38 #define ENABLELIGHTING 0
40 /* =============================================================
44 static void gammaUpdateAlphaMode( GLcontext
*ctx
)
46 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
47 CARD32 a
= gmesa
->AlphaTestMode
;
48 CARD32 b
= gmesa
->AlphaBlendMode
;
49 CARD32 f
= gmesa
->AB_FBReadMode_Save
= 0;
50 GLubyte refByte
= (GLint
) (ctx
->Color
.AlphaRef
* 255.0);
52 a
&= ~(AT_CompareMask
| AT_RefValueMask
);
53 b
&= ~(AB_SrcBlendMask
| AB_DstBlendMask
);
57 switch ( ctx
->Color
.AlphaFunc
) {
84 if ( ctx
->Color
.AlphaEnabled
) {
86 a
|= AlphaTestModeEnable
;
88 a
&= ~AlphaTestModeEnable
;
91 switch ( ctx
->Color
.BlendSrcRGB
) {
101 case GL_ONE_MINUS_DST_COLOR
:
102 b
|= AB_Src_OneMinusDstColor
;
105 b
|= AB_Src_SrcAlpha
;
107 case GL_ONE_MINUS_SRC_ALPHA
:
108 b
|= AB_Src_OneMinusSrcAlpha
;
111 b
|= AB_Src_DstAlpha
;
112 f
|= FBReadSrcEnable
;
114 case GL_ONE_MINUS_DST_ALPHA
:
115 b
|= AB_Src_OneMinusDstAlpha
;
116 f
|= FBReadSrcEnable
;
118 case GL_SRC_ALPHA_SATURATE
:
119 b
|= AB_Src_SrcAlphaSaturate
;
123 switch ( ctx
->Color
.BlendDstRGB
) {
131 b
|= AB_Dst_SrcColor
;
133 case GL_ONE_MINUS_SRC_COLOR
:
134 b
|= AB_Dst_OneMinusSrcColor
;
137 b
|= AB_Dst_SrcAlpha
;
139 case GL_ONE_MINUS_SRC_ALPHA
:
140 b
|= AB_Dst_OneMinusSrcAlpha
;
143 b
|= AB_Dst_DstAlpha
;
144 f
|= FBReadSrcEnable
;
146 case GL_ONE_MINUS_DST_ALPHA
:
147 b
|= AB_Dst_OneMinusDstAlpha
;
148 f
|= FBReadSrcEnable
;
152 if ( ctx
->Color
.BlendEnabled
) {
153 f
|= FBReadDstEnable
;
154 b
|= AlphaBlendModeEnable
;
156 b
&= ~AlphaBlendModeEnable
;
159 if ( gmesa
->AlphaTestMode
!= a
) {
160 gmesa
->AlphaTestMode
= a
;
161 gmesa
->dirty
|= GAMMA_UPLOAD_ALPHA
;
163 if ( gmesa
->AlphaBlendMode
!= b
) {
164 gmesa
->AlphaBlendMode
= b
;
165 gmesa
->dirty
|= GAMMA_UPLOAD_BLEND
;
167 gmesa
->AB_FBReadMode_Save
= f
;
170 static void gammaDDAlphaFunc( GLcontext
*ctx
, GLenum func
, GLfloat ref
)
172 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
175 FLUSH_BATCH( gmesa
);
177 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
180 static void gammaDDBlendEquation( GLcontext
*ctx
, GLenum mode
)
182 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
184 FLUSH_BATCH( gmesa
);
186 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
189 static void gammaDDBlendFuncSeparate( GLcontext
*ctx
,
190 GLenum sfactorRGB
, GLenum dfactorRGB
,
191 GLenum sfactorA
, GLenum dfactorA
)
193 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
195 FLUSH_BATCH( gmesa
);
197 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
201 /* ================================================================
205 static void gammaDDClear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
206 GLint cx
, GLint cy
, GLint cw
, GLint ch
)
208 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
209 GLINTDRIPtr gDRIPriv
= (GLINTDRIPtr
)gmesa
->driScreen
->pDevPriv
;
212 FLUSH_BATCH( gmesa
);
214 /* Update and emit any new state. We need to do this here to catch
215 * changes to the masks.
216 * FIXME: Just update the masks?
218 if ( gmesa
->new_state
)
219 gammaDDUpdateHWState( ctx
);
222 /* Flush any partially filled buffers */
223 FLUSH_DMA_BUFFER(gmesa
);
225 DRM_SPINLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
226 gmesa
->driScreen
->drawLockID
);
227 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa
);
230 if (mask
& DD_DEPTH_BIT
) {
231 /* Turn off writes the FB */
232 CHECK_DMA_BUFFER(gmesa
, 1);
233 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeDisable
);
235 mask
&= ~DD_DEPTH_BIT
;
238 * Turn Rectangle2DControl off when the window is not clipped
239 * (i.e., the GID tests are not necessary). This dramatically
240 * increases the performance of the depth clears.
242 if (!gmesa
->NotClipped
) {
243 CHECK_DMA_BUFFER(gmesa
, 1);
244 WRITE(gmesa
->buf
, Rectangle2DControl
, 1);
247 temp
= (gmesa
->LBReadMode
& LBPartialProdMask
) | LBWindowOriginBot
;
248 if (gDRIPriv
->numMultiDevices
== 2) temp
|= LBScanLineInt2
;
250 CHECK_DMA_BUFFER(gmesa
, 5);
251 WRITE(gmesa
->buf
, LBReadMode
, temp
);
252 WRITE(gmesa
->buf
, DeltaMode
, DM_DepthEnable
);
253 WRITE(gmesa
->buf
, DepthMode
, (DepthModeEnable
|
255 DM_SourceDepthRegister
|
257 WRITE(gmesa
->buf
, GLINTDepth
, gmesa
->ClearDepth
);
259 /* Increment the frame count */
262 gmesa
->FrameCount
&= 0x0f;
264 gmesa
->FrameCount
&= 0xff;
267 /* Force FCP to be written */
268 WRITE(gmesa
->buf
, GLINTWindow
, (WindowEnable
|
270 (gmesa
->Window
& W_GIDMask
) |
272 W_LBUpdateFromRegisters
|
273 W_OverrideWriteFiltering
|
274 (gmesa
->FrameCount
<< 9)));
276 /* Clear part of the depth and FCP buffers */
278 int y
= gmesa
->driScreen
->fbHeight
- gmesa
->driDrawable
->y
- gmesa
->driDrawable
->h
;
279 int x
= gmesa
->driDrawable
->x
;
280 int w
= gmesa
->driDrawable
->w
;
281 int h
= gmesa
->driDrawable
->h
;
285 if (gmesa
->WindowChanged
) {
286 gmesa
->WindowChanged
= GL_FALSE
;
294 /* Handle the case where the height < # of FCPs */
296 if (gmesa
->FrameCount
> h
)
297 gmesa
->FrameCount
= 0;
299 y
+= gmesa
->FrameCount
;
301 h
= (gmesa
->FrameCount
+1)*hsub
;
302 h
-= (int)(gmesa
->FrameCount
*hsub
);
303 y
+= gmesa
->FrameCount
*hsub
;
309 CHECK_DMA_BUFFER(gmesa
, 2);
310 WRITE(gmesa
->buf
, Rectangle2DMode
, ((h
& 0xfff)<<12) |
312 WRITE(gmesa
->buf
, DrawRectangle2D
, ((y
& 0xffff)<<16) |
315 CHECK_DMA_BUFFER(gmesa
, 8);
316 WRITE(gmesa
->buf
, StartXDom
, x
<<16);
317 WRITE(gmesa
->buf
, StartY
, y
<<16);
318 WRITE(gmesa
->buf
, StartXSub
, (x
+w
)<<16);
319 WRITE(gmesa
->buf
, GLINTCount
, h
);
320 WRITE(gmesa
->buf
, dY
, 1<<16);
321 WRITE(gmesa
->buf
, dXDom
, 0<<16);
322 WRITE(gmesa
->buf
, dXSub
, 0<<16);
323 WRITE(gmesa
->buf
, Render
, 0x00000040); /* NOT_DONE */
328 CHECK_DMA_BUFFER(gmesa
, 6);
329 WRITE(gmesa
->buf
, DepthMode
, gmesa
->DepthMode
);
330 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
331 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
);
332 WRITE(gmesa
->buf
, GLINTWindow
, gmesa
->Window
);
333 WRITE(gmesa
->buf
, FastClearDepth
, gmesa
->ClearDepth
);
334 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeEnable
);
336 /* Turn on Depth FCP */
337 if (gmesa
->Window
& W_DepthFCP
) {
338 CHECK_DMA_BUFFER(gmesa
, 1);
339 WRITE(gmesa
->buf
, WindowOr
, (gmesa
->FrameCount
<< 9));
342 /* Turn off GID clipping if window is not clipped */
343 if (gmesa
->NotClipped
) {
344 CHECK_DMA_BUFFER(gmesa
, 1);
345 WRITE(gmesa
->buf
, Rectangle2DControl
, 0);
349 if (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) {
350 int y
= gmesa
->driScreen
->fbHeight
- gmesa
->driDrawable
->y
- gmesa
->driDrawable
->h
;
351 int x
= gmesa
->driDrawable
->x
;
352 int w
= gmesa
->driDrawable
->w
;
353 int h
= gmesa
->driDrawable
->h
;
355 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
357 if (x
< 0) { w
-= -x
; x
= 0; }
359 /* Turn on GID clipping if window is clipped */
360 if (!gmesa
->NotClipped
) {
361 CHECK_DMA_BUFFER(gmesa
, 1);
362 WRITE(gmesa
->buf
, Rectangle2DControl
, 1);
365 CHECK_DMA_BUFFER(gmesa
, 18);
366 WRITE(gmesa
->buf
, FBBlockColor
, gmesa
->ClearColor
);
367 WRITE(gmesa
->buf
, ColorDDAMode
, ColorDDADisable
);
368 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeEnable
);
369 WRITE(gmesa
->buf
, DepthMode
, 0);
370 WRITE(gmesa
->buf
, DeltaMode
, 0);
371 WRITE(gmesa
->buf
, AlphaBlendMode
, 0);
373 WRITE(gmesa
->buf
, dY
, 1<<16);
374 WRITE(gmesa
->buf
, dXDom
, 0<<16);
375 WRITE(gmesa
->buf
, dXSub
, 0<<16);
376 WRITE(gmesa
->buf
, StartXSub
, (x
+w
)<<16);
377 WRITE(gmesa
->buf
, GLINTCount
, h
);
378 WRITE(gmesa
->buf
, StartXDom
, x
<<16);
379 WRITE(gmesa
->buf
, StartY
, y
<<16);
380 WRITE(gmesa
->buf
, Render
, 0x00000048); /* NOT_DONE */
382 WRITE(gmesa
->buf
, Rectangle2DMode
, (((h
& 0xfff)<<12) |
384 WRITE(gmesa
->buf
, DrawRectangle2D
, (((y
& 0xffff)<<16) |
387 WRITE(gmesa
->buf
, DepthMode
, gmesa
->DepthMode
);
388 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
389 WRITE(gmesa
->buf
, AlphaBlendMode
, gmesa
->AlphaBlendMode
);
390 WRITE(gmesa
->buf
, ColorDDAMode
, gmesa
->ColorDDAMode
);
392 /* Turn off GID clipping if window is clipped */
393 if (gmesa
->NotClipped
) {
394 CHECK_DMA_BUFFER(gmesa
, 1);
395 WRITE(gmesa
->buf
, Rectangle2DControl
, 0);
400 PROCESS_DMA_BUFFER_TOP_HALF(gmesa
);
402 DRM_SPINUNLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
403 gmesa
->driScreen
->drawLockID
);
404 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa
);
406 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa
);
410 _swrast_Clear( ctx
, mask
, all
, cx
, cy
, cw
, ch
);
413 /* =============================================================
417 static void gammaUpdateZMode( GLcontext
*ctx
)
419 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
420 CARD32 z
= gmesa
->DepthMode
;
421 CARD32 delta
= gmesa
->DeltaMode
;
422 CARD32 window
= gmesa
->Window
;
423 CARD32 lbread
= gmesa
->LBReadMode
;
425 z
&= ~DM_CompareMask
;
427 switch ( ctx
->Depth
.Func
) {
444 z
|= DM_GreaterEqual
;
454 if ( ctx
->Depth
.Test
) {
455 z
|= DepthModeEnable
;
456 delta
|= DM_DepthEnable
;
457 window
|= W_DepthFCP
;
458 lbread
|= LBReadDstEnable
;
460 z
&= ~DepthModeEnable
;
461 delta
&= ~DM_DepthEnable
;
462 window
&= ~W_DepthFCP
;
463 lbread
&= ~LBReadDstEnable
;
466 if ( ctx
->Depth
.Mask
) {
473 if ( gmesa
->DepthMode
!= z
){
475 gmesa
->DepthMode
= z
;
476 gmesa
->DeltaMode
= delta
;
477 gmesa
->Window
= window
;
478 gmesa
->LBReadMode
= lbread
;
479 gmesa
->dirty
|= GAMMA_UPLOAD_DEPTH
;
485 static void gammaDDDepthFunc( GLcontext
*ctx
, GLenum func
)
487 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
489 FLUSH_BATCH( gmesa
);
490 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
493 static void gammaDDDepthMask( GLcontext
*ctx
, GLboolean flag
)
495 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
497 FLUSH_BATCH( gmesa
);
498 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
501 static void gammaDDClearDepth( GLcontext
*ctx
, GLclampd d
)
503 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
505 switch ( gmesa
->DepthSize
) {
507 gmesa
->ClearDepth
= d
* 0x0000ffff;
510 gmesa
->ClearDepth
= d
* 0x00ffffff;
513 gmesa
->ClearDepth
= d
* 0xffffffff;
518 static void gammaDDFinish( GLcontext
*ctx
)
520 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
522 FLUSH_DMA_BUFFER(gmesa
);
525 static void gammaDDFlush( GLcontext
*ctx
)
527 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
529 FLUSH_DMA_BUFFER(gmesa
);
532 /* =============================================================
536 static void gammaUpdateFogAttrib( GLcontext
*ctx
)
538 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
539 CARD32 f
= gmesa
->FogMode
;
540 CARD32 g
= gmesa
->GeometryMode
;
541 CARD32 d
= gmesa
->DeltaMode
;
543 if (ctx
->Fog
.Enabled
) {
555 switch (ctx
->Fog
.Mode
) {
563 g
|= GM_FogExpSquared
;
567 if ( gmesa
->FogMode
!= f
) {
569 gmesa
->dirty
|= GAMMA_UPLOAD_FOG
;
572 if ( gmesa
->GeometryMode
!= g
) {
573 gmesa
->GeometryMode
= g
;
574 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
577 if ( gmesa
->DeltaMode
!= d
) {
578 gmesa
->DeltaMode
= d
;
579 gmesa
->dirty
|= GAMMA_UPLOAD_DEPTH
;
583 static void gammaDDFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
585 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
587 FLUSH_BATCH( gmesa
);
588 gmesa
->new_state
|= GAMMA_NEW_FOG
;
591 /* =============================================================
594 static void gammaDDLineWidth( GLcontext
*ctx
, GLfloat width
)
596 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
598 CHECK_DMA_BUFFER(gmesa
, 3);
599 WRITE(gmesa
->buf
, LineWidth
, (GLuint
)width
);
600 WRITEF(gmesa
->buf
, AAlineWidth
, width
);
601 WRITE(gmesa
->buf
, LineWidthOffset
, (GLuint
)(width
-1)/2);
604 static void gammaDDLineStipple( GLcontext
*ctx
, GLint factor
, GLushort pattern
)
606 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
608 gmesa
->LineMode
&= ~(LM_StippleMask
| LM_RepeatFactorMask
);
609 gmesa
->LineMode
|= ((GLuint
)(factor
- 1) << 1) | ((GLuint
)pattern
<< 10);
611 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
616 /* =============================================================
619 static void gammaDDPointSize( GLcontext
*ctx
, GLfloat size
)
621 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
623 CHECK_DMA_BUFFER(gmesa
, 2);
624 WRITE(gmesa
->buf
, PointSize
, (GLuint
)size
);
625 WRITEF(gmesa
->buf
, AApointSize
, size
);
628 /* =============================================================
632 static void gammaUpdatePolygon( GLcontext
*ctx
)
634 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
635 CARD32 g
= gmesa
->GeometryMode
;
637 g
&= ~(GM_PolyOffsetFillEnable
| GM_PolyOffsetPointEnable
|
638 GM_PolyOffsetLineEnable
);
640 if (ctx
->Polygon
.OffsetFill
) g
|= GM_PolyOffsetFillEnable
;
641 if (ctx
->Polygon
.OffsetPoint
) g
|= GM_PolyOffsetPointEnable
;
642 if (ctx
->Polygon
.OffsetLine
) g
|= GM_PolyOffsetLineEnable
;
644 g
&= ~GM_FB_PolyMask
;
646 switch (ctx
->Polygon
.FrontMode
) {
648 g
|= GM_FrontPolyFill
;
651 g
|= GM_FrontPolyLine
;
654 g
|= GM_FrontPolyPoint
;
658 switch (ctx
->Polygon
.BackMode
) {
660 g
|= GM_BackPolyFill
;
663 g
|= GM_BackPolyLine
;
666 g
|= GM_BackPolyPoint
;
670 if ( gmesa
->GeometryMode
!= g
) {
671 gmesa
->GeometryMode
= g
;
672 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
675 gmesa
->dirty
|= GAMMA_UPLOAD_POLYGON
;
678 static void gammaDDPolygonMode( GLcontext
*ctx
, GLenum face
, GLenum mode
)
680 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
682 FLUSH_BATCH( gmesa
);
684 gmesa
->new_state
|= GAMMA_NEW_POLYGON
;
687 static void gammaUpdateStipple( GLcontext
*ctx
)
689 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
691 FLUSH_BATCH( gmesa
);
693 if (ctx
->Polygon
.StippleFlag
) {
694 gmesa
->AreaStippleMode
|= AreaStippleModeEnable
/* | ASM_X32 | ASM_Y32*/;
696 gmesa
->AreaStippleMode
&= ~AreaStippleModeEnable
;
699 gmesa
->dirty
|= GAMMA_UPLOAD_STIPPLE
;
702 static void gammaDDPolygonStipple( GLcontext
*ctx
, const GLubyte
*mask
)
704 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
705 FLUSH_BATCH( gmesa
);
706 gmesa
->new_state
|= GAMMA_NEW_STIPPLE
;
709 /* =============================================================
713 static void gammaUpdateClipping( GLcontext
*ctx
)
715 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
716 GLint x1
, y1
, x2
, y2
;
718 if ( gmesa
->driDrawable
) {
719 x1
= gmesa
->driDrawable
->x
+ ctx
->Scissor
.X
;
720 y1
= gmesa
->driScreen
->fbHeight
-
721 (gmesa
->driDrawable
->y
+
722 gmesa
->driDrawable
->h
) + ctx
->Scissor
.Y
;
723 x2
= x1
+ ctx
->Scissor
.Width
;
724 y2
= y1
+ ctx
->Scissor
.Height
;
726 gmesa
->ScissorMinXY
= x1
| (y1
<< 16);
727 gmesa
->ScissorMaxXY
= x2
| (y2
<< 16);
728 if (ctx
->Scissor
.Enabled
)
729 gmesa
->ScissorMode
|= UserScissorEnable
;
731 gmesa
->ScissorMode
&= ~UserScissorEnable
;
733 gmesa
->dirty
|= GAMMA_UPLOAD_CLIP
;
737 static void gammaDDScissor( GLcontext
*ctx
,
738 GLint x
, GLint y
, GLsizei w
, GLsizei h
)
740 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
742 FLUSH_BATCH( gmesa
);
743 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
746 /* =============================================================
750 static void gammaUpdateCull( GLcontext
*ctx
)
752 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
753 CARD32 g
= gmesa
->GeometryMode
;
755 g
&= ~(GM_PolyCullMask
| GM_FFMask
);
757 if (ctx
->Polygon
.FrontFace
== GL_CCW
) {
758 g
|= GM_FrontFaceCCW
;
763 switch ( ctx
->Polygon
.CullFaceMode
) {
765 g
|= GM_PolyCullFront
;
768 g
|= GM_PolyCullBack
;
770 case GL_FRONT_AND_BACK
:
771 g
|= GM_PolyCullBoth
;
775 if ( ctx
->Polygon
.CullFlag
) {
776 g
|= GM_PolyCullEnable
;
778 g
&= ~GM_PolyCullEnable
;
781 if ( gmesa
->GeometryMode
!= g
) {
782 gmesa
->GeometryMode
= g
;
783 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
787 static void gammaDDCullFace( GLcontext
*ctx
, GLenum mode
)
789 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
791 FLUSH_BATCH( gmesa
);
792 gmesa
->new_state
|= GAMMA_NEW_CULL
;
795 static void gammaDDFrontFace( GLcontext
*ctx
, GLenum mode
)
797 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
799 FLUSH_BATCH( gmesa
);
800 gmesa
->new_state
|= GAMMA_NEW_CULL
;
803 /* =============================================================
807 static void gammaUpdateMasks( GLcontext
*ctx
)
809 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
812 GLuint mask
= gammaPackColor( gmesa
->gammaScreen
->cpp
,
813 ctx
->Color
.ColorMask
[RCOMP
],
814 ctx
->Color
.ColorMask
[GCOMP
],
815 ctx
->Color
.ColorMask
[BCOMP
],
816 ctx
->Color
.ColorMask
[ACOMP
] );
818 if (gmesa
->gammaScreen
->cpp
== 2) mask
|= mask
<< 16;
820 if ( gmesa
->FBHardwareWriteMask
!= mask
) {
821 gmesa
->FBHardwareWriteMask
= mask
;
822 gmesa
->dirty
|= GAMMA_UPLOAD_MASKS
;
826 static void gammaDDColorMask( GLcontext
*ctx
, GLboolean r
, GLboolean g
,
827 GLboolean b
, GLboolean a
)
829 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
831 FLUSH_BATCH( gmesa
);
832 gmesa
->new_state
|= GAMMA_NEW_MASKS
;
835 /* =============================================================
836 * Rendering attributes
838 * We really don't want to recalculate all this every time we bind a
839 * texture. These things shouldn't change all that often, so it makes
840 * sense to break them out of the core texture state update routines.
844 static void gammaDDLightfv(GLcontext
*ctx
, GLenum light
, GLenum pname
,
845 const GLfloat
*params
, GLint nParams
)
847 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
854 CHECK_DMA_BUFFER(gmesa
, 3);
855 /* We don't do alpha */
856 WRITEF(gmesa
->buf
, Light0AmbientIntensityBlue
, params
[2]);
857 WRITEF(gmesa
->buf
, Light0AmbientIntensityGreen
, params
[1]);
858 WRITEF(gmesa
->buf
, Light0AmbientIntensityRed
, params
[0]);
861 CHECK_DMA_BUFFER(gmesa
, 3);
862 /* We don't do alpha */
863 WRITEF(gmesa
->buf
, Light0DiffuseIntensityBlue
, params
[2]);
864 WRITEF(gmesa
->buf
, Light0DiffuseIntensityGreen
, params
[1]);
865 WRITEF(gmesa
->buf
, Light0DiffuseIntensityRed
, params
[0]);
868 CHECK_DMA_BUFFER(gmesa
, 3);
869 /* We don't do alpha */
870 WRITEF(gmesa
->buf
, Light0SpecularIntensityBlue
, params
[2]);
871 WRITEF(gmesa
->buf
, Light0SpecularIntensityGreen
, params
[1]);
872 WRITEF(gmesa
->buf
, Light0SpecularIntensityRed
, params
[0]);
875 /* Normalize <x,y,z> */
876 x
= params
[0]; y
= params
[1]; z
= params
[2]; w
= params
[3];
877 l
= sqrt(x
*x
+ y
*y
+ z
*z
+ w
*w
);
882 if (params
[3] != 0.0) {
883 gmesa
->Light0Mode
|= Light0ModeAttenuation
;
884 gmesa
->Light0Mode
|= Light0ModeLocal
;
886 gmesa
->Light0Mode
&= ~Light0ModeAttenuation
;
887 gmesa
->Light0Mode
&= ~Light0ModeLocal
;
889 CHECK_DMA_BUFFER(gmesa
, 5);
890 WRITE(gmesa
->buf
, Light0Mode
, gmesa
->Light0Mode
);
891 WRITEF(gmesa
->buf
, Light0PositionW
, w
);
892 WRITEF(gmesa
->buf
, Light0PositionZ
, z
);
893 WRITEF(gmesa
->buf
, Light0PositionY
, y
);
894 WRITEF(gmesa
->buf
, Light0PositionX
, x
);
896 case GL_SPOT_DIRECTION
:
897 CHECK_DMA_BUFFER(gmesa
, 3);
898 /* WRITEF(gmesa->buf, Light0SpotlightDirectionW, params[3]); */
899 WRITEF(gmesa
->buf
, Light0SpotlightDirectionZ
, params
[2]);
900 WRITEF(gmesa
->buf
, Light0SpotlightDirectionY
, params
[1]);
901 WRITEF(gmesa
->buf
, Light0SpotlightDirectionX
, params
[0]);
903 case GL_SPOT_EXPONENT
:
904 CHECK_DMA_BUFFER(gmesa
, 1);
905 WRITEF(gmesa
->buf
, Light0SpotlightExponent
, params
[0]);
908 if (params
[0] != 180.0)
909 gmesa
->Light0Mode
|= Light0ModeSpotLight
;
911 gmesa
->Light0Mode
&= ~Light0ModeSpotLight
;
912 CHECK_DMA_BUFFER(gmesa
, 2);
913 WRITE(gmesa
->buf
, Light0Mode
, gmesa
->Light0Mode
);
914 WRITEF(gmesa
->buf
, Light0CosSpotlightCutoffAngle
, cos(params
[0]*DEG2RAD
));
916 case GL_CONSTANT_ATTENUATION
:
917 CHECK_DMA_BUFFER(gmesa
, 1);
918 WRITEF(gmesa
->buf
, Light0ConstantAttenuation
, params
[0]);
920 case GL_LINEAR_ATTENUATION
:
921 CHECK_DMA_BUFFER(gmesa
, 1);
922 WRITEF(gmesa
->buf
, Light0LinearAttenuation
, params
[0]);
924 case GL_QUADRATIC_ATTENUATION
:
925 CHECK_DMA_BUFFER(gmesa
, 1);
926 WRITEF(gmesa
->buf
, Light0QuadraticAttenuation
, params
[0]);
933 static void gammaDDLightModelfv( GLcontext
*ctx
, GLenum pname
,
934 const GLfloat
*params
)
936 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
939 case GL_LIGHT_MODEL_AMBIENT
:
940 CHECK_DMA_BUFFER(gmesa
, 3);
941 /* We don't do alpha */
942 WRITEF(gmesa
->buf
, SceneAmbientColorBlue
, params
[2]);
943 WRITEF(gmesa
->buf
, SceneAmbientColorGreen
, params
[1]);
944 WRITEF(gmesa
->buf
, SceneAmbientColorRed
, params
[0]);
946 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
947 if (params
[0] != 0.0)
948 gmesa
->LightingMode
|= LightingModeLocalViewer
;
950 gmesa
->LightingMode
&= ~LightingModeLocalViewer
;
951 CHECK_DMA_BUFFER(gmesa
, 1);
952 WRITE(gmesa
->buf
, LightingMode
, gmesa
->LightingMode
);
954 case GL_LIGHT_MODEL_TWO_SIDE
:
955 if (params
[0] == 1.0f
) {
956 gmesa
->LightingMode
|= LightingModeTwoSides
;
957 gmesa
->MaterialMode
|= MaterialModeTwoSides
;
959 gmesa
->LightingMode
&= ~LightingModeTwoSides
;
960 gmesa
->MaterialMode
&= ~MaterialModeTwoSides
;
962 CHECK_DMA_BUFFER(gmesa
, 2);
963 WRITE(gmesa
->buf
, LightingMode
, gmesa
->LightingMode
);
964 WRITE(gmesa
->buf
, MaterialMode
, gmesa
->MaterialMode
);
970 static void gammaDDShadeModel( GLcontext
*ctx
, GLenum mode
)
972 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
973 CARD32 g
= gmesa
->GeometryMode
;
974 CARD32 c
= gmesa
->ColorDDAMode
;
976 g
&= ~GM_ShadingMask
;
977 c
&= ~ColorDDAShadingMask
;
985 g
|= GM_GouraudShading
;
986 c
|= ColorDDAGouraud
;
992 if ( gmesa
->ColorDDAMode
!= c
) {
993 FLUSH_BATCH( gmesa
);
994 gmesa
->ColorDDAMode
= c
;
996 gmesa
->dirty
|= GAMMA_UPLOAD_SHADE
;
999 if ( gmesa
->GeometryMode
!= g
) {
1000 FLUSH_BATCH( gmesa
);
1001 gmesa
->GeometryMode
= g
;
1003 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
1007 /* =============================================================
1011 static void gammaDDClearColor( GLcontext
*ctx
, const GLfloat color
[4])
1013 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1015 UNCLAMPED_FLOAT_TO_UBYTE(c
[0], color
[0]);
1016 UNCLAMPED_FLOAT_TO_UBYTE(c
[1], color
[1]);
1017 UNCLAMPED_FLOAT_TO_UBYTE(c
[2], color
[2]);
1018 UNCLAMPED_FLOAT_TO_UBYTE(c
[3], color
[3]);
1020 gmesa
->ClearColor
= gammaPackColor( gmesa
->gammaScreen
->cpp
,
1021 c
[0], c
[1], c
[2], c
[3] );
1023 if (gmesa
->gammaScreen
->cpp
== 2) gmesa
->ClearColor
|= gmesa
->ClearColor
<<16;
1027 static void gammaDDLogicalOpcode( GLcontext
*ctx
, GLenum opcode
)
1029 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1031 FLUSH_BATCH( gmesa
);
1033 if ( ctx
->Color
.ColorLogicOpEnabled
) {
1034 gmesa
->LogicalOpMode
= opcode
<< 1 | LogicalOpModeEnable
;
1036 gmesa
->LogicalOpMode
= LogicalOpModeDisable
;
1039 gmesa
->dirty
|= GAMMA_UPLOAD_LOGICOP
;
1042 static void gammaDDDrawBuffer( GLcontext
*ctx
, GLenum mode
)
1044 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1046 FLUSH_BATCH( gmesa
);
1050 gmesa
->drawOffset
= gmesa
->readOffset
= 0;
1053 gmesa
->drawOffset
= gmesa
->readOffset
= gmesa
->driScreen
->fbHeight
* gmesa
->driScreen
->fbWidth
* gmesa
->gammaScreen
->cpp
;
1058 static void gammaDDReadBuffer( GLcontext
*ctx
, GLenum mode
)
1063 /* =============================================================
1064 * Window position and viewport transformation
1067 void gammaUpdateWindow( GLcontext
*ctx
)
1069 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1070 __DRIdrawablePrivate
*dPriv
= gmesa
->driDrawable
;
1071 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1072 GLfloat yoffset
= gmesa
->driScreen
->fbHeight
- (GLfloat
)dPriv
->y
- dPriv
->h
;
1073 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1075 GLfloat sx
= v
[MAT_SX
];
1076 GLfloat tx
= v
[MAT_TX
] + xoffset
;
1077 GLfloat sy
= v
[MAT_SY
];
1078 GLfloat ty
= v
[MAT_TY
] + yoffset
;
1079 GLfloat sz
= v
[MAT_SZ
] * gmesa
->depth_scale
;
1080 GLfloat tz
= v
[MAT_TZ
] * gmesa
->depth_scale
;
1082 gmesa
->dirty
|= GAMMA_UPLOAD_VIEWPORT
;
1084 gmesa
->ViewportScaleX
= sx
;
1085 gmesa
->ViewportScaleY
= sy
;
1086 gmesa
->ViewportScaleZ
= sz
;
1087 gmesa
->ViewportOffsetX
= tx
;
1088 gmesa
->ViewportOffsetY
= ty
;
1089 gmesa
->ViewportOffsetZ
= tz
;
1094 static void gammaDDViewport( GLcontext
*ctx
, GLint x
, GLint y
,
1095 GLsizei width
, GLsizei height
)
1097 gammaUpdateWindow( ctx
);
1100 static void gammaDDDepthRange( GLcontext
*ctx
, GLclampd nearval
,
1103 gammaUpdateWindow( ctx
);
1106 void gammaUpdateViewportOffset( GLcontext
*ctx
)
1108 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1109 __DRIdrawablePrivate
*dPriv
= gmesa
->driDrawable
;
1110 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1111 GLfloat yoffset
= gmesa
->driScreen
->fbHeight
- (GLfloat
)dPriv
->y
- dPriv
->h
;
1112 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1114 GLfloat tx
= v
[MAT_TX
] + xoffset
;
1115 GLfloat ty
= v
[MAT_TY
] + yoffset
;
1117 if ( gmesa
->ViewportOffsetX
!= tx
||
1118 gmesa
->ViewportOffsetY
!= ty
)
1120 gmesa
->ViewportOffsetX
= tx
;
1121 gmesa
->ViewportOffsetY
= ty
;
1123 gmesa
->new_state
|= GAMMA_NEW_WINDOW
;
1126 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
1134 static void gammaLoadHWMatrix(GLcontext
*ctx
)
1136 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1139 gmesa
->TransformMode
&= ~XM_XformTexture
;
1141 switch (ctx
->Transform
.MatrixMode
) {
1143 gmesa
->TransformMode
|= XM_UseModelViewMatrix
;
1144 m
= ctx
->ModelviewMatrixStack
.Top
->m
;
1145 CHECK_DMA_BUFFER(gmesa
, 16);
1146 WRITEF(gmesa
->buf
, ModelViewMatrix0
, m
[0]);
1147 WRITEF(gmesa
->buf
, ModelViewMatrix1
, m
[1]);
1148 WRITEF(gmesa
->buf
, ModelViewMatrix2
, m
[2]);
1149 WRITEF(gmesa
->buf
, ModelViewMatrix3
, m
[3]);
1150 WRITEF(gmesa
->buf
, ModelViewMatrix4
, m
[4]);
1151 WRITEF(gmesa
->buf
, ModelViewMatrix5
, m
[5]);
1152 WRITEF(gmesa
->buf
, ModelViewMatrix6
, m
[6]);
1153 WRITEF(gmesa
->buf
, ModelViewMatrix7
, m
[7]);
1154 WRITEF(gmesa
->buf
, ModelViewMatrix8
, m
[8]);
1155 WRITEF(gmesa
->buf
, ModelViewMatrix9
, m
[9]);
1156 WRITEF(gmesa
->buf
, ModelViewMatrix10
, m
[10]);
1157 WRITEF(gmesa
->buf
, ModelViewMatrix11
, m
[11]);
1158 WRITEF(gmesa
->buf
, ModelViewMatrix12
, m
[12]);
1159 WRITEF(gmesa
->buf
, ModelViewMatrix13
, m
[13]);
1160 WRITEF(gmesa
->buf
, ModelViewMatrix14
, m
[14]);
1161 WRITEF(gmesa
->buf
, ModelViewMatrix15
, m
[15]);
1164 m
= ctx
->ProjectionMatrixStack
.Top
->m
;
1165 CHECK_DMA_BUFFER(gmesa
, 16);
1166 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix0
, m
[0]);
1167 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix1
, m
[1]);
1168 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix2
, m
[2]);
1169 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix3
, m
[3]);
1170 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix4
, m
[4]);
1171 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix5
, m
[5]);
1172 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix6
, m
[6]);
1173 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix7
, m
[7]);
1174 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix8
, m
[8]);
1175 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix9
, m
[9]);
1176 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix10
, m
[10]);
1177 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix11
, m
[11]);
1178 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix12
, m
[12]);
1179 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix13
, m
[13]);
1180 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix14
, m
[14]);
1181 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix15
, m
[15]);
1184 m
= ctx
->TextureMatrixStack
[0].Top
->m
;
1185 CHECK_DMA_BUFFER(gmesa
, 16);
1186 gmesa
->TransformMode
|= XM_XformTexture
;
1187 WRITEF(gmesa
->buf
, TextureMatrix0
, m
[0]);
1188 WRITEF(gmesa
->buf
, TextureMatrix1
, m
[1]);
1189 WRITEF(gmesa
->buf
, TextureMatrix2
, m
[2]);
1190 WRITEF(gmesa
->buf
, TextureMatrix3
, m
[3]);
1191 WRITEF(gmesa
->buf
, TextureMatrix4
, m
[4]);
1192 WRITEF(gmesa
->buf
, TextureMatrix5
, m
[5]);
1193 WRITEF(gmesa
->buf
, TextureMatrix6
, m
[6]);
1194 WRITEF(gmesa
->buf
, TextureMatrix7
, m
[7]);
1195 WRITEF(gmesa
->buf
, TextureMatrix8
, m
[8]);
1196 WRITEF(gmesa
->buf
, TextureMatrix9
, m
[9]);
1197 WRITEF(gmesa
->buf
, TextureMatrix10
, m
[10]);
1198 WRITEF(gmesa
->buf
, TextureMatrix11
, m
[11]);
1199 WRITEF(gmesa
->buf
, TextureMatrix12
, m
[12]);
1200 WRITEF(gmesa
->buf
, TextureMatrix13
, m
[13]);
1201 WRITEF(gmesa
->buf
, TextureMatrix14
, m
[14]);
1202 WRITEF(gmesa
->buf
, TextureMatrix15
, m
[15]);
1206 /* ERROR!!! -- how did this happen? */
1210 gmesa
->dirty
|= GAMMA_UPLOAD_TRANSFORM
;
1214 /* =============================================================
1215 * State enable/disable
1218 static void gammaDDEnable( GLcontext
*ctx
, GLenum cap
, GLboolean state
)
1220 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1225 FLUSH_BATCH( gmesa
);
1226 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
1230 FLUSH_BATCH( gmesa
);
1231 gmesa
->new_state
|= GAMMA_NEW_CULL
;
1235 FLUSH_BATCH( gmesa
);
1236 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
1241 CARD32 d
= gmesa
->DitherMode
;
1242 FLUSH_BATCH( gmesa
);
1245 d
|= DM_DitherEnable
;
1247 d
&= ~DM_DitherEnable
;
1250 if ( gmesa
->DitherMode
!= d
) {
1251 gmesa
->DitherMode
= d
;
1252 gmesa
->dirty
|= GAMMA_UPLOAD_DITHER
;
1259 FLUSH_BATCH( gmesa
);
1260 gmesa
->new_state
|= GAMMA_NEW_FOG
;
1264 case GL_INDEX_LOGIC_OP
:
1265 case GL_COLOR_LOGIC_OP
:
1266 FLUSH_BATCH( gmesa
);
1267 gmesa
->new_state
|= GAMMA_NEW_LOGICOP
;
1273 CARD32 l
= gmesa
->LightingMode
;
1274 FLUSH_BATCH( gmesa
);
1277 l
|= LightingModeEnable
;
1279 l
&= ~LightingModeEnable
;
1282 if ( gmesa
->LightingMode
!= l
) {
1283 gmesa
->LightingMode
= l
;
1284 gmesa
->dirty
|= GAMMA_UPLOAD_LIGHT
;
1289 case GL_COLOR_MATERIAL
:
1291 CARD32 m
= gmesa
->MaterialMode
;
1292 FLUSH_BATCH( gmesa
);
1295 m
|= MaterialModeEnable
;
1297 m
&= ~MaterialModeEnable
;
1300 if ( gmesa
->MaterialMode
!= m
) {
1301 gmesa
->MaterialMode
= m
;
1302 gmesa
->dirty
|= GAMMA_UPLOAD_LIGHT
;
1308 case GL_LINE_SMOOTH
:
1309 FLUSH_BATCH( gmesa
);
1311 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1312 gmesa
->LineMode
|= LM_AntialiasEnable
;
1314 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1315 gmesa
->LineMode
&= ~LM_AntialiasEnable
;
1317 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
1320 case GL_POINT_SMOOTH
:
1321 FLUSH_BATCH( gmesa
);
1323 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1324 gmesa
->PointMode
|= PM_AntialiasEnable
;
1326 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1327 gmesa
->PointMode
&= ~PM_AntialiasEnable
;
1329 gmesa
->dirty
|= GAMMA_UPLOAD_POINTMODE
;
1332 case GL_POLYGON_SMOOTH
:
1333 FLUSH_BATCH( gmesa
);
1335 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1336 gmesa
->TriangleMode
|= TM_AntialiasEnable
;
1338 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1339 gmesa
->TriangleMode
&= ~TM_AntialiasEnable
;
1341 gmesa
->dirty
|= GAMMA_UPLOAD_TRIMODE
;
1344 case GL_SCISSOR_TEST
:
1345 FLUSH_BATCH( gmesa
);
1346 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
1349 case GL_POLYGON_OFFSET_FILL
:
1350 case GL_POLYGON_OFFSET_POINT
:
1351 case GL_POLYGON_OFFSET_LINE
:
1352 FLUSH_BATCH( gmesa
);
1353 gmesa
->new_state
|= GAMMA_NEW_POLYGON
;
1356 case GL_LINE_STIPPLE
:
1357 FLUSH_BATCH( gmesa
);
1359 gmesa
->LineMode
|= LM_StippleEnable
;
1361 gmesa
->LineMode
&= ~LM_StippleEnable
;
1362 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
1365 case GL_POLYGON_STIPPLE
:
1366 FLUSH_BATCH( gmesa
);
1367 gmesa
->new_state
|= GAMMA_NEW_STIPPLE
;
1375 /* =============================================================
1376 * State initialization, management
1381 * Load the current context's state into the hardware.
1383 * NOTE: Be VERY careful about ensuring the context state is marked for
1384 * upload, the only place it shouldn't be uploaded is when the setup
1385 * state has changed in ReducedPrimitiveChange as this comes right after
1388 * Blits of any type should always upload the context and masks after
1391 void gammaEmitHwState( gammaContextPtr gmesa
)
1393 if (!gmesa
->driDrawable
) return;
1395 if (!gmesa
->dirty
) return;
1398 /* Flush any partially filled buffers */
1399 FLUSH_DMA_BUFFER(gmesa
);
1401 DRM_SPINLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
1402 gmesa
->driScreen
->drawLockID
);
1403 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa
);
1406 if (gmesa
->dirty
& GAMMA_UPLOAD_VIEWPORT
) {
1407 gmesa
->dirty
&= ~GAMMA_UPLOAD_VIEWPORT
;
1408 CHECK_DMA_BUFFER(gmesa
, 6);
1409 WRITEF(gmesa
->buf
, ViewPortOffsetX
, gmesa
->ViewportOffsetX
);
1410 WRITEF(gmesa
->buf
, ViewPortOffsetY
, gmesa
->ViewportOffsetY
);
1411 WRITEF(gmesa
->buf
, ViewPortOffsetZ
, gmesa
->ViewportOffsetZ
);
1412 WRITEF(gmesa
->buf
, ViewPortScaleX
, gmesa
->ViewportScaleX
);
1413 WRITEF(gmesa
->buf
, ViewPortScaleY
, gmesa
->ViewportScaleY
);
1414 WRITEF(gmesa
->buf
, ViewPortScaleZ
, gmesa
->ViewportScaleZ
);
1416 if ( (gmesa
->dirty
& GAMMA_UPLOAD_POINTMODE
) ||
1417 (gmesa
->dirty
& GAMMA_UPLOAD_LINEMODE
) ||
1418 (gmesa
->dirty
& GAMMA_UPLOAD_TRIMODE
) ) {
1419 CHECK_DMA_BUFFER(gmesa
, 1);
1420 WRITE(gmesa
->buf
, AntialiasMode
, gmesa
->AntialiasMode
);
1422 if (gmesa
->dirty
& GAMMA_UPLOAD_POINTMODE
) {
1423 gmesa
->dirty
&= ~GAMMA_UPLOAD_POINTMODE
;
1424 CHECK_DMA_BUFFER(gmesa
, 1);
1425 WRITE(gmesa
->buf
, PointMode
, gmesa
->PointMode
);
1427 if (gmesa
->dirty
& GAMMA_UPLOAD_LINEMODE
) {
1428 gmesa
->dirty
&= ~GAMMA_UPLOAD_LINEMODE
;
1429 CHECK_DMA_BUFFER(gmesa
, 2);
1430 WRITE(gmesa
->buf
, LineMode
, gmesa
->LineMode
);
1431 WRITE(gmesa
->buf
, LineStippleMode
, gmesa
->LineMode
);
1433 if (gmesa
->dirty
& GAMMA_UPLOAD_TRIMODE
) {
1434 gmesa
->dirty
&= ~GAMMA_UPLOAD_TRIMODE
;
1435 CHECK_DMA_BUFFER(gmesa
, 1);
1436 WRITE(gmesa
->buf
, TriangleMode
, gmesa
->TriangleMode
);
1438 if (gmesa
->dirty
& GAMMA_UPLOAD_FOG
) {
1440 UNCLAMPED_FLOAT_TO_RGB_CHAN( c
, gmesa
->glCtx
->Fog
.Color
);
1441 col
= gammaPackColor(4, c
[0], c
[1], c
[2], 0);
1442 gmesa
->dirty
&= ~GAMMA_UPLOAD_FOG
;
1443 CHECK_DMA_BUFFER(gmesa
, 5);
1445 WRITE(gmesa
->buf
, FogMode
, gmesa
->FogMode
);
1446 WRITE(gmesa
->buf
, FogColor
, col
);
1447 WRITEF(gmesa
->buf
, FStart
, gmesa
->glCtx
->Fog
.Start
);
1449 WRITEF(gmesa
->buf
, FogEnd
, gmesa
->glCtx
->Fog
.End
);
1450 WRITEF(gmesa
->buf
, FogDensity
, gmesa
->glCtx
->Fog
.Density
);
1451 WRITEF(gmesa
->buf
, FogScale
,
1452 1.0f
/(gmesa
->glCtx
->Fog
.End
- gmesa
->glCtx
->Fog
.Start
));
1454 if (gmesa
->dirty
& GAMMA_UPLOAD_DITHER
) {
1455 gmesa
->dirty
&= ~GAMMA_UPLOAD_DITHER
;
1456 CHECK_DMA_BUFFER(gmesa
, 1);
1457 WRITE(gmesa
->buf
, DitherMode
, gmesa
->DitherMode
);
1459 if (gmesa
->dirty
& GAMMA_UPLOAD_LOGICOP
) {
1460 gmesa
->dirty
&= ~GAMMA_UPLOAD_LOGICOP
;
1461 CHECK_DMA_BUFFER(gmesa
, 1);
1462 WRITE(gmesa
->buf
, LogicalOpMode
, gmesa
->LogicalOpMode
);
1464 if (gmesa
->dirty
& GAMMA_UPLOAD_CLIP
) {
1465 gmesa
->dirty
&= ~GAMMA_UPLOAD_CLIP
;
1466 CHECK_DMA_BUFFER(gmesa
, 3);
1467 WRITE(gmesa
->buf
, ScissorMinXY
, gmesa
->ScissorMinXY
);
1468 WRITE(gmesa
->buf
, ScissorMaxXY
, gmesa
->ScissorMaxXY
);
1469 WRITE(gmesa
->buf
, ScissorMode
, gmesa
->ScissorMode
);
1471 if (gmesa
->dirty
& GAMMA_UPLOAD_MASKS
) {
1472 gmesa
->dirty
&= ~GAMMA_UPLOAD_MASKS
;
1473 CHECK_DMA_BUFFER(gmesa
, 1);
1474 WRITE(gmesa
->buf
, FBHardwareWriteMask
, gmesa
->FBHardwareWriteMask
);
1476 if (gmesa
->dirty
& GAMMA_UPLOAD_ALPHA
) {
1477 gmesa
->dirty
&= ~GAMMA_UPLOAD_ALPHA
;
1478 CHECK_DMA_BUFFER(gmesa
, 1);
1479 WRITE(gmesa
->buf
, AlphaTestMode
, gmesa
->AlphaTestMode
);
1481 if (gmesa
->dirty
& GAMMA_UPLOAD_BLEND
) {
1482 gmesa
->dirty
&= ~GAMMA_UPLOAD_BLEND
;
1483 CHECK_DMA_BUFFER(gmesa
, 1);
1484 WRITE(gmesa
->buf
, AlphaBlendMode
, gmesa
->AlphaBlendMode
);
1486 CHECK_DMA_BUFFER(gmesa
, 1);
1487 if (gmesa
->glCtx
->Color
.BlendEnabled
|| gmesa
->glCtx
->Color
.AlphaEnabled
) {
1488 WRITE(gmesa
->buf
, FBReadMode
, gmesa
->FBReadMode
| gmesa
->AB_FBReadMode_Save
);
1490 WRITE(gmesa
->buf
, FBReadMode
, gmesa
->FBReadMode
);
1492 if (gmesa
->dirty
& GAMMA_UPLOAD_LIGHT
) {
1493 gmesa
->dirty
&= ~GAMMA_UPLOAD_LIGHT
;
1494 CHECK_DMA_BUFFER(gmesa
, 2);
1495 WRITE(gmesa
->buf
, LightingMode
, gmesa
->LightingMode
);
1496 WRITE(gmesa
->buf
, MaterialMode
, gmesa
->MaterialMode
);
1498 if (gmesa
->dirty
& GAMMA_UPLOAD_SHADE
) {
1499 gmesa
->dirty
&= ~GAMMA_UPLOAD_SHADE
;
1500 CHECK_DMA_BUFFER(gmesa
, 1);
1501 WRITE(gmesa
->buf
, ColorDDAMode
, gmesa
->ColorDDAMode
);
1503 if (gmesa
->dirty
& GAMMA_UPLOAD_POLYGON
) {
1504 gmesa
->dirty
&= ~GAMMA_UPLOAD_POLYGON
;
1505 CHECK_DMA_BUFFER(gmesa
, 2);
1506 WRITEF(gmesa
->buf
, PolygonOffsetBias
, gmesa
->glCtx
->Polygon
.OffsetUnits
);
1507 WRITEF(gmesa
->buf
, PolygonOffsetFactor
, gmesa
->glCtx
->Polygon
.OffsetFactor
);
1509 if (gmesa
->dirty
& GAMMA_UPLOAD_STIPPLE
) {
1510 gmesa
->dirty
&= ~GAMMA_UPLOAD_STIPPLE
;
1511 CHECK_DMA_BUFFER(gmesa
, 33);
1512 WRITE(gmesa
->buf
, AreaStippleMode
, gmesa
->AreaStippleMode
);
1513 WRITE(gmesa
->buf
, AreaStipplePattern0
, gmesa
->glCtx
->PolygonStipple
[0]);
1514 WRITE(gmesa
->buf
, AreaStipplePattern1
, gmesa
->glCtx
->PolygonStipple
[1]);
1515 WRITE(gmesa
->buf
, AreaStipplePattern2
, gmesa
->glCtx
->PolygonStipple
[2]);
1516 WRITE(gmesa
->buf
, AreaStipplePattern3
, gmesa
->glCtx
->PolygonStipple
[3]);
1517 WRITE(gmesa
->buf
, AreaStipplePattern4
, gmesa
->glCtx
->PolygonStipple
[4]);
1518 WRITE(gmesa
->buf
, AreaStipplePattern5
, gmesa
->glCtx
->PolygonStipple
[5]);
1519 WRITE(gmesa
->buf
, AreaStipplePattern6
, gmesa
->glCtx
->PolygonStipple
[6]);
1520 WRITE(gmesa
->buf
, AreaStipplePattern7
, gmesa
->glCtx
->PolygonStipple
[7]);
1521 WRITE(gmesa
->buf
, AreaStipplePattern8
, gmesa
->glCtx
->PolygonStipple
[8]);
1522 WRITE(gmesa
->buf
, AreaStipplePattern9
, gmesa
->glCtx
->PolygonStipple
[9]);
1523 WRITE(gmesa
->buf
, AreaStipplePattern10
, gmesa
->glCtx
->PolygonStipple
[10]);
1524 WRITE(gmesa
->buf
, AreaStipplePattern11
, gmesa
->glCtx
->PolygonStipple
[11]);
1525 WRITE(gmesa
->buf
, AreaStipplePattern12
, gmesa
->glCtx
->PolygonStipple
[12]);
1526 WRITE(gmesa
->buf
, AreaStipplePattern13
, gmesa
->glCtx
->PolygonStipple
[13]);
1527 WRITE(gmesa
->buf
, AreaStipplePattern14
, gmesa
->glCtx
->PolygonStipple
[14]);
1528 WRITE(gmesa
->buf
, AreaStipplePattern15
, gmesa
->glCtx
->PolygonStipple
[15]);
1529 WRITE(gmesa
->buf
, AreaStipplePattern16
, gmesa
->glCtx
->PolygonStipple
[16]);
1530 WRITE(gmesa
->buf
, AreaStipplePattern17
, gmesa
->glCtx
->PolygonStipple
[17]);
1531 WRITE(gmesa
->buf
, AreaStipplePattern18
, gmesa
->glCtx
->PolygonStipple
[18]);
1532 WRITE(gmesa
->buf
, AreaStipplePattern19
, gmesa
->glCtx
->PolygonStipple
[19]);
1533 WRITE(gmesa
->buf
, AreaStipplePattern20
, gmesa
->glCtx
->PolygonStipple
[20]);
1534 WRITE(gmesa
->buf
, AreaStipplePattern21
, gmesa
->glCtx
->PolygonStipple
[21]);
1535 WRITE(gmesa
->buf
, AreaStipplePattern22
, gmesa
->glCtx
->PolygonStipple
[22]);
1536 WRITE(gmesa
->buf
, AreaStipplePattern23
, gmesa
->glCtx
->PolygonStipple
[23]);
1537 WRITE(gmesa
->buf
, AreaStipplePattern24
, gmesa
->glCtx
->PolygonStipple
[24]);
1538 WRITE(gmesa
->buf
, AreaStipplePattern25
, gmesa
->glCtx
->PolygonStipple
[25]);
1539 WRITE(gmesa
->buf
, AreaStipplePattern26
, gmesa
->glCtx
->PolygonStipple
[26]);
1540 WRITE(gmesa
->buf
, AreaStipplePattern27
, gmesa
->glCtx
->PolygonStipple
[27]);
1541 WRITE(gmesa
->buf
, AreaStipplePattern28
, gmesa
->glCtx
->PolygonStipple
[28]);
1542 WRITE(gmesa
->buf
, AreaStipplePattern29
, gmesa
->glCtx
->PolygonStipple
[29]);
1543 WRITE(gmesa
->buf
, AreaStipplePattern30
, gmesa
->glCtx
->PolygonStipple
[30]);
1544 WRITE(gmesa
->buf
, AreaStipplePattern31
, gmesa
->glCtx
->PolygonStipple
[31]);
1546 if (gmesa
->dirty
& GAMMA_UPLOAD_DEPTH
) {
1547 gmesa
->dirty
&= ~GAMMA_UPLOAD_DEPTH
;
1548 CHECK_DMA_BUFFER(gmesa
, 4);
1549 WRITE(gmesa
->buf
, DepthMode
, gmesa
->DepthMode
);
1550 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
1551 WRITE(gmesa
->buf
, GLINTWindow
,gmesa
->Window
| (gmesa
->FrameCount
<< 9));
1552 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
);
1554 if (gmesa
->dirty
& GAMMA_UPLOAD_GEOMETRY
) {
1555 gmesa
->dirty
&= ~GAMMA_UPLOAD_GEOMETRY
;
1556 CHECK_DMA_BUFFER(gmesa
, 1);
1557 WRITE(gmesa
->buf
, GeometryMode
, gmesa
->GeometryMode
);
1559 if (gmesa
->dirty
& GAMMA_UPLOAD_TRANSFORM
) {
1560 gmesa
->dirty
&= ~GAMMA_UPLOAD_TRANSFORM
;
1561 CHECK_DMA_BUFFER(gmesa
, 1);
1562 WRITE(gmesa
->buf
, TransformMode
, gmesa
->TransformMode
);
1564 if (gmesa
->dirty
& GAMMA_UPLOAD_TEX0
) {
1565 gammaTextureObjectPtr curTex
= gmesa
->CurrentTexObj
[0];
1566 gmesa
->dirty
&= ~GAMMA_UPLOAD_TEX0
;
1568 CHECK_DMA_BUFFER(gmesa
, 21);
1569 WRITE(gmesa
->buf
, GeometryMode
, gmesa
->GeometryMode
| GM_TextureEnable
);
1570 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
| DM_TextureEnable
);
1571 WRITE(gmesa
->buf
, TextureAddressMode
, curTex
->TextureAddressMode
);
1572 WRITE(gmesa
->buf
, TextureReadMode
, curTex
->TextureReadMode
);
1573 WRITE(gmesa
->buf
, TextureColorMode
, curTex
->TextureColorMode
);
1574 WRITE(gmesa
->buf
, TextureFilterMode
, curTex
->TextureFilterMode
);
1575 WRITE(gmesa
->buf
, TextureFormat
, curTex
->TextureFormat
);
1576 WRITE(gmesa
->buf
, GLINTBorderColor
, curTex
->TextureBorderColor
);
1577 WRITE(gmesa
->buf
, TxBaseAddr0
, curTex
->TextureBaseAddr
[0]);
1578 WRITE(gmesa
->buf
, TxBaseAddr1
, curTex
->TextureBaseAddr
[1]);
1579 WRITE(gmesa
->buf
, TxBaseAddr2
, curTex
->TextureBaseAddr
[2]);
1580 WRITE(gmesa
->buf
, TxBaseAddr3
, curTex
->TextureBaseAddr
[3]);
1581 WRITE(gmesa
->buf
, TxBaseAddr4
, curTex
->TextureBaseAddr
[4]);
1582 WRITE(gmesa
->buf
, TxBaseAddr5
, curTex
->TextureBaseAddr
[5]);
1583 WRITE(gmesa
->buf
, TxBaseAddr6
, curTex
->TextureBaseAddr
[6]);
1584 WRITE(gmesa
->buf
, TxBaseAddr7
, curTex
->TextureBaseAddr
[7]);
1585 WRITE(gmesa
->buf
, TxBaseAddr8
, curTex
->TextureBaseAddr
[8]);
1586 WRITE(gmesa
->buf
, TxBaseAddr9
, curTex
->TextureBaseAddr
[9]);
1587 WRITE(gmesa
->buf
, TxBaseAddr10
, curTex
->TextureBaseAddr
[10]);
1588 WRITE(gmesa
->buf
, TxBaseAddr11
, curTex
->TextureBaseAddr
[11]);
1589 WRITE(gmesa
->buf
, TxBaseAddr12
, curTex
->TextureBaseAddr
[12]);
1590 WRITE(gmesa
->buf
, TextureCacheControl
, (TCC_Enable
| TCC_Invalidate
));
1592 CHECK_DMA_BUFFER(gmesa
, 6);
1593 WRITE(gmesa
->buf
, GeometryMode
, gmesa
->GeometryMode
);
1594 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
1595 WRITE(gmesa
->buf
, TextureAddressMode
, TextureAddressModeDisable
);
1596 WRITE(gmesa
->buf
, TextureReadMode
, TextureReadModeDisable
);
1597 WRITE(gmesa
->buf
, TextureFilterMode
, TextureFilterModeDisable
);
1598 WRITE(gmesa
->buf
, TextureColorMode
, TextureColorModeDisable
);
1602 PROCESS_DMA_BUFFER_TOP_HALF(gmesa
);
1604 DRM_SPINUNLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
1605 gmesa
->driScreen
->drawLockID
);
1606 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa
);
1608 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa
);
1612 void gammaDDUpdateHWState( GLcontext
*ctx
)
1614 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1615 int new_state
= gmesa
->new_state
;
1619 FLUSH_BATCH( gmesa
);
1621 gmesa
->new_state
= 0;
1623 /* Update the various parts of the context's state.
1625 if ( new_state
& GAMMA_NEW_ALPHA
)
1626 gammaUpdateAlphaMode( ctx
);
1628 if ( new_state
& GAMMA_NEW_DEPTH
)
1629 gammaUpdateZMode( ctx
);
1631 if ( new_state
& GAMMA_NEW_FOG
)
1632 gammaUpdateFogAttrib( ctx
);
1634 if ( new_state
& GAMMA_NEW_CLIP
)
1635 gammaUpdateClipping( ctx
);
1637 if ( new_state
& GAMMA_NEW_POLYGON
)
1638 gammaUpdatePolygon( ctx
);
1640 if ( new_state
& GAMMA_NEW_CULL
)
1641 gammaUpdateCull( ctx
);
1643 if ( new_state
& GAMMA_NEW_MASKS
)
1644 gammaUpdateMasks( ctx
);
1646 if ( new_state
& GAMMA_NEW_WINDOW
)
1647 gammaUpdateWindow( ctx
);
1649 if ( new_state
& GAMMA_NEW_STIPPLE
)
1650 gammaUpdateStipple( ctx
);
1655 gammaEmitHwState( gmesa
);
1659 static void gammaDDUpdateState( GLcontext
*ctx
, GLuint new_state
)
1661 _swrast_InvalidateState( ctx
, new_state
);
1662 _swsetup_InvalidateState( ctx
, new_state
);
1663 _ac_InvalidateState( ctx
, new_state
);
1664 _tnl_InvalidateState( ctx
, new_state
);
1665 GAMMA_CONTEXT(ctx
)->new_gl_state
|= new_state
;
1669 /* Initialize the context's hardware state.
1671 void gammaDDInitState( gammaContextPtr gmesa
)
1673 gmesa
->new_state
= 0;
1676 /* Initialize the driver's state functions.
1678 void gammaDDInitStateFuncs( GLcontext
*ctx
)
1680 ctx
->Driver
.UpdateState
= gammaDDUpdateState
;
1682 ctx
->Driver
.Clear
= gammaDDClear
;
1683 ctx
->Driver
.ClearIndex
= NULL
;
1684 ctx
->Driver
.ClearColor
= gammaDDClearColor
;
1685 ctx
->Driver
.DrawBuffer
= gammaDDDrawBuffer
;
1686 ctx
->Driver
.ReadBuffer
= gammaDDReadBuffer
;
1688 ctx
->Driver
.IndexMask
= NULL
;
1689 ctx
->Driver
.ColorMask
= gammaDDColorMask
;
1691 ctx
->Driver
.AlphaFunc
= gammaDDAlphaFunc
;
1692 ctx
->Driver
.BlendEquation
= gammaDDBlendEquation
;
1693 ctx
->Driver
.BlendFuncSeparate
= gammaDDBlendFuncSeparate
;
1694 ctx
->Driver
.ClearDepth
= gammaDDClearDepth
;
1695 ctx
->Driver
.CullFace
= gammaDDCullFace
;
1696 ctx
->Driver
.FrontFace
= gammaDDFrontFace
;
1697 ctx
->Driver
.DepthFunc
= gammaDDDepthFunc
;
1698 ctx
->Driver
.DepthMask
= gammaDDDepthMask
;
1699 ctx
->Driver
.DepthRange
= gammaDDDepthRange
;
1700 ctx
->Driver
.Enable
= gammaDDEnable
;
1701 ctx
->Driver
.Finish
= gammaDDFinish
;
1702 ctx
->Driver
.Flush
= gammaDDFlush
;
1704 ctx
->Driver
.Fogfv
= gammaDDFogfv
;
1706 ctx
->Driver
.Hint
= NULL
;
1707 ctx
->Driver
.LineWidth
= gammaDDLineWidth
;
1708 ctx
->Driver
.LineStipple
= gammaDDLineStipple
;
1710 ctx
->Driver
.Lightfv
= gammaDDLightfv
;
1711 ctx
->Driver
.LightModelfv
= gammaDDLightModelfv
;
1713 ctx
->Driver
.LogicOpcode
= gammaDDLogicalOpcode
;
1714 ctx
->Driver
.PointSize
= gammaDDPointSize
;
1715 ctx
->Driver
.PolygonMode
= gammaDDPolygonMode
;
1716 ctx
->Driver
.PolygonStipple
= gammaDDPolygonStipple
;
1717 ctx
->Driver
.Scissor
= gammaDDScissor
;
1718 ctx
->Driver
.ShadeModel
= gammaDDShadeModel
;
1719 ctx
->Driver
.ClearStencil
= NULL
;
1720 ctx
->Driver
.StencilFunc
= NULL
;
1721 ctx
->Driver
.StencilMask
= NULL
;
1722 ctx
->Driver
.StencilOp
= NULL
;
1723 ctx
->Driver
.Viewport
= gammaDDViewport
;