intel: Set depth to 6 for cubemaps
[mesa.git] / src / mesa / drivers / dri / i915 / i830_state.c
index 645ebe305774410b90153bf7a31ceca0fa9ae888..3136ced5ffbd4d043fabf1b9f82be755b9a87429 100644 (file)
 #include "main/macros.h"
 #include "main/enums.h"
 #include "main/dd.h"
-
-#include "texmem.h"
+#include "main/state.h"
 
 #include "drivers/common/driverfuncs.h"
 
 #include "intel_screen.h"
 #include "intel_batchbuffer.h"
+#include "intel_mipmap_tree.h"
 #include "intel_fbo.h"
 #include "intel_buffers.h"
 
@@ -47,7 +47,7 @@
 #define FILE_DEBUG_FLAG DEBUG_STATE
 
 static void
-i830StencilFuncSeparate(GLcontext * ctx, GLenum face, GLenum func, GLint ref,
+i830StencilFuncSeparate(struct gl_context * ctx, GLenum face, GLenum func, GLint ref,
                         GLuint mask)
 {
    struct i830_context *i830 = i830_context(ctx);
@@ -72,7 +72,7 @@ i830StencilFuncSeparate(GLcontext * ctx, GLenum face, GLenum func, GLint ref,
 }
 
 static void
-i830StencilMaskSeparate(GLcontext * ctx, GLenum face, GLuint mask)
+i830StencilMaskSeparate(struct gl_context * ctx, GLenum face, GLuint mask)
 {
    struct i830_context *i830 = i830_context(ctx);
 
@@ -87,7 +87,7 @@ i830StencilMaskSeparate(GLcontext * ctx, GLenum face, GLuint mask)
 }
 
 static void
-i830StencilOpSeparate(GLcontext * ctx, GLenum face, GLenum fail, GLenum zfail,
+i830StencilOpSeparate(struct gl_context * ctx, GLenum face, GLenum fail, GLenum zfail,
                       GLenum zpass)
 {
    struct i830_context *i830 = i830_context(ctx);
@@ -199,7 +199,7 @@ i830StencilOpSeparate(GLcontext * ctx, GLenum face, GLenum fail, GLenum zfail,
 }
 
 static void
-i830AlphaFunc(GLcontext * ctx, GLenum func, GLfloat ref)
+i830AlphaFunc(struct gl_context * ctx, GLenum func, GLfloat ref)
 {
    struct i830_context *i830 = i830_context(ctx);
    int test = intel_translate_compare_func(func);
@@ -228,13 +228,13 @@ i830AlphaFunc(GLcontext * ctx, GLenum func, GLfloat ref)
  * I'm not sure which is correct.
  */
 static void
-i830EvalLogicOpBlendState(GLcontext * ctx)
+i830EvalLogicOpBlendState(struct gl_context * ctx)
 {
    struct i830_context *i830 = i830_context(ctx);
 
    I830_STATECHANGE(i830, I830_UPLOAD_CTX);
 
-   if (RGBA_LOGICOP_ENABLED(ctx)) {
+   if (ctx->Color.ColorLogicOpEnabled) {
       i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~(ENABLE_COLOR_BLEND |
                                                   ENABLE_LOGIC_OP_MASK);
       i830->state.Ctx[I830_CTXREG_ENABLES_1] |= (DISABLE_COLOR_BLEND |
@@ -255,7 +255,7 @@ i830EvalLogicOpBlendState(GLcontext * ctx)
 }
 
 static void
-i830BlendColor(GLcontext * ctx, const GLfloat color[4])
+i830BlendColor(struct gl_context * ctx, const GLfloat color[4])
 {
    struct i830_context *i830 = i830_context(ctx);
    GLubyte r, g, b, a;
@@ -279,7 +279,7 @@ i830BlendColor(GLcontext * ctx, const GLfloat color[4])
  * change the interpretation of the blend function.
  */
 static void
-i830_set_blend_state(GLcontext * ctx)
+i830_set_blend_state(struct gl_context * ctx)
 {
    struct i830_context *i830 = i830_context(ctx);
    int funcA;
@@ -291,10 +291,10 @@ i830_set_blend_state(GLcontext * ctx)
 
 
    funcRGB =
-      SRC_BLND_FACT(intel_translate_blend_factor(ctx->Color.BlendSrcRGB))
-      | DST_BLND_FACT(intel_translate_blend_factor(ctx->Color.BlendDstRGB));
+      SRC_BLND_FACT(intel_translate_blend_factor(ctx->Color.Blend[0].SrcRGB))
+      | DST_BLND_FACT(intel_translate_blend_factor(ctx->Color.Blend[0].DstRGB));
 
-   switch (ctx->Color.BlendEquationRGB) {
+   switch (ctx->Color.Blend[0].EquationRGB) {
    case GL_FUNC_ADD:
       eqnRGB = BLENDFUNC_ADD;
       break;
@@ -314,15 +314,15 @@ i830_set_blend_state(GLcontext * ctx)
       break;
    default:
       fprintf(stderr, "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
-              __FUNCTION__, __LINE__, ctx->Color.BlendEquationRGB);
+              __FUNCTION__, __LINE__, ctx->Color.Blend[0].EquationRGB);
       return;
    }
 
 
-   funcA = SRC_ABLEND_FACT(intel_translate_blend_factor(ctx->Color.BlendSrcA))
-      | DST_ABLEND_FACT(intel_translate_blend_factor(ctx->Color.BlendDstA));
+   funcA = SRC_ABLEND_FACT(intel_translate_blend_factor(ctx->Color.Blend[0].SrcA))
+      | DST_ABLEND_FACT(intel_translate_blend_factor(ctx->Color.Blend[0].DstA));
 
-   switch (ctx->Color.BlendEquationA) {
+   switch (ctx->Color.Blend[0].EquationA) {
    case GL_FUNC_ADD:
       eqnA = BLENDFUNC_ADD;
       break;
@@ -342,7 +342,7 @@ i830_set_blend_state(GLcontext * ctx)
       break;
    default:
       fprintf(stderr, "[%s:%u] Invalid alpha blend equation (0x%04x).\n",
-              __FUNCTION__, __LINE__, ctx->Color.BlendEquationA);
+              __FUNCTION__, __LINE__, ctx->Color.Blend[0].EquationA);
       return;
    }
 
@@ -385,7 +385,7 @@ i830_set_blend_state(GLcontext * ctx)
 
 
 static void
-i830BlendEquationSeparate(GLcontext * ctx, GLenum modeRGB, GLenum modeA)
+i830BlendEquationSeparate(struct gl_context * ctx, GLenum modeRGB, GLenum modeA)
 {
    DBG("%s -> %s, %s\n", __FUNCTION__,
        _mesa_lookup_enum_by_nr(modeRGB),
@@ -398,7 +398,7 @@ i830BlendEquationSeparate(GLcontext * ctx, GLenum modeRGB, GLenum modeA)
 
 
 static void
-i830BlendFuncSeparate(GLcontext * ctx, GLenum sfactorRGB,
+i830BlendFuncSeparate(struct gl_context * ctx, GLenum sfactorRGB,
                       GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA)
 {
    DBG("%s -> RGB(%s, %s) A(%s, %s)\n", __FUNCTION__,
@@ -417,7 +417,7 @@ i830BlendFuncSeparate(GLcontext * ctx, GLenum sfactorRGB,
 
 
 static void
-i830DepthFunc(GLcontext * ctx, GLenum func)
+i830DepthFunc(struct gl_context * ctx, GLenum func)
 {
    struct i830_context *i830 = i830_context(ctx);
    int test = intel_translate_compare_func(func);
@@ -431,7 +431,7 @@ i830DepthFunc(GLcontext * ctx, GLenum func)
 }
 
 static void
-i830DepthMask(GLcontext * ctx, GLboolean flag)
+i830DepthMask(struct gl_context * ctx, GLboolean flag)
 {
    struct i830_context *i830 = i830_context(ctx);
 
@@ -449,18 +449,16 @@ i830DepthMask(GLcontext * ctx, GLboolean flag)
 
 /** Called from ctx->Driver.Viewport() */
 static void
-i830Viewport(GLcontext * ctx,
+i830Viewport(struct gl_context * ctx,
               GLint x, GLint y, GLsizei width, GLsizei height)
 {
    intelCalcViewport(ctx);
-
-   intel_viewport(ctx, x, y, width, height);
 }
 
 
 /** Called from ctx->Driver.DepthRange() */
 static void
-i830DepthRange(GLcontext * ctx, GLclampd nearval, GLclampd farval)
+i830DepthRange(struct gl_context * ctx, GLclampd nearval, GLclampd farval)
 {
    intelCalcViewport(ctx);
 }
@@ -472,7 +470,7 @@ i830DepthRange(GLcontext * ctx, GLclampd nearval, GLclampd farval)
  * Fortunately stipple is usually a repeating pattern.
  */
 static void
-i830PolygonStipple(GLcontext * ctx, const GLubyte * mask)
+i830PolygonStipple(struct gl_context * ctx, const GLubyte * mask)
 {
    struct i830_context *i830 = i830_context(ctx);
    const GLubyte *m = mask;
@@ -528,7 +526,7 @@ i830PolygonStipple(GLcontext * ctx, const GLubyte * mask)
  * Hardware clipping
  */
 static void
-i830Scissor(GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h)
+i830Scissor(struct gl_context * ctx, GLint x, GLint y, GLsizei w, GLsizei h)
 {
    struct i830_context *i830 = i830_context(ctx);
    int x1, y1, x2, y2;
@@ -568,7 +566,7 @@ i830Scissor(GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h)
 }
 
 static void
-i830LogicOp(GLcontext * ctx, GLenum opcode)
+i830LogicOp(struct gl_context * ctx, GLenum opcode)
 {
    struct i830_context *i830 = i830_context(ctx);
    int tmp = intel_translate_logic_op(opcode);
@@ -583,7 +581,7 @@ i830LogicOp(GLcontext * ctx, GLenum opcode)
 
 
 static void
-i830CullFaceFrontFace(GLcontext * ctx, GLenum unused)
+i830CullFaceFrontFace(struct gl_context * ctx, GLenum unused)
 {
    struct i830_context *i830 = i830_context(ctx);
    GLuint mode;
@@ -611,7 +609,7 @@ i830CullFaceFrontFace(GLcontext * ctx, GLenum unused)
 }
 
 static void
-i830LineWidth(GLcontext * ctx, GLfloat widthf)
+i830LineWidth(struct gl_context * ctx, GLfloat widthf)
 {
    struct i830_context *i830 = i830_context(ctx);
    int width;
@@ -620,7 +618,7 @@ i830LineWidth(GLcontext * ctx, GLfloat widthf)
    DBG("%s\n", __FUNCTION__);
    
    width = (int) (widthf * 2);
-   CLAMP_SELF(width, 1, 15);
+   width = CLAMP(width, 1, 15);
 
    state5 = i830->state.Ctx[I830_CTXREG_STATE5] & ~FIXED_LINE_WIDTH_MASK;
    state5 |= (ENABLE_FIXED_LINE_WIDTH | FIXED_LINE_WIDTH(width));
@@ -632,14 +630,14 @@ i830LineWidth(GLcontext * ctx, GLfloat widthf)
 }
 
 static void
-i830PointSize(GLcontext * ctx, GLfloat size)
+i830PointSize(struct gl_context * ctx, GLfloat size)
 {
    struct i830_context *i830 = i830_context(ctx);
    GLint point_size = (int) size;
 
    DBG("%s\n", __FUNCTION__);
    
-   CLAMP_SELF(point_size, 1, 256);
+   point_size = CLAMP(point_size, 1, 256);
    I830_STATECHANGE(i830, I830_UPLOAD_CTX);
    i830->state.Ctx[I830_CTXREG_STATE5] &= ~FIXED_POINT_WIDTH_MASK;
    i830->state.Ctx[I830_CTXREG_STATE5] |= (ENABLE_FIXED_POINT_WIDTH |
@@ -652,7 +650,7 @@ i830PointSize(GLcontext * ctx, GLfloat size)
  */
 
 static void
-i830ColorMask(GLcontext * ctx,
+i830ColorMask(struct gl_context * ctx,
               GLboolean r, GLboolean g, GLboolean b, GLboolean a)
 {
    struct i830_context *i830 = i830_context(ctx);
@@ -674,21 +672,21 @@ i830ColorMask(GLcontext * ctx,
 }
 
 static void
-update_specular(GLcontext * ctx)
+update_specular(struct gl_context * ctx)
 {
    struct i830_context *i830 = i830_context(ctx);
 
    I830_STATECHANGE(i830, I830_UPLOAD_CTX);
    i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_SPEC_ADD_MASK;
 
-   if (NEED_SECONDARY_COLOR(ctx))
+   if (_mesa_need_secondary_color(ctx))
       i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_SPEC_ADD;
    else
       i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_SPEC_ADD;
 }
 
 static void
-i830LightModelfv(GLcontext * ctx, GLenum pname, const GLfloat * param)
+i830LightModelfv(struct gl_context * ctx, GLenum pname, const GLfloat * param)
 {
    DBG("%s\n", __FUNCTION__);
    
@@ -700,7 +698,7 @@ i830LightModelfv(GLcontext * ctx, GLenum pname, const GLfloat * param)
 /* In Mesa 3.5 we can reliably do native flatshading.
  */
 static void
-i830ShadeModel(GLcontext * ctx, GLenum mode)
+i830ShadeModel(struct gl_context * ctx, GLenum mode)
 {
    struct i830_context *i830 = i830_context(ctx);
    I830_STATECHANGE(i830, I830_UPLOAD_CTX);
@@ -729,7 +727,7 @@ i830ShadeModel(GLcontext * ctx, GLenum mode)
  * Fog
  */
 static void
-i830Fogfv(GLcontext * ctx, GLenum pname, const GLfloat * param)
+i830Fogfv(struct gl_context * ctx, GLenum pname, const GLfloat * param)
 {
    struct i830_context *i830 = i830_context(ctx);
 
@@ -750,7 +748,7 @@ i830Fogfv(GLcontext * ctx, GLenum pname, const GLfloat * param)
  */
 
 static void
-i830Enable(GLcontext * ctx, GLenum cap, GLboolean state)
+i830Enable(struct gl_context * ctx, GLenum cap, GLboolean state)
 {
    struct i830_context *i830 = i830_context(ctx);
 
@@ -847,11 +845,11 @@ i830Enable(GLcontext * ctx, GLenum cap, GLboolean state)
 
    case GL_STENCIL_TEST:
       {
-         GLboolean hw_stencil = GL_FALSE;
+         bool hw_stencil = false;
          if (ctx->DrawBuffer) {
             struct intel_renderbuffer *irbStencil
                = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_STENCIL);
-            hw_stencil = (irbStencil && irbStencil->region);
+            hw_stencil = (irbStencil && irbStencil->mt->region);
          }
          if (hw_stencil) {
             I830_STATECHANGE(i830, I830_UPLOAD_CTX);
@@ -1069,7 +1067,7 @@ i830_init_packets(struct i830_context *i830)
 }
 
 void
-i830_update_provoking_vertex(GLcontext * ctx)
+i830_update_provoking_vertex(struct gl_context * ctx)
 {
    struct i830_context *i830 = i830_context(ctx);
 
@@ -1121,15 +1119,12 @@ i830InitStateFuncs(struct dd_function_table *functions)
 void
 i830InitState(struct i830_context *i830)
 {
-   GLcontext *ctx = &i830->intel.ctx;
+   struct gl_context *ctx = &i830->intel.ctx;
 
    i830_init_packets(i830);
 
    _mesa_init_driver_state(ctx);
 
-   memcpy(&i830->initial, &i830->state, sizeof(i830->state));
-
-   i830->current = &i830->state;
    i830->state.emitted = 0;
    i830->state.active = (I830_UPLOAD_INVARIENT |
                          I830_UPLOAD_RASTER_RULES |