i965g: add constant buffer setter
[mesa.git] / src / mesa / swrast / s_triangle.c
index 0598052f50c2a543a0df78450d2a288881b513ed..1ab0e19f922860013e6aae57381dea6db7d88e51 100644 (file)
@@ -44,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,
@@ -53,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;
 }
 
 
@@ -132,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;         \
@@ -183,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;         \
@@ -264,7 +268,7 @@ affine_span(GLcontext *ctx, SWspan *span,
             struct affine_info *info)
 {
    GLchan sample[4];  /* the filtered texture sample */
-   const GLuint texEnableSave = ctx->Texture._EnabledUnits;
+   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
@@ -395,7 +399,7 @@ affine_span(GLcontext *ctx, SWspan *span,
    GLchan *dest = span->array->rgba[0];
 
    /* Disable tex units so they're not re-applied in swrast_write_rgba_span */
-   ctx->Texture._EnabledUnits = 0x0;
+   ctx->Texture._EnabledCoordUnits = 0x0;
 
    span->intTex[0] -= FIXED_HALF;
    span->intTex[1] -= FIXED_HALF;
@@ -502,7 +506,7 @@ affine_span(GLcontext *ctx, SWspan *span,
    _swrast_write_rgba_span(ctx, span);
 
    /* re-enable texture units */
-   ctx->Texture._EnabledUnits = texEnableSave;
+   ctx->Texture._EnabledCoordUnits = texEnableSave;
 
 #undef SPAN_NEAREST
 #undef SPAN_LINEAR
@@ -524,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;         \
@@ -661,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);
@@ -775,7 +780,7 @@ fast_persp_span(GLcontext *ctx, SWspan *span,
 #undef SPAN_LINEAR
 
    /* restore state */
-   ctx->Texture._EnabledUnits = savedTexEnable;
+   ctx->Texture._EnabledCoordUnits = texEnableSave;
 }
 
 
@@ -794,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;                     \
@@ -1018,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 &&
@@ -1050,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;