fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / i915 / i915_state.c
index d6c3e90d96248a344c9f4e52f4d913c71b46ce19..0627f102da206f318aed16922f1db98e8a4ebbb5 100644 (file)
@@ -3,6 +3,26 @@
  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  * All Rights Reserved.
  * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the 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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ * 
  **************************************************************************/
 
 
 #include "i915_context.h"
 #include "i915_reg.h"
 
-static int translate_compare_func( GLenum func )
-{
-   switch(func) {
-   case GL_NEVER: 
-      return COMPAREFUNC_NEVER; 
-   case GL_LESS: 
-      return COMPAREFUNC_LESS; 
-   case GL_LEQUAL: 
-      return COMPAREFUNC_LEQUAL; 
-   case GL_GREATER: 
-      return COMPAREFUNC_GREATER; 
-   case GL_GEQUAL: 
-      return COMPAREFUNC_GEQUAL; 
-   case GL_NOTEQUAL: 
-      return COMPAREFUNC_NOTEQUAL; 
-   case GL_EQUAL: 
-      return COMPAREFUNC_EQUAL; 
-   case GL_ALWAYS: 
-   default:
-      return COMPAREFUNC_ALWAYS; 
-   }
-}
 
 
-static void i915StencilFunc(GLcontext *ctx, GLenum func, GLint ref,
-                           GLuint mask)
+static void
+i915StencilFuncSeparate(GLcontext *ctx, GLenum face, GLenum func, GLint ref,
+                        GLuint mask)
 {
    i915ContextPtr i915 = I915_CONTEXT(ctx);
-   int test = translate_compare_func( func );
+   int test = intel_translate_compare_func( func );
 
    mask = mask & 0xff;
 
@@ -71,7 +70,8 @@ static void i915StencilFunc(GLcontext *ctx, GLenum func, GLint ref,
                                       (test << S5_STENCIL_TEST_FUNC_SHIFT)); 
 }
 
-static void i915StencilMask(GLcontext *ctx, GLuint mask)
+static void
+i915StencilMaskSeparate(GLcontext *ctx, GLenum face, GLuint mask)
 {
    i915ContextPtr i915 = I915_CONTEXT(ctx);
 
@@ -86,37 +86,15 @@ static void i915StencilMask(GLcontext *ctx, GLuint mask)
                                        STENCIL_WRITE_MASK(mask));
 }
 
-static int translate_stencil_op( GLenum op )
-{
-   switch(op) {
-   case GL_KEEP: 
-      return STENCILOP_KEEP; 
-   case GL_ZERO: 
-      return STENCILOP_ZERO; 
-   case GL_REPLACE: 
-      return STENCILOP_REPLACE; 
-   case GL_INCR: 
-      return STENCILOP_INCRSAT;
-   case GL_DECR: 
-      return STENCILOP_DECRSAT;
-   case GL_INCR_WRAP:
-      return STENCILOP_INCR; 
-   case GL_DECR_WRAP:
-      return STENCILOP_DECR; 
-   case GL_INVERT: 
-      return STENCILOP_INVERT; 
-   default: 
-      return 0;
-   }
-}
 
