mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / swrast / s_triangle.c
index 124aa5f8edd2f2005a3938c9c185a1bf1c25dde4..5f430944874176c7ffabce708488a118adb3af69 100644 (file)
@@ -17,7 +17,7 @@
  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * THE AUTHORS 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.
  */
@@ -36,6 +36,7 @@
 #include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/state.h"
+#include "main/samplerobj.h"
 #include "program/prog_instruction.h"
 
 #include "s_aatriangle.h"
@@ -56,10 +57,10 @@ _swrast_culltriangle( struct gl_context *ctx,
                       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 ex = v1->attrib[VARYING_SLOT_POS][0] - v0->attrib[VARYING_SLOT_POS][0];
+   GLfloat ey = v1->attrib[VARYING_SLOT_POS][1] - v0->attrib[VARYING_SLOT_POS][1];
+   GLfloat fx = v2->attrib[VARYING_SLOT_POS][0] - v0->attrib[VARYING_SLOT_POS][0];
+   GLfloat fy = v2->attrib[VARYING_SLOT_POS][1] - v0->attrib[VARYING_SLOT_POS][1];
    GLfloat c = ex*fy-ey*fx;
 
    if (c * swrast->_BackfaceSign * swrast->_BackfaceCullSign <= 0.0F)
@@ -142,7 +143,7 @@ _swrast_culltriangle( struct gl_context *ctx,
 
 #define RENDER_SPAN( span )                                            \
    GLuint i;                                                           \
-   GLubyte rgba[MAX_WIDTH][4];                                         \
+   GLubyte (*rgba)[4] = swrast->SpanArrays->rgba8;                     \
    span.intTex[0] -= FIXED_HALF; /* off-by-one error? */               \
    span.intTex[1] -= FIXED_HALF;                                       \
    for (i = 0; i < span.end; i++) {                                    \
@@ -200,7 +201,8 @@ _swrast_culltriangle( struct gl_context *ctx,
 
 #define RENDER_SPAN( span )                                            \
    GLuint i;                                                           \
-   GLubyte rgba[MAX_WIDTH][4];                                         \
+   GLubyte (*rgba)[4] = swrast->SpanArrays->rgba8;                     \
+   GLubyte *mask = swrast->SpanArrays->mask;                            \
    span.intTex[0] -= FIXED_HALF; /* off-by-one error? */               \
    span.intTex[1] -= FIXED_HALF;                                       \
    for (i = 0; i < span.end; i++) {                                    \
@@ -215,17 +217,17 @@ _swrast_culltriangle( struct gl_context *ctx,
          rgba[i][BCOMP] = texture[pos+0];                              \
          rgba[i][ACOMP] = 0xff;                                        \
          zRow[i] = z;                                                  \
-         span.array->mask[i] = 1;                                      \
+         mask[i] = 1;                                                  \
       }                                                                        \
       else {                                                           \
-         span.array->mask[i] = 0;                                      \
+         mask[i] = 0;                                                  \
       }                                                                        \
       span.intTex[0] += span.intTexStep[0];                            \
       span.intTex[1] += span.intTexStep[1];                            \
       span.z += span.zStep;                                            \
    }                                                                   \
    _swrast_put_row(ctx, rb, GL_UNSIGNED_BYTE,                           \
-                   span.end, span.x, span.y, rgba, span.array->mask);
+                   span.end, span.x, span.y, rgba, mask);
 
 #include "s_tritemp.h"
 
@@ -676,13 +678,13 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
    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);
-   tex_coord[1] = span->attrStart[FRAG_ATTRIB_TEX0][1] * (info->tmask + 1);
-   tex_step[1] = span->attrStepX[FRAG_ATTRIB_TEX0][1] * (info->tmask + 1);
-   /* span->attrStart[FRAG_ATTRIB_TEX0][2] only if 3D-texturing, here only 2D */
-   tex_coord[2] = span->attrStart[FRAG_ATTRIB_TEX0][3];
-   tex_step[2] = span->attrStepX[FRAG_ATTRIB_TEX0][3];
+   tex_coord[0] = span->attrStart[VARYING_SLOT_TEX0][0]  * (info->smask + 1);
+   tex_step[0] = span->attrStepX[VARYING_SLOT_TEX0][0] * (info->smask + 1);
+   tex_coord[1] = span->attrStart[VARYING_SLOT_TEX0][1] * (info->tmask + 1);
+   tex_step[1] = span->attrStepX[VARYING_SLOT_TEX0][1] * (info->tmask + 1);
+   /* span->attrStart[VARYING_SLOT_TEX0][2] only if 3D-texturing, here only 2D */
+   tex_coord[2] = span->attrStart[VARYING_SLOT_TEX0][3];
+   tex_step[2] = span->attrStepX[VARYING_SLOT_TEX0][3];
 
    switch (info->filter) {
    case GL_NEAREST:
@@ -937,23 +939,23 @@ _swrast_add_spec_terms_triangle(struct gl_context *ctx, const SWvertex *v0,
    COPY_CHAN4( cSave[1], ncv1->color );
    COPY_CHAN4( cSave[2], ncv2->color );
    /* sum v0 */
-   rSum = CHAN_TO_FLOAT(ncv0->color[0]) + ncv0->attrib[FRAG_ATTRIB_COL1][0];
-   gSum = CHAN_TO_FLOAT(ncv0->color[1]) + ncv0->attrib[FRAG_ATTRIB_COL1][1];
-   bSum = CHAN_TO_FLOAT(ncv0->color[2]) + ncv0->attrib[FRAG_ATTRIB_COL1][2];
+   rSum = CHAN_TO_FLOAT(ncv0->color[0]) + ncv0->attrib[VARYING_SLOT_COL1][0];
+   gSum = CHAN_TO_FLOAT(ncv0->color[1]) + ncv0->attrib[VARYING_SLOT_COL1][1];
+   bSum = CHAN_TO_FLOAT(ncv0->color[2]) + ncv0->attrib[VARYING_SLOT_COL1][2];
    UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[0], rSum);
    UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[1], gSum);
    UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[2], bSum);
    /* sum v1 */
-   rSum = CHAN_TO_FLOAT(ncv1->color[0]) + ncv1->attrib[FRAG_ATTRIB_COL1][0];
-   gSum = CHAN_TO_FLOAT(ncv1->color[1]) + ncv1->attrib[FRAG_ATTRIB_COL1][1];
-   bSum = CHAN_TO_FLOAT(ncv1->color[2]) + ncv1->attrib[FRAG_ATTRIB_COL1][2];
+   rSum = CHAN_TO_FLOAT(ncv1->color[0]) + ncv1->attrib[VARYING_SLOT_COL1][0];
+   gSum = CHAN_TO_FLOAT(ncv1->color[1]) + ncv1->attrib[VARYING_SLOT_COL1][1];
+   bSum = CHAN_TO_FLOAT(ncv1->color[2]) + ncv1->attrib[VARYING_SLOT_COL1][2];
    UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[0], rSum);
    UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[1], gSum);
    UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[2], bSum);
    /* sum v2 */
