i965g: add constant buffer setter
[mesa.git] / src / mesa / swrast / s_triangle.c
index 2033ab55291ff8b9781fb950dbbaee0f65b3d25d..1ab0e19f922860013e6aae57381dea6db7d88e51 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.3
+ * Version:  7.3
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
@@ -35,6 +35,7 @@
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/texformat.h"
+#include "shader/prog_instruction.h"
 
 #include "s_aatriangle.h"
 #include "s_context.h"
@@ -43,8 +44,9 @@
 #include "s_triangle.h"
 
 
-/*
- * Just used for feedback mode.
+/**
+ * Test if a triangle should be culled.  Used for feedback and selection mode.
+ * \return GL_TRUE if the triangle is to be culled, GL_FALSE otherwise.
  */
 GLboolean
 _swrast_culltriangle( GLcontext *ctx,
@@ -52,16 +54,17 @@ _swrast_culltriangle( GLcontext *ctx,
                       const SWvertex *v1,
                       const SWvertex *v2 )
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLfloat ex = v1->attrib[FRAG_ATTRIB_WPOS][0] - v0->attrib[FRAG_ATTRIB_WPOS][0];
    GLfloat ey = v1->attrib[FRAG_ATTRIB_WPOS][1] - v0->attrib[FRAG_ATTRIB_WPOS][1];
    GLfloat fx = v2->attrib[FRAG_ATTRIB_WPOS][0] - v0->attrib[FRAG_ATTRIB_WPOS][0];
    GLfloat fy = v2->attrib[FRAG_ATTRIB_WPOS][1] - v0->attrib[FRAG_ATTRIB_WPOS][1];
    GLfloat c = ex*fy-ey*fx;
 
-   if (c * SWRAST_CONTEXT(ctx)->_BackfaceCullSign > 0)
-      return 0;
+   if (c * swrast->_BackfaceSign * swrast->_BackfaceCullSign <= 0.0F)
+      return GL_FALSE;
 
-   return 1;
+   return GL_TRUE;
 }
 
 
@@ -131,7 +134,8 @@ _swrast_culltriangle( GLcontext *ctx,
 
 #define SETUP_CODE                                                     \
    struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; \
-   struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;     \
+   struct gl_texture_object *obj =                                     \
+      ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];               \
    const GLint b = obj->BaseLevel;                                     \
    const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;           \
    const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;         \
@@ -182,7 +186,8 @@ _swrast_culltriangle( GLcontext *ctx,
 
 #define SETUP_CODE                                                     \
    struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; \
-   struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;     \
+   struct gl_texture_object *obj =                                     \
+      ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];               \
    const GLint b = obj->BaseLevel;                                     \
    const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;           \
    const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;         \