-static void i915StencilOp(GLcontext *ctx, GLenum fail, GLenum zfail,
-                         GLenum zpass)
+static void
+i915StencilOpSeparate(GLcontext *ctx, GLenum face, GLenum fail, GLenum zfail,
+                      GLenum zpass)
 {
    i915ContextPtr i915 = I915_CONTEXT(ctx);
-   int fop = translate_stencil_op(fail); 
-   int dfop = translate_stencil_op(zfail); 
-   int dpop = translate_stencil_op(zpass);
+   int fop = intel_translate_stencil_op(fail); 
+   int dfop = intel_translate_stencil_op(zfail); 
+   int dpop = intel_translate_stencil_op(zpass);
 
 
    if (INTEL_DEBUG&DEBUG_DRI)
@@ -139,7 +117,7 @@ static void i915StencilOp(GLcontext *ctx, GLenum fail, GLenum zfail,
 static void i915AlphaFunc(GLcontext *ctx, GLenum func, GLfloat ref)
 {
    i915ContextPtr i915 = I915_CONTEXT(ctx);
-   int test = translate_compare_func( func );
+   int test = intel_translate_compare_func( func );
    GLubyte refByte;
 
    UNCLAMPED_FLOAT_TO_UBYTE(refByte, ref);
@@ -194,43 +172,6 @@ static void i915BlendColor(GLcontext *ctx, const GLfloat color[4])
    i915->state.Ctx[I915_CTXREG_BLENDCOLOR1] = (a<<24) | (r<<16) | (g<<8) | b;
 }
 
-static int translate_blend_factor( GLenum factor )
-{
-   switch(factor) {
-   case GL_ZERO: 
-      return BLENDFACT_ZERO; 
-   case GL_SRC_ALPHA: 
-      return BLENDFACT_SRC_ALPHA; 
-   case GL_ONE: 
-      return BLENDFACT_ONE; 
-   case GL_SRC_COLOR: 
-      return BLENDFACT_SRC_COLR; 
-   case GL_ONE_MINUS_SRC_COLOR: 
-      return BLENDFACT_INV_SRC_COLR; 
-   case GL_DST_COLOR: 
-      return BLENDFACT_DST_COLR; 
-   case GL_ONE_MINUS_DST_COLOR: 
-      return BLENDFACT_INV_DST_COLR; 
-   case GL_ONE_MINUS_SRC_ALPHA:
-      return BLENDFACT_INV_SRC_ALPHA; 
-   case GL_DST_ALPHA: 
-      return BLENDFACT_DST_ALPHA; 
-   case GL_ONE_MINUS_DST_ALPHA:
-      return BLENDFACT_INV_DST_ALPHA; 
-   case GL_SRC_ALPHA_SATURATE: 
-      return BLENDFACT_SRC_ALPHA_SATURATE;
-   case GL_CONSTANT_COLOR:
-      return BLENDFACT_CONST_COLOR; 
-   case GL_ONE_MINUS_CONSTANT_COLOR:
-      return BLENDFACT_INV_CONST_COLOR;
-   case GL_CONSTANT_ALPHA:
-      return BLENDFACT_CONST_ALPHA; 
-   case GL_ONE_MINUS_CONSTANT_ALPHA:
-      return BLENDFACT_INV_CONST_ALPHA;
-   default:
-      return BLENDFACT_ZERO;
-   }
-}
 
 #define DST_BLND_FACT(f) ((f)<<S6_CBUF_DST_BLEND_FACT_SHIFT)
 #define SRC_BLND_FACT(f) ((f)<<S6_CBUF_SRC_BLEND_FACT_SHIFT)
@@ -280,12 +221,12 @@ static void i915UpdateBlendState( GLcontext *ctx )
       srcA = dstA = GL_ONE;
    }
 
-   lis6 |= SRC_BLND_FACT(translate_blend_factor(srcRGB)); 
-   lis6 |= DST_BLND_FACT(translate_blend_factor(dstRGB)); 
+   lis6 |= SRC_BLND_FACT(intel_translate_blend_factor(srcRGB)); 
+   lis6 |= DST_BLND_FACT(intel_translate_blend_factor(dstRGB)); 
    lis6 |= translate_blend_equation( eqRGB ) << S6_CBUF_BLEND_FUNC_SHIFT;
 
-   iab |= SRC_ABLND_FACT(translate_blend_factor(srcA)); 
-   iab |= DST_ABLND_FACT(translate_blend_factor(dstA)); 
+   iab |= SRC_ABLND_FACT(intel_translate_blend_factor(srcA)); 
+   iab |= DST_ABLND_FACT(intel_translate_blend_factor(dstA)); 
    iab |= translate_blend_equation( eqA ) << IAB_FUNC_SHIFT;
 
    if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) 
