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 uint32_t a
= gmesa
->AlphaTestMode
;
48 uint32_t b
= gmesa
->AlphaBlendMode
;
49 uint32_t 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 gammaDDBlendEquationSeparate( GLcontext
*ctx
,
181 GLenum modeRGB
, GLenum modeA
)
183 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
185 assert( modeRGB
== modeA
);
186 FLUSH_BATCH( gmesa
);
188 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
191 static void gammaDDBlendFuncSeparate( GLcontext
*ctx
,
192 GLenum sfactorRGB
, GLenum dfactorRGB
,
193 GLenum sfactorA
, GLenum dfactorA
)
195 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
197 FLUSH_BATCH( gmesa
);
199 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
203 /* ================================================================
207 static void gammaDDClear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
208 GLint cx
, GLint cy
, GLint cw
, GLint ch
)
210 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
211 GLINTDRIPtr gDRIPriv
= (GLINTDRIPtr
)gmesa
->driScreen
->pDevPriv
;
214 FLUSH_BATCH( gmesa
);
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?
220 if ( gmesa
->new_state
)
221 gammaDDUpdateHWState( ctx
);
224 /* Flush any partially filled buffers */
225 FLUSH_DMA_BUFFER(gmesa
);
227 DRM_SPINLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
228 gmesa
->driScreen
->drawLockID
);
229 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa
);
232 if (mask
& DD_DEPTH_BIT
) {
233 /* Turn off writes the FB */
234 CHECK_DMA_BUFFER(gmesa
, 1);
235 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeDisable
);
237 mask
&= ~DD_DEPTH_BIT
;
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.
244 if (!gmesa
->NotClipped
) {
245 CHECK_DMA_BUFFER(gmesa
, 1);
246 WRITE(gmesa
->buf
, Rectangle2DControl
, 1);
249 temp
= (gmesa
->LBReadMode
& LBPartialProdMask
) | LBWindowOriginBot
;
250 if (gDRIPriv
->numMultiDevices
== 2) temp
|= LBScanLineInt2
;
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
|
257 DM_SourceDepthRegister
|
259 WRITE(gmesa
->buf
, GLINTDepth
, gmesa
->ClearDepth
);
261 /* Increment the frame count */
264 gmesa
->FrameCount
&= 0x0f;
266 gmesa
->FrameCount
&= 0xff;
269 /* Force FCP to be written */
270 WRITE(gmesa
->buf
, GLINTWindow
, (WindowEnable
|
272 (gmesa
->Window
& W_GIDMask
) |
274 W_LBUpdateFromRegisters
|
275 W_OverrideWriteFiltering
|
276 (gmesa
->FrameCount
<< 9)));
278 /* Clear part of the depth and FCP buffers */
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
;
287 if (gmesa
->WindowChanged
) {
288 gmesa
->WindowChanged
= GL_FALSE
;
296 /* Handle the case where the height < # of FCPs */
298 if (gmesa
->FrameCount
> h
)
299 gmesa
->FrameCount
= 0;
301 y
+= gmesa
->FrameCount
;
303 h
= (gmesa
->FrameCount
+1)*hsub
;
304 h
-= (int)(gmesa
->FrameCount
*hsub
);
305 y
+= gmesa
->FrameCount
*hsub
;
311 CHECK_DMA_BUFFER(gmesa
, 2);
312 WRITE(gmesa
->buf
, Rectangle2DMode
, ((h
& 0xfff)<<12) |
314 WRITE(gmesa
->buf
, DrawRectangle2D
, ((y
& 0xffff)<<16) |
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 */
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
);
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));
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);
351 if (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) {
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
;
357 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
359 if (x
< 0) { w
-= -x
; x
= 0; }
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);
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);
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 */
384 WRITE(gmesa
->buf
, Rectangle2DMode
, (((h
& 0xfff)<<12) |
386 WRITE(gmesa
->buf
, DrawRectangle2D
, (((y
& 0xffff)<<16) |
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
);
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);
402 PROCESS_DMA_BUFFER_TOP_HALF(gmesa
);
404 DRM_SPINUNLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
405 gmesa
->driScreen
->drawLockID
);
406 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa
);
408 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa
);
412 _swrast_Clear( ctx
, mask
, all
, cx
, cy
, cw
, ch
);
415 /* =============================================================
419 static void gammaUpdateZMode( GLcontext
*ctx
)
421 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
422 uint32_t z
= gmesa
->DepthMode
;
423 uint32_t delta
= gmesa
->DeltaMode
;
424 uint32_t window
= gmesa
->Window
;
425 uint32_t lbread
= gmesa
->LBReadMode
;
427 z
&= ~DM_CompareMask
;
429 switch ( ctx
->Depth
.Func
) {
446 z
|= DM_GreaterEqual
;
456 if ( ctx
->Depth
.Test
) {
457 z
|= DepthModeEnable
;
458 delta
|= DM_DepthEnable
;
459 window
|= W_DepthFCP
;
460 lbread
|= LBReadDstEnable
;
462 z
&= ~DepthModeEnable
;
463 delta
&= ~DM_DepthEnable
;
464 window
&= ~W_DepthFCP
;
465 lbread
&= ~LBReadDstEnable
;
468 if ( ctx
->Depth
.Mask
) {
475 if ( gmesa
->DepthMode
!= z
){
477 gmesa
->DepthMode
= z
;
478 gmesa
->DeltaMode
= delta
;
479 gmesa
->Window
= window
;
480 gmesa
->LBReadMode
= lbread
;
481 gmesa
->dirty
|= GAMMA_UPLOAD_DEPTH
;
487 static void gammaDDDepthFunc( GLcontext
*ctx
, GLenum func
)
489 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
491 FLUSH_BATCH( gmesa
);
492 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
495 static void gammaDDDepthMask( GLcontext
*ctx
, GLboolean flag
)
497 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
499 FLUSH_BATCH( gmesa
);
500 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
503 static void gammaDDClearDepth( GLcontext
*ctx
, GLclampd d
)
505 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
507 switch ( gmesa
->DepthSize
) {
509 gmesa
->ClearDepth
= d
* 0x0000ffff;
512 gmesa
->ClearDepth
= d
* 0x00ffffff;
515 gmesa
->ClearDepth
= d
* 0xffffffff;
520 static void gammaDDFinish( GLcontext
*ctx
)
522 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
524 FLUSH_DMA_BUFFER(gmesa
);
527 static void gammaDDFlush( GLcontext
*ctx
)
529 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
531 FLUSH_DMA_BUFFER(gmesa
);
534 /* =============================================================
538 static void gammaUpdateFogAttrib( GLcontext
*ctx
)
540 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
541 uint32_t f
= gmesa
->FogMode
;
542 uint32_t g
= gmesa
->GeometryMode
;
543 uint32_t d
= gmesa
->DeltaMode
;
545 if (ctx
->Fog
.Enabled
) {
557 switch (ctx
->Fog
.Mode
) {
565 g
|= GM_FogExpSquared
;
569 if ( gmesa
->FogMode
!= f
) {
571 gmesa
->dirty
|= GAMMA_UPLOAD_FOG
;
574 if ( gmesa
->GeometryMode
!= g
) {
575 gmesa
->GeometryMode
= g
;
576 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
579 if ( gmesa
->DeltaMode
!= d
) {
580 gmesa
->DeltaMode
= d
;
581 gmesa
->dirty
|= GAMMA_UPLOAD_DEPTH
;
586 static void gammaDDFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
588 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
590 FLUSH_BATCH( gmesa
);
591 gmesa
->new_state
|= GAMMA_NEW_FOG
;
595 /* =============================================================
598 static void gammaDDLineWidth( GLcontext
*ctx
, GLfloat width
)
600 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
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);
608 static void gammaDDLineStipple( GLcontext
*ctx
, GLint factor
, GLushort pattern
)
610 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
612 gmesa
->LineMode
&= ~(LM_StippleMask
| LM_RepeatFactorMask
);
613 gmesa
->LineMode
|= ((GLuint
)(factor
- 1) << 1) | ((GLuint
)pattern
<< 10);
615 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
620 /* =============================================================
623 static void gammaDDPointSize( GLcontext
*ctx
, GLfloat size
)
625 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
627 CHECK_DMA_BUFFER(gmesa
, 2);
628 WRITE(gmesa
->buf
, PointSize
, (GLuint
)size
);
629 WRITEF(gmesa
->buf
, AApointSize
, size
);
632 /* =============================================================
636 static void gammaUpdatePolygon( GLcontext
*ctx
)
638 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
639 uint32_t g
= gmesa
->GeometryMode
;
641 g
&= ~(GM_PolyOffsetFillEnable
| GM_PolyOffsetPointEnable
|
642 GM_PolyOffsetLineEnable
);
644 if (ctx
->Polygon
.OffsetFill
) g
|= GM_PolyOffsetFillEnable
;
645 if (ctx
->Polygon
.OffsetPoint
) g
|= GM_PolyOffsetPointEnable
;
646 if (ctx
->Polygon
.OffsetLine
) g
|= GM_PolyOffsetLineEnable
;
648 g
&= ~GM_FB_PolyMask
;
650 switch (ctx
->Polygon
.FrontMode
) {
652 g
|= GM_FrontPolyFill
;
655 g
|= GM_FrontPolyLine
;
658 g
|= GM_FrontPolyPoint
;
662 switch (ctx
->Polygon
.BackMode
) {
664 g
|= GM_BackPolyFill
;
667 g
|= GM_BackPolyLine
;
670 g
|= GM_BackPolyPoint
;
674 if ( gmesa
->GeometryMode
!= g
) {
675 gmesa
->GeometryMode
= g
;
676 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
679 gmesa
->dirty
|= GAMMA_UPLOAD_POLYGON
;
682 static void gammaDDPolygonMode( GLcontext
*ctx
, GLenum face
, GLenum mode
)
684 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
686 FLUSH_BATCH( gmesa
);
688 gmesa
->new_state
|= GAMMA_NEW_POLYGON
;
691 static void gammaUpdateStipple( GLcontext
*ctx
)
693 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
695 FLUSH_BATCH( gmesa
);
697 if (ctx
->Polygon
.StippleFlag
) {
698 gmesa
->AreaStippleMode
|= AreaStippleModeEnable
/* | ASM_X32 | ASM_Y32*/;
700 gmesa
->AreaStippleMode
&= ~AreaStippleModeEnable
;
703 gmesa
->dirty
|= GAMMA_UPLOAD_STIPPLE
;
706 static void gammaDDPolygonStipple( GLcontext
*ctx
, const GLubyte
*mask
)
708 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
709 FLUSH_BATCH( gmesa
);
710 gmesa
->new_state
|= GAMMA_NEW_STIPPLE
;
713 /* =============================================================
717 static void gammaUpdateClipping( GLcontext
*ctx
)
719 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
720 GLint x1
, y1
, x2
, y2
;
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
;
730 gmesa
->ScissorMinXY
= x1
| (y1
<< 16);
731 gmesa
->ScissorMaxXY
= x2
| (y2
<< 16);
732 if (ctx
->Scissor
.Enabled
)
733 gmesa
->ScissorMode
|= UserScissorEnable
;
735 gmesa
->ScissorMode
&= ~UserScissorEnable
;
737 gmesa
->dirty
|= GAMMA_UPLOAD_CLIP
;
741 static void gammaDDScissor( GLcontext
*ctx
,
742 GLint x
, GLint y
, GLsizei w
, GLsizei h
)
744 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
746 FLUSH_BATCH( gmesa
);
747 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
750 /* =============================================================
754 static void gammaUpdateCull( GLcontext
*ctx
)
756 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
757 uint32_t g
= gmesa
->GeometryMode
;
759 g
&= ~(GM_PolyCullMask
| GM_FFMask
);
761 if (ctx
->Polygon
.FrontFace
== GL_CCW
) {
762 g
|= GM_FrontFaceCCW
;
767 switch ( ctx
->Polygon
.CullFaceMode
) {
769 g
|= GM_PolyCullFront
;
772 g
|= GM_PolyCullBack
;
774 case GL_FRONT_AND_BACK
:
775 g
|= GM_PolyCullBoth
;
779 if ( ctx
->Polygon
.CullFlag
) {
780 g
|= GM_PolyCullEnable
;
782 g
&= ~GM_PolyCullEnable
;
785 if ( gmesa
->GeometryMode
!= g
) {
786 gmesa
->GeometryMode
= g
;
787 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
791 static void gammaDDCullFace( GLcontext
*ctx
, GLenum mode
)
793 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
795 FLUSH_BATCH( gmesa
);
796 gmesa
->new_state
|= GAMMA_NEW_CULL
;
799 static void gammaDDFrontFace( GLcontext
*ctx
, GLenum mode
)
801 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
803 FLUSH_BATCH( gmesa
);
804 gmesa
->new_state
|= GAMMA_NEW_CULL
;
807 /* =============================================================
811 static void gammaUpdateMasks( GLcontext
*ctx
)
813 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
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
] );
822 if (gmesa
->gammaScreen
->cpp
== 2) mask
|= mask
<< 16;
824 if ( gmesa
->FBHardwareWriteMask
!= mask
) {
825 gmesa
->FBHardwareWriteMask
= mask
;
826 gmesa
->dirty
|= GAMMA_UPLOAD_MASKS
;
830 static void gammaDDColorMask( GLcontext
*ctx
, GLboolean r
, GLboolean g
,
831 GLboolean b
, GLboolean a
)
833 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
835 FLUSH_BATCH( gmesa
);
836 gmesa
->new_state
|= GAMMA_NEW_MASKS
;
839 /* =============================================================
840 * Rendering attributes
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.
848 static void gammaDDLightfv(GLcontext
*ctx
, GLenum light
, GLenum pname
,
849 const GLfloat
*params
, GLint nParams
)
851 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
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]);
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]);
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]);
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
);
886 if (params
[3] != 0.0) {
887 gmesa
->Light0Mode
|= Light0ModeAttenuation
;
888 gmesa
->Light0Mode
|= Light0ModeLocal
;
890 gmesa
->Light0Mode
&= ~Light0ModeAttenuation
;
891 gmesa
->Light0Mode
&= ~Light0ModeLocal
;
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
);
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]);
907 case GL_SPOT_EXPONENT
:
908 CHECK_DMA_BUFFER(gmesa
, 1);
909 WRITEF(gmesa
->buf
, Light0SpotlightExponent
, params
[0]);
912 if (params
[0] != 180.0)
913 gmesa
->Light0Mode
|= Light0ModeSpotLight
;
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
));
920 case GL_CONSTANT_ATTENUATION
:
921 CHECK_DMA_BUFFER(gmesa
, 1);
922 WRITEF(gmesa
->buf
, Light0ConstantAttenuation
, params
[0]);
924 case GL_LINEAR_ATTENUATION
:
925 CHECK_DMA_BUFFER(gmesa
, 1);
926 WRITEF(gmesa
->buf
, Light0LinearAttenuation
, params
[0]);
928 case GL_QUADRATIC_ATTENUATION
:
929 CHECK_DMA_BUFFER(gmesa
, 1);
930 WRITEF(gmesa
->buf
, Light0QuadraticAttenuation
, params
[0]);
937 static void gammaDDLightModelfv( GLcontext
*ctx
, GLenum pname
,
938 const GLfloat
*params
)
940 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
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]);
950 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
951 if (params
[0] != 0.0)
952 gmesa
->LightingMode
|= LightingModeLocalViewer
;
954 gmesa
->LightingMode
&= ~LightingModeLocalViewer
;
955 CHECK_DMA_BUFFER(gmesa
, 1);
956 WRITE(gmesa
->buf
, LightingMode
, gmesa
->LightingMode
);
958 case GL_LIGHT_MODEL_TWO_SIDE
:
959 if (params
[0] == 1.0f
) {
960 gmesa
->LightingMode
|= LightingModeTwoSides
;
961 gmesa
->MaterialMode
|= MaterialModeTwoSides
;
963 gmesa
->LightingMode
&= ~LightingModeTwoSides
;
964 gmesa
->MaterialMode
&= ~MaterialModeTwoSides
;
966 CHECK_DMA_BUFFER(gmesa
, 2);
967 WRITE(gmesa
->buf
, LightingMode
, gmesa
->LightingMode
);
968 WRITE(gmesa
->buf
, MaterialMode
, gmesa
->MaterialMode
);
974 static void gammaDDShadeModel( GLcontext
*ctx
, GLenum mode
)
976 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
977 uint32_t g
= gmesa
->GeometryMode
;
978 uint32_t c
= gmesa
->ColorDDAMode
;
980 g
&= ~GM_ShadingMask
;
981 c
&= ~ColorDDAShadingMask
;
989 g
|= GM_GouraudShading
;
990 c
|= ColorDDAGouraud
;
996 if ( gmesa
->ColorDDAMode
!= c
) {
997 FLUSH_BATCH( gmesa
);
998 gmesa
->ColorDDAMode
= c
;
1000 gmesa
->dirty
|= GAMMA_UPLOAD_SHADE
;
1003 if ( gmesa
->GeometryMode
!= g
) {
1004 FLUSH_BATCH( gmesa
);
1005 gmesa
->GeometryMode
= g
;
1007 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
1011 /* =============================================================
1015 static void gammaDDClearColor( GLcontext
*ctx
, const GLfloat color
[4])
1017 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
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]);
1024 gmesa
->ClearColor
= gammaPackColor( gmesa
->gammaScreen
->cpp
,
1025 c
[0], c
[1], c
[2], c
[3] );
1027 if (gmesa
->gammaScreen
->cpp
== 2) gmesa
->ClearColor
|= gmesa
->ClearColor
<<16;
1031 static void gammaDDLogicalOpcode( GLcontext
*ctx
, GLenum opcode
)
1033 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1035 FLUSH_BATCH( gmesa
);
1037 if ( ctx
->Color
.ColorLogicOpEnabled
) {
1038 gmesa
->LogicalOpMode
= opcode
<< 1 | LogicalOpModeEnable
;
1040 gmesa
->LogicalOpMode
= LogicalOpModeDisable
;
1043 gmesa
->dirty
|= GAMMA_UPLOAD_LOGICOP
;
1046 static void gammaDDDrawBuffer( GLcontext
*ctx
, GLenum mode
)
1048 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1050 FLUSH_BATCH( gmesa
);
1054 gmesa
->drawOffset
= gmesa
->readOffset
= 0;
1057 gmesa
->drawOffset
= gmesa
->readOffset
= gmesa
->driScreen
->fbHeight
* gmesa
->driScreen
->fbWidth
* gmesa
->gammaScreen
->cpp
;
1062 static void gammaDDReadBuffer( GLcontext
*ctx
, GLenum mode
)
1067 /* =============================================================
1068 * Window position and viewport transformation
1071 void gammaUpdateWindow( GLcontext
*ctx
)
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
;
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
;
1086 gmesa
->dirty
|= GAMMA_UPLOAD_VIEWPORT
;
1088 gmesa
->ViewportScaleX
= sx
;
1089 gmesa
->ViewportScaleY
= sy
;
1090 gmesa
->ViewportScaleZ
= sz
;
1091 gmesa
->ViewportOffsetX
= tx
;
1092 gmesa
->ViewportOffsetY
= ty
;
1093 gmesa
->ViewportOffsetZ
= tz
;
1098 static void gammaDDViewport( GLcontext
*ctx
, GLint x
, GLint y
,
1099 GLsizei width
, GLsizei height
)
1101 gammaUpdateWindow( ctx
);
1104 static void gammaDDDepthRange( GLcontext
*ctx
, GLclampd nearval
,
1107 gammaUpdateWindow( ctx
);
1110 void gammaUpdateViewportOffset( GLcontext
*ctx
)
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
;
1118 GLfloat tx
= v
[MAT_TX
] + xoffset
;
1119 GLfloat ty
= v
[MAT_TY
] + yoffset
;
1121 if ( gmesa
->ViewportOffsetX
!= tx
||
1122 gmesa
->ViewportOffsetY
!= ty
)
1124 gmesa
->ViewportOffsetX
= tx
;
1125 gmesa
->ViewportOffsetY
= ty
;
1127 gmesa
->new_state
|= GAMMA_NEW_WINDOW
;
1130 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
1138 static void gammaLoadHWMatrix(GLcontext
*ctx
)
1140 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1143 gmesa
->TransformMode
&= ~XM_XformTexture
;
1145 switch (ctx
->Transform
.MatrixMode
) {
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]);
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]);
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]);
1210 /* ERROR!!! -- how did this happen? */
1214 gmesa
->dirty
|= GAMMA_UPLOAD_TRANSFORM
;
1218 /* =============================================================
1219 * State enable/disable
1222 static void gammaDDEnable( GLcontext
*ctx
, GLenum cap
, GLboolean state
)
1224 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1229 FLUSH_BATCH( gmesa
);
1230 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
1234 FLUSH_BATCH( gmesa
);
1235 gmesa
->new_state
|= GAMMA_NEW_CULL
;
1239 FLUSH_BATCH( gmesa
);
1240 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
1245 uint32_t d
= gmesa
->DitherMode
;
1246 FLUSH_BATCH( gmesa
);
1249 d
|= DM_DitherEnable
;
1251 d
&= ~DM_DitherEnable
;
1254 if ( gmesa
->DitherMode
!= d
) {
1255 gmesa
->DitherMode
= d
;
1256 gmesa
->dirty
|= GAMMA_UPLOAD_DITHER
;
1263 FLUSH_BATCH( gmesa
);
1264 gmesa
->new_state
|= GAMMA_NEW_FOG
;
1268 case GL_INDEX_LOGIC_OP
:
1269 case GL_COLOR_LOGIC_OP
:
1270 FLUSH_BATCH( gmesa
);
1271 gmesa
->new_state
|= GAMMA_NEW_LOGICOP
;
1277 uint32_t l
= gmesa
->LightingMode
;
1278 FLUSH_BATCH( gmesa
);
1281 l
|= LightingModeEnable
;
1283 l
&= ~LightingModeEnable
;
1286 if ( gmesa
->LightingMode
!= l
) {
1287 gmesa
->LightingMode
= l
;
1288 gmesa
->dirty
|= GAMMA_UPLOAD_LIGHT
;
1293 case GL_COLOR_MATERIAL
:
1295 uint32_t m
= gmesa
->MaterialMode
;
1296 FLUSH_BATCH( gmesa
);
1299 m
|= MaterialModeEnable
;
1301 m
&= ~MaterialModeEnable
;
1304 if ( gmesa
->MaterialMode
!= m
) {
1305 gmesa
->MaterialMode
= m
;
1306 gmesa
->dirty
|= GAMMA_UPLOAD_LIGHT
;
1312 case GL_LINE_SMOOTH
:
1313 FLUSH_BATCH( gmesa
);
1315 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1316 gmesa
->LineMode
|= LM_AntialiasEnable
;
1318 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1319 gmesa
->LineMode
&= ~LM_AntialiasEnable
;
1321 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
1324 case GL_POINT_SMOOTH
:
1325 FLUSH_BATCH( gmesa
);
1327 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1328 gmesa
->PointMode
|= PM_AntialiasEnable
;
1330 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1331 gmesa
->PointMode
&= ~PM_AntialiasEnable
;
1333 gmesa
->dirty
|= GAMMA_UPLOAD_POINTMODE
;
1336 case GL_POLYGON_SMOOTH
:
1337 FLUSH_BATCH( gmesa
);
1339 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1340 gmesa
->TriangleMode
|= TM_AntialiasEnable
;
1342 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1343 gmesa
->TriangleMode
&= ~TM_AntialiasEnable
;
1345 gmesa
->dirty
|= GAMMA_UPLOAD_TRIMODE
;
1348 case GL_SCISSOR_TEST
:
1349 FLUSH_BATCH( gmesa
);
1350 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
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
;
1360 case GL_LINE_STIPPLE
:
1361 FLUSH_BATCH( gmesa
);
1363 gmesa
->LineMode
|= LM_StippleEnable
;
1365 gmesa
->LineMode
&= ~LM_StippleEnable
;
1366 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
1369 case GL_POLYGON_STIPPLE
:
1370 FLUSH_BATCH( gmesa
);
1371 gmesa
->new_state
|= GAMMA_NEW_STIPPLE
;
1379 /* =============================================================
1380 * State initialization, management
1385 * Load the current context's state into the hardware.
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
1392 * Blits of any type should always upload the context and masks after
1395 void gammaEmitHwState( gammaContextPtr gmesa
)
1397 if (!gmesa
->driDrawable
) return;
1399 if (!gmesa
->dirty
) return;
1402 /* Flush any partially filled buffers */
1403 FLUSH_DMA_BUFFER(gmesa
);
1405 DRM_SPINLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
1406 gmesa
->driScreen
->drawLockID
);
1407 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa
);
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
);
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
);
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
);
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
);
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
);
1442 if (gmesa
->dirty
& GAMMA_UPLOAD_FOG
) {
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);
1449 WRITE(gmesa
->buf
, FogMode
, gmesa
->FogMode
);
1450 WRITE(gmesa
->buf
, FogColor
, col
);
1451 WRITEF(gmesa
->buf
, FStart
, gmesa
->glCtx
->Fog
.Start
);
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
));
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
);
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
);
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
);
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
);
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
);
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
);
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
);
1494 WRITE(gmesa
->buf
, FBReadMode
, gmesa
->FBReadMode
);
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
);
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
);
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
);
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]);
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
);
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
);
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
);
1568 if (gmesa
->dirty
& GAMMA_UPLOAD_TEX0
) {
1569 gammaTextureObjectPtr curTex
= gmesa
->CurrentTexObj
[0];
1570 gmesa
->dirty
&= ~GAMMA_UPLOAD_TEX0
;
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
, TxBaseAddr12
, curTex
->TextureBaseAddr
[12]);
1594 WRITE(gmesa
->buf
, TextureCacheControl
, (TCC_Enable
| TCC_Invalidate
));
1596 CHECK_DMA_BUFFER(gmesa
, 6);
1597 WRITE(gmesa
->buf
, GeometryMode
, gmesa
->GeometryMode
);
1598 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
1599 WRITE(gmesa
->buf
, TextureAddressMode
, TextureAddressModeDisable
);
1600 WRITE(gmesa
->buf
, TextureReadMode
, TextureReadModeDisable
);
1601 WRITE(gmesa
->buf
, TextureFilterMode
, TextureFilterModeDisable
);
1602 WRITE(gmesa
->buf
, TextureColorMode
, TextureColorModeDisable
);
1606 PROCESS_DMA_BUFFER_TOP_HALF(gmesa
);
1608 DRM_SPINUNLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
1609 gmesa
->driScreen
->drawLockID
);
1610 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa
);
1612 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa
);
1616 void gammaDDUpdateHWState( GLcontext
*ctx
)
1618 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1619 int new_state
= gmesa
->new_state
;
1623 FLUSH_BATCH( gmesa
);
1625 gmesa
->new_state
= 0;
1627 /* Update the various parts of the context's state.
1629 if ( new_state
& GAMMA_NEW_ALPHA
)
1630 gammaUpdateAlphaMode( ctx
);
1632 if ( new_state
& GAMMA_NEW_DEPTH
)
1633 gammaUpdateZMode( ctx
);
1635 if ( new_state
& GAMMA_NEW_FOG
)
1636 gammaUpdateFogAttrib( ctx
);
1638 if ( new_state
& GAMMA_NEW_CLIP
)
1639 gammaUpdateClipping( ctx
);
1641 if ( new_state
& GAMMA_NEW_POLYGON
)
1642 gammaUpdatePolygon( ctx
);
1644 if ( new_state
& GAMMA_NEW_CULL
)
1645 gammaUpdateCull( ctx
);
1647 if ( new_state
& GAMMA_NEW_MASKS
)
1648 gammaUpdateMasks( ctx
);
1650 if ( new_state
& GAMMA_NEW_WINDOW
)
1651 gammaUpdateWindow( ctx
);
1653 if ( new_state
& GAMMA_NEW_STIPPLE
)
1654 gammaUpdateStipple( ctx
);
1659 gammaEmitHwState( gmesa
);
1663 static void gammaDDUpdateState( GLcontext
*ctx
, GLuint new_state
)
1665 _swrast_InvalidateState( ctx
, new_state
);
1666 _swsetup_InvalidateState( ctx
, new_state
);
1667 _ac_InvalidateState( ctx
, new_state
);
1668 _tnl_InvalidateState( ctx
, new_state
);
1669 GAMMA_CONTEXT(ctx
)->new_gl_state
|= new_state
;
1673 /* Initialize the context's hardware state.
1675 void gammaDDInitState( gammaContextPtr gmesa
)
1677 gmesa
->new_state
= 0;
1680 /* Initialize the driver's state functions.
1682 void gammaDDInitStateFuncs( GLcontext
*ctx
)
1684 ctx
->Driver
.UpdateState
= gammaDDUpdateState
;
1686 ctx
->Driver
.Clear
= gammaDDClear
;
1687 ctx
->Driver
.ClearIndex
= NULL
;
1688 ctx
->Driver
.ClearColor
= gammaDDClearColor
;
1689 ctx
->Driver
.DrawBuffer
= gammaDDDrawBuffer
;
1690 ctx
->Driver
.ReadBuffer
= gammaDDReadBuffer
;
1692 ctx
->Driver
.IndexMask
= NULL
;
1693 ctx
->Driver
.ColorMask
= gammaDDColorMask
;
1695 ctx
->Driver
.AlphaFunc
= gammaDDAlphaFunc
;
1696 ctx
->Driver
.BlendEquationSeparate
= gammaDDBlendEquationSeparate
;
1697 ctx
->Driver
.BlendFuncSeparate
= gammaDDBlendFuncSeparate
;
1698 ctx
->Driver
.ClearDepth
= gammaDDClearDepth
;
1699 ctx
->Driver
.CullFace
= gammaDDCullFace
;
1700 ctx
->Driver
.FrontFace
= gammaDDFrontFace
;
1701 ctx
->Driver
.DepthFunc
= gammaDDDepthFunc
;
1702 ctx
->Driver
.DepthMask
= gammaDDDepthMask
;
1703 ctx
->Driver
.DepthRange
= gammaDDDepthRange
;
1704 ctx
->Driver
.Enable
= gammaDDEnable
;
1705 ctx
->Driver
.Finish
= gammaDDFinish
;
1706 ctx
->Driver
.Flush
= gammaDDFlush
;
1708 ctx
->Driver
.Fogfv
= gammaDDFogfv
;
1710 ctx
->Driver
.Hint
= NULL
;
1711 ctx
->Driver
.LineWidth
= gammaDDLineWidth
;
1712 ctx
->Driver
.LineStipple
= gammaDDLineStipple
;
1714 ctx
->Driver
.Lightfv
= gammaDDLightfv
;
1715 ctx
->Driver
.LightModelfv
= gammaDDLightModelfv
;
1717 ctx
->Driver
.LogicOpcode
= gammaDDLogicalOpcode
;
1718 ctx
->Driver
.PointSize
= gammaDDPointSize
;
1719 ctx
->Driver
.PolygonMode
= gammaDDPolygonMode
;
1720 ctx
->Driver
.PolygonStipple
= gammaDDPolygonStipple
;
1721 ctx
->Driver
.Scissor
= gammaDDScissor
;
1722 ctx
->Driver
.ShadeModel
= gammaDDShadeModel
;
1723 ctx
->Driver
.ClearStencil
= NULL
;
1724 ctx
->Driver
.StencilFunc
= NULL
;
1725 ctx
->Driver
.StencilMask
= NULL
;
1726 ctx
->Driver
.StencilOp
= NULL
;
1727 ctx
->Driver
.Viewport
= gammaDDViewport
;