2 * Copyright 2001 by Alan Hourihane.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
22 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
27 #include "gamma_context.h"
28 #include "gamma_macros.h"
31 #include "glint_dri.h"
33 #include "swrast/swrast.h"
34 #include "swrast_setup/swrast_setup.h"
38 #define ENABLELIGHTING 0
40 /* =============================================================
44 static void gammaUpdateAlphaMode( GLcontext *ctx )
46 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
47 u_int32_t a = gmesa->AlphaTestMode;
48 u_int32_t b = gmesa->AlphaBlendMode;
49 u_int32_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 )
209 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
210 GLINTDRIPtr gDRIPriv = (GLINTDRIPtr)gmesa->driScreen->pDevPriv;
213 FLUSH_BATCH( gmesa );
215 /* Update and emit any new state. We need to do this here to catch
216 * changes to the masks.
217 * FIXME: Just update the masks?
219 if ( gmesa->new_state )
220 gammaDDUpdateHWState( ctx );
223 /* Flush any partially filled buffers */
224 FLUSH_DMA_BUFFER(gmesa);
226 DRM_SPINLOCK(&gmesa->driScreen->pSAREA->drawable_lock,
227 gmesa->driScreen->drawLockID);
228 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa);
231 if (mask & BUFFER_BIT_DEPTH) {
232 /* Turn off writes the FB */
233 CHECK_DMA_BUFFER(gmesa, 1);
234 WRITE(gmesa->buf, FBWriteMode, FBWriteModeDisable);
236 mask &= ~BUFFER_BIT_DEPTH;
239 * Turn Rectangle2DControl off when the window is not clipped
240 * (i.e., the GID tests are not necessary). This dramatically
241 * increases the performance of the depth clears.
243 if (!gmesa->NotClipped) {
244 CHECK_DMA_BUFFER(gmesa, 1);
245 WRITE(gmesa->buf, Rectangle2DControl, 1);
248 temp = (gmesa->LBReadMode & LBPartialProdMask) | LBWindowOriginBot;
249 if (gDRIPriv->numMultiDevices == 2) temp |= LBScanLineInt2;
251 CHECK_DMA_BUFFER(gmesa, 5);
252 WRITE(gmesa->buf, LBReadMode, temp);
253 WRITE(gmesa->buf, DeltaMode, DM_DepthEnable);
254 WRITE(gmesa->buf, DepthMode, (DepthModeEnable |
256 DM_SourceDepthRegister |
258 WRITE(gmesa->buf, GLINTDepth, gmesa->ClearDepth);
260 /* Increment the frame count */
263 gmesa->FrameCount &= 0x0f;
265 gmesa->FrameCount &= 0xff;
268 /* Force FCP to be written */
269 WRITE(gmesa->buf, GLINTWindow, (WindowEnable |
271 (gmesa->Window & W_GIDMask) |
273 W_LBUpdateFromRegisters |
274 W_OverrideWriteFiltering |
275 (gmesa->FrameCount << 9)));
277 /* Clear part of the depth and FCP buffers */
279 int y = gmesa->driScreen->fbHeight - gmesa->driDrawable->y - gmesa->driDrawable->h;
280 int x = gmesa->driDrawable->x;
281 int w = gmesa->driDrawable->w;
282 int h = gmesa->driDrawable->h;
286 if (gmesa->WindowChanged) {
287 gmesa->WindowChanged = GL_FALSE;
295 /* Handle the case where the height < # of FCPs */
297 if (gmesa->FrameCount > h)
298 gmesa->FrameCount = 0;
300 y += gmesa->FrameCount;
302 h = (gmesa->FrameCount+1)*hsub;
303 h -= (int)(gmesa->FrameCount*hsub);
304 y += gmesa->FrameCount*hsub;
310 CHECK_DMA_BUFFER(gmesa, 2);
311 WRITE(gmesa->buf, Rectangle2DMode, ((h & 0xfff)<<12) |
313 WRITE(gmesa->buf, DrawRectangle2D, ((y & 0xffff)<<16) |
316 CHECK_DMA_BUFFER(gmesa, 8);
317 WRITE(gmesa->buf, StartXDom, x<<16);
318 WRITE(gmesa->buf, StartY, y<<16);
319 WRITE(gmesa->buf, StartXSub, (x+w)<<16);
320 WRITE(gmesa->buf, GLINTCount, h);
321 WRITE(gmesa->buf, dY, 1<<16);
322 WRITE(gmesa->buf, dXDom, 0<<16);
323 WRITE(gmesa->buf, dXSub, 0<<16);
324 WRITE(gmesa->buf, Render, 0x00000040); /* NOT_DONE */
329 CHECK_DMA_BUFFER(gmesa, 6);
330 WRITE(gmesa->buf, DepthMode, gmesa->DepthMode);
331 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode);
332 WRITE(gmesa->buf, LBReadMode, gmesa->LBReadMode);
333 WRITE(gmesa->buf, GLINTWindow, gmesa->Window);
334 WRITE(gmesa->buf, FastClearDepth, gmesa->ClearDepth);
335 WRITE(gmesa->buf, FBWriteMode, FBWriteModeEnable);
337 /* Turn on Depth FCP */
338 if (gmesa->Window & W_DepthFCP) {
339 CHECK_DMA_BUFFER(gmesa, 1);
340 WRITE(gmesa->buf, WindowOr, (gmesa->FrameCount << 9));
343 /* Turn off GID clipping if window is not clipped */
344 if (gmesa->NotClipped) {
345 CHECK_DMA_BUFFER(gmesa, 1);
346 WRITE(gmesa->buf, Rectangle2DControl, 0);
350 if (mask & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT)) {
351 int y = gmesa->driScreen->fbHeight - gmesa->driDrawable->y - gmesa->driDrawable->h;
352 int x = gmesa->driDrawable->x;
353 int w = gmesa->driDrawable->w;
354 int h = gmesa->driDrawable->h;
356 mask &= ~(BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT);
358 if (x < 0) { w -= -x; x = 0; }
360 /* Turn on GID clipping if window is clipped */
361 if (!gmesa->NotClipped) {
362 CHECK_DMA_BUFFER(gmesa, 1);
363 WRITE(gmesa->buf, Rectangle2DControl, 1);
366 CHECK_DMA_BUFFER(gmesa, 18);
367 WRITE(gmesa->buf, FBBlockColor, gmesa->ClearColor);
368 WRITE(gmesa->buf, ColorDDAMode, ColorDDADisable);
369 WRITE(gmesa->buf, FBWriteMode, FBWriteModeEnable);
370 WRITE(gmesa->buf, DepthMode, 0);
371 WRITE(gmesa->buf, DeltaMode, 0);
372 WRITE(gmesa->buf, AlphaBlendMode, 0);
374 WRITE(gmesa->buf, dY, 1<<16);
375 WRITE(gmesa->buf, dXDom, 0<<16);
376 WRITE(gmesa->buf, dXSub, 0<<16);
377 WRITE(gmesa->buf, StartXSub, (x+w)<<16);
378 WRITE(gmesa->buf, GLINTCount, h);
379 WRITE(gmesa->buf, StartXDom, x<<16);
380 WRITE(gmesa->buf, StartY, y<<16);
381 WRITE(gmesa->buf, Render, 0x00000048); /* NOT_DONE */
383 WRITE(gmesa->buf, Rectangle2DMode, (((h & 0xfff)<<12) |
385 WRITE(gmesa->buf, DrawRectangle2D, (((y & 0xffff)<<16) |
388 WRITE(gmesa->buf, DepthMode, gmesa->DepthMode);
389 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode);
390 WRITE(gmesa->buf, AlphaBlendMode, gmesa->AlphaBlendMode);
391 WRITE(gmesa->buf, ColorDDAMode, gmesa->ColorDDAMode);
393 /* Turn off GID clipping if window is clipped */
394 if (gmesa->NotClipped) {
395 CHECK_DMA_BUFFER(gmesa, 1);
396 WRITE(gmesa->buf, Rectangle2DControl, 0);
401 PROCESS_DMA_BUFFER_TOP_HALF(gmesa);
403 DRM_SPINUNLOCK(&gmesa->driScreen->pSAREA->drawable_lock,
404 gmesa->driScreen->drawLockID);
405 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa);
407 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa);
411 _swrast_Clear( ctx, mask );
414 /* =============================================================
418 static void gammaUpdateZMode( GLcontext *ctx )
420 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
421 u_int32_t z = gmesa->DepthMode;
422 u_int32_t delta = gmesa->DeltaMode;
423 u_int32_t window = gmesa->Window;
424 u_int32_t lbread = gmesa->LBReadMode;
426 z &= ~DM_CompareMask;
428 switch ( ctx->Depth.Func ) {
445 z |= DM_GreaterEqual;
455 if ( ctx->Depth.Test ) {
456 z |= DepthModeEnable;
457 delta |= DM_DepthEnable;
458 window |= W_DepthFCP;
459 lbread |= LBReadDstEnable;
461 z &= ~DepthModeEnable;
462 delta &= ~DM_DepthEnable;
463 window &= ~W_DepthFCP;
464 lbread &= ~LBReadDstEnable;
467 if ( ctx->Depth.Mask ) {
474 if ( gmesa->DepthMode != z ){
476 gmesa->DepthMode = z;
477 gmesa->DeltaMode = delta;
478 gmesa->Window = window;
479 gmesa->LBReadMode = lbread;
480 gmesa->dirty |= GAMMA_UPLOAD_DEPTH;
486 static void gammaDDDepthFunc( GLcontext *ctx, GLenum func )
488 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
490 FLUSH_BATCH( gmesa );
491 gmesa->new_state |= GAMMA_NEW_DEPTH;
494 static void gammaDDDepthMask( GLcontext *ctx, GLboolean flag )
496 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
498 FLUSH_BATCH( gmesa );
499 gmesa->new_state |= GAMMA_NEW_DEPTH;
502 static void gammaDDClearDepth( GLcontext *ctx, GLclampd d )
504 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
506 switch ( gmesa->DepthSize ) {
508 gmesa->ClearDepth = d * 0x0000ffff;
511 gmesa->ClearDepth = d * 0x00ffffff;
514 gmesa->ClearDepth = d * 0xffffffff;
519 static void gammaDDFinish( GLcontext *ctx )
521 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
523 FLUSH_DMA_BUFFER(gmesa);
526 static void gammaDDFlush( GLcontext *ctx )
528 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
530 FLUSH_DMA_BUFFER(gmesa);
533 /* =============================================================
537 static void gammaUpdateFogAttrib( GLcontext *ctx )
539 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
540 u_int32_t f = gmesa->FogMode;
541 u_int32_t g = gmesa->GeometryMode;
542 u_int32_t d = gmesa->DeltaMode;
544 if (ctx->Fog.Enabled) {
556 switch (ctx->Fog.Mode) {
564 g |= GM_FogExpSquared;
568 if ( gmesa->FogMode != f ) {
570 gmesa->dirty |= GAMMA_UPLOAD_FOG;
573 if ( gmesa->GeometryMode != g ) {
574 gmesa->GeometryMode = g;
575 gmesa->dirty |= GAMMA_UPLOAD_GEOMETRY;
578 if ( gmesa->DeltaMode != d ) {
579 gmesa->DeltaMode = d;
580 gmesa->dirty |= GAMMA_UPLOAD_DEPTH;
585 static void gammaDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *param )
587 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
589 FLUSH_BATCH( gmesa );
590 gmesa->new_state |= GAMMA_NEW_FOG;
594 /* =============================================================
597 static void gammaDDLineWidth( GLcontext *ctx, GLfloat width )
599 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
601 CHECK_DMA_BUFFER(gmesa, 3);
602 WRITE(gmesa->buf, LineWidth, (GLuint)width);
603 WRITEF(gmesa->buf, AAlineWidth, width);
604 WRITE(gmesa->buf, LineWidthOffset, (GLuint)(width-1)/2);
607 static void gammaDDLineStipple( GLcontext *ctx, GLint factor, GLushort pattern )
609 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
611 gmesa->LineMode &= ~(LM_StippleMask | LM_RepeatFactorMask);
612 gmesa->LineMode |= ((GLuint)(factor - 1) << 1) | ((GLuint)pattern << 10);
614 gmesa->dirty |= GAMMA_UPLOAD_LINEMODE;
619 /* =============================================================
622 static void gammaDDPointSize( GLcontext *ctx, GLfloat size )
624 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
626 CHECK_DMA_BUFFER(gmesa, 2);
627 WRITE(gmesa->buf, PointSize, (GLuint)size);
628 WRITEF(gmesa->buf, AApointSize, size);
631 /* =============================================================
635 static void gammaUpdatePolygon( GLcontext *ctx )
637 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
638 u_int32_t g = gmesa->GeometryMode;
640 g &= ~(GM_PolyOffsetFillEnable | GM_PolyOffsetPointEnable |
641 GM_PolyOffsetLineEnable);
643 if (ctx->Polygon.OffsetFill) g |= GM_PolyOffsetFillEnable;
644 if (ctx->Polygon.OffsetPoint) g |= GM_PolyOffsetPointEnable;
645 if (ctx->Polygon.OffsetLine) g |= GM_PolyOffsetLineEnable;
647 g &= ~GM_FB_PolyMask;
649 switch (ctx->Polygon.FrontMode) {
651 g |= GM_FrontPolyFill;
654 g |= GM_FrontPolyLine;
657 g |= GM_FrontPolyPoint;
661 switch (ctx->Polygon.BackMode) {
663 g |= GM_BackPolyFill;
666 g |= GM_BackPolyLine;
669 g |= GM_BackPolyPoint;
673 if ( gmesa->GeometryMode != g ) {
674 gmesa->GeometryMode = g;
675 gmesa->dirty |= GAMMA_UPLOAD_GEOMETRY;
678 gmesa->dirty |= GAMMA_UPLOAD_POLYGON;
681 static void gammaDDPolygonMode( GLcontext *ctx, GLenum face, GLenum mode)
683 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
685 FLUSH_BATCH( gmesa );
687 gmesa->new_state |= GAMMA_NEW_POLYGON;
690 static void gammaUpdateStipple( GLcontext *ctx )
692 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
694 FLUSH_BATCH( gmesa );
696 if (ctx->Polygon.StippleFlag) {
697 gmesa->AreaStippleMode |= AreaStippleModeEnable/* | ASM_X32 | ASM_Y32*/;
699 gmesa->AreaStippleMode &= ~AreaStippleModeEnable;
702 gmesa->dirty |= GAMMA_UPLOAD_STIPPLE;
705 static void gammaDDPolygonStipple( GLcontext *ctx, const GLubyte *mask)
707 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
708 FLUSH_BATCH( gmesa );
709 gmesa->new_state |= GAMMA_NEW_STIPPLE;
712 /* =============================================================
716 static void gammaUpdateClipping( GLcontext *ctx )
718 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
719 GLint x1, y1, x2, y2;
721 if ( gmesa->driDrawable ) {
722 x1 = gmesa->driDrawable->x + ctx->Scissor.X;
723 y1 = gmesa->driScreen->fbHeight -
724 (gmesa->driDrawable->y +
725 gmesa->driDrawable->h) + ctx->Scissor.Y;
726 x2 = x1 + ctx->Scissor.Width;
727 y2 = y1 + ctx->Scissor.Height;
729 gmesa->ScissorMinXY = x1 | (y1 << 16);
730 gmesa->ScissorMaxXY = x2 | (y2 << 16);
731 if (ctx->Scissor.Enabled)
732 gmesa->ScissorMode |= UserScissorEnable;
734 gmesa->ScissorMode &= ~UserScissorEnable;
736 gmesa->dirty |= GAMMA_UPLOAD_CLIP;
740 static void gammaDDScissor( GLcontext *ctx,
741 GLint x, GLint y, GLsizei w, GLsizei h )
743 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
745 FLUSH_BATCH( gmesa );
746 gmesa->new_state |= GAMMA_NEW_CLIP;
749 /* =============================================================
753 static void gammaUpdateCull( GLcontext *ctx )
755 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
756 u_int32_t g = gmesa->GeometryMode;
758 g &= ~(GM_PolyCullMask | GM_FFMask);
760 if (ctx->Polygon.FrontFace == GL_CCW) {
761 g |= GM_FrontFaceCCW;
766 switch ( ctx->Polygon.CullFaceMode ) {
768 g |= GM_PolyCullFront;
771 g |= GM_PolyCullBack;
773 case GL_FRONT_AND_BACK:
774 g |= GM_PolyCullBoth;
778 if ( ctx->Polygon.CullFlag ) {
779 g |= GM_PolyCullEnable;
781 g &= ~GM_PolyCullEnable;
784 if ( gmesa->GeometryMode != g ) {
785 gmesa->GeometryMode = g;
786 gmesa->dirty |= GAMMA_UPLOAD_GEOMETRY;
790 static void gammaDDCullFace( GLcontext *ctx, GLenum mode )
792 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
794 FLUSH_BATCH( gmesa );
795 gmesa->new_state |= GAMMA_NEW_CULL;
798 static void gammaDDFrontFace( GLcontext *ctx, GLenum mode )
800 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
802 FLUSH_BATCH( gmesa );
803 gmesa->new_state |= GAMMA_NEW_CULL;
806 /* =============================================================
810 static void gammaUpdateMasks( GLcontext *ctx )
812 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
815 GLuint mask = gammaPackColor( gmesa->gammaScreen->cpp,
816 ctx->Color.ColorMask[RCOMP],
817 ctx->Color.ColorMask[GCOMP],
818 ctx->Color.ColorMask[BCOMP],
819 ctx->Color.ColorMask[ACOMP] );
821 if (gmesa->gammaScreen->cpp == 2) mask |= mask << 16;
823 if ( gmesa->FBHardwareWriteMask != mask ) {
824 gmesa->FBHardwareWriteMask = mask;
825 gmesa->dirty |= GAMMA_UPLOAD_MASKS;
829 static void gammaDDColorMask( GLcontext *ctx, GLboolean r, GLboolean g,
830 GLboolean b, GLboolean a)
832 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
834 FLUSH_BATCH( gmesa );
835 gmesa->new_state |= GAMMA_NEW_MASKS;
838 /* =============================================================
839 * Rendering attributes
841 * We really don't want to recalculate all this every time we bind a
842 * texture. These things shouldn't change all that often, so it makes
843 * sense to break them out of the core texture state update routines.
847 static void gammaDDLightfv(GLcontext *ctx, GLenum light, GLenum pname,
848 const GLfloat *params, GLint nParams)
850 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
857 CHECK_DMA_BUFFER(gmesa, 3);
858 /* We don't do alpha */
859 WRITEF(gmesa->buf, Light0AmbientIntensityBlue, params[2]);
860 WRITEF(gmesa->buf, Light0AmbientIntensityGreen, params[1]);
861 WRITEF(gmesa->buf, Light0AmbientIntensityRed, params[0]);
864 CHECK_DMA_BUFFER(gmesa, 3);
865 /* We don't do alpha */
866 WRITEF(gmesa->buf, Light0DiffuseIntensityBlue, params[2]);
867 WRITEF(gmesa->buf, Light0DiffuseIntensityGreen, params[1]);
868 WRITEF(gmesa->buf, Light0DiffuseIntensityRed, params[0]);
871 CHECK_DMA_BUFFER(gmesa, 3);
872 /* We don't do alpha */
873 WRITEF(gmesa->buf, Light0SpecularIntensityBlue, params[2]);
874 WRITEF(gmesa->buf, Light0SpecularIntensityGreen, params[1]);
875 WRITEF(gmesa->buf, Light0SpecularIntensityRed, params[0]);
878 /* Normalize <x,y,z> */
879 x = params[0]; y = params[1]; z = params[2]; w = params[3];
880 l = sqrt(x*x + y*y + z*z + w*w);
885 if (params[3] != 0.0) {
886 gmesa->Light0Mode |= Light0ModeAttenuation;
887 gmesa->Light0Mode |= Light0ModeLocal;
889 gmesa->Light0Mode &= ~Light0ModeAttenuation;
890 gmesa->Light0Mode &= ~Light0ModeLocal;
892 CHECK_DMA_BUFFER(gmesa, 5);
893 WRITE(gmesa->buf, Light0Mode, gmesa->Light0Mode);
894 WRITEF(gmesa->buf, Light0PositionW, w);
895 WRITEF(gmesa->buf, Light0PositionZ, z);
896 WRITEF(gmesa->buf, Light0PositionY, y);
897 WRITEF(gmesa->buf, Light0PositionX, x);
899 case GL_SPOT_DIRECTION:
900 CHECK_DMA_BUFFER(gmesa, 3);
901 /* WRITEF(gmesa->buf, Light0SpotlightDirectionW, params[3]); */
902 WRITEF(gmesa->buf, Light0SpotlightDirectionZ, params[2]);
903 WRITEF(gmesa->buf, Light0SpotlightDirectionY, params[1]);
904 WRITEF(gmesa->buf, Light0SpotlightDirectionX, params[0]);
906 case GL_SPOT_EXPONENT:
907 CHECK_DMA_BUFFER(gmesa, 1);
908 WRITEF(gmesa->buf, Light0SpotlightExponent, params[0]);
911 if (params[0] != 180.0)
912 gmesa->Light0Mode |= Light0ModeSpotLight;
914 gmesa->Light0Mode &= ~Light0ModeSpotLight;
915 CHECK_DMA_BUFFER(gmesa, 2);
916 WRITE(gmesa->buf, Light0Mode, gmesa->Light0Mode);
917 WRITEF(gmesa->buf, Light0CosSpotlightCutoffAngle, cos(params[0]*DEG2RAD));
919 case GL_CONSTANT_ATTENUATION:
920 CHECK_DMA_BUFFER(gmesa, 1);
921 WRITEF(gmesa->buf, Light0ConstantAttenuation, params[0]);
923 case GL_LINEAR_ATTENUATION:
924 CHECK_DMA_BUFFER(gmesa, 1);
925 WRITEF(gmesa->buf, Light0LinearAttenuation, params[0]);
927 case GL_QUADRATIC_ATTENUATION:
928 CHECK_DMA_BUFFER(gmesa, 1);
929 WRITEF(gmesa->buf, Light0QuadraticAttenuation, params[0]);
936 static void gammaDDLightModelfv( GLcontext *ctx, GLenum pname,
937 const GLfloat *params )
939 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
942 case GL_LIGHT_MODEL_AMBIENT:
943 CHECK_DMA_BUFFER(gmesa, 3);
944 /* We don't do alpha */
945 WRITEF(gmesa->buf, SceneAmbientColorBlue, params[2]);
946 WRITEF(gmesa->buf, SceneAmbientColorGreen, params[1]);
947 WRITEF(gmesa->buf, SceneAmbientColorRed, params[0]);
949 case GL_LIGHT_MODEL_LOCAL_VIEWER:
950 if (params[0] != 0.0)
951 gmesa->LightingMode |= LightingModeLocalViewer;
953 gmesa->LightingMode &= ~LightingModeLocalViewer;
954 CHECK_DMA_BUFFER(gmesa, 1);
955 WRITE(gmesa->buf, LightingMode, gmesa->LightingMode);
957 case GL_LIGHT_MODEL_TWO_SIDE:
958 if (params[0] == 1.0f) {
959 gmesa->LightingMode |= LightingModeTwoSides;
960 gmesa->MaterialMode |= MaterialModeTwoSides;
962 gmesa->LightingMode &= ~LightingModeTwoSides;
963 gmesa->MaterialMode &= ~MaterialModeTwoSides;
965 CHECK_DMA_BUFFER(gmesa, 2);
966 WRITE(gmesa->buf, LightingMode, gmesa->LightingMode);
967 WRITE(gmesa->buf, MaterialMode, gmesa->MaterialMode);
973 static void gammaDDShadeModel( GLcontext *ctx, GLenum mode )
975 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
976 u_int32_t g = gmesa->GeometryMode;
977 u_int32_t c = gmesa->ColorDDAMode;
979 g &= ~GM_ShadingMask;
980 c &= ~ColorDDAShadingMask;
988 g |= GM_GouraudShading;
989 c |= ColorDDAGouraud;
995 if ( gmesa->ColorDDAMode != c ) {
996 FLUSH_BATCH( gmesa );
997 gmesa->ColorDDAMode = c;
999 gmesa->dirty |= GAMMA_UPLOAD_SHADE;
1002 if ( gmesa->GeometryMode != g ) {
1003 FLUSH_BATCH( gmesa );
1004 gmesa->GeometryMode = g;
1006 gmesa->dirty |= GAMMA_UPLOAD_GEOMETRY;
1010 /* =============================================================
1014 static void gammaDDClearColor( GLcontext *ctx, const GLfloat color[4])
1016 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1018 UNCLAMPED_FLOAT_TO_UBYTE(c[0], color[0]);
1019 UNCLAMPED_FLOAT_TO_UBYTE(c[1], color[1]);
1020 UNCLAMPED_FLOAT_TO_UBYTE(c[2], color[2]);
1021 UNCLAMPED_FLOAT_TO_UBYTE(c[3], color[3]);
1023 gmesa->ClearColor = gammaPackColor( gmesa->gammaScreen->cpp,
1024 c[0], c[1], c[2], c[3] );
1026 if (gmesa->gammaScreen->cpp == 2) gmesa->ClearColor |= gmesa->ClearColor<<16;
1030 static void gammaDDLogicalOpcode( GLcontext *ctx, GLenum opcode )
1032 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1034 FLUSH_BATCH( gmesa );
1036 if ( ctx->Color.ColorLogicOpEnabled ) {
1037 gmesa->LogicalOpMode = opcode << 1 | LogicalOpModeEnable;
1039 gmesa->LogicalOpMode = LogicalOpModeDisable;
1042 gmesa->dirty |= GAMMA_UPLOAD_LOGICOP;
1045 static void gammaDDDrawBuffer( GLcontext *ctx, GLenum mode )
1047 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1049 FLUSH_BATCH( gmesa );
1053 gmesa->drawOffset = gmesa->readOffset = 0;
1056 gmesa->drawOffset = gmesa->readOffset = gmesa->driScreen->fbHeight * gmesa->driScreen->fbWidth * gmesa->gammaScreen->cpp;
1061 static void gammaDDReadBuffer( GLcontext *ctx, GLenum mode )
1066 /* =============================================================
1067 * Window position and viewport transformation
1070 void gammaUpdateWindow( GLcontext *ctx )
1072 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1073 __DRIdrawablePrivate *dPriv = gmesa->driDrawable;
1074 GLfloat xoffset = (GLfloat)dPriv->x;
1075 GLfloat yoffset = gmesa->driScreen->fbHeight - (GLfloat)dPriv->y - dPriv->h;
1076 const GLfloat *v = ctx->Viewport._WindowMap.m;
1078 GLfloat sx = v[MAT_SX];
1079 GLfloat tx = v[MAT_TX] + xoffset;
1080 GLfloat sy = v[MAT_SY];
1081 GLfloat ty = v[MAT_TY] + yoffset;
1082 GLfloat sz = v[MAT_SZ] * gmesa->depth_scale;
1083 GLfloat tz = v[MAT_TZ] * gmesa->depth_scale;
1085 gmesa->dirty |= GAMMA_UPLOAD_VIEWPORT;
1087 gmesa->ViewportScaleX = sx;
1088 gmesa->ViewportScaleY = sy;
1089 gmesa->ViewportScaleZ = sz;
1090 gmesa->ViewportOffsetX = tx;
1091 gmesa->ViewportOffsetY = ty;
1092 gmesa->ViewportOffsetZ = tz;
1097 static void gammaDDViewport( GLcontext *ctx, GLint x, GLint y,
1098 GLsizei width, GLsizei height )
1100 gammaUpdateWindow( ctx );
1103 static void gammaDDDepthRange( GLcontext *ctx, GLclampd nearval,
1106 gammaUpdateWindow( ctx );
1109 void gammaUpdateViewportOffset( GLcontext *ctx )
1111 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1112 __DRIdrawablePrivate *dPriv = gmesa->driDrawable;
1113 GLfloat xoffset = (GLfloat)dPriv->x;
1114 GLfloat yoffset = gmesa->driScreen->fbHeight - (GLfloat)dPriv->y - dPriv->h;
1115 const GLfloat *v = ctx->Viewport._WindowMap.m;
1117 GLfloat tx = v[MAT_TX] + xoffset;
1118 GLfloat ty = v[MAT_TY] + yoffset;
1120 if ( gmesa->ViewportOffsetX != tx ||
1121 gmesa->ViewportOffsetY != ty )
1123 gmesa->ViewportOffsetX = tx;
1124 gmesa->ViewportOffsetY = ty;
1126 gmesa->new_state |= GAMMA_NEW_WINDOW;
1129 gmesa->new_state |= GAMMA_NEW_CLIP;
1137 static void gammaLoadHWMatrix(GLcontext *ctx)
1139 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1142 gmesa->TransformMode &= ~XM_XformTexture;
1144 switch (ctx->Transform.MatrixMode) {
1146 gmesa->TransformMode |= XM_UseModelViewMatrix;
1147 m = ctx->ModelviewMatrixStack.Top->m;
1148 CHECK_DMA_BUFFER(gmesa, 16);
1149 WRITEF(gmesa->buf, ModelViewMatrix0, m[0]);
1150 WRITEF(gmesa->buf, ModelViewMatrix1, m[1]);
1151 WRITEF(gmesa->buf, ModelViewMatrix2, m[2]);
1152 WRITEF(gmesa->buf, ModelViewMatrix3, m[3]);
1153 WRITEF(gmesa->buf, ModelViewMatrix4, m[4]);
1154 WRITEF(gmesa->buf, ModelViewMatrix5, m[5]);
1155 WRITEF(gmesa->buf, ModelViewMatrix6, m[6]);
1156 WRITEF(gmesa->buf, ModelViewMatrix7, m[7]);
1157 WRITEF(gmesa->buf, ModelViewMatrix8, m[8]);
1158 WRITEF(gmesa->buf, ModelViewMatrix9, m[9]);
1159 WRITEF(gmesa->buf, ModelViewMatrix10, m[10]);
1160 WRITEF(gmesa->buf, ModelViewMatrix11, m[11]);
1161 WRITEF(gmesa->buf, ModelViewMatrix12, m[12]);
1162 WRITEF(gmesa->buf, ModelViewMatrix13, m[13]);
1163 WRITEF(gmesa->buf, ModelViewMatrix14, m[14]);
1164 WRITEF(gmesa->buf, ModelViewMatrix15, m[15]);
1167 m = ctx->ProjectionMatrixStack.Top->m;
1168 CHECK_DMA_BUFFER(gmesa, 16);
1169 WRITEF(gmesa->buf, ModelViewProjectionMatrix0, m[0]);
1170 WRITEF(gmesa->buf, ModelViewProjectionMatrix1, m[1]);
1171 WRITEF(gmesa->buf, ModelViewProjectionMatrix2, m[2]);
1172 WRITEF(gmesa->buf, ModelViewProjectionMatrix3, m[3]);
1173 WRITEF(gmesa->buf, ModelViewProjectionMatrix4, m[4]);
1174 WRITEF(gmesa->buf, ModelViewProjectionMatrix5, m[5]);
1175 WRITEF(gmesa->buf, ModelViewProjectionMatrix6, m[6]);
1176 WRITEF(gmesa->buf, ModelViewProjectionMatrix7, m[7]);
1177 WRITEF(gmesa->buf, ModelViewProjectionMatrix8, m[8]);
1178 WRITEF(gmesa->buf, ModelViewProjectionMatrix9, m[9]);
1179 WRITEF(gmesa->buf, ModelViewProjectionMatrix10, m[10]);
1180 WRITEF(gmesa->buf, ModelViewProjectionMatrix11, m[11]);
1181 WRITEF(gmesa->buf, ModelViewProjectionMatrix12, m[12]);
1182 WRITEF(gmesa->buf, ModelViewProjectionMatrix13, m[13]);
1183 WRITEF(gmesa->buf, ModelViewProjectionMatrix14, m[14]);
1184 WRITEF(gmesa->buf, ModelViewProjectionMatrix15, m[15]);
1187 m = ctx->TextureMatrixStack[0].Top->m;
1188 CHECK_DMA_BUFFER(gmesa, 16);
1189 gmesa->TransformMode |= XM_XformTexture;
1190 WRITEF(gmesa->buf, TextureMatrix0, m[0]);
1191 WRITEF(gmesa->buf, TextureMatrix1, m[1]);
1192 WRITEF(gmesa->buf, TextureMatrix2, m[2]);
1193 WRITEF(gmesa->buf, TextureMatrix3, m[3]);
1194 WRITEF(gmesa->buf, TextureMatrix4, m[4]);
1195 WRITEF(gmesa->buf, TextureMatrix5, m[5]);
1196 WRITEF(gmesa->buf, TextureMatrix6, m[6]);
1197 WRITEF(gmesa->buf, TextureMatrix7, m[7]);
1198 WRITEF(gmesa->buf, TextureMatrix8, m[8]);
1199 WRITEF(gmesa->buf, TextureMatrix9, m[9]);
1200 WRITEF(gmesa->buf, TextureMatrix10, m[10]);
1201 WRITEF(gmesa->buf, TextureMatrix11, m[11]);
1202 WRITEF(gmesa->buf, TextureMatrix12, m[12]);
1203 WRITEF(gmesa->buf, TextureMatrix13, m[13]);
1204 WRITEF(gmesa->buf, TextureMatrix14, m[14]);
1205 WRITEF(gmesa->buf, TextureMatrix15, m[15]);
1209 /* ERROR!!! -- how did this happen? */
1213 gmesa->dirty |= GAMMA_UPLOAD_TRANSFORM;
1217 /* =============================================================
1218 * State enable/disable
1221 static void gammaDDEnable( GLcontext *ctx, GLenum cap, GLboolean state )
1223 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1228 FLUSH_BATCH( gmesa );
1229 gmesa->new_state |= GAMMA_NEW_ALPHA;
1233 FLUSH_BATCH( gmesa );
1234 gmesa->new_state |= GAMMA_NEW_CULL;
1238 FLUSH_BATCH( gmesa );
1239 gmesa->new_state |= GAMMA_NEW_DEPTH;
1244 u_int32_t d = gmesa->DitherMode;
1245 FLUSH_BATCH( gmesa );
1248 d |= DM_DitherEnable;
1250 d &= ~DM_DitherEnable;
1253 if ( gmesa->DitherMode != d ) {
1254 gmesa->DitherMode = d;
1255 gmesa->dirty |= GAMMA_UPLOAD_DITHER;
1262 FLUSH_BATCH( gmesa );
1263 gmesa->new_state |= GAMMA_NEW_FOG;
1267 case GL_INDEX_LOGIC_OP:
1268 case GL_COLOR_LOGIC_OP:
1269 FLUSH_BATCH( gmesa );
1270 gmesa->new_state |= GAMMA_NEW_LOGICOP;
1276 u_int32_t l = gmesa->LightingMode;
1277 FLUSH_BATCH( gmesa );
1280 l |= LightingModeEnable;
1282 l &= ~LightingModeEnable;
1285 if ( gmesa->LightingMode != l ) {
1286 gmesa->LightingMode = l;
1287 gmesa->dirty |= GAMMA_UPLOAD_LIGHT;
1292 case GL_COLOR_MATERIAL:
1294 u_int32_t m = gmesa->MaterialMode;
1295 FLUSH_BATCH( gmesa );
1298 m |= MaterialModeEnable;
1300 m &= ~MaterialModeEnable;
1303 if ( gmesa->MaterialMode != m ) {
1304 gmesa->MaterialMode = m;
1305 gmesa->dirty |= GAMMA_UPLOAD_LIGHT;
1311 case GL_LINE_SMOOTH:
1312 FLUSH_BATCH( gmesa );
1314 gmesa->AntialiasMode |= AntialiasModeEnable;
1315 gmesa->LineMode |= LM_AntialiasEnable;
1317 gmesa->AntialiasMode &= ~AntialiasModeEnable;
1318 gmesa->LineMode &= ~LM_AntialiasEnable;
1320 gmesa->dirty |= GAMMA_UPLOAD_LINEMODE;
1323 case GL_POINT_SMOOTH:
1324 FLUSH_BATCH( gmesa );
1326 gmesa->AntialiasMode |= AntialiasModeEnable;
1327 gmesa->PointMode |= PM_AntialiasEnable;
1329 gmesa->AntialiasMode &= ~AntialiasModeEnable;
1330 gmesa->PointMode &= ~PM_AntialiasEnable;
1332 gmesa->dirty |= GAMMA_UPLOAD_POINTMODE;
1335 case GL_POLYGON_SMOOTH:
1336 FLUSH_BATCH( gmesa );
1338 gmesa->AntialiasMode |= AntialiasModeEnable;
1339 gmesa->TriangleMode |= TM_AntialiasEnable;
1341 gmesa->AntialiasMode &= ~AntialiasModeEnable;
1342 gmesa->TriangleMode &= ~TM_AntialiasEnable;
1344 gmesa->dirty |= GAMMA_UPLOAD_TRIMODE;
1347 case GL_SCISSOR_TEST:
1348 FLUSH_BATCH( gmesa );
1349 gmesa->new_state |= GAMMA_NEW_CLIP;
1352 case GL_POLYGON_OFFSET_FILL:
1353 case GL_POLYGON_OFFSET_POINT:
1354 case GL_POLYGON_OFFSET_LINE:
1355 FLUSH_BATCH( gmesa );
1356 gmesa->new_state |= GAMMA_NEW_POLYGON;
1359 case GL_LINE_STIPPLE:
1360 FLUSH_BATCH( gmesa );
1362 gmesa->LineMode |= LM_StippleEnable;
1364 gmesa->LineMode &= ~LM_StippleEnable;
1365 gmesa->dirty |= GAMMA_UPLOAD_LINEMODE;
1368 case GL_POLYGON_STIPPLE:
1369 FLUSH_BATCH( gmesa );
1370 gmesa->new_state |= GAMMA_NEW_STIPPLE;
1378 /* =============================================================
1379 * State initialization, management
1384 * Load the current context's state into the hardware.
1386 * NOTE: Be VERY careful about ensuring the context state is marked for
1387 * upload, the only place it shouldn't be uploaded is when the setup
1388 * state has changed in ReducedPrimitiveChange as this comes right after
1391 * Blits of any type should always upload the context and masks after
1394 void gammaEmitHwState( gammaContextPtr gmesa )
1396 if (!gmesa->driDrawable) return;
1398 if (!gmesa->dirty) return;
1401 /* Flush any partially filled buffers */
1402 FLUSH_DMA_BUFFER(gmesa);
1404 DRM_SPINLOCK(&gmesa->driScreen->pSAREA->drawable_lock,
1405 gmesa->driScreen->drawLockID);
1406 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa);
1409 if (gmesa->dirty & GAMMA_UPLOAD_VIEWPORT) {
1410 gmesa->dirty &= ~GAMMA_UPLOAD_VIEWPORT;
1411 CHECK_DMA_BUFFER(gmesa, 6);
1412 WRITEF(gmesa->buf, ViewPortOffsetX, gmesa->ViewportOffsetX);
1413 WRITEF(gmesa->buf, ViewPortOffsetY, gmesa->ViewportOffsetY);
1414 WRITEF(gmesa->buf, ViewPortOffsetZ, gmesa->ViewportOffsetZ);
1415 WRITEF(gmesa->buf, ViewPortScaleX, gmesa->ViewportScaleX);
1416 WRITEF(gmesa->buf, ViewPortScaleY, gmesa->ViewportScaleY);
1417 WRITEF(gmesa->buf, ViewPortScaleZ, gmesa->ViewportScaleZ);
1419 if ( (gmesa->dirty & GAMMA_UPLOAD_POINTMODE) ||
1420 (gmesa->dirty & GAMMA_UPLOAD_LINEMODE) ||
1421 (gmesa->dirty & GAMMA_UPLOAD_TRIMODE) ) {
1422 CHECK_DMA_BUFFER(gmesa, 1);
1423 WRITE(gmesa->buf, AntialiasMode, gmesa->AntialiasMode);
1425 if (gmesa->dirty & GAMMA_UPLOAD_POINTMODE) {
1426 gmesa->dirty &= ~GAMMA_UPLOAD_POINTMODE;
1427 CHECK_DMA_BUFFER(gmesa, 1);
1428 WRITE(gmesa->buf, PointMode, gmesa->PointMode);
1430 if (gmesa->dirty & GAMMA_UPLOAD_LINEMODE) {
1431 gmesa->dirty &= ~GAMMA_UPLOAD_LINEMODE;
1432 CHECK_DMA_BUFFER(gmesa, 2);
1433 WRITE(gmesa->buf, LineMode, gmesa->LineMode);
1434 WRITE(gmesa->buf, LineStippleMode, gmesa->LineMode);
1436 if (gmesa->dirty & GAMMA_UPLOAD_TRIMODE) {
1437 gmesa->dirty &= ~GAMMA_UPLOAD_TRIMODE;
1438 CHECK_DMA_BUFFER(gmesa, 1);
1439 WRITE(gmesa->buf, TriangleMode, gmesa->TriangleMode);
1441 if (gmesa->dirty & GAMMA_UPLOAD_FOG) {
1443 UNCLAMPED_FLOAT_TO_RGB_CHAN( c, gmesa->glCtx->Fog.Color );
1444 col = gammaPackColor(4, c[0], c[1], c[2], 0);
1445 gmesa->dirty &= ~GAMMA_UPLOAD_FOG;
1446 CHECK_DMA_BUFFER(gmesa, 5);
1448 WRITE(gmesa->buf, FogMode, gmesa->FogMode);
1449 WRITE(gmesa->buf, FogColor, col);
1450 WRITEF(gmesa->buf, FStart, gmesa->glCtx->Fog.Start);
1452 WRITEF(gmesa->buf, FogEnd, gmesa->glCtx->Fog.End);
1453 WRITEF(gmesa->buf, FogDensity, gmesa->glCtx->Fog.Density);
1454 WRITEF(gmesa->buf, FogScale,
1455 1.0f/(gmesa->glCtx->Fog.End - gmesa->glCtx->Fog.Start));
1457 if (gmesa->dirty & GAMMA_UPLOAD_DITHER) {
1458 gmesa->dirty &= ~GAMMA_UPLOAD_DITHER;
1459 CHECK_DMA_BUFFER(gmesa, 1);
1460 WRITE(gmesa->buf, DitherMode, gmesa->DitherMode);
1462 if (gmesa->dirty & GAMMA_UPLOAD_LOGICOP) {
1463 gmesa->dirty &= ~GAMMA_UPLOAD_LOGICOP;
1464 CHECK_DMA_BUFFER(gmesa, 1);
1465 WRITE(gmesa->buf, LogicalOpMode, gmesa->LogicalOpMode);
1467 if (gmesa->dirty & GAMMA_UPLOAD_CLIP) {
1468 gmesa->dirty &= ~GAMMA_UPLOAD_CLIP;
1469 CHECK_DMA_BUFFER(gmesa, 3);
1470 WRITE(gmesa->buf, ScissorMinXY, gmesa->ScissorMinXY);
1471 WRITE(gmesa->buf, ScissorMaxXY, gmesa->ScissorMaxXY);
1472 WRITE(gmesa->buf, ScissorMode, gmesa->ScissorMode);
1474 if (gmesa->dirty & GAMMA_UPLOAD_MASKS) {
1475 gmesa->dirty &= ~GAMMA_UPLOAD_MASKS;
1476 CHECK_DMA_BUFFER(gmesa, 1);
1477 WRITE(gmesa->buf, FBHardwareWriteMask, gmesa->FBHardwareWriteMask);
1479 if (gmesa->dirty & GAMMA_UPLOAD_ALPHA) {
1480 gmesa->dirty &= ~GAMMA_UPLOAD_ALPHA;
1481 CHECK_DMA_BUFFER(gmesa, 1);
1482 WRITE(gmesa->buf, AlphaTestMode, gmesa->AlphaTestMode);
1484 if (gmesa->dirty & GAMMA_UPLOAD_BLEND) {
1485 gmesa->dirty &= ~GAMMA_UPLOAD_BLEND;
1486 CHECK_DMA_BUFFER(gmesa, 1);
1487 WRITE(gmesa->buf, AlphaBlendMode, gmesa->AlphaBlendMode);
1489 CHECK_DMA_BUFFER(gmesa, 1);
1490 if (gmesa->glCtx->Color.BlendEnabled || gmesa->glCtx->Color.AlphaEnabled) {
1491 WRITE(gmesa->buf, FBReadMode, gmesa->FBReadMode | gmesa->AB_FBReadMode_Save);
1493 WRITE(gmesa->buf, FBReadMode, gmesa->FBReadMode);
1495 if (gmesa->dirty & GAMMA_UPLOAD_LIGHT) {
1496 gmesa->dirty &= ~GAMMA_UPLOAD_LIGHT;
1497 CHECK_DMA_BUFFER(gmesa, 2);
1498 WRITE(gmesa->buf, LightingMode, gmesa->LightingMode);
1499 WRITE(gmesa->buf, MaterialMode, gmesa->MaterialMode);
1501 if (gmesa->dirty & GAMMA_UPLOAD_SHADE) {
1502 gmesa->dirty &= ~GAMMA_UPLOAD_SHADE;
1503 CHECK_DMA_BUFFER(gmesa, 1);
1504 WRITE(gmesa->buf, ColorDDAMode, gmesa->ColorDDAMode);
1506 if (gmesa->dirty & GAMMA_UPLOAD_POLYGON) {
1507 gmesa->dirty &= ~GAMMA_UPLOAD_POLYGON;
1508 CHECK_DMA_BUFFER(gmesa, 2);
1509 WRITEF(gmesa->buf, PolygonOffsetBias, gmesa->glCtx->Polygon.OffsetUnits);
1510 WRITEF(gmesa->buf, PolygonOffsetFactor, gmesa->glCtx->Polygon.OffsetFactor);
1512 if (gmesa->dirty & GAMMA_UPLOAD_STIPPLE) {
1513 gmesa->dirty &= ~GAMMA_UPLOAD_STIPPLE;
1514 CHECK_DMA_BUFFER(gmesa, 33);
1515 WRITE(gmesa->buf, AreaStippleMode, gmesa->AreaStippleMode);
1516 WRITE(gmesa->buf, AreaStipplePattern0, gmesa->glCtx->PolygonStipple[0]);
1517 WRITE(gmesa->buf, AreaStipplePattern1, gmesa->glCtx->PolygonStipple[1]);
1518 WRITE(gmesa->buf, AreaStipplePattern2, gmesa->glCtx->PolygonStipple[2]);
1519 WRITE(gmesa->buf, AreaStipplePattern3, gmesa->glCtx->PolygonStipple[3]);
1520 WRITE(gmesa->buf, AreaStipplePattern4, gmesa->glCtx->PolygonStipple[4]);
1521 WRITE(gmesa->buf, AreaStipplePattern5, gmesa->glCtx->PolygonStipple[5]);
1522 WRITE(gmesa->buf, AreaStipplePattern6, gmesa->glCtx->PolygonStipple[6]);
1523 WRITE(gmesa->buf, AreaStipplePattern7, gmesa->glCtx->PolygonStipple[7]);
1524 WRITE(gmesa->buf, AreaStipplePattern8, gmesa->glCtx->PolygonStipple[8]);
1525 WRITE(gmesa->buf, AreaStipplePattern9, gmesa->glCtx->PolygonStipple[9]);
1526 WRITE(gmesa->buf, AreaStipplePattern10, gmesa->glCtx->PolygonStipple[10]);
1527 WRITE(gmesa->buf, AreaStipplePattern11, gmesa->glCtx->PolygonStipple[11]);
1528 WRITE(gmesa->buf, AreaStipplePattern12, gmesa->glCtx->PolygonStipple[12]);
1529 WRITE(gmesa->buf, AreaStipplePattern13, gmesa->glCtx->PolygonStipple[13]);
1530 WRITE(gmesa->buf, AreaStipplePattern14, gmesa->glCtx->PolygonStipple[14]);
1531 WRITE(gmesa->buf, AreaStipplePattern15, gmesa->glCtx->PolygonStipple[15]);
1532 WRITE(gmesa->buf, AreaStipplePattern16, gmesa->glCtx->PolygonStipple[16]);
1533 WRITE(gmesa->buf, AreaStipplePattern17, gmesa->glCtx->PolygonStipple[17]);
1534 WRITE(gmesa->buf, AreaStipplePattern18, gmesa->glCtx->PolygonStipple[18]);
1535 WRITE(gmesa->buf, AreaStipplePattern19, gmesa->glCtx->PolygonStipple[19]);
1536 WRITE(gmesa->buf, AreaStipplePattern20, gmesa->glCtx->PolygonStipple[20]);
1537 WRITE(gmesa->buf, AreaStipplePattern21, gmesa->glCtx->PolygonStipple[21]);
1538 WRITE(gmesa->buf, AreaStipplePattern22, gmesa->glCtx->PolygonStipple[22]);
1539 WRITE(gmesa->buf, AreaStipplePattern23, gmesa->glCtx->PolygonStipple[23]);
1540 WRITE(gmesa->buf, AreaStipplePattern24, gmesa->glCtx->PolygonStipple[24]);
1541 WRITE(gmesa->buf, AreaStipplePattern25, gmesa->glCtx->PolygonStipple[25]);
1542 WRITE(gmesa->buf, AreaStipplePattern26, gmesa->glCtx->PolygonStipple[26]);
1543 WRITE(gmesa->buf, AreaStipplePattern27, gmesa->glCtx->PolygonStipple[27]);
1544 WRITE(gmesa->buf, AreaStipplePattern28, gmesa->glCtx->PolygonStipple[28]);
1545 WRITE(gmesa->buf, AreaStipplePattern29, gmesa->glCtx->PolygonStipple[29]);
1546 WRITE(gmesa->buf, AreaStipplePattern30, gmesa->glCtx->PolygonStipple[30]);
1547 WRITE(gmesa->buf, AreaStipplePattern31, gmesa->glCtx->PolygonStipple[31]);
1549 if (gmesa->dirty & GAMMA_UPLOAD_DEPTH) {
1550 gmesa->dirty &= ~GAMMA_UPLOAD_DEPTH;
1551 CHECK_DMA_BUFFER(gmesa, 4);
1552 WRITE(gmesa->buf, DepthMode, gmesa->DepthMode);
1553 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode);
1554 WRITE(gmesa->buf, GLINTWindow,gmesa->Window | (gmesa->FrameCount << 9));
1555 WRITE(gmesa->buf, LBReadMode, gmesa->LBReadMode);
1557 if (gmesa->dirty & GAMMA_UPLOAD_GEOMETRY) {
1558 gmesa->dirty &= ~GAMMA_UPLOAD_GEOMETRY;
1559 CHECK_DMA_BUFFER(gmesa, 1);
1560 WRITE(gmesa->buf, GeometryMode, gmesa->GeometryMode);
1562 if (gmesa->dirty & GAMMA_UPLOAD_TRANSFORM) {
1563 gmesa->dirty &= ~GAMMA_UPLOAD_TRANSFORM;
1564 CHECK_DMA_BUFFER(gmesa, 1);
1565 WRITE(gmesa->buf, TransformMode, gmesa->TransformMode);
1567 if (gmesa->dirty & GAMMA_UPLOAD_TEX0) {
1568 gammaTextureObjectPtr curTex = gmesa->CurrentTexObj[0];
1569 gmesa->dirty &= ~GAMMA_UPLOAD_TEX0;
1571 CHECK_DMA_BUFFER(gmesa, 21);
1572 WRITE(gmesa->buf, GeometryMode, gmesa->GeometryMode | GM_TextureEnable);
1573 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode | DM_TextureEnable);
1574 WRITE(gmesa->buf, TextureAddressMode, curTex->TextureAddressMode);
1575 WRITE(gmesa->buf, TextureReadMode, curTex->TextureReadMode);
1576 WRITE(gmesa->buf, TextureColorMode, curTex->TextureColorMode);
1577 WRITE(gmesa->buf, TextureFilterMode, curTex->TextureFilterMode);
1578 WRITE(gmesa->buf, TextureFormat, curTex->TextureFormat);
1579 WRITE(gmesa->buf, GLINTBorderColor, curTex->TextureBorderColor);
1580 WRITE(gmesa->buf, TxBaseAddr0, curTex->TextureBaseAddr[0]);
1581 WRITE(gmesa->buf, TxBaseAddr1, curTex->TextureBaseAddr[1]);
1582 WRITE(gmesa->buf, TxBaseAddr2, curTex->TextureBaseAddr[2]);
1583 WRITE(gmesa->buf, TxBaseAddr3, curTex->TextureBaseAddr[3]);
1584 WRITE(gmesa->buf, TxBaseAddr4, curTex->TextureBaseAddr[4]);
1585 WRITE(gmesa->buf, TxBaseAddr5, curTex->TextureBaseAddr[5]);
1586 WRITE(gmesa->buf, TxBaseAddr6, curTex->TextureBaseAddr[6]);
1587 WRITE(gmesa->buf, TxBaseAddr7, curTex->TextureBaseAddr[7]);
1588 WRITE(gmesa->buf, TxBaseAddr8, curTex->TextureBaseAddr[8]);
1589 WRITE(gmesa->buf, TxBaseAddr9, curTex->TextureBaseAddr[9]);
1590 WRITE(gmesa->buf, TxBaseAddr10, curTex->TextureBaseAddr[10]);
1591 WRITE(gmesa->buf, TxBaseAddr11, curTex->TextureBaseAddr[11]);
1592 WRITE(gmesa->buf, TextureCacheControl, (TCC_Enable | TCC_Invalidate));
1594 CHECK_DMA_BUFFER(gmesa, 6);
1595 WRITE(gmesa->buf, GeometryMode, gmesa->GeometryMode);
1596 WRITE(gmesa->buf, DeltaMode, gmesa->DeltaMode);
1597 WRITE(gmesa->buf, TextureAddressMode, TextureAddressModeDisable);
1598 WRITE(gmesa->buf, TextureReadMode, TextureReadModeDisable);
1599 WRITE(gmesa->buf, TextureFilterMode, TextureFilterModeDisable);
1600 WRITE(gmesa->buf, TextureColorMode, TextureColorModeDisable);
1604 PROCESS_DMA_BUFFER_TOP_HALF(gmesa);
1606 DRM_SPINUNLOCK(&gmesa->driScreen->pSAREA->drawable_lock,
1607 gmesa->driScreen->drawLockID);
1608 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa);
1610 PROCESS_DMA_BUFFER_BOTTOM_HALF(gmesa);
1614 void gammaDDUpdateHWState( GLcontext *ctx )
1616 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
1617 int new_state = gmesa->new_state;
1621 FLUSH_BATCH( gmesa );
1623 gmesa->new_state = 0;
1625 /* Update the various parts of the context's state.
1627 if ( new_state & GAMMA_NEW_ALPHA )
1628 gammaUpdateAlphaMode( ctx );
1630 if ( new_state & GAMMA_NEW_DEPTH )
1631 gammaUpdateZMode( ctx );
1633 if ( new_state & GAMMA_NEW_FOG )
1634 gammaUpdateFogAttrib( ctx );
1636 if ( new_state & GAMMA_NEW_CLIP )
1637 gammaUpdateClipping( ctx );
1639 if ( new_state & GAMMA_NEW_POLYGON )
1640 gammaUpdatePolygon( ctx );
1642 if ( new_state & GAMMA_NEW_CULL )
1643 gammaUpdateCull( ctx );
1645 if ( new_state & GAMMA_NEW_MASKS )
1646 gammaUpdateMasks( ctx );
1648 if ( new_state & GAMMA_NEW_WINDOW )
1649 gammaUpdateWindow( ctx );
1651 if ( new_state & GAMMA_NEW_STIPPLE )
1652 gammaUpdateStipple( ctx );
1657 gammaEmitHwState( gmesa );
1661 static void gammaDDUpdateState( GLcontext *ctx, GLuint new_state )
1663 _swrast_InvalidateState( ctx, new_state );
1664 _swsetup_InvalidateState( ctx, new_state );
1665 _vbo_InvalidateState( ctx, new_state );
1666 _tnl_InvalidateState( ctx, new_state );
1667 GAMMA_CONTEXT(ctx)->new_gl_state |= new_state;
1671 /* Initialize the context's hardware state.
1673 void gammaDDInitState( gammaContextPtr gmesa )
1675 gmesa->new_state = 0;
1678 /* Initialize the driver's state functions.
1680 void gammaDDInitStateFuncs( GLcontext *ctx )
1682 ctx->Driver.UpdateState = gammaDDUpdateState;
1684 ctx->Driver.Clear = gammaDDClear;
1685 ctx->Driver.ClearIndex = NULL;
1686 ctx->Driver.ClearColor = gammaDDClearColor;
1687 ctx->Driver.DrawBuffer = gammaDDDrawBuffer;
1688 ctx->Driver.ReadBuffer = gammaDDReadBuffer;
1690 ctx->Driver.IndexMask = NULL;
1691 ctx->Driver.ColorMask = gammaDDColorMask;
1693 ctx->Driver.AlphaFunc = gammaDDAlphaFunc;
1694 ctx->Driver.BlendEquationSeparate = gammaDDBlendEquationSeparate;
1695 ctx->Driver.BlendFuncSeparate = gammaDDBlendFuncSeparate;
1696 ctx->Driver.ClearDepth = gammaDDClearDepth;
1697 ctx->Driver.CullFace = gammaDDCullFace;
1698 ctx->Driver.FrontFace = gammaDDFrontFace;
1699 ctx->Driver.DepthFunc = gammaDDDepthFunc;
1700 ctx->Driver.DepthMask = gammaDDDepthMask;
1701 ctx->Driver.DepthRange = gammaDDDepthRange;
1702 ctx->Driver.Enable = gammaDDEnable;
1703 ctx->Driver.Finish = gammaDDFinish;
1704 ctx->Driver.Flush = gammaDDFlush;
1706 ctx->Driver.Fogfv = gammaDDFogfv;
1708 ctx->Driver.Hint = NULL;
1709 ctx->Driver.LineWidth = gammaDDLineWidth;
1710 ctx->Driver.LineStipple = gammaDDLineStipple;
1712 ctx->Driver.Lightfv = gammaDDLightfv;
1713 ctx->Driver.LightModelfv = gammaDDLightModelfv;
1715 ctx->Driver.LogicOpcode = gammaDDLogicalOpcode;
1716 ctx->Driver.PointSize = gammaDDPointSize;
1717 ctx->Driver.PolygonMode = gammaDDPolygonMode;
1718 ctx->Driver.PolygonStipple = gammaDDPolygonStipple;
1719 ctx->Driver.Scissor = gammaDDScissor;
1720 ctx->Driver.ShadeModel = gammaDDShadeModel;
1721 ctx->Driver.Viewport = gammaDDViewport;