-   rSum = CHAN_TO_FLOAT(ncv2->color[0]) + ncv2->attrib[FRAG_ATTRIB_COL1][0];
-   gSum = CHAN_TO_FLOAT(ncv2->color[1]) + ncv2->attrib[FRAG_ATTRIB_COL1][1];
-   bSum = CHAN_TO_FLOAT(ncv2->color[2]) + ncv2->attrib[FRAG_ATTRIB_COL1][2];
+   rSum = CHAN_TO_FLOAT(ncv2->color[0]) + ncv2->attrib[VARYING_SLOT_COL1][0];
+   gSum = CHAN_TO_FLOAT(ncv2->color[1]) + ncv2->attrib[VARYING_SLOT_COL1][1];
+   bSum = CHAN_TO_FLOAT(ncv2->color[2]) + ncv2->attrib[VARYING_SLOT_COL1][2];
    UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[0], rSum);
    UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[1], gSum);
    UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[2], bSum);
@@ -1038,34 +1040,41 @@ _swrast_choose_triangle( struct gl_context *ctx )
        * needs to be interpolated.
        */
       if (ctx->Texture._EnabledCoordUnits ||
-          ctx->FragmentProgram._Current ||
+         _swrast_use_fragment_program(ctx) ||
           ctx->ATIFragmentShader._Enabled ||
           _mesa_need_secondary_color(ctx) ||
           swrast->_FogEnabled) {
          /* Ugh, we do a _lot_ of tests to pick the best textured tri func */
          const struct gl_texture_object *texObj2D;
+         const struct gl_sampler_object *samp;
          const struct gl_texture_image *texImg;
          const struct swrast_texture_image *swImg;
          GLenum minFilter, magFilter, envMode;
          gl_format format;
          texObj2D = ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
+         if (ctx->Texture.Unit[0].Sampler)
+            samp = ctx->Texture.Unit[0].Sampler;
+         else if (texObj2D)
+            samp = &texObj2D->Sampler;
+         else
+            samp = NULL;
 
          texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL;
          swImg = swrast_texture_image_const(texImg);
 
          format = texImg ? texImg->TexFormat : MESA_FORMAT_NONE;
-         minFilter = texObj2D ? texObj2D->Sampler.MinFilter : GL_NONE;
-         magFilter = texObj2D ? texObj2D->Sampler.MagFilter : GL_NONE;
+         minFilter = texObj2D ? samp->MinFilter : GL_NONE;
+         magFilter = texObj2D ? samp->MagFilter : GL_NONE;
          envMode = ctx->Texture.Unit[0].EnvMode;
 
          /* First see if we can use an optimized 2-D texture function */
          if (ctx->Texture._EnabledCoordUnits == 0x1
-             && !ctx->FragmentProgram._Current
+             && !_swrast_use_fragment_program(ctx)
              && !ctx->ATIFragmentShader._Enabled
              && ctx->Texture._EnabledUnits == 0x1
              && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
-             && texObj2D->Sampler.WrapS == GL_REPEAT
-             && texObj2D->Sampler.WrapT == GL_REPEAT
+             && samp->WrapS == GL_REPEAT
+             && samp->WrapT == GL_REPEAT
              && texObj2D->_Swizzle == SWIZZLE_NOOP
              && swImg->_IsPowerOfTwo
              && texImg->Border == 0