dri/nouveau: Kill a bunch of ternary operators.
[mesa.git] / src / mesa / drivers / dri / sis / sis_state.c
index 8349c42d297ab63a4bebda1889aa503ee31cda8b..e53c326441b6fe0dfae0142c3d2c5585d15e2b44 100644 (file)
@@ -24,7 +24,6 @@ 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:
@@ -36,24 +35,21 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sis_state.h"
 #include "sis_tris.h"
 #include "sis_lock.h"
-#include "sis_tex.h"
 
-#include "context.h"
-#include "enums.h"
-#include "colormac.h"
+#include "main/context.h"
+#include "main/macros.h"
 #include "swrast/swrast.h"
-#include "array_cache/acache.h"
+#include "vbo/vbo.h"
 #include "tnl/tnl.h"
 #include "swrast_setup/swrast_setup.h"
 
-#include "tnl/t_pipeline.h"
 
 /* =============================================================
  * Alpha blending
  */
 
 static void
-sisDDAlphaFunc( GLcontext * ctx, GLenum func, GLfloat ref )
+sisDDAlphaFunc( struct gl_context * ctx, GLenum func, GLfloat ref )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    GLubyte refbyte;
@@ -98,7 +94,7 @@ sisDDAlphaFunc( GLcontext * ctx, GLenum func, GLfloat ref )
 }
 
 static void
-sisDDBlendFuncSeparate( GLcontext *ctx, 
+sisDDBlendFuncSeparate( struct gl_context *ctx, 
                        GLenum sfactorRGB, GLenum dfactorRGB,
                        GLenum sfactorA,   GLenum dfactorA )
 {
@@ -197,7 +193,7 @@ sisDDBlendFuncSeparate( GLcontext *ctx,
  */
 
 static void
-sisDDDepthFunc( GLcontext * ctx, GLenum func )
+sisDDDepthFunc( struct gl_context * ctx, GLenum func )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    __GLSiSHardware *prev = &smesa->prev;
@@ -239,7 +235,7 @@ sisDDDepthFunc( GLcontext * ctx, GLenum func )
 }
 
 void
-sisDDDepthMask( GLcontext * ctx, GLboolean flag )
+sisDDDepthMask( struct gl_context * ctx, GLboolean flag )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    __GLSiSHardware *prev = &smesa->prev;
@@ -251,7 +247,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;
@@ -281,7 +277,7 @@ sisDDDepthMask( GLcontext * ctx, GLboolean flag )
  */
 
 void
-sisUpdateClipping( GLcontext *ctx )
+sisUpdateClipping( struct gl_context *ctx )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
 
@@ -290,6 +286,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;
@@ -322,7 +324,7 @@ sisUpdateClipping( GLcontext *ctx )
 }
 
 static void
-sisDDScissor( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h )
+sisDDScissor( struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h )
 {
    if (ctx->Scissor.Enabled)
       sisUpdateClipping( ctx );
@@ -333,7 +335,7 @@ sisDDScissor( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h )
  */
 
 static void
-sisUpdateCull( GLcontext *ctx )
+sisUpdateCull( struct gl_context *ctx )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    GLint cullflag, frontface;
@@ -354,13 +356,13 @@ sisUpdateCull( GLcontext *ctx )
 
 
 static void
-sisDDCullFace( GLcontext *ctx, GLenum mode )
+sisDDCullFace( struct gl_context *ctx, GLenum mode )
 {
    sisUpdateCull( ctx );
 }
 
 static void
-sisDDFrontFace( GLcontext *ctx, GLenum mode )
+sisDDFrontFace( struct gl_context *ctx, GLenum mode )
 {
    sisUpdateCull( ctx );
 }
@@ -369,7 +371,7 @@ sisDDFrontFace( GLcontext *ctx, GLenum mode )
  * Masks
  */
 
-static void sisDDColorMask( GLcontext *ctx,
+static void sisDDColorMask( struct gl_context *ctx,
                            GLboolean r, GLboolean g,
                            GLboolean b, GLboolean a )
 {
@@ -400,7 +402,26 @@ static void sisDDColorMask( GLcontext *ctx,
  * Rendering attributes
  */
 
-static void sisDDShadeModel( GLcontext *ctx, GLenum mode )
+static void sisUpdateSpecular(struct gl_context *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(struct gl_context *ctx, GLenum pname,
+                             const GLfloat *param)
+{
+   if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) {
+      sisUpdateSpecular(ctx);
+   }
+}
+
+static void sisDDShadeModel( struct gl_context *ctx, GLenum mode )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
 
@@ -416,7 +437,7 @@ static void sisDDShadeModel( GLcontext *ctx, GLenum mode )
  * Viewport
  */
 
-static void sisCalcViewport( GLcontext *ctx )
+static void sisCalcViewport( struct gl_context *ctx )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    const GLfloat *v = ctx->Viewport._WindowMap.m;
@@ -432,14 +453,14 @@ static void sisCalcViewport( GLcontext *ctx )
    m[MAT_TZ] =   v[MAT_TZ] * smesa->depth_scale;
 }
 
-static void sisDDViewport( GLcontext *ctx,
+static void sisDDViewport( struct gl_context *ctx,
                           GLint x, GLint y,
                           GLsizei width, GLsizei height )
 {
    sisCalcViewport( ctx );
 }
 
-static void sisDDDepthRange( GLcontext *ctx,
+static void sisDDDepthRange( struct gl_context *ctx,
                             GLclampd nearval, GLclampd farval )
 {
    sisCalcViewport( ctx );
@@ -450,7 +471,7 @@ static void sisDDDepthRange( GLcontext *ctx,
  */
 
 static void
-sisDDLogicOpCode( GLcontext *ctx, GLenum opcode )
+sisDDLogicOpCode( struct gl_context *ctx, GLenum opcode )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
 
@@ -516,35 +537,34 @@ sisDDLogicOpCode( GLcontext *ctx, GLenum opcode )
    }
 }
 
-void sisDDDrawBuffer( GLcontext *ctx, GLenum mode )
+void sisDDDrawBuffer( struct gl_context *ctx, GLenum mode )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    __GLSiSHardware *prev = &smesa->prev;
    __GLSiSHardware *current = &smesa->current;
-   int pitch;
 
-   /*
-    * _DrawDestMask is easier to cope with than <mode>.
-    */
-   switch ( ctx->DrawBuffer->_ColorDrawBufferMask[0] ) {
-   case BUFFER_BIT_FRONT_LEFT:
+   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 );
-      pitch = smesa->frontPitch;
+      current->hwOffsetDest = smesa->front.offset >> 1;
+      current->hwDstSet |= smesa->front.pitch >> 2;
       break;
-   case BUFFER_BIT_BACK_LEFT:
+   case BUFFER_BACK_LEFT:
       FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_FALSE );
-      pitch = smesa->backPitch;
+      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;
    }
 
-   current->hwOffsetDest = (smesa->drawOffset) >> 1;
-   current->hwDstSet &= ~MASK_DstBufferPitch;
-   current->hwDstSet |= pitch >> 2;
-
    if (current->hwDstSet != prev->hwDstSet) {
       prev->hwDstSet = current->hwDstSet;
       smesa->GlobalFlag |= GFLAG_DESTSETTING;
@@ -569,7 +589,7 @@ void sisDDDrawBuffer( GLcontext *ctx, GLenum mode )
  */
 
 static void
-sisDDEnable( GLcontext * ctx, GLenum cap, GLboolean state )
+sisDDEnable( struct gl_context * ctx, GLenum cap, GLboolean state )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
 
@@ -598,7 +618,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;
@@ -638,7 +658,11 @@ sisDDEnable( GLcontext * ctx, GLenum cap, GLboolean state )
                                   MASK_StencilWriteEnable);
       }
       break;
-    }
+   case GL_LIGHTING:
+   case GL_COLOR_SUM_EXT:
+      sisUpdateSpecular(ctx);
+      break;
+   }
 }
 
 
