mesa: lift default symlinks target into Makefile.template
[mesa.git] / src / mesa / drivers / dri / sis / sis_state.c
index 9d093595a1c344e48071e9a1a7e754a8a296f91e..98e8d02fabe7d80f9e060cea66ea104f6c12ef68 100644 (file)
@@ -18,13 +18,12 @@ Software.
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
-ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
-/* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */
 
 /*
  * Authors:
@@ -38,11 +37,11 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sis_lock.h"
 #include "sis_tex.h"
 
-#include "context.h"
-#include "enums.h"
-#include "colormac.h"
+#include "main/context.h"
+#include "main/enums.h"
+#include "main/colormac.h"
 #include "swrast/swrast.h"
-#include "array_cache/acache.h"
+#include "vbo/vbo.h"
 #include "tnl/tnl.h"
 #include "swrast_setup/swrast_setup.h"
 
@@ -98,18 +97,18 @@ sisDDAlphaFunc( GLcontext * ctx, GLenum func, GLfloat ref )
 }
 
 static void
-sisDDBlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor )
+sisDDBlendFuncSeparate( GLcontext *ctx, 
+                       GLenum sfactorRGB, GLenum dfactorRGB,
+                       GLenum sfactorA,   GLenum dfactorA )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
 
    __GLSiSHardware *prev = &smesa->prev;
    __GLSiSHardware *current = &smesa->current;
 
-   /* TODO: in ICD, if no blend, it will reset these value */
-   /* blending enable */
-   current->hwDstSrcBlend = 0x10000;   /* Default destination alpha */
+   current->hwDstSrcBlend = 0;
 
-   switch (dfactor)
+   switch (dfactorRGB)
    {
    case GL_ZERO:
       current->hwDstSrcBlend |= SiS_D_ZERO;
@@ -129,15 +128,24 @@ sisDDBlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor )
    case GL_ONE_MINUS_SRC_ALPHA:
       current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_ALPHA;
       break;
+   case GL_DST_COLOR:
+      current->hwDstSrcBlend |= SiS_D_DST_COLOR;
+      break;
+   case GL_ONE_MINUS_DST_COLOR:
+      current->hwDstSrcBlend |= SiS_D_ONE_MINUS_DST_COLOR;
+      break;
    case GL_DST_ALPHA:
       current->hwDstSrcBlend |= SiS_D_DST_ALPHA;
       break;
    case GL_ONE_MINUS_DST_ALPHA:
       current->hwDstSrcBlend |= SiS_D_ONE_MINUS_DST_ALPHA;
       break;
+   default:
+      fprintf(stderr, "Unknown dst blend function 0x%x\n", dfactorRGB);
+      break;
    }
 
-   switch (sfactor)
+   switch (sfactorRGB)
    {
    case GL_ZERO:
       current->hwDstSrcBlend |= SiS_S_ZERO;
@@ -145,27 +153,36 @@ sisDDBlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor )
    case GL_ONE:
       current->hwDstSrcBlend |= SiS_S_ONE;
       break;
+   case GL_SRC_COLOR:
+      current->hwDstSrcBlend |= SiS_S_SRC_COLOR;
+      break;
+   case GL_ONE_MINUS_SRC_COLOR:
+      current->hwDstSrcBlend |= SiS_S_ONE_MINUS_SRC_COLOR;
+      break;
    case GL_SRC_ALPHA:
       current->hwDstSrcBlend |= SiS_S_SRC_ALPHA;
       break;
    case GL_ONE_MINUS_SRC_ALPHA:
       current->hwDstSrcBlend |= SiS_S_ONE_MINUS_SRC_ALPHA;
       break;
-   case GL_DST_ALPHA:
-      current->hwDstSrcBlend |= SiS_S_DST_ALPHA;
-      break;
-   case GL_ONE_MINUS_DST_ALPHA:
-      current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_ALPHA;
-      break;
    case GL_DST_COLOR:
       current->hwDstSrcBlend |= SiS_S_DST_COLOR;
       break;
    case GL_ONE_MINUS_DST_COLOR:
       current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_COLOR;
       break;