@@ -263,6 +268,7 @@ affine_span(GLcontext *ctx, SWspan *span,
             struct affine_info *info)
 {
    GLchan sample[4];  /* the filtered texture sample */
+   const GLuint texEnableSave = ctx->Texture._EnabledCoordUnits;
 
    /* Instead of defining a function for each mode, a test is done
     * between the outer and inner loops. This is to reduce code size
@@ -392,6 +398,9 @@ affine_span(GLcontext *ctx, SWspan *span,
    GLuint i;
    GLchan *dest = span->array->rgba[0];
 
+   /* Disable tex units so they're not re-applied in swrast_write_rgba_span */
+   ctx->Texture._EnabledCoordUnits = 0x0;
+
    span->intTex[0] -= FIXED_HALF;
    span->intTex[1] -= FIXED_HALF;
    switch (info->filter) {
@@ -493,8 +502,12 @@ affine_span(GLcontext *ctx, SWspan *span,
    }
    span->interpMask &= ~SPAN_RGBA;
    ASSERT(span->arrayMask & SPAN_RGBA);
+
    _swrast_write_rgba_span(ctx, span);
 
+   /* re-enable texture units */
+   ctx->Texture._EnabledCoordUnits = texEnableSave;
+
 #undef SPAN_NEAREST
 #undef SPAN_LINEAR
 }
@@ -515,7 +528,8 @@ affine_span(GLcontext *ctx, SWspan *span,
 #define SETUP_CODE                                                     \
    struct affine_info info;                                            \
    struct gl_texture_unit *unit = ctx->Texture.Unit+0;                 \
-   struct gl_texture_object *obj = unit->Current2D;                    \
+   struct gl_texture_object *obj =                                     \
+      ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];               \
    const GLint b = obj->BaseLevel;                                     \
    const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;           \
    const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;         \
@@ -652,8 +666,8 @@ fast_persp_span(GLcontext *ctx, SWspan *span,
    GLfloat tex_coord[3], tex_step[3];
    GLchan *dest = span->array->rgba[0];
 
-   const GLuint savedTexEnable = ctx->Texture._EnabledUnits;
-   ctx->Texture._EnabledUnits = 0;
+   const GLuint texEnableSave = ctx->Texture._EnabledCoordUnits;
+   ctx->Texture._EnabledCoordUnits = 0;
 
    tex_coord[0] = span->attrStart[FRAG_ATTRIB_TEX0][0]  * (info->smask + 1);
    tex_step[0] = span->attrStepX[FRAG_ATTRIB_TEX0][0] * (info->smask + 1);
@@ -766,7 +780,7 @@ fast_persp_span(GLcontext *ctx, SWspan *span,
 #undef SPAN_LINEAR
 
    /* restore state */
-   ctx->Texture._EnabledUnits = savedTexEnable;
+   ctx->Texture._EnabledCoordUnits = texEnableSave;
 }
 
 
@@ -785,7 +799,8 @@ fast_persp_span(GLcontext *ctx, SWspan *span,
 #define SETUP_CODE                                                     \
    struct persp_info info;                                             \
    const struct gl_texture_unit *unit = ctx->Texture.Unit+0;           \
-   const struct gl_texture_object *obj = unit->Current2D;              \
+   struct gl_texture_object *obj =                                     \
+      ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];               \
    const GLint b = obj->BaseLevel;                                     \
    info.texture = (const GLchan *) obj->Image[0][b]->Data;             \
    info.twidth_log2 = obj->Image[0][b]->WidthLog2;                     \
@@ -1009,7 +1024,7 @@ _swrast_choose_triangle( GLcontext *ctx )
           ctx->Depth.Test &&
           ctx->Depth.Mask == GL_FALSE &&
           ctx->Depth.Func == GL_LESS &&
-          !ctx->Stencil.Enabled) {
+          !ctx->Stencil._Enabled) {
          if ((rgbmode &&
               ctx->Color.ColorMask[0] == 0 &&
               ctx->Color.ColorMask[1] == 0 &&
@@ -1041,7 +1056,8 @@ _swrast_choose_triangle( GLcontext *ctx )
          const struct gl_texture_image *texImg;
          GLenum minFilter, magFilter, envMode;
          GLint format;
-         texObj2D = ctx->Texture.Unit[0].Current2D;
+         texObj2D = ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
+
          texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL;
          format = texImg ? texImg->TexFormat->MesaFormat : -1;
          minFilter = texObj2D ? texObj2D->MinFilter : (GLenum) 0;
@@ -1055,6 +1071,7 @@ _swrast_choose_triangle( GLcontext *ctx )
              && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
              && texObj2D->WrapS == GL_REPEAT
              && texObj2D->WrapT == GL_REPEAT
+             && texObj2D->_Swizzle == SWIZZLE_NOOP
              && texImg->_IsPowerOfTwo
              && texImg->Border == 0
              && texImg->Width == texImg->RowStride
@@ -1062,7 +1079,8 @@ _swrast_choose_triangle( GLcontext *ctx )
              && minFilter == magFilter
              && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR
              && !swrast->_FogEnabled
-             && ctx->Texture.Unit[0].EnvMode != GL_COMBINE_EXT) {
+             && ctx->Texture.Unit[0].EnvMode != GL_COMBINE_EXT
+             && ctx->Texture.Unit[0].EnvMode != GL_COMBINE4_NV) {
            if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) {
               if (minFilter == GL_NEAREST
                   && format == MESA_FORMAT_RGB