@@ -648,7 +672,7 @@ sisDDEnable( GLcontext * ctx, GLenum cap, GLboolean state )
 
 /* Called before beginning of rendering. */
 void
-sisUpdateHWState( GLcontext *ctx )
+sisUpdateHWState( struct gl_context *ctx )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
    __GLSiSHardware *prev = &smesa->prev;
@@ -674,13 +698,13 @@ sisUpdateHWState( GLcontext *ctx )
 }
 
 static void
-sisDDInvalidateState( GLcontext *ctx, GLuint new_state )
+sisDDInvalidateState( struct gl_context *ctx, GLuint new_state )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
 
    _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;
 }
@@ -691,12 +715,11 @@ void sisDDInitState( sisContextPtr smesa )
 {
    __GLSiSHardware *current = &smesa->current;
    __GLSiSHardware *prev = &(smesa->prev);
-   GLcontext *ctx = smesa->glCtx;
+   struct gl_context *ctx = smesa->glCtx;
 
    /* add Texture Perspective Enable */
    prev->hwCapEnable = MASK_FogPerspectiveEnable | MASK_TextureCacheEnable |
       MASK_TexturePerspectiveEnable | MASK_DitherEnable;
-   /*| MASK_SpecularEnable*/
 
    /*
    prev->hwCapEnable2 = 0x00aa0080;
@@ -797,14 +820,15 @@ 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 );
 }
 
 /* Initialize the driver's state functions.
  */
-void sisDDInitStateFuncs( GLcontext *ctx )
+void sisDDInitStateFuncs( struct gl_context *ctx )
 {
-  ctx->Driver.UpdateState       = sisDDInvalidateState;
+   ctx->Driver.UpdateState      = sisDDInvalidateState;
 
    ctx->Driver.Clear            = sisDDClear;
    ctx->Driver.ClearColor       = sisDDClearColor;
@@ -831,19 +855,9 @@ void sisDDInitStateFuncs( GLcontext *ctx )
    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.Bitmap           = _swrast_Bitmap;
-   ctx->Driver.CopyPixels       = _swrast_CopyPixels;
-   ctx->Driver.DrawPixels       = _swrast_DrawPixels;
-   ctx->Driver.ReadPixels       = _swrast_ReadPixels;
-
-  /* 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;
 }