+   case GL_DST_ALPHA:
+      current->hwDstSrcBlend |= SiS_S_DST_ALPHA;
+      break;
+   case GL_ONE_MINUS_DST_ALPHA:
+      current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_ALPHA;
+      break;
    case GL_SRC_ALPHA_SATURATE:
       current->hwDstSrcBlend |= SiS_S_SRC_ALPHA_SATURATE;
       break;
+   default:
+      fprintf(stderr, "Unknown src blend function 0x%x\n", sfactorRGB);
+      break;
    }
 
    if (current->hwDstSrcBlend != prev->hwDstSrcBlend) {
@@ -233,7 +250,7 @@ sisDDDepthMask( GLcontext * ctx, GLboolean flag )
    if (ctx->Visual.stencilBits) {
       if (flag || (ctx->Stencil.WriteMask[0] != 0)) {
          current->hwCapEnable |= MASK_ZWriteEnable;
-         if (flag && (ctx->Stencil.WriteMask[0] == 0xff)) {
+         if (flag && ((ctx->Stencil.WriteMask[0] & 0xff) == 0xff)) {
              current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable;
          } else {
             current->hwCapEnable2 |= MASK_ZMaskWriteEnable;
@@ -272,6 +289,12 @@ sisUpdateClipping( GLcontext *ctx )
 
    GLint x1, y1, x2, y2;
 
+   if (smesa->is6326) {
+      /* XXX: 6326 has its own clipping for now. Should be fixed */
+      sis6326UpdateClipping(ctx);
+      return;
+   }
+
    x1 = 0;
    y1 = 0;
    x2 = smesa->width - 1;
@@ -366,10 +389,10 @@ static void sisDDColorMask( GLcontext *ctx,
       current->hwCapEnable2 |= (MASK_AlphaMaskWriteEnable |
                              MASK_ColorMaskWriteEnable);
 
-      current->hwDstMask = (r) ? GET_RMASK(smesa) : 0 |
-                          (g) ? GET_GMASK(smesa) : 0 |
-                          (b) ? GET_BMASK(smesa) : 0 |
-                          (a) ? GET_AMASK(smesa) : 0;
+      current->hwDstMask = (r) ? smesa->redMask : 0 |
+                          (g) ? smesa->greenMask : 0 |
+                          (b) ? smesa->blueMask : 0 |
+                          (a) ? smesa->alphaMask : 0;
    }
    
    if (current->hwDstMask != prev->hwDstMask) {
@@ -382,6 +405,25 @@ static void sisDDColorMask( GLcontext *ctx,
  * Rendering attributes
  */
 
+static void sisUpdateSpecular(GLcontext *ctx)
+{
+   sisContextPtr smesa = SIS_CONTEXT(ctx);
+   __GLSiSHardware *current = &smesa->current;
+
+   if (NEED_SECONDARY_COLOR(ctx))
+      current->hwCapEnable |= MASK_SpecularEnable;
+   else
+      current->hwCapEnable &= ~MASK_SpecularEnable;
+}
+
+static void sisDDLightModelfv(GLcontext *ctx, GLenum pname,
+                             const GLfloat *param)
+{
+   if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) {
+      sisUpdateSpecular(ctx);
+   }
+}
+
 static void sisDDShadeModel( GLcontext *ctx, GLenum mode )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
@@ -439,9 +481,6 @@ sisDDLogicOpCode( GLcontext *ctx, GLenum opcode )
    __GLSiSHardware *prev = &smesa->prev;
    __GLSiSHardware *current = &smesa->current;
 
-   if (!ctx->Color.ColorLogicOpEnabled)
-      return;
-
    current->hwDstSet &= ~MASK_ROP2;
    switch (opcode)
    {
@@ -504,33 +543,31 @@ sisDDLogicOpCode( GLcontext *ctx, GLenum opcode )
 void sisDDDrawBuffer( GLcontext *ctx, GLenum mode )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
-
    __GLSiSHardware *prev = &smesa->prev;
    __GLSiSHardware *current = &smesa->current;
 
-   /*
-    * _DrawDestMask is easier to cope with than <mode>.
-    */
-   switch ( ctx->Color._DrawDestMask ) {
-   case FRONT_LEFT_BIT:
-   case BACK_LEFT_BIT:
+   if (ctx->DrawBuffer->_NumColorDrawBuffers != 1) {
+      FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_TRUE );
+      return;
+   }
+
+   current->hwDstSet &= ~MASK_DstBufferPitch;
+   switch ( ctx->DrawBuffer->_ColorDrawBufferIndexes[0] ) {
+   case BUFFER_FRONT_LEFT:
       FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_FALSE );
+      current->hwOffsetDest = smesa->front.offset >> 1;
+      current->hwDstSet |= smesa->front.pitch >> 2;
+      break;
+   case BUFFER_BACK_LEFT:
+      FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_FALSE );
+      current->hwOffsetDest = smesa->back.offset >> 1;
+      current->hwDstSet |= smesa->back.pitch >> 2;
       break;
    default:
-      /* GL_NONE or GL_FRONT_AND_BACK or stereo left&right, etc */
       FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_TRUE );
       return;
    }
 
-   /* We want to update the s/w rast state too so that sisDDSetBuffer()
-    * gets called.
-    */
-   _swrast_DrawBuffer(ctx, mode);
-
-   current->hwOffsetDest = (smesa->drawOffset) >> 1;
-   current->hwDstSet &= ~MASK_DstBufferPitch;
-   current->hwDstSet |= smesa->drawPitch >> 2;
-
    if (current->hwDstSet != prev->hwDstSet) {
       prev->hwDstSet = current->hwDstSet;
       smesa->GlobalFlag |= GFLAG_DESTSETTING;
@@ -542,19 +579,6 @@ void sisDDDrawBuffer( GLcontext *ctx, GLenum mode )
    }
 }
 
-static void
-sisDDHint( GLcontext *ctx, GLenum target, GLenum mode )
-{
-   
-   switch (target) {
-   case GL_FOG_HINT:
-      /* Update fog mode setting */
-      sisDDFogfv(ctx, GL_FOG_MODE, NULL);
-      break;
-   }
-   
-}
-
 /* =============================================================
  * Polygon stipple
  */
@@ -597,7 +621,7 @@ sisDDEnable( GLcontext * ctx, GLenum cap, GLboolean state )
          current->hwCapEnable &= ~MASK_CullEnable;
       break;
    case GL_DEPTH_TEST:
-      if (state && smesa->depthbuffer)
+      if (state && smesa->depth.offset != 0)
          current->hwCapEnable |= MASK_ZTestEnable;
       else
          current->hwCapEnable &= ~MASK_ZTestEnable;
@@ -637,54 +661,13 @@ sisDDEnable( GLcontext * ctx, GLenum cap, GLboolean state )
                                   MASK_StencilWriteEnable);
       }
       break;
-    }
-}
-
-/* =============================================================
- * Pixel functions
- */
-
-static void
-sisDDDrawPixels( GLcontext *ctx,
-                GLint x, GLint y, GLsizei width, GLsizei height,
-                GLenum format, GLenum type,
-                const struct gl_pixelstore_attrib *unpack,
-                const GLvoid *pixels )
-{
-   sisContextPtr smesa = SIS_CONTEXT(ctx);
-
-   LOCK_HARDWARE();
-   _swrast_DrawPixels( ctx, x, y, width, height, format, type, unpack, pixels );
-   UNLOCK_HARDWARE();
-}
-
-static void
-sisDDReadPixels( GLcontext *ctx,
-                GLint x, GLint y, GLsizei width, GLsizei height,
-                GLenum format, GLenum type,
-                const struct gl_pixelstore_attrib *pack,
-                GLvoid *pixels )
-{
-   sisContextPtr smesa = SIS_CONTEXT(ctx);
-
-   LOCK_HARDWARE();
-   _swrast_ReadPixels( ctx, x, y, width, height, format, type, pack, 
-                      pixels);
-   UNLOCK_HARDWARE();
+   case GL_LIGHTING:
+   case GL_COLOR_SUM_EXT:
+      sisUpdateSpecular(ctx);
+      break;
+   }
 }
 
