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"
32 #include "glint_dri.h"
34 #include "swrast/swrast.h"
35 #include "swrast_setup/swrast_setup.h"
36 #include "array_cache/acache.h"
39 #define ENABLELIGHTING 0
41 /* =============================================================
45 static void gammaUpdateAlphaMode( GLcontext
*ctx
)
47 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
48 uint32_t a
= gmesa
->AlphaTestMode
;
49 uint32_t b
= gmesa
->AlphaBlendMode
;
50 uint32_t f
= gmesa
->AB_FBReadMode_Save
= 0;
51 GLubyte refByte
= (GLint
) (ctx
->Color
.AlphaRef
* 255.0);
53 a
&= ~(AT_CompareMask
| AT_RefValueMask
);
54 b
&= ~(AB_SrcBlendMask
| AB_DstBlendMask
);
58 switch ( ctx
->Color
.AlphaFunc
) {
85 if ( ctx
->Color
.AlphaEnabled
) {
87 a
|= AlphaTestModeEnable
;
89 a
&= ~AlphaTestModeEnable
;
92 switch ( ctx
->Color
.BlendSrcRGB
) {
100 b
|= AB_Src_DstColor
;
102 case GL_ONE_MINUS_DST_COLOR
:
103 b
|= AB_Src_OneMinusDstColor
;
106 b
|= AB_Src_SrcAlpha
;
108 case GL_ONE_MINUS_SRC_ALPHA
:
109 b
|= AB_Src_OneMinusSrcAlpha
;
112 b
|= AB_Src_DstAlpha
;
113 f
|= FBReadSrcEnable
;
115 case GL_ONE_MINUS_DST_ALPHA
:
116 b
|= AB_Src_OneMinusDstAlpha
;
117 f
|= FBReadSrcEnable
;
119 case GL_SRC_ALPHA_SATURATE
:
120 b
|= AB_Src_SrcAlphaSaturate
;
124 switch ( ctx
->Color
.BlendDstRGB
) {
132 b
|= AB_Dst_SrcColor
;
134 case GL_ONE_MINUS_SRC_COLOR
:
135 b
|= AB_Dst_OneMinusSrcColor
;
138 b
|= AB_Dst_SrcAlpha
;
140 case GL_ONE_MINUS_SRC_ALPHA
:
141 b
|= AB_Dst_OneMinusSrcAlpha
;
144 b
|= AB_Dst_DstAlpha
;
145 f
|= FBReadSrcEnable
;
147 case GL_ONE_MINUS_DST_ALPHA
:
148 b
|= AB_Dst_OneMinusDstAlpha
;
149 f
|= FBReadSrcEnable
;
153 if ( ctx
->Color
.BlendEnabled
) {
154 f
|= FBReadDstEnable
;
155 b
|= AlphaBlendModeEnable
;
157 b
&= ~AlphaBlendModeEnable
;
160 if ( gmesa
->AlphaTestMode
!= a
) {
161 gmesa
->AlphaTestMode
= a
;
162 gmesa
->dirty
|= GAMMA_UPLOAD_ALPHA
;
164 if ( gmesa
->AlphaBlendMode
!= b
) {
165 gmesa
->AlphaBlendMode
= b
;
166 gmesa
->dirty
|= GAMMA_UPLOAD_BLEND
;
168 gmesa
->AB_FBReadMode_Save
= f
;
171 static void gammaDDAlphaFunc( GLcontext
*ctx
, GLenum func
, GLfloat ref
)
173 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
176 FLUSH_BATCH( gmesa
);
178 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
181 static void gammaDDBlendEquationSeparate( GLcontext
*ctx
,
182 GLenum modeRGB
, GLenum modeA
)
184 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
186 assert( modeRGB
== modeA
);
187 FLUSH_BATCH( gmesa
);
189 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
192 static void gammaDDBlendFuncSeparate( GLcontext
*ctx
,
193 GLenum sfactorRGB
, GLenum dfactorRGB
,
194 GLenum sfactorA
, GLenum dfactorA
)
196 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
198 FLUSH_BATCH( gmesa
);
200 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
204 /* ================================================================
208 static void gammaDDClear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
209 GLint cx
, GLint cy
, GLint cw
, GLint ch
)
211 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
212 GLINTDRIPtr gDRIPriv
= (GLINTDRIPtr
)gmesa
->driScreen
->pDevPriv
;
215 FLUSH_BATCH( gmesa
);
217 /* Update and emit any new state. We need to do this here to catch
218 * changes to the masks.
219 * FIXME: Just update the masks?
221 if ( gmesa
->new_state
)
222 gammaDDUpdateHWState( ctx
);
225 /* Flush any partially filled buffers */
226 FLUSH_DMA_BUFFER(gmesa
);
228 DRM_SPINLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
229 gmesa
->driScreen
->drawLockID
);
230 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa
);
233 if (mask
& DD_DEPTH_BIT
) {
234 /* Turn off writes the FB */
235 CHECK_DMA_BUFFER(gmesa
, 1);
236 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeDisable
);
238 mask
&= ~DD_DEPTH_BIT
;
241 * Turn Rectangle2DControl off when the window is not clipped
242 * (i.e., the GID tests are not necessary). This dramatically
243 * increases the performance of the depth clears.
245 if (!gmesa
->NotClipped
) {
246 CHECK_DMA_BUFFER(gmesa
, 1);
247 WRITE(gmesa
->buf
, Rectangle2DControl
, 1);
250 temp
= (gmesa
->LBReadMode
& LBPartialProdMask
) | LBWindowOriginBot
;
251 if (gDRIPriv
->numMultiDevices
== 2) temp
|= LBScanLineInt2
;
253 CHECK_DMA_BUFFER(gmesa
, 5);
254 WRITE(gmesa
->buf
, LBReadMode
, temp
);
255 WRITE(gmesa
->buf
, DeltaMode
, DM_DepthEnable
);
256 WRITE(gmesa
->buf
, DepthMode
, (DepthModeEnable
|
258 DM_SourceDepthRegister
|
260 WRITE(gmesa
->buf
, GLINTDepth
, gmesa
->ClearDepth
);
262 /* Increment the frame count */
265 gmesa
->FrameCount
&= 0x0f;
267 gmesa
->FrameCount
&= 0xff;
270 /* Force FCP to be written */
271 WRITE(gmesa
->buf
, GLINTWindow
, (WindowEnable
|
273 (gmesa
->Window
& W_GIDMask
) |
275 W_LBUpdateFromRegisters
|
276 W_OverrideWriteFiltering
|
277 (gmesa
->FrameCount
<< 9)));
279 /* Clear part of the depth and FCP buffers */
281 int y
= gmesa
->driScreen
->fbHeight
- gmesa
->driDrawable
->y
- gmesa
->driDrawable
->h
;
282 int x
= gmesa
->driDrawable
->x
;
283 int w
= gmesa
->driDrawable
->w
;
284 int h
= gmesa
->driDrawable
->h
;
288 if (gmesa
->WindowChanged
) {
289 gmesa
->WindowChanged
= GL_FALSE
;
297 /* Handle the case where the height < # of FCPs */
299 if (gmesa
->FrameCount
> h
)
300 gmesa
->FrameCount
= 0;
302 y
+= gmesa
->FrameCount
;
304 h
= (gmesa
->FrameCount
+1)*hsub
;
305 h
-= (int)(gmesa
->FrameCount
*hsub
);
306 y
+= gmesa
->FrameCount
*hsub
;
312 CHECK_DMA_BUFFER(gmesa
, 2);
313 WRITE(gmesa
->buf
, Rectangle2DMode
, ((h
& 0xfff)<<12) |
315 WRITE(gmesa
->buf
, DrawRectangle2D
, ((y
& 0xffff)<<16) |
318 CHECK_DMA_BUFFER(gmesa
, 8);
319 WRITE(gmesa
->buf
, StartXDom
, x
<<16);
320 WRITE(gmesa
->buf
, StartY
, y
<<16);
321 WRITE(gmesa
->buf
, StartXSub
, (x
+w
)<<16);
322 WRITE(gmesa
->buf
, GLINTCount
, h
);
323 WRITE(gmesa
->buf
, dY
, 1<<16);
324 WRITE(gmesa
->buf
, dXDom
, 0<<16);
325 WRITE(gmesa
->buf
, dXSub
, 0<<16);
326 WRITE(gmesa
->buf
, Render
, 0x00000040); /* NOT_DONE */
331 CHECK_DMA_BUFFER(gmesa
, 6);
332 WRITE(gmesa
->buf
, DepthMode
, gmesa
->DepthMode
);
333 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
334 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
);
335 WRITE(gmesa
->buf
, GLINTWindow
, gmesa
->Window
);
336 WRITE(gmesa
->buf
, FastClearDepth
, gmesa
->ClearDepth
);
337 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeEnable
);
339 /* Turn on Depth FCP */
340 if (gmesa
->Window
& W_DepthFCP
) {
341 CHECK_DMA_BUFFER(gmesa
, 1);
342 WRITE(gmesa
->buf
, WindowOr
, (gmesa
->FrameCount
<< 9));
345 /* Turn off GID clipping if window is not clipped */
346 if (gmesa
->NotClipped
) {
347 CHECK_DMA_BUFFER(gmesa
, 1);
348 WRITE(gmesa
->buf
, Rectangle2DControl
, 0);
352 if (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) {
353 int y
= gmesa
->driScreen
->fbHeight
- gmesa
->driDrawable
->y
- gmesa
->driDrawable
->h
;
354 int x
= gmesa
->driDrawable
->x
;
355 int w
= gmesa
->driDrawable
->w
;
356 int h
= gmesa
->driDrawable
->h
;
358 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
360 if (x
< 0) { w
-= -x
; x
= 0; }
362 /* Turn on GID clipping if window is clipped */
363 if (!gmesa
->NotClipped
) {
364 CHECK_DMA_BUFFER(gmesa
, 1);
365 WRITE(gmesa
->buf
, Rectangle2DControl
, 1);
368 CHECK_DMA_BUFFER(gmesa
, 18);
369 WRITE(gmesa
->buf
, FBBlockColor
, gmesa
->ClearColor
);
370 WRITE(gmesa
->buf
, ColorDDAMode
, ColorDDADisable
);
371 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeEnable
);
372 WRITE(gmesa
->buf
, DepthMode
, 0);
373 WRITE(gmesa
->buf
, DeltaMode
, 0);
374 WRITE(gmesa
->buf
, AlphaBlendMode
, 0);
376 WRITE(gmesa
->buf
, dY
, 1<<16);
377 WRITE(gmesa
->buf
, dXDom
, 0<<16);
378 WRITE(gmesa
->buf
, dXSub
, 0<<16);
379 WRITE(gmesa
->buf
, StartXSub
, (x
+w
)<<16);
380 WRITE(gmesa
->buf
, GLINTCount
, h
);
381 WRITE(gmesa
->buf
, StartXDom
, x
<<16);
382 WRITE(gmesa
->buf
, StartY
, y
<<16);
383 WRITE(gmesa
->buf
, Render
, 0x00000048); /* NOT_DONE */
385 WRITE(gmesa
->buf
, Rectangle2DMode
, (((h
& 0xfff)<<12) |
387 WRITE(gmesa
->buf
, DrawRectangle2D
, (((y
& 0xffff)<<16) |
390 WRITE(gmesa
->buf
, DepthMode
, gmesa
->DepthMode
);
391 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
392 WRITE(gmesa
->buf
, AlphaBlendMode
, gmesa
->AlphaBlendMode
);
393 WRITE(gmesa
->buf
, ColorDDAMode
, gmesa
->ColorDDAMode
);
395 /* Turn off GID clipping if window is clipped */
396 if (gmesa
->NotClipped
) {
397 CHECK_DMA_BUFFER(gmesa
, 1);
398 WRITE(gmesa
->buf
, Rectangle2DControl
, 0);
403 PROCESS_DMA_BUFFER_TOP_HALF(gmesa
);
405 DRM_SPINUNLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
406 gmesa
->driScreen
->drawLockID
);
407 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa
);
409 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa
);
413 _swrast_Clear( ctx
, mask
, all
, cx
, cy
, cw
, ch
);
416 /* =============================================================
420 static void gammaUpdateZMode( GLcontext
*ctx
)
422 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
423 uint32_t z
= gmesa
->DepthMode
;
424 uint32_t delta
= gmesa
->DeltaMode
;
425 uint32_t window
= gmesa
->Window
;
426 uint32_t lbread
= gmesa
->LBReadMode
;
428 z
&= ~DM_CompareMask
;
430 switch ( ctx
->Depth
.Func
) {
447 z
|= DM_GreaterEqual
;
457 if ( ctx
->Depth
.Test
) {
458 z
|= DepthModeEnable
;
459 delta
|= DM_DepthEnable
;
460 window
|= W_DepthFCP
;
461 lbread
|= LBReadDstEnable
;
463 z
&= ~DepthModeEnable
;
464 delta
&= ~DM_DepthEnable
;
465 window
&= ~W_DepthFCP
;
466 lbread
&= ~LBReadDstEnable
;
469 if ( ctx
->Depth
.Mask
) {
476 if ( gmesa
->DepthMode
!= z
){
478 gmesa
->DepthMode
= z
;
479 gmesa
->DeltaMode
= delta
;
480 gmesa
->Window
= window
;
481 gmesa
->LBReadMode
= lbread
;
482 gmesa
->dirty
|= GAMMA_UPLOAD_DEPTH
;
488 static void gammaDDDepthFunc( GLcontext
*ctx
, GLenum func
)
490 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
492 FLUSH_BATCH( gmesa
);
493 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
496 static void gammaDDDepthMask( GLcontext
*ctx
, GLboolean flag
)
498 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
500 FLUSH_BATCH( gmesa
);
501 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
504 static void gammaDDClearDepth( GLcontext
*ctx
, GLclampd d
)
506 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
508 switch ( gmesa
->DepthSize
) {
510 gmesa
->ClearDepth
= d
* 0x0000ffff;
513 gmesa
->ClearDepth
= d
* 0x00ffffff;
516 gmesa
->ClearDepth
= d
* 0xffffffff;
521 static void gammaDDFinish( GLcontext
*ctx
)
523 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
525 FLUSH_DMA_BUFFER(gmesa
);
528 static void gammaDDFlush( GLcontext
*ctx
)
530 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
532 FLUSH_DMA_BUFFER(gmesa
);
535 /* =============================================================
539 static void gammaUpdateFogAttrib( GLcontext
*ctx
)
541 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
542 uint32_t f
= gmesa
->FogMode
;
543 uint32_t g
= gmesa
->GeometryMode
;
544 uint32_t d
= gmesa
->DeltaMode
;
546 if (ctx
->Fog
.Enabled
) {
558 switch (ctx
->Fog
.Mode
) {
566 g
|= GM_FogExpSquared
;
570 if ( gmesa
->FogMode
!= f
) {
572 gmesa
->dirty
|= GAMMA_UPLOAD_FOG
;
575 if ( gmesa
->GeometryMode
!= g
) {
576 gmesa
->GeometryMode
= g
;
577 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
580 if ( gmesa
->DeltaMode
!= d
) {
581 gmesa
->DeltaMode
= d
;
582 gmesa
->dirty
|= GAMMA_UPLOAD_DEPTH
;
587 static void gammaDDFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
589 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
591 FLUSH_BATCH( gmesa
);
592 gmesa
->new_state
|= GAMMA_NEW_FOG
;
596 /* =============================================================
599 static void gammaDDLineWidth( GLcontext
*ctx
, GLfloat width
)
601 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
603 CHECK_DMA_BUFFER(gmesa
, 3);
604 WRITE(gmesa
->buf
, LineWidth
, (GLuint
)width
);
605 WRITEF(gmesa
->buf
, AAlineWidth
, width
);
606 WRITE(gmesa
->buf
, LineWidthOffset
, (GLuint
)(width
-1)/2);
609 static void gammaDDLineStipple( GLcontext
*ctx
, GLint factor
, GLushort pattern
)
611 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
613 gmesa
->LineMode
&= ~(LM_StippleMask
| LM_RepeatFactorMask
);
614 gmesa
->LineMode
|= ((GLuint
)(factor
- 1) << 1) | ((GLuint
)pattern
<< 10);
616 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
621 /* =============================================================
624 static void gammaDDPointSize( GLcontext
*ctx
, GLfloat size
)
626 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
628 CHECK_DMA_BUFFER(gmesa
, 2);
629 WRITE(gmesa
->buf
, PointSize
, (GLuint
)size
);
630 WRITEF(gmesa
->buf
, AApointSize
, size
);
633 /* =============================================================
637 static void gammaUpdatePolygon( GLcontext
*ctx
)
639 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
640 uint32_t g
= gmesa
->GeometryMode
;
642 g
&= ~(GM_PolyOffsetFillEnable
| GM_PolyOffsetPointEnable
|
643 GM_PolyOffsetLineEnable
);
645 if (ctx
->Polygon
.OffsetFill
) g
|= GM_PolyOffsetFillEnable
;
646 if (ctx
->Polygon
.OffsetPoint
) g
|= GM_PolyOffsetPointEnable
;
647 if (ctx
->Polygon
.OffsetLine
) g
|= GM_PolyOffsetLineEnable
;
649 g
&= ~GM_FB_PolyMask
;
651 switch (ctx
->Polygon
.FrontMode
) {
653 g
|= GM_FrontPolyFill
;
656 g
|= GM_FrontPolyLine
;
659 g
|= GM_FrontPolyPoint
;
663 switch (ctx
->Polygon
.BackMode
) {
665 g
|= GM_BackPolyFill
;
668 g
|= GM_BackPolyLine
;
671 g
|= GM_BackPolyPoint
;
675 if ( gmesa
->GeometryMode
!= g
) {
676 gmesa
->GeometryMode
= g
;
677 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
680 gmesa
->dirty
|= GAMMA_UPLOAD_POLYGON
;
683 static void gammaDDPolygonMode( GLcontext
*ctx
, GLenum face
, GLenum mode
)
685 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
687 FLUSH_BATCH( gmesa
);
689 gmesa
->new_state
|= GAMMA_NEW_POLYGON
;
692 static void gammaUpdateStipple( GLcontext
*ctx
)
694 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
696 FLUSH_BATCH( gmesa
);
698 if (ctx
->Polygon
.StippleFlag
) {
699 gmesa
->AreaStippleMode
|= AreaStippleModeEnable
/* | ASM_X32 | ASM_Y32*/;
701 gmesa
->AreaStippleMode
&= ~AreaStippleModeEnable
;
704 gmesa
->dirty
|= GAMMA_UPLOAD_STIPPLE
;
707 static void gammaDDPolygonStipple( GLcontext
*ctx
, const GLubyte
*mask
)
709 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
710 FLUSH_BATCH( gmesa
);
711 gmesa
->new_state
|= GAMMA_NEW_STIPPLE
;
714 /* =============================================================
718 static void gammaUpdateClipping( GLcontext
*ctx
)
720 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
721 GLint x1
, y1
, x2
, y2
;
723 if ( gmesa
->driDrawable
) {
724 x1
= gmesa
->driDrawable
->x
+ ctx
->Scissor
.X
;
725 y1
= gmesa
->driScreen
->fbHeight
-
726 (gmesa
->driDrawable
->y
+
727 gmesa
->driDrawable
->h
) + ctx
->Scissor
.Y
;
728 x2
= x1
+ ctx
->Scissor
.Width
;
729 y2
= y1
+ ctx
->Scissor
.Height
;
731 gmesa
->ScissorMinXY
= x1
| (y1
<< 16);
732 gmesa
->ScissorMaxXY
= x2
| (y2
<< 16);
733 if (ctx
->Scissor
.Enabled
)
734 gmesa
->ScissorMode
|= UserScissorEnable
;
736 gmesa
->ScissorMode
&= ~UserScissorEnable
;
738 gmesa
->dirty
|= GAMMA_UPLOAD_CLIP
;
742 static void gammaDDScissor( GLcontext
*ctx
,
743 GLint x
, GLint y
, GLsizei w
, GLsizei h
)
745 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
747 FLUSH_BATCH( gmesa
);
748 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
751 /* =============================================================
755 static void gammaUpdateCull( GLcontext
*ctx
)
757 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
758 uint32_t g
= gmesa
->GeometryMode
;
760 g
&= ~(GM_PolyCullMask
| GM_FFMask
);
762 if (ctx
->Polygon
.FrontFace
== GL_CCW
) {
763 g
|= GM_FrontFaceCCW
;
768 switch ( ctx
->Polygon
.CullFaceMode
) {
770 g
|= GM_PolyCullFront
;
773 g
|= GM_PolyCullBack
;
775 case GL_FRONT_AND_BACK
:
776 g
|= GM_PolyCullBoth
;
780 if ( ctx
->Polygon
.CullFlag
) {
781 g
|= GM_PolyCullEnable
;
783 g
&= ~GM_PolyCullEnable
;
786 if ( gmesa
->GeometryMode
!= g
) {
787 gmesa
->GeometryMode
= g
;
788 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
792 static void gammaDDCullFace( GLcontext
*ctx
, GLenum mode
)
794 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
796 FLUSH_BATCH( gmesa
);
797 gmesa
->new_state
|= GAMMA_NEW_CULL
;
800 static void gammaDDFrontFace( GLcontext
*ctx
, GLenum mode
)
802 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
804 FLUSH_BATCH( gmesa
);
805 gmesa
->new_state
|= GAMMA_NEW_CULL
;
808 /* =============================================================
812 static void gammaUpdateMasks( GLcontext
*ctx
)
814 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
817 GLuint mask
= gammaPackColor( gmesa
->gammaScreen
->cpp
,
818 ctx
->Color
.ColorMask
[RCOMP
],
819 ctx
->Color
.ColorMask
[GCOMP
],
820 ctx
->Color
.ColorMask
[BCOMP
],
821 ctx
->Color
.ColorMask
[ACOMP
] );
823 if (gmesa
->gammaScreen
->cpp
== 2) mask
|= mask
<< 16;
825 if ( gmesa
->FBHardwareWriteMask
!= mask
) {
826 gmesa
->FBHardwareWriteMask
= mask
;
827 gmesa
->dirty
|= GAMMA_UPLOAD_MASKS
;
831 static void gammaDDColorMask( GLcontext
*ctx
, GLboolean r
, GLboolean g
,
832 GLboolean b
, GLboolean a
)
834 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
836 FLUSH_BATCH( gmesa
);
837 gmesa
->new_state
|= GAMMA_NEW_MASKS
;
840 /* =============================================================
841 * Rendering attributes
843 * We really don't want to recalculate all this every time we bind a
844 * texture. These things shouldn't change all that often, so it makes
845 * sense to break them out of the core texture state update routines.
849 static void gammaDDLightfv(GLcontext
*ctx
, GLenum light
, GLenum pname
,
850 const GLfloat
*params
, GLint nParams
)
852 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
859 CHECK_DMA_BUFFER(gmesa
, 3);
860 /* We don't do alpha */
861 WRITEF(gmesa
->buf
, Light0AmbientIntensityBlue
, params
[2]);
862 WRITEF(gmesa
->buf
, Light0AmbientIntensityGreen
, params
[1]);
863 WRITEF(gmesa
->buf
, Light0AmbientIntensityRed
, params
[0]);
866 CHECK_DMA_BUFFER(gmesa
, 3);
867 /* We don't do alpha */
868 WRITEF(gmesa
->buf
, Light0DiffuseIntensityBlue
, params
[2]);
869 WRITEF(gmesa
->buf
, Light0DiffuseIntensityGreen
, params
[1]);
870 WRITEF(gmesa
->buf
, Light0DiffuseIntensityRed
, params
[0]);
873 CHECK_DMA_BUFFER(gmesa
, 3);
874 /* We don't do alpha */
875 WRITEF(gmesa
->buf
, Light0SpecularIntensityBlue
, params
[2]);
876 WRITEF(gmesa
->buf
, Light0SpecularIntensityGreen
, params
[1]);
877 WRITEF(gmesa
->buf
, Light0SpecularIntensityRed
, params
[0]);
880 /* Normalize <x,y,z> */
881 x
= params
[0]; y
= params
[1]; z
= params
[2]; w
= params
[3];
882 l
= sqrt(x
*x
+ y
*y
+ z
*z
+ w
*w
);
887 if (params
[3] != 0.0) {
888 gmesa
->Light0Mode
|= Light0ModeAttenuation
;
889 gmesa
->Light0Mode
|= Light0ModeLocal
;
891 gmesa
->Light0Mode
&= ~Light0ModeAttenuation
;
892 gmesa
->Light0Mode
&= ~Light0ModeLocal
;
894 CHECK_DMA_BUFFER(gmesa
, 5);
895 WRITE(gmesa
->buf
, Light0Mode
, gmesa
->Light0Mode
);
896 WRITEF(gmesa
->buf
, Light0PositionW
, w
);
897 WRITEF(gmesa
->buf
, Light0PositionZ
, z
);
898 WRITEF(gmesa
->buf
, Light0PositionY
, y
);
899 WRITEF(gmesa
->buf
, Light0PositionX
, x
);
901 case GL_SPOT_DIRECTION
:
902 CHECK_DMA_BUFFER(gmesa
, 3);
903 /* WRITEF(gmesa->buf, Light0SpotlightDirectionW, params[3]); */
904 WRITEF(gmesa
->buf
, Light0SpotlightDirectionZ
, params
[2]);
905 WRITEF(gmesa
->buf
, Light0SpotlightDirectionY
, params
[1]);
906 WRITEF(gmesa
->buf
, Light0SpotlightDirectionX
, params
[0]);
908 case GL_SPOT_EXPONENT
:
909 CHECK_DMA_BUFFER(gmesa
, 1);
910 WRITEF(gmesa
->buf
, Light0SpotlightExponent
, params
[0]);
913 if (params
[0] != 180.0)
914 gmesa
->Light0Mode
|= Light0ModeSpotLight
;
916 gmesa
->Light0Mode
&= ~Light0ModeSpotLight
;
917 CHECK_DMA_BUFFER(gmesa
, 2);
918 WRITE(gmesa
->buf
, Light0Mode
, gmesa
->Light0Mode
);
919 WRITEF(gmesa
->buf
, Light0CosSpotlightCutoffAngle
, cos(params
[0]*DEG2RAD
));
921 case GL_CONSTANT_ATTENUATION
:
922 CHECK_DMA_BUFFER(gmesa
, 1);
923 WRITEF(gmesa
->buf
, Light0ConstantAttenuation
, params
[0]);
925 case GL_LINEAR_ATTENUATION
:
926 CHECK_DMA_BUFFER(gmesa
, 1);
927 WRITEF(gmesa
->buf
, Light0LinearAttenuation
, params
[0]);
929 case GL_QUADRATIC_ATTENUATION
:
930 CHECK_DMA_BUFFER(gmesa
, 1);
931 WRITEF(gmesa
->buf
, Light0QuadraticAttenuation
, params
[0]);
938 static void gammaDDLightModelfv( GLcontext
*ctx
, GLenum pname
,
939 const GLfloat
*params
)
941 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
944 case GL_LIGHT_MODEL_AMBIENT
:
945 CHECK_DMA_BUFFER(gmesa
, 3);
946 /* We don't do alpha */
947 WRITEF(gmesa
->buf
, SceneAmbientColorBlue
, params
[2]);
948 WRITEF(gmesa
->buf
, SceneAmbientColorGreen
, params
[1]);
949 WRITEF(gmesa
->buf
, SceneAmbientColorRed
, params
[0]);
951 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
952 if (params
[0] != 0.0)
953 gmesa
->LightingMode
|= LightingModeLocalViewer
;
955 gmesa
->LightingMode
&= ~LightingModeLocalViewer
;
956 CHECK_DMA_BUFFER(gmesa
, 1);
957 WRITE(gmesa
->buf
, LightingMode
, gmesa
->LightingMode
);
959 case GL_LIGHT_MODEL_TWO_SIDE
:
960 if (params
[0] == 1.0f
) {
961 gmesa
->LightingMode
|= LightingModeTwoSides
;
962 gmesa
->MaterialMode
|= MaterialModeTwoSides
;
964 gmesa
->LightingMode
&= ~LightingModeTwoSides
;
965 gmesa
->MaterialMode
&= ~MaterialModeTwoSides
;
967 CHECK_DMA_BUFFER(gmesa
, 2);
968 WRITE(gmesa
->buf
, LightingMode
, gmesa
->LightingMode
);
969 WRITE(gmesa
->buf
, MaterialMode
, gmesa
->MaterialMode
);
975 static void gammaDDShadeModel( GLcontext
*ctx
, GLenum mode
)
977 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
978 uint32_t g
= gmesa
->GeometryMode
;
979 uint32_t c
= gmesa
->ColorDDAMode
;
981 g
&= ~GM_ShadingMask
;
982 c
&= ~ColorDDAShadingMask
;
990 g
|= GM_GouraudShading
;
991 c
|= ColorDDAGouraud
;
997 if ( gmesa
->ColorDDAMode
!= c
) {
998 FLUSH_BATCH( gmesa
);
999 gmesa
->ColorDDAMode
= c
;
1001 gmesa
->dirty
|= GAMMA_UPLOAD_SHADE
;
1004 if ( gmesa
->GeometryMode
!= g
) {
1005 FLUSH_BATCH( gmesa
);
1006 gmesa
->GeometryMode
= g
;
1008 gmesa
->dirty
|= GAMMA_UPLOAD_GEOMETRY
;
1012 /* =============================================================
1016 static void gammaDDClearColor( GLcontext
*ctx
, const GLfloat color
[4])
1018 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1020 UNCLAMPED_FLOAT_TO_UBYTE(c
[0], color
[0]);
1021 UNCLAMPED_FLOAT_TO_UBYTE(c
[1], color
[1]);
1022 UNCLAMPED_FLOAT_TO_UBYTE(c
[2], color
[2]);
1023 UNCLAMPED_FLOAT_TO_UBYTE(c
[3], color
[3]);
1025 gmesa
->ClearColor
= gammaPackColor( gmesa
->gammaScreen
->cpp
,
1026 c
[0], c
[1], c
[2], c
[3] );
1028 if (gmesa
->gammaScreen
->cpp
== 2) gmesa
->ClearColor
|= gmesa
->ClearColor
<<16;
1032 static void gammaDDLogicalOpcode( GLcontext
*ctx
, GLenum opcode
)
1034 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1036 FLUSH_BATCH( gmesa
);
1038 if ( ctx
->Color
.ColorLogicOpEnabled
) {
1039 gmesa
->LogicalOpMode
= opcode
<< 1 | LogicalOpModeEnable
;
1041 gmesa
->LogicalOpMode
= LogicalOpModeDisable
;
1044 gmesa
->dirty
|= GAMMA_UPLOAD_LOGICOP
;
1047 static void gammaDDDrawBuffer( GLcontext
*ctx
, GLenum mode
)
1049 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1051 FLUSH_BATCH( gmesa
);
1055 gmesa
->drawOffset
= gmesa
->readOffset
= 0;
1058 gmesa
->drawOffset
= gmesa
->readOffset
= gmesa
->driScreen
->fbHeight
* gmesa
->driScreen
->fbWidth
* gmesa
->gammaScreen
->cpp
;
1063 static void gammaDDReadBuffer( GLcontext
*ctx
, GLenum mode
)
1068 /* =============================================================
1069 * Window position and viewport transformation
1072 void gammaUpdateWindow( GLcontext
*ctx
)
1074 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1075 __DRIdrawablePrivate
*dPriv
= gmesa
->driDrawable
;
1076 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1077 GLfloat yoffset
= gmesa
->driScreen
->fbHeight
- (GLfloat
)dPriv
->y
- dPriv
->h
;
1078 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1080 GLfloat sx
= v
[MAT_SX
];
1081 GLfloat tx
= v
[MAT_TX
] + xoffset
;
1082 GLfloat sy
= v
[MAT_SY
];
1083 GLfloat ty
= v
[MAT_TY
] + yoffset
;
1084 GLfloat sz
= v
[MAT_SZ
] * gmesa
->depth_scale
;
1085 GLfloat tz
= v
[MAT_TZ
] * gmesa
->depth_scale
;
1087 gmesa
->dirty
|= GAMMA_UPLOAD_VIEWPORT
;
1089 gmesa
->ViewportScaleX
= sx
;
1090 gmesa
->ViewportScaleY
= sy
;
1091 gmesa
->ViewportScaleZ
= sz
;
1092 gmesa
->ViewportOffsetX
= tx
;
1093 gmesa
->ViewportOffsetY
= ty
;
1094 gmesa
->ViewportOffsetZ
= tz
;
1099 static void gammaDDViewport( GLcontext
*ctx
, GLint x
, GLint y
,
1100 GLsizei width
, GLsizei height
)
1102 /* update size of Mesa/software ancillary buffers */
1103 _mesa_ResizeBuffersMESA();
1104 gammaUpdateWindow( ctx
);
1107 static void gammaDDDepthRange( GLcontext
*ctx
, GLclampd nearval
,
1110 gammaUpdateWindow( ctx
);
1113 void gammaUpdateViewportOffset( GLcontext
*ctx
)
1115 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1116 __DRIdrawablePrivate
*dPriv
= gmesa
->driDrawable
;
1117 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1118 GLfloat yoffset
= gmesa
->driScreen
->fbHeight
- (GLfloat
)dPriv
->y
- dPriv
->h
;
1119 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1121 GLfloat tx
= v
[MAT_TX
] + xoffset
;
1122 GLfloat ty
= v
[MAT_TY
] + yoffset
;
1124 if ( gmesa
->ViewportOffsetX
!= tx
||
1125 gmesa
->ViewportOffsetY
!= ty
)
1127 gmesa
->ViewportOffsetX
= tx
;
1128 gmesa
->ViewportOffsetY
= ty
;
1130 gmesa
->new_state
|= GAMMA_NEW_WINDOW
;
1133 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
1141 static void gammaLoadHWMatrix(GLcontext
*ctx
)
1143 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1146 gmesa
->TransformMode
&= ~XM_XformTexture
;
1148 switch (ctx
->Transform
.MatrixMode
) {
1150 gmesa
->TransformMode
|= XM_UseModelViewMatrix
;
1151 m
= ctx
->ModelviewMatrixStack
.Top
->m
;
1152 CHECK_DMA_BUFFER(gmesa
, 16);
1153 WRITEF(gmesa
->buf
, ModelViewMatrix0
, m
[0]);
1154 WRITEF(gmesa
->buf
, ModelViewMatrix1
, m
[1]);
1155 WRITEF(gmesa
->buf
, ModelViewMatrix2
, m
[2]);
1156 WRITEF(gmesa
->buf
, ModelViewMatrix3
, m
[3]);
1157 WRITEF(gmesa
->buf
, ModelViewMatrix4
, m
[4]);
1158 WRITEF(gmesa
->buf
, ModelViewMatrix5
, m
[5]);
1159 WRITEF(gmesa
->buf
, ModelViewMatrix6
, m
[6]);
1160 WRITEF(gmesa
->buf
, ModelViewMatrix7
, m
[7]);
1161 WRITEF(gmesa
->buf
, ModelViewMatrix8
, m
[8]);
1162 WRITEF(gmesa
->buf
, ModelViewMatrix9
, m
[9]);
1163 WRITEF(gmesa
->buf
, ModelViewMatrix10
, m
[10]);
1164 WRITEF(gmesa
->buf
, ModelViewMatrix11
, m
[11]);
1165 WRITEF(gmesa
->buf
, ModelViewMatrix12
, m
[12]);
1166 WRITEF(gmesa
->buf
, ModelViewMatrix13
, m
[13]);
1167 WRITEF(gmesa
->buf
, ModelViewMatrix14
, m
[14]);
1168 WRITEF(gmesa
->buf
, ModelViewMatrix15
, m
[15]);
1171 m
= ctx
->ProjectionMatrixStack
.Top
->m
;
1172 CHECK_DMA_BUFFER(gmesa
, 16);
1173 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix0
, m
[0]);
1174 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix1
, m
[1]);
1175 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix2
, m
[2]);
1176 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix3
, m
[3]);
1177 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix4
, m
[4]);
1178 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix5
, m
[5]);
1179 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix6
, m
[6]);
1180 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix7
, m
[7]);
1181 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix8
, m
[8]);
1182 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix9
, m
[9]);
1183 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix10
, m
[10]);
1184 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix11
, m
[11]);
1185 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix12
, m
[12]);
1186 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix13
, m
[13]);
1187 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix14
, m
[14]);
1188 WRITEF(gmesa
->buf
, ModelViewProjectionMatrix15
, m
[15]);
1191 m
= ctx
->TextureMatrixStack
[0].Top
->m
;
1192 CHECK_DMA_BUFFER(gmesa
, 16);
1193 gmesa
->TransformMode
|= XM_XformTexture
;
1194 WRITEF(gmesa
->buf
, TextureMatrix0
, m
[0]);
1195 WRITEF(gmesa
->buf
, TextureMatrix1
, m
[1]);
1196 WRITEF(gmesa
->buf
, TextureMatrix2
, m
[2]);
1197 WRITEF(gmesa
->buf
, TextureMatrix3
, m
[3]);
1198 WRITEF(gmesa
->buf
, TextureMatrix4
, m
[4]);
1199 WRITEF(gmesa
->buf
, TextureMatrix5
, m
[5]);
1200 WRITEF(gmesa
->buf
, TextureMatrix6
, m
[6]);
1201 WRITEF(gmesa
->buf
, TextureMatrix7
, m
[7]);
1202 WRITEF(gmesa
->buf
, TextureMatrix8
, m
[8]);
1203 WRITEF(gmesa
->buf
, TextureMatrix9
, m
[9]);
1204 WRITEF(gmesa
->buf
, TextureMatrix10
, m
[10]);
1205 WRITEF(gmesa
->buf
, TextureMatrix11
, m
[11]);
1206 WRITEF(gmesa
->buf
, TextureMatrix12
, m
[12]);
1207 WRITEF(gmesa
->buf
, TextureMatrix13
, m
[13]);
1208 WRITEF(gmesa
->buf
, TextureMatrix14
, m
[14]);
1209 WRITEF(gmesa
->buf
, TextureMatrix15
, m
[15]);
1213 /* ERROR!!! -- how did this happen? */
1217 gmesa
->dirty
|= GAMMA_UPLOAD_TRANSFORM
;
1221 /* =============================================================
1222 * State enable/disable
1225 static void gammaDDEnable( GLcontext
*ctx
, GLenum cap
, GLboolean state
)
1227 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1232 FLUSH_BATCH( gmesa
);
1233 gmesa
->new_state
|= GAMMA_NEW_ALPHA
;
1237 FLUSH_BATCH( gmesa
);
1238 gmesa
->new_state
|= GAMMA_NEW_CULL
;
1242 FLUSH_BATCH( gmesa
);
1243 gmesa
->new_state
|= GAMMA_NEW_DEPTH
;
1248 uint32_t d
= gmesa
->DitherMode
;
1249 FLUSH_BATCH( gmesa
);
1252 d
|= DM_DitherEnable
;
1254 d
&= ~DM_DitherEnable
;
1257 if ( gmesa
->DitherMode
!= d
) {
1258 gmesa
->DitherMode
= d
;
1259 gmesa
->dirty
|= GAMMA_UPLOAD_DITHER
;
1266 FLUSH_BATCH( gmesa
);
1267 gmesa
->new_state
|= GAMMA_NEW_FOG
;
1271 case GL_INDEX_LOGIC_OP
:
1272 case GL_COLOR_LOGIC_OP
:
1273 FLUSH_BATCH( gmesa
);
1274 gmesa
->new_state
|= GAMMA_NEW_LOGICOP
;
1280 uint32_t l
= gmesa
->LightingMode
;
1281 FLUSH_BATCH( gmesa
);
1284 l
|= LightingModeEnable
;
1286 l
&= ~LightingModeEnable
;
1289 if ( gmesa
->LightingMode
!= l
) {
1290 gmesa
->LightingMode
= l
;
1291 gmesa
->dirty
|= GAMMA_UPLOAD_LIGHT
;
1296 case GL_COLOR_MATERIAL
:
1298 uint32_t m
= gmesa
->MaterialMode
;
1299 FLUSH_BATCH( gmesa
);
1302 m
|= MaterialModeEnable
;
1304 m
&= ~MaterialModeEnable
;
1307 if ( gmesa
->MaterialMode
!= m
) {
1308 gmesa
->MaterialMode
= m
;
1309 gmesa
->dirty
|= GAMMA_UPLOAD_LIGHT
;
1315 case GL_LINE_SMOOTH
:
1316 FLUSH_BATCH( gmesa
);
1318 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1319 gmesa
->LineMode
|= LM_AntialiasEnable
;
1321 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1322 gmesa
->LineMode
&= ~LM_AntialiasEnable
;
1324 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
1327 case GL_POINT_SMOOTH
:
1328 FLUSH_BATCH( gmesa
);
1330 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1331 gmesa
->PointMode
|= PM_AntialiasEnable
;
1333 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1334 gmesa
->PointMode
&= ~PM_AntialiasEnable
;
1336 gmesa
->dirty
|= GAMMA_UPLOAD_POINTMODE
;
1339 case GL_POLYGON_SMOOTH
:
1340 FLUSH_BATCH( gmesa
);
1342 gmesa
->AntialiasMode
|= AntialiasModeEnable
;
1343 gmesa
->TriangleMode
|= TM_AntialiasEnable
;
1345 gmesa
->AntialiasMode
&= ~AntialiasModeEnable
;
1346 gmesa
->TriangleMode
&= ~TM_AntialiasEnable
;
1348 gmesa
->dirty
|= GAMMA_UPLOAD_TRIMODE
;
1351 case GL_SCISSOR_TEST
:
1352 FLUSH_BATCH( gmesa
);
1353 gmesa
->new_state
|= GAMMA_NEW_CLIP
;
1356 case GL_POLYGON_OFFSET_FILL
:
1357 case GL_POLYGON_OFFSET_POINT
:
1358 case GL_POLYGON_OFFSET_LINE
:
1359 FLUSH_BATCH( gmesa
);
1360 gmesa
->new_state
|= GAMMA_NEW_POLYGON
;
1363 case GL_LINE_STIPPLE
:
1364 FLUSH_BATCH( gmesa
);
1366 gmesa
->LineMode
|= LM_StippleEnable
;
1368 gmesa
->LineMode
&= ~LM_StippleEnable
;
1369 gmesa
->dirty
|= GAMMA_UPLOAD_LINEMODE
;
1372 case GL_POLYGON_STIPPLE
:
1373 FLUSH_BATCH( gmesa
);
1374 gmesa
->new_state
|= GAMMA_NEW_STIPPLE
;
1382 /* =============================================================
1383 * State initialization, management
1388 * Load the current context's state into the hardware.
1390 * NOTE: Be VERY careful about ensuring the context state is marked for
1391 * upload, the only place it shouldn't be uploaded is when the setup
1392 * state has changed in ReducedPrimitiveChange as this comes right after
1395 * Blits of any type should always upload the context and masks after
1398 void gammaEmitHwState( gammaContextPtr gmesa
)
1400 if (!gmesa
->driDrawable
) return;
1402 if (!gmesa
->dirty
) return;
1405 /* Flush any partially filled buffers */
1406 FLUSH_DMA_BUFFER(gmesa
);
1408 DRM_SPINLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
1409 gmesa
->driScreen
->drawLockID
);
1410 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa
);
1413 if (gmesa
->dirty
& GAMMA_UPLOAD_VIEWPORT
) {
1414 gmesa
->dirty
&= ~GAMMA_UPLOAD_VIEWPORT
;
1415 CHECK_DMA_BUFFER(gmesa
, 6);
1416 WRITEF(gmesa
->buf
, ViewPortOffsetX
, gmesa
->ViewportOffsetX
);
1417 WRITEF(gmesa
->buf
, ViewPortOffsetY
, gmesa
->ViewportOffsetY
);
1418 WRITEF(gmesa
->buf
, ViewPortOffsetZ
, gmesa
->ViewportOffsetZ
);
1419 WRITEF(gmesa
->buf
, ViewPortScaleX
, gmesa
->ViewportScaleX
);
1420 WRITEF(gmesa
->buf
, ViewPortScaleY
, gmesa
->ViewportScaleY
);
1421 WRITEF(gmesa
->buf
, ViewPortScaleZ
, gmesa
->ViewportScaleZ
);
1423 if ( (gmesa
->dirty
& GAMMA_UPLOAD_POINTMODE
) ||
1424 (gmesa
->dirty
& GAMMA_UPLOAD_LINEMODE
) ||
1425 (gmesa
->dirty
& GAMMA_UPLOAD_TRIMODE
) ) {
1426 CHECK_DMA_BUFFER(gmesa
, 1);
1427 WRITE(gmesa
->buf
, AntialiasMode
, gmesa
->AntialiasMode
);
1429 if (gmesa
->dirty
& GAMMA_UPLOAD_POINTMODE
) {
1430 gmesa
->dirty
&= ~GAMMA_UPLOAD_POINTMODE
;
1431 CHECK_DMA_BUFFER(gmesa
, 1);
1432 WRITE(gmesa
->buf
, PointMode
, gmesa
->PointMode
);
1434 if (gmesa
->dirty
& GAMMA_UPLOAD_LINEMODE
) {
1435 gmesa
->dirty
&= ~GAMMA_UPLOAD_LINEMODE
;
1436 CHECK_DMA_BUFFER(gmesa
, 2);
1437 WRITE(gmesa
->buf
, LineMode
, gmesa
->LineMode
);
1438 WRITE(gmesa
->buf
, LineStippleMode
, gmesa
->LineMode
);
1440 if (gmesa
->dirty
& GAMMA_UPLOAD_TRIMODE
) {
1441 gmesa
->dirty
&= ~GAMMA_UPLOAD_TRIMODE
;
1442 CHECK_DMA_BUFFER(gmesa
, 1);
1443 WRITE(gmesa
->buf
, TriangleMode
, gmesa
->TriangleMode
);
1445 if (gmesa
->dirty
& GAMMA_UPLOAD_FOG
) {
1447 UNCLAMPED_FLOAT_TO_RGB_CHAN( c
, gmesa
->glCtx
->Fog
.Color
);
1448 col
= gammaPackColor(4, c
[0], c
[1], c
[2], 0);
1449 gmesa
->dirty
&= ~GAMMA_UPLOAD_FOG
;
1450 CHECK_DMA_BUFFER(gmesa
, 5);
1452 WRITE(gmesa
->buf
, FogMode
, gmesa
->FogMode
);
1453 WRITE(gmesa
->buf
, FogColor
, col
);
1454 WRITEF(gmesa
->buf
, FStart
, gmesa
->glCtx
->Fog
.Start
);
1456 WRITEF(gmesa
->buf
, FogEnd
, gmesa
->glCtx
->Fog
.End
);
1457 WRITEF(gmesa
->buf
, FogDensity
, gmesa
->glCtx
->Fog
.Density
);
1458 WRITEF(gmesa
->buf
, FogScale
,
1459 1.0f
/(gmesa
->glCtx
->Fog
.End
- gmesa
->glCtx
->Fog
.Start
));
1461 if (gmesa
->dirty
& GAMMA_UPLOAD_DITHER
) {
1462 gmesa
->dirty
&= ~GAMMA_UPLOAD_DITHER
;
1463 CHECK_DMA_BUFFER(gmesa
, 1);
1464 WRITE(gmesa
->buf
, DitherMode
, gmesa
->DitherMode
);
1466 if (gmesa
->dirty
& GAMMA_UPLOAD_LOGICOP
) {
1467 gmesa
->dirty
&= ~GAMMA_UPLOAD_LOGICOP
;
1468 CHECK_DMA_BUFFER(gmesa
, 1);
1469 WRITE(gmesa
->buf
, LogicalOpMode
, gmesa
->LogicalOpMode
);
1471 if (gmesa
->dirty
& GAMMA_UPLOAD_CLIP
) {
1472 gmesa
->dirty
&= ~GAMMA_UPLOAD_CLIP
;
1473 CHECK_DMA_BUFFER(gmesa
, 3);
1474 WRITE(gmesa
->buf
, ScissorMinXY
, gmesa
->ScissorMinXY
);
1475 WRITE(gmesa
->buf
, ScissorMaxXY
, gmesa
->ScissorMaxXY
);
1476 WRITE(gmesa
->buf
, ScissorMode
, gmesa
->ScissorMode
);
1478 if (gmesa
->dirty
& GAMMA_UPLOAD_MASKS
) {
1479 gmesa
->dirty
&= ~GAMMA_UPLOAD_MASKS
;
1480 CHECK_DMA_BUFFER(gmesa
, 1);
1481 WRITE(gmesa
->buf
, FBHardwareWriteMask
, gmesa
->FBHardwareWriteMask
);
1483 if (gmesa
->dirty
& GAMMA_UPLOAD_ALPHA
) {
1484 gmesa
->dirty
&= ~GAMMA_UPLOAD_ALPHA
;
1485 CHECK_DMA_BUFFER(gmesa
, 1);
1486 WRITE(gmesa
->buf
, AlphaTestMode
, gmesa
->AlphaTestMode
);
1488 if (gmesa
->dirty
& GAMMA_UPLOAD_BLEND
) {
1489 gmesa
->dirty
&= ~GAMMA_UPLOAD_BLEND
;
1490 CHECK_DMA_BUFFER(gmesa
, 1);
1491 WRITE(gmesa
->buf
, AlphaBlendMode
, gmesa
->AlphaBlendMode
);
1493 CHECK_DMA_BUFFER(gmesa
, 1);
1494 if (gmesa
->glCtx
->Color
.BlendEnabled
|| gmesa
->glCtx
->Color
.AlphaEnabled
) {
1495 WRITE(gmesa
->buf
, FBReadMode
, gmesa
->FBReadMode
| gmesa
->AB_FBReadMode_Save
);
1497 WRITE(gmesa
->buf
, FBReadMode
, gmesa
->FBReadMode
);
1499 if (gmesa
->dirty
& GAMMA_UPLOAD_LIGHT
) {
1500 gmesa
->dirty
&= ~GAMMA_UPLOAD_LIGHT
;
1501 CHECK_DMA_BUFFER(gmesa
, 2);
1502 WRITE(gmesa
->buf
, LightingMode
, gmesa
->LightingMode
);
1503 WRITE(gmesa
->buf
, MaterialMode
, gmesa
->MaterialMode
);
1505 if (gmesa
->dirty
& GAMMA_UPLOAD_SHADE
) {
1506 gmesa
->dirty
&= ~GAMMA_UPLOAD_SHADE
;
1507 CHECK_DMA_BUFFER(gmesa
, 1);
1508 WRITE(gmesa
->buf
, ColorDDAMode
, gmesa
->ColorDDAMode
);
1510 if (gmesa
->dirty
& GAMMA_UPLOAD_POLYGON
) {
1511 gmesa
->dirty
&= ~GAMMA_UPLOAD_POLYGON
;
1512 CHECK_DMA_BUFFER(gmesa
, 2);
1513 WRITEF(gmesa
->buf
, PolygonOffsetBias
, gmesa
->glCtx
->Polygon
.OffsetUnits
);
1514 WRITEF(gmesa
->buf
, PolygonOffsetFactor
, gmesa
->glCtx
->Polygon
.OffsetFactor
);
1516 if (gmesa
->dirty
& GAMMA_UPLOAD_STIPPLE
) {
1517 gmesa
->dirty
&= ~GAMMA_UPLOAD_STIPPLE
;
1518 CHECK_DMA_BUFFER(gmesa
, 33);
1519 WRITE(gmesa
->buf
, AreaStippleMode
, gmesa
->AreaStippleMode
);
1520 WRITE(gmesa
->buf
, AreaStipplePattern0
, gmesa
->glCtx
->PolygonStipple
[0]);
1521 WRITE(gmesa
->buf
, AreaStipplePattern1
, gmesa
->glCtx
->PolygonStipple
[1]);
1522 WRITE(gmesa
->buf
, AreaStipplePattern2
, gmesa
->glCtx
->PolygonStipple
[2]);
1523 WRITE(gmesa
->buf
, AreaStipplePattern3
, gmesa
->glCtx
->PolygonStipple
[3]);
1524 WRITE(gmesa
->buf
, AreaStipplePattern4
, gmesa
->glCtx
->PolygonStipple
[4]);
1525 WRITE(gmesa
->buf
, AreaStipplePattern5
, gmesa
->glCtx
->PolygonStipple
[5]);
1526 WRITE(gmesa
->buf
, AreaStipplePattern6
, gmesa
->glCtx
->PolygonStipple
[6]);
1527 WRITE(gmesa
->buf
, AreaStipplePattern7
, gmesa
->glCtx
->PolygonStipple
[7]);
1528 WRITE(gmesa
->buf
, AreaStipplePattern8
, gmesa
->glCtx
->PolygonStipple
[8]);
1529 WRITE(gmesa
->buf
, AreaStipplePattern9
, gmesa
->glCtx
->PolygonStipple
[9]);
1530 WRITE(gmesa
->buf
, AreaStipplePattern10
, gmesa
->glCtx
->PolygonStipple
[10]);
1531 WRITE(gmesa
->buf
, AreaStipplePattern11
, gmesa
->glCtx
->PolygonStipple
[11]);
1532 WRITE(gmesa
->buf
, AreaStipplePattern12
, gmesa
->glCtx
->PolygonStipple
[12]);
1533 WRITE(gmesa
->buf
, AreaStipplePattern13
, gmesa
->glCtx
->PolygonStipple
[13]);
1534 WRITE(gmesa
->buf
, AreaStipplePattern14
, gmesa
->glCtx
->PolygonStipple
[14]);
1535 WRITE(gmesa
->buf
, AreaStipplePattern15
, gmesa
->glCtx
->PolygonStipple
[15]);
1536 WRITE(gmesa
->buf
, AreaStipplePattern16
, gmesa
->glCtx
->PolygonStipple
[16]);
1537 WRITE(gmesa
->buf
, AreaStipplePattern17
, gmesa
->glCtx
->PolygonStipple
[17]);
1538 WRITE(gmesa
->buf
, AreaStipplePattern18
, gmesa
->glCtx
->PolygonStipple
[18]);
1539 WRITE(gmesa
->buf
, AreaStipplePattern19
, gmesa
->glCtx
->PolygonStipple
[19]);
1540 WRITE(gmesa
->buf
, AreaStipplePattern20
, gmesa
->glCtx
->PolygonStipple
[20]);
1541 WRITE(gmesa
->buf
, AreaStipplePattern21
, gmesa
->glCtx
->PolygonStipple
[21]);
1542 WRITE(gmesa
->buf
, AreaStipplePattern22
, gmesa
->glCtx
->PolygonStipple
[22]);
1543 WRITE(gmesa
->buf
, AreaStipplePattern23
, gmesa
->glCtx
->PolygonStipple
[23]);
1544 WRITE(gmesa
->buf
, AreaStipplePattern24
, gmesa
->glCtx
->PolygonStipple
[24]);
1545 WRITE(gmesa
->buf
, AreaStipplePattern25
, gmesa
->glCtx
->PolygonStipple
[25]);
1546 WRITE(gmesa
->buf
, AreaStipplePattern26
, gmesa
->glCtx
->PolygonStipple
[26]);
1547 WRITE(gmesa
->buf
, AreaStipplePattern27
, gmesa
->glCtx
->PolygonStipple
[27]);
1548 WRITE(gmesa
->buf
, AreaStipplePattern28
, gmesa
->glCtx
->PolygonStipple
[28]);
1549 WRITE(gmesa
->buf
, AreaStipplePattern29
, gmesa
->glCtx
->PolygonStipple
[29]);
1550 WRITE(gmesa
->buf
, AreaStipplePattern30
, gmesa
->glCtx
->PolygonStipple
[30]);
1551 WRITE(gmesa
->buf
, AreaStipplePattern31
, gmesa
->glCtx
->PolygonStipple
[31]);
1553 if (gmesa
->dirty
& GAMMA_UPLOAD_DEPTH
) {
1554 gmesa
->dirty
&= ~GAMMA_UPLOAD_DEPTH
;
1555 CHECK_DMA_BUFFER(gmesa
, 4);
1556 WRITE(gmesa
->buf
, DepthMode
, gmesa
->DepthMode
);
1557 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
1558 WRITE(gmesa
->buf
, GLINTWindow
,gmesa
->Window
| (gmesa
->FrameCount
<< 9));
1559 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
);
1561 if (gmesa
->dirty
& GAMMA_UPLOAD_GEOMETRY
) {
1562 gmesa
->dirty
&= ~GAMMA_UPLOAD_GEOMETRY
;
1563 CHECK_DMA_BUFFER(gmesa
, 1);
1564 WRITE(gmesa
->buf
, GeometryMode
, gmesa
->GeometryMode
);
1566 if (gmesa
->dirty
& GAMMA_UPLOAD_TRANSFORM
) {
1567 gmesa
->dirty
&= ~GAMMA_UPLOAD_TRANSFORM
;
1568 CHECK_DMA_BUFFER(gmesa
, 1);
1569 WRITE(gmesa
->buf
, TransformMode
, gmesa
->TransformMode
);
1571 if (gmesa
->dirty
& GAMMA_UPLOAD_TEX0
) {
1572 gammaTextureObjectPtr curTex
= gmesa
->CurrentTexObj
[0];
1573 gmesa
->dirty
&= ~GAMMA_UPLOAD_TEX0
;
1575 CHECK_DMA_BUFFER(gmesa
, 21);
1576 WRITE(gmesa
->buf
, GeometryMode
, gmesa
->GeometryMode
| GM_TextureEnable
);
1577 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
| DM_TextureEnable
);
1578 WRITE(gmesa
->buf
, TextureAddressMode
, curTex
->TextureAddressMode
);
1579 WRITE(gmesa
->buf
, TextureReadMode
, curTex
->TextureReadMode
);
1580 WRITE(gmesa
->buf
, TextureColorMode
, curTex
->TextureColorMode
);
1581 WRITE(gmesa
->buf
, TextureFilterMode
, curTex
->TextureFilterMode
);
1582 WRITE(gmesa
->buf
, TextureFormat
, curTex
->TextureFormat
);
1583 WRITE(gmesa
->buf
, GLINTBorderColor
, curTex
->TextureBorderColor
);
1584 WRITE(gmesa
->buf
, TxBaseAddr0
, curTex
->TextureBaseAddr
[0]);
1585 WRITE(gmesa
->buf
, TxBaseAddr1
, curTex
->TextureBaseAddr
[1]);
1586 WRITE(gmesa
->buf
, TxBaseAddr2
, curTex
->TextureBaseAddr
[2]);
1587 WRITE(gmesa
->buf
, TxBaseAddr3
, curTex
->TextureBaseAddr
[3]);
1588 WRITE(gmesa
->buf
, TxBaseAddr4
, curTex
->TextureBaseAddr
[4]);
1589 WRITE(gmesa
->buf
, TxBaseAddr5
, curTex
->TextureBaseAddr
[5]);
1590 WRITE(gmesa
->buf
, TxBaseAddr6
, curTex
->TextureBaseAddr
[6]);
1591 WRITE(gmesa
->buf
, TxBaseAddr7
, curTex
->TextureBaseAddr
[7]);
1592 WRITE(gmesa
->buf
, TxBaseAddr8
, curTex
->TextureBaseAddr
[8]);
1593 WRITE(gmesa
->buf
, TxBaseAddr9
, curTex
->TextureBaseAddr
[9]);
1594 WRITE(gmesa
->buf
, TxBaseAddr10
, curTex
->TextureBaseAddr
[10]);
1595 WRITE(gmesa
->buf
, TxBaseAddr11
, curTex
->TextureBaseAddr
[11]);
1596 WRITE(gmesa
->buf
, TxBaseAddr12
, curTex
->TextureBaseAddr
[12]);
1597 WRITE(gmesa
->buf
, TextureCacheControl
, (TCC_Enable
| TCC_Invalidate
));
1599 CHECK_DMA_BUFFER(gmesa
, 6);
1600 WRITE(gmesa
->buf
, GeometryMode
, gmesa
->GeometryMode
);
1601 WRITE(gmesa
->buf
, DeltaMode
, gmesa
->DeltaMode
);
1602 WRITE(gmesa
->buf
, TextureAddressMode
, TextureAddressModeDisable
);
1603 WRITE(gmesa
->buf
, TextureReadMode
, TextureReadModeDisable
);
1604 WRITE(gmesa
->buf
, TextureFilterMode
, TextureFilterModeDisable
);
1605 WRITE(gmesa
->buf
, TextureColorMode
, TextureColorModeDisable
);
1609 PROCESS_DMA_BUFFER_TOP_HALF(gmesa
);
1611 DRM_SPINUNLOCK(&gmesa
->driScreen
->pSAREA
->drawable_lock
,
1612 gmesa
->driScreen
->drawLockID
);
1613 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa
);
1615 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa
);
1619 void gammaDDUpdateHWState( GLcontext
*ctx
)
1621 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
1622 int new_state
= gmesa
->new_state
;
1626 FLUSH_BATCH( gmesa
);
1628 gmesa
->new_state
= 0;
1630 /* Update the various parts of the context's state.
1632 if ( new_state
& GAMMA_NEW_ALPHA
)
1633 gammaUpdateAlphaMode( ctx
);
1635 if ( new_state
& GAMMA_NEW_DEPTH
)
1636 gammaUpdateZMode( ctx
);
1638 if ( new_state
& GAMMA_NEW_FOG
)
1639 gammaUpdateFogAttrib( ctx
);
1641 if ( new_state
& GAMMA_NEW_CLIP
)
1642 gammaUpdateClipping( ctx
);
1644 if ( new_state
& GAMMA_NEW_POLYGON
)
1645 gammaUpdatePolygon( ctx
);
1647 if ( new_state
& GAMMA_NEW_CULL
)
1648 gammaUpdateCull( ctx
);
1650 if ( new_state
& GAMMA_NEW_MASKS
)
1651 gammaUpdateMasks( ctx
);
1653 if ( new_state
& GAMMA_NEW_WINDOW
)
1654 gammaUpdateWindow( ctx
);
1656 if ( new_state
& GAMMA_NEW_STIPPLE
)
1657 gammaUpdateStipple( ctx
);
1662 gammaEmitHwState( gmesa
);
1666 static void gammaDDUpdateState( GLcontext
*ctx
, GLuint new_state
)
1668 _swrast_InvalidateState( ctx
, new_state
);
1669 _swsetup_InvalidateState( ctx
, new_state
);
1670 _ac_InvalidateState( ctx
, new_state
);
1671 _tnl_InvalidateState( ctx
, new_state
);
1672 GAMMA_CONTEXT(ctx
)->new_gl_state
|= new_state
;
1676 /* Initialize the context's hardware state.
1678 void gammaDDInitState( gammaContextPtr gmesa
)
1680 gmesa
->new_state
= 0;
1683 /* Initialize the driver's state functions.
1685 void gammaDDInitStateFuncs( GLcontext
*ctx
)
1687 ctx
->Driver
.UpdateState
= gammaDDUpdateState
;
1689 ctx
->Driver
.Clear
= gammaDDClear
;
1690 ctx
->Driver
.ClearIndex
= NULL
;
1691 ctx
->Driver
.ClearColor
= gammaDDClearColor
;
1692 ctx
->Driver
.DrawBuffer
= gammaDDDrawBuffer
;
1693 ctx
->Driver
.ReadBuffer
= gammaDDReadBuffer
;
1695 ctx
->Driver
.IndexMask
= NULL
;
1696 ctx
->Driver
.ColorMask
= gammaDDColorMask
;
1698 ctx
->Driver
.AlphaFunc
= gammaDDAlphaFunc
;
1699 ctx
->Driver
.BlendEquationSeparate
= gammaDDBlendEquationSeparate
;
1700 ctx
->Driver
.BlendFuncSeparate
= gammaDDBlendFuncSeparate
;
1701 ctx
->Driver
.ClearDepth
= gammaDDClearDepth
;
1702 ctx
->Driver
.CullFace
= gammaDDCullFace
;
1703 ctx
->Driver
.FrontFace
= gammaDDFrontFace
;
1704 ctx
->Driver
.DepthFunc
= gammaDDDepthFunc
;
1705 ctx
->Driver
.DepthMask
= gammaDDDepthMask
;
1706 ctx
->Driver
.DepthRange
= gammaDDDepthRange
;
1707 ctx
->Driver
.Enable
= gammaDDEnable
;
1708 ctx
->Driver
.Finish
= gammaDDFinish
;
1709 ctx
->Driver
.Flush
= gammaDDFlush
;
1711 ctx
->Driver
.Fogfv
= gammaDDFogfv
;
1713 ctx
->Driver
.Hint
= NULL
;
1714 ctx
->Driver
.LineWidth
= gammaDDLineWidth
;
1715 ctx
->Driver
.LineStipple
= gammaDDLineStipple
;
1717 ctx
->Driver
.Lightfv
= gammaDDLightfv
;
1718 ctx
->Driver
.LightModelfv
= gammaDDLightModelfv
;
1720 ctx
->Driver
.LogicOpcode
= gammaDDLogicalOpcode
;
1721 ctx
->Driver
.PointSize
= gammaDDPointSize
;
1722 ctx
->Driver
.PolygonMode
= gammaDDPolygonMode
;
1723 ctx
->Driver
.PolygonStipple
= gammaDDPolygonStipple
;
1724 ctx
->Driver
.Scissor
= gammaDDScissor
;
1725 ctx
->Driver
.ShadeModel
= gammaDDShadeModel
;
1726 ctx
->Driver
.ClearStencil
= NULL
;
1727 ctx
->Driver
.StencilFunc
= NULL
;
1728 ctx
->Driver
.StencilMask
= NULL
;
1729 ctx
->Driver
.StencilOp
= NULL
;
1730 ctx
->Driver
.Viewport
= gammaDDViewport
;