@@ -321,7 +262,7 @@ static void i915BlendEquationSeparate(GLcontext *ctx, GLenum eqRGB,
 static void i915DepthFunc(GLcontext *ctx, GLenum func)
 {
    i915ContextPtr i915 = I915_CONTEXT(ctx);
-   int test = translate_compare_func( func );
+   int test = intel_translate_compare_func( func );
 
    if (INTEL_DEBUG&DEBUG_DRI)
       fprintf(stderr, "%s\n", __FUNCTION__);
@@ -442,64 +383,11 @@ static void i915Scissor(GLcontext *ctx, GLint x, GLint y,
 static void i915LogicOp(GLcontext *ctx, GLenum opcode)
 {
    i915ContextPtr i915 = I915_CONTEXT(ctx);
-   int tmp = 0;
+   int tmp = intel_translate_logic_op(opcode);
 
    if (INTEL_DEBUG&DEBUG_DRI)
       fprintf(stderr, "%s\n", __FUNCTION__);
 
-   switch(opcode) {
-   case GL_CLEAR: 
-      tmp = LOGICOP_CLEAR; 
-      break;
-   case GL_AND: 
-      tmp = LOGICOP_AND; 
-      break;
-   case GL_AND_REVERSE: 
-      tmp = LOGICOP_AND_RVRSE; 
-      break;
-   case GL_COPY: 
-      tmp = LOGICOP_COPY; 
-      break;
-   case GL_COPY_INVERTED: 
-      tmp = LOGICOP_COPY_INV; 
-      break;
-   case GL_AND_INVERTED: 
-      tmp = LOGICOP_AND_INV; 
-      break;
-   case GL_NOOP: 
-      tmp = LOGICOP_NOOP; 
-      break;
-   case GL_XOR: 
-      tmp = LOGICOP_XOR; 
-      break;
-   case GL_OR: 
-      tmp = LOGICOP_OR; 
-      break;
-   case GL_OR_INVERTED: 
-      tmp = LOGICOP_OR_INV; 
-      break;
-   case GL_NOR: 
-      tmp = LOGICOP_NOR; 
-      break;
-   case GL_EQUIV: 
-      tmp = LOGICOP_EQUIV; 
-      break;
-   case GL_INVERT: 
-      tmp = LOGICOP_INV; 
-      break;
-   case GL_OR_REVERSE: 
-      tmp = LOGICOP_OR_RVRSE; 
-      break;
-   case GL_NAND: 
-      tmp = LOGICOP_NAND; 
-      break;
-   case GL_SET: 
-      tmp = LOGICOP_SET; 
-      break;
-   default:
-      return;
-   }
-
    I915_STATECHANGE(i915, I915_UPLOAD_CTX);
    i915->state.Ctx[I915_CTXREG_STATE4] &= ~LOGICOP_MASK;
    i915->state.Ctx[I915_CTXREG_STATE4] |= LOGIC_OP_FUNC(tmp);
@@ -636,19 +524,19 @@ static void i915ShadeModel(GLcontext *ctx, GLenum mode)
 /* =============================================================
  * Fog
  */
-static void update_fog( GLcontext *ctx )
+void i915_update_fog( GLcontext *ctx )
 {
    i915ContextPtr i915 = I915_CONTEXT(ctx);
    GLenum mode;
    GLboolean enabled;
    GLboolean try_pixel_fog;
    
-   if (ctx->FragmentProgram.Enabled && ctx->FragmentProgram.Current) {
+   if (ctx->FragmentProgram._Active) {
       /* Pull in static fog state from program */
       
-      mode = ctx->FragmentProgram.Current->FogOption;
+      mode = ctx->FragmentProgram._Current->FogOption;
       enabled = (mode != GL_NONE);
-      try_pixel_fog = 1;
+      try_pixel_fog = 0;
    }
    else {
       enabled = ctx->Fog.Enabled;
@@ -738,7 +626,6 @@ static void i915Fogfv(GLcontext *ctx, GLenum pname, const GLfloat *param)
    case GL_FOG_MODE:
    case GL_FOG_START:
    case GL_FOG_END: 
-      update_fog( ctx );
       break;
 
    case GL_FOG_DENSITY:
@@ -773,7 +660,6 @@ static void i915Hint(GLcontext *ctx, GLenum target, GLenum state)
 {
    switch (target) {
    case GL_FOG_HINT:
-      update_fog( ctx );
       break;
    default:
       break;
@@ -818,7 +704,6 @@ static void i915Enable(GLcontext *ctx, GLenum cap, GLboolean state)
       break;
 
    case GL_FRAGMENT_PROGRAM_ARB:
-      update_fog( ctx );
       break;
 
    case GL_DITHER:
@@ -858,7 +743,6 @@ static void i915Enable(GLcontext *ctx, GLenum cap, GLboolean state)
       break;
 
    case GL_FOG:
-      update_fog( ctx );
       break;
 
    case GL_CULL_FACE:
@@ -975,16 +859,16 @@ static void i915_init_packets( i915ContextPtr i915 )
       i915->state.Buffer[I915_DESTREG_CBUFADDR0] = _3DSTATE_BUF_INFO_CMD;
       i915->state.Buffer[I915_DESTREG_CBUFADDR1] = 
         (BUF_3D_ID_COLOR_BACK | 
-         BUF_3D_PITCH(screen->frontPitch * screen->cpp) |
+         BUF_3D_PITCH(screen->front.pitch * screen->cpp) |
          BUF_3D_USE_FENCE);
 
 
       i915->state.Buffer[I915_DESTREG_DBUFADDR0] = _3DSTATE_BUF_INFO_CMD;
       i915->state.Buffer[I915_DESTREG_DBUFADDR1] = 
         (BUF_3D_ID_DEPTH |
-         BUF_3D_PITCH(screen->depthPitch * screen->cpp) |
+         BUF_3D_PITCH(screen->depth.pitch * screen->cpp) |
          BUF_3D_USE_FENCE);
-      i915->state.Buffer[I915_DESTREG_DBUFADDR2] = screen->depthOffset;
+      i915->state.Buffer[I915_DESTREG_DBUFADDR2] = screen->depth.offset;
 
 
       i915->state.Buffer[I915_DESTREG_DV0] = _3DSTATE_DST_BUF_VARS_CMD;
@@ -1047,9 +931,9 @@ void i915InitStateFunctions( struct dd_function_table *functions )
    functions->PolygonStipple = i915PolygonStipple;
    functions->Scissor = i915Scissor;
    functions->ShadeModel = i915ShadeModel;
-   functions->StencilFunc = i915StencilFunc;
-   functions->StencilMask = i915StencilMask;
-   functions->StencilOp = i915StencilOp;
+   functions->StencilFuncSeparate = i915StencilFuncSeparate;
+   functions->StencilMaskSeparate = i915StencilMaskSeparate;
+   functions->StencilOpSeparate = i915StencilOpSeparate;
 }