-static void
-sisDDBitmap( GLcontext *ctx, GLint px, GLint py,
-            GLsizei width, GLsizei height,
-            const struct gl_pixelstore_attrib *unpack,
-            const GLubyte *bitmap )
-{
-   sisContextPtr smesa = SIS_CONTEXT(ctx);
-
-   LOCK_HARDWARE();
-   _swrast_Bitmap( ctx, px, py, width, height, unpack, bitmap );
-   UNLOCK_HARDWARE();
-}
 
 /* =============================================================
  * State initialization, management
@@ -698,9 +681,6 @@ sisUpdateHWState( GLcontext *ctx )
    __GLSiSHardware *prev = &smesa->prev;
    __GLSiSHardware *current = &smesa->current;
 
-   if (smesa->NewGLState & _NEW_TEXTURE)
-      sisUpdateTextureState( ctx );
-
    /* enable setting 1 */
    if (current->hwCapEnable ^ prev->hwCapEnable) {
       prev->hwCapEnable = current->hwCapEnable;
@@ -713,27 +693,6 @@ sisUpdateHWState( GLcontext *ctx )
       smesa->GlobalFlag |= GFLAG_ENABLESETTING2;
    }
 
-  /* TODO: if fog disable, don't check */
-  if (current->hwCapEnable & MASK_FogEnable) {
-      /* fog setting */
-      if (current->hwFog != prev->hwFog) {
-         prev->hwFog = current->hwFog;
-         smesa->GlobalFlag |= GFLAG_FOGSETTING;
-       }
-      if (current->hwFogFar != prev->hwFogFar) {
-         prev->hwFogFar = current->hwFogFar;
-         smesa->GlobalFlag |= GFLAG_FOGSETTING;
-       }
-      if (current->hwFogInverse != prev->hwFogInverse) {
-         prev->hwFogInverse = current->hwFogInverse;
-         smesa->GlobalFlag |= GFLAG_FOGSETTING;
-       }
-      if (current->hwFogDensity != prev->hwFogDensity) {
-         prev->hwFogDensity = current->hwFogDensity;
-         smesa->GlobalFlag |= GFLAG_FOGSETTING;
-       }
-    }
-
    if (smesa->GlobalFlag & GFLAG_RENDER_STATES)
       sis_update_render_state( smesa );
 
