mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / swrast / s_triangle.c
index c4d504b06bf2e19b816c83e3d237150f2a457b6c..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)
@@ -132,7 +133,7 @@ _swrast_culltriangle( struct gl_context *ctx,
    const GLfloat twidth = (GLfloat) texImg->Width;                     \
    const GLfloat theight = (GLfloat) texImg->Height;                   \
    const GLint twidth_log2 = texImg->WidthLog2;                                \
-   const GLubyte *texture = (const GLubyte *) swImg->Data;             \
+   const GLubyte *texture = (const GLubyte *) swImg->Map;              \
    const GLint smask = texImg->Width - 1;                              \
    const GLint tmask = texImg->Height - 1;                             \
    ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);                    \
@@ -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++) {                                    \
@@ -157,7 +158,8 @@ _swrast_culltriangle( struct gl_context *ctx,
       span.intTex[0] += span.intTexStep[0];                            \
       span.intTex[1] += span.intTexStep[1];                            \
    }                                                                   \
-   rb->PutRow(ctx, rb, span.end, span.x, span.y, rgba, NULL);
+   _swrast_put_row(ctx, rb, GL_UNSIGNED_BYTE, span.end,                 \
+                   span.x, span.y, rgba, NULL);
 
 #include "s_tritemp.h"
 
@@ -189,7 +191,7 @@ _swrast_culltriangle( struct gl_context *ctx,
    const GLfloat twidth = (GLfloat) texImg->Width;                     \
    const GLfloat theight = (GLfloat) texImg->Height;                   \
    const GLint twidth_log2 = texImg->WidthLog2;                                \
-   const GLubyte *texture = (const GLubyte *) swImg->Data;             \
+   const GLubyte *texture = (const GLubyte *) swImg->Map;              \
    const GLint smask = texImg->Width - 1;                              \
    const GLint tmask = texImg->Height - 1;                             \
    ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);                    \
@@ -199,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++) {                                    \
@@ -214,16 +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;                                            \
    }                                                                   \
-   rb->PutRow(ctx, rb, span.end, span.x, span.y, rgba, span.array->mask);
+   _swrast_put_row(ctx, rb, GL_UNSIGNED_BYTE,                           \
+                   span.end, span.x, span.y, rgba, mask);
 
 #include "s_tritemp.h"
 
@@ -543,7 +547,7 @@ affine_span(struct gl_context *ctx, SWspan *span,
       swrast_texture_image_const(texImg);                              \
    const GLfloat twidth = (GLfloat) texImg->Width;                     \
    const GLfloat theight = (GLfloat) texImg->Height;                   \
-   info.texture = (const GLchan *) swImg->Data;                                \
+   info.texture = (const GLchan *) swImg->Map;                         \
    info.twidth_log2 = texImg->WidthLog2;                               \
    info.smask = texImg->Width - 1;                                     \
    info.tmask = texImg->Height - 1;                                    \
@@ -674,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:
@@ -810,7 +814,7 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
       obj->Image[0][obj->BaseLevel];                                   \
    const struct swrast_texture_image *swImg =                          \
       swrast_texture_image_const(texImg);                              \
-   info.texture = (const GLchan *) swImg->Data;                                \
+   info.texture = (const GLchan *) swImg->Map;                         \
    info.twidth_log2 = texImg->WidthLog2;                               \
    info.smask = texImg->Width - 1;                                     \
    info.tmask = texImg->Height - 1;                                    \
@@ -874,19 +878,21 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
 /*
  * Special tri function for occlusion testing
  */
-#define NAME occlusion_zless_triangle
+#define NAME occlusion_zless_16_triangle
 #define INTERP_Z 1
 #define SETUP_CODE                                                     \
-   struct gl_renderbuffer *rb = ctx->DrawBuffer->_DepthBuffer;         \
+   struct gl_renderbuffer *rb =                                         \
+      ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;           \
    struct gl_query_object *q = ctx->Query.CurrentOcclusionObject;      \
    ASSERT(ctx->Depth.Test);                                            \
    ASSERT(!ctx->Depth.Mask);                                           \
    ASSERT(ctx->Depth.Func == GL_LESS);                                 \
+   assert(rb->Format == MESA_FORMAT_Z16);                               \
    if (!q) {                                                           \
       return;                                                          \
    }
 #define RENDER_SPAN( span )                                            \
-   if (rb->Format == MESA_FORMAT_Z16) {                                        \
+   {                                                                    \
       GLuint i;                                                                \
       const GLushort *zRow = (const GLushort *)                                \
          _swrast_pixel_address(rb, span.x, span.y);                     \
@@ -897,17 +903,6 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
          }                                                             \
          span.z += span.zStep;                                         \
       }                                                                        \
-   }                                                                   \
-   else {                                                              \
-      GLuint i;                                                                \
-      const GLuint *zRow = (const GLuint *)                            \
-         _swrast_pixel_address(rb, span.x, span.y);                    \
-      for (i = 0; i < span.end; i++) {                                 \
-         if ((GLuint)span.z < zRow[i]) {                               \
-            q->Result++;                                               \
-         }                                                             \
-         span.z += span.zStep;                                         \
-      }                                                                        \
    }
 #include "s_tritemp.h"
 
@@ -944,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);
@@ -1014,6 +1009,8 @@ _swrast_choose_triangle( struct gl_context *ctx )
    }
 
    if (ctx->RenderMode==GL_RENDER) {
+      struct gl_renderbuffer *depthRb =
+         ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
 
       if (ctx->Polygon.SmoothFlag) {
          _swrast_set_aa_triangle_function(ctx);
@@ -1026,12 +1023,14 @@ _swrast_choose_triangle( struct gl_context *ctx )
           ctx->Depth.Test &&
           ctx->Depth.Mask == GL_FALSE &&
           ctx->Depth.Func == GL_LESS &&
-          !ctx->Stencil._Enabled) {
+          !ctx->Stencil._Enabled &&
+          depthRb &&
+          depthRb->Format == MESA_FORMAT_Z16) {
          if (ctx->Color.ColorMask[0][0] == 0 &&
             ctx->Color.ColorMask[0][1] == 0 &&
             ctx->Color.ColorMask[0][2] == 0 &&
             ctx->Color.ColorMask[0][3] == 0) {
-            USE(occlusion_zless_triangle);
+            USE(occlusion_zless_16_triangle);
             return;
          }
       }
@@ -1041,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