@@ -748,7 +707,7 @@ sisDDInvalidateState( GLcontext *ctx, GLuint new_state )
 
    _swrast_InvalidateState( ctx, new_state );
    _swsetup_InvalidateState( ctx, new_state );
-   _ac_InvalidateState( ctx, new_state );
+   _vbo_InvalidateState( ctx, new_state );
    _tnl_InvalidateState( ctx, new_state );
    smesa->NewGLState |= new_state;
 }
@@ -764,7 +723,6 @@ void sisDDInitState( sisContextPtr smesa )
    /* add Texture Perspective Enable */
    prev->hwCapEnable = MASK_FogPerspectiveEnable | MASK_TextureCacheEnable |
       MASK_TexturePerspectiveEnable | MASK_DitherEnable;
-   /*| MASK_SpecularEnable*/
 
    /*
    prev->hwCapEnable2 = 0x00aa0080;
@@ -808,11 +766,11 @@ void sisDDInitState( sisContextPtr smesa )
    prev->texture[0].hwTextureMip = 0;
 #endif
 
-   /* Texture Blending seeting */
-   prev->hwTexBlendClr0 = L_REPLACE__RGB_STAGE0;
-   prev->hwTexBlendClr1 = 0x294B4000;
-   prev->hwTexBlendAlpha0 = 0x333A0000;
-   prev->hwTexBlendAlpha1 = 0x333A0000;
+   /* Texture Blending setting -- use fragment color/alpha*/
+   prev->hwTexBlendColor0 = STAGE0_C_CF;
+   prev->hwTexBlendColor1 = STAGE1_C_CF;
+   prev->hwTexBlendAlpha0 = STAGE0_A_AF;
+   prev->hwTexBlendAlpha1 = STAGE1_A_AF;
    
    switch (smesa->bytesPerPixel)
    {
@@ -854,7 +812,7 @@ void sisDDInitState( sisContextPtr smesa )
 
    smesa->clearColorPattern = 0;
 
-   smesa->AGPParseSet = MASK_PsTexture1FromB;
+   smesa->AGPParseSet = MASK_PsTexture1FromB | MASK_PsBumpTextureFromC;
    smesa->dwPrimitiveSet = OP_3D_Texture1FromB | OP_3D_TextureBumpFromC;
 
    sisUpdateZStencilPattern( smesa, 1.0, 0 );
@@ -865,6 +823,7 @@ void sisDDInitState( sisContextPtr smesa )
    /* Set initial fog settings. Start and end are the same case.  */
    sisDDFogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
    sisDDFogfv( ctx, GL_FOG_END, &ctx->Fog.End );
+   sisDDFogfv( ctx, GL_FOG_COORDINATE_SOURCE_EXT, NULL );
    sisDDFogfv( ctx, GL_FOG_MODE, NULL );
 }
 
@@ -872,7 +831,7 @@ void sisDDInitState( sisContextPtr smesa )
  */
 void sisDDInitStateFuncs( GLcontext *ctx )
 {
-  ctx->Driver.UpdateState       = sisDDInvalidateState;
+   ctx->Driver.UpdateState      = sisDDInvalidateState;
 
    ctx->Driver.Clear            = sisDDClear;
    ctx->Driver.ClearColor       = sisDDClearColor;
@@ -880,39 +839,28 @@ void sisDDInitStateFuncs( GLcontext *ctx )
    ctx->Driver.ClearStencil     = sisDDClearStencil;
 
    ctx->Driver.AlphaFunc        = sisDDAlphaFunc;
-   ctx->Driver.Bitmap           = sisDDBitmap;
-   ctx->Driver.BlendFunc        = sisDDBlendFunc;
+   ctx->Driver.BlendFuncSeparate = sisDDBlendFuncSeparate;
    ctx->Driver.ColorMask        = sisDDColorMask;
    ctx->Driver.CullFace                 = sisDDCullFace;
    ctx->Driver.DepthMask        = sisDDDepthMask;
    ctx->Driver.DepthFunc        = sisDDDepthFunc;
    ctx->Driver.DepthRange       = sisDDDepthRange;
    ctx->Driver.DrawBuffer       = sisDDDrawBuffer;
-   ctx->Driver.DrawPixels       = sisDDDrawPixels;
    ctx->Driver.Enable           = sisDDEnable;
    ctx->Driver.FrontFace        = sisDDFrontFace;
    ctx->Driver.Fogfv            = sisDDFogfv;
-   ctx->Driver.Hint             = sisDDHint;
+   ctx->Driver.Hint             = NULL;
    ctx->Driver.Lightfv          = NULL;
    ctx->Driver.LogicOpcode      = sisDDLogicOpCode;
    ctx->Driver.PolygonMode      = NULL;
    ctx->Driver.PolygonStipple   = NULL;
    ctx->Driver.ReadBuffer       = NULL;
-   ctx->Driver.ReadPixels       = sisDDReadPixels;
    ctx->Driver.RenderMode       = NULL;
    ctx->Driver.Scissor          = sisDDScissor;
    ctx->Driver.ShadeModel       = sisDDShadeModel;
+   ctx->Driver.LightModelfv     = sisDDLightModelfv;
    ctx->Driver.Viewport                 = sisDDViewport;
 
-  /* Pixel path fallbacks.
-   */
-  ctx->Driver.Accum             = _swrast_Accum;
-  ctx->Driver.CopyPixels        = _swrast_CopyPixels;
-
-  /* Swrast hooks for imaging extensions:
-   */
-  ctx->Driver.CopyColorTable    = _swrast_CopyColorTable;
-  ctx->Driver.CopyColorSubTable         = _swrast_CopyColorSubTable;
-  ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
-  ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
+   /* XXX this should go away */
+   ctx->Driver.ResizeBuffers    = sisReAllocateBuffers;
 }