mesa: add _mesa_program_state_value_size() helper
[mesa.git] / src / mesa / swrast / s_points.c
index 61ff4d0b84cde4395ddf641125f8bdd124f21ef8..1c6c239042aaef8aac20d1be8a3c2f417b3afd3d 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * 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
- * 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.
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
  */
 
-
+#include "main/framebuffer.h"
 #include "main/glheader.h"
-#include "main/colormac.h"
-#include "main/context.h"
 #include "main/macros.h"
-#include "main/texstate.h"
 #include "s_context.h"
 #include "s_feedback.h"
 #include "s_points.h"
@@ -39,9 +36,9 @@
  */
 #define CULL_INVALID(V)                              \
    do {                                              \
-      float tmp = (V)->attrib[FRAG_ATTRIB_WPOS][0]   \
-                + (V)->attrib[FRAG_ATTRIB_WPOS][1];  \
-      if (IS_INF_OR_NAN(tmp))                        \
+      float tmp = (V)->attrib[VARYING_SLOT_POS][0]   \
+                + (V)->attrib[VARYING_SLOT_POS][1];  \
+      if (util_is_inf_or_nan(tmp))                   \
         return;                                     \
    } while(0)
 
@@ -53,8 +50,8 @@
  * or just the glPointSize value.
  * Must also clamp to user-defined range and implmentation limits.
  */
-static INLINE GLfloat
-get_size(const GLcontext *ctx, const SWvertex *vert, GLboolean smoothed)
+static inline GLfloat
+get_size(const struct gl_context *ctx, const SWvertex *vert, GLboolean smoothed)
 {
    GLfloat size;
 
@@ -82,7 +79,7 @@ get_size(const GLcontext *ctx, const SWvertex *vert, GLboolean smoothed)
  * Draw a point sprite
  */
 static void
-sprite_point(GLcontext *ctx, const SWvertex *vert)
+sprite_point(struct gl_context *ctx, const SWvertex *vert)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    SWspan span;
@@ -95,9 +92,9 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
 
    /* z coord */
    if (ctx->DrawBuffer->Visual.depthBits <= 16)
-      span.z = FloatToFixed(vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+      span.z = FloatToFixed(vert->attrib[VARYING_SLOT_POS][2] + 0.5F);
    else
-      span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+      span.z = (GLuint) (vert->attrib[VARYING_SLOT_POS][2] + 0.5F);
    span.zStep = 0;
 
    size = get_size(ctx, vert, GL_FALSE);
@@ -118,31 +115,32 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
    span.alphaStep = 0;
 
    /* need these for fragment programs */
-   span.attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F;
-   span.attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
-   span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
+   span.attrStart[VARYING_SLOT_POS][3] = 1.0F;
+   span.attrStepX[VARYING_SLOT_POS][3] = 0.0F;
+   span.attrStepY[VARYING_SLOT_POS][3] = 0.0F;
 
    {
       GLfloat s, r, dsdx;
 
       /* texcoord / pointcoord interpolants */
-      s = 0.0;
-      dsdx = 1.0 / size;
+      s = 0.0F;
+      dsdx = 1.0F / size;
       if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) {
-         dtdy = 1.0 / size;
-         t0 = 0.5 * dtdy;
+         dtdy = 1.0F / size;
+         t0 = 0.5F * dtdy;
       }
       else {
          /* GL_UPPER_LEFT */
-         dtdy = -1.0 / size;
-         t0 = 1.0 + 0.5 * dtdy;
+         dtdy = -1.0F / size;
+         t0 = 1.0F + 0.5F * dtdy;
       }
 
       ATTRIB_LOOP_BEGIN
-         if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0) {
-            const GLuint u = attr - FRAG_ATTRIB_TEX0;
-            /* a texcoord */
-            if (ctx->Point.CoordReplace[u]) {
+         if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
+            /* a texcoord attribute */
+            const GLuint u = attr - VARYING_SLOT_TEX0;
+            assert(u < MAX_TEXTURE_COORD_UNITS);
+            if (ctx->Point.CoordReplace & (1u << u)) {
                tCoords[numTcoords++] = attr;
 
                if (ctx->Point.SpriteRMode == GL_ZERO)
@@ -170,15 +168,15 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
                continue;
             }
          }
-         else if (attr == FRAG_ATTRIB_FOGC) {
-            /* GLSL gl_PointCoord is stored in fog.zw */
-            span.attrStart[FRAG_ATTRIB_FOGC][2] = 0.0;
-            span.attrStart[FRAG_ATTRIB_FOGC][3] = 0.0; /* t0 set below */
-            span.attrStepX[FRAG_ATTRIB_FOGC][2] = dsdx;
-            span.attrStepX[FRAG_ATTRIB_FOGC][3] = 0.0;
-            span.attrStepY[FRAG_ATTRIB_FOGC][2] = 0.0;
-            span.attrStepY[FRAG_ATTRIB_FOGC][3] = dtdy;
-            tCoords[numTcoords++] = FRAG_ATTRIB_FOGC;
+         else if (attr == VARYING_SLOT_PNTC) {
+            /* GLSL gl_PointCoord.xy (.zw undefined) */
+            span.attrStart[VARYING_SLOT_PNTC][0] = 0.0;
+            span.attrStart[VARYING_SLOT_PNTC][1] = 0.0; /* t0 set below */
+            span.attrStepX[VARYING_SLOT_PNTC][0] = dsdx;
+            span.attrStepX[VARYING_SLOT_PNTC][1] = 0.0;
+            span.attrStepY[VARYING_SLOT_PNTC][0] = 0.0;
+            span.attrStepY[VARYING_SLOT_PNTC][1] = dtdy;
+            tCoords[numTcoords++] = VARYING_SLOT_PNTC;
             continue;
          }
          /* use vertex's texcoord/attrib */
@@ -190,8 +188,8 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
 
    /* compute pos, bounds and render */
    {
-      const GLfloat x = vert->attrib[FRAG_ATTRIB_WPOS][0];
-      const GLfloat y = vert->attrib[FRAG_ATTRIB_WPOS][1];
+      const GLfloat x = vert->attrib[VARYING_SLOT_POS][0];
+      const GLfloat y = vert->attrib[VARYING_SLOT_POS][1];
       GLint iSize = (GLint) (size + 0.5F);
       GLint xmin, xmax, ymin, ymax, iy;
       GLint iRadius;
@@ -210,9 +208,9 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
       else {
          /* even size */
          /* 0.501 factor allows conformance to pass */
-         xmin = (GLint) (x + 0.501) - iRadius;
+         xmin = (GLint) (x + 0.501F) - iRadius;
          xmax = xmin + iSize - 1;
-         ymin = (GLint) (y + 0.501) - iRadius;
+         ymin = (GLint) (y + 0.501F) - iRadius;
          ymax = ymin + iSize - 1;
       }
 
@@ -221,10 +219,7 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
          GLuint i;
          /* setup texcoord T for this row */
          for (i = 0; i < numTcoords; i++) {
-            if (tCoords[i] == FRAG_ATTRIB_FOGC)
-               span.attrStart[FRAG_ATTRIB_FOGC][3] = tcoord;
-            else
-               span.attrStart[tCoords[i]][1] = tcoord;
+            span.attrStart[tCoords[i]][1] = tcoord;
          }
 
          /* these might get changed by span clipping */
@@ -244,10 +239,9 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
  * Draw smooth/antialiased point.  RGB or CI mode.
  */
 static void
-smooth_point(GLcontext *ctx, const SWvertex *vert)
+smooth_point(struct gl_context *ctx, const SWvertex *vert)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   const GLboolean ciMode = !ctx->Visual.rgbMode;
    SWspan span;
    GLfloat size, alphaAtten;
 
@@ -255,15 +249,15 @@ smooth_point(GLcontext *ctx, const SWvertex *vert)
 
    /* z coord */
    if (ctx->DrawBuffer->Visual.depthBits <= 16)
-      span.z = FloatToFixed(vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+      span.z = FloatToFixed(vert->attrib[VARYING_SLOT_POS][2] + 0.5F);
    else
-      span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+      span.z = (GLuint) (vert->attrib[VARYING_SLOT_POS][2] + 0.5F);
    span.zStep = 0;
 
    size = get_size(ctx, vert, GL_TRUE);
 
    /* alpha attenuation / fade factor */
-   if (ctx->Multisample._Enabled) {
+   if (_mesa_is_multisample_enabled(ctx)) {
       if (vert->pointSize >= ctx->Point.Threshold) {
          alphaAtten = 1.0F;
       }
@@ -294,9 +288,9 @@ smooth_point(GLcontext *ctx, const SWvertex *vert)
    span.alphaStep = 0;
 
    /* need these for fragment programs */
-   span.attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F;
-   span.attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
-   span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
+   span.attrStart[VARYING_SLOT_POS][3] = 1.0F;
+   span.attrStepX[VARYING_SLOT_POS][3] = 0.0F;
+   span.attrStepY[VARYING_SLOT_POS][3] = 0.0F;
 
    ATTRIB_LOOP_BEGIN
       COPY_4V(span.attrStart[attr], vert->attrib[attr]);
@@ -306,8 +300,8 @@ smooth_point(GLcontext *ctx, const SWvertex *vert)
 
    /* compute pos, bounds and render */
    {
-      const GLfloat x = vert->attrib[FRAG_ATTRIB_WPOS][0];
-      const GLfloat y = vert->attrib[FRAG_ATTRIB_WPOS][1];
+      const GLfloat x = vert->attrib[VARYING_SLOT_POS][0];
+      const GLfloat y = vert->attrib[VARYING_SLOT_POS][1];
       const GLfloat radius = 0.5F * size;
       const GLfloat rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
       const GLfloat rmax = radius + 0.7071F;
@@ -338,10 +332,6 @@ smooth_point(GLcontext *ctx, const SWvertex *vert)
                if (dist2 >= rmin2) {
                   /* compute partial coverage */
                   coverage = 1.0F - (dist2 - rmin2) * cscale;
-                  if (ciMode) {
-                     /* coverage in [0,15] */
-                     coverage *= 15.0;
-                  }
                }
                else {
                   /* full coverage */
@@ -369,10 +359,9 @@ smooth_point(GLcontext *ctx, const SWvertex *vert)
  * Draw large (size >= 1) non-AA point.  RGB or CI mode.
  */
 static void
-large_point(GLcontext *ctx, const SWvertex *vert)
+large_point(struct gl_context *ctx, const SWvertex *vert)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   const GLboolean ciMode = !ctx->Visual.rgbMode;
    SWspan span;
    GLfloat size;
 
@@ -380,9 +369,9 @@ large_point(GLcontext *ctx, const SWvertex *vert)
 
    /* z coord */
    if (ctx->DrawBuffer->Visual.depthBits <= 16)
-      span.z = FloatToFixed(vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+      span.z = FloatToFixed(vert->attrib[VARYING_SLOT_POS][2] + 0.5F);
    else
-      span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+      span.z = (GLuint) (vert->attrib[VARYING_SLOT_POS][2] + 0.5F);
    span.zStep = 0;
 
    size = get_size(ctx, vert, GL_FALSE);
@@ -392,27 +381,20 @@ large_point(GLcontext *ctx, const SWvertex *vert)
    span.arrayMask = SPAN_XY;
    span.facing = swrast->PointLineFacing;
 
-   if (ciMode) {
-      span.interpMask = SPAN_Z | SPAN_INDEX;
-      span.index = FloatToFixed(vert->attrib[FRAG_ATTRIB_CI][0]);
-      span.indexStep = 0;
-   }
-   else {
-      span.interpMask = SPAN_Z | SPAN_RGBA;
-      span.red   = ChanToFixed(vert->color[0]);
-      span.green = ChanToFixed(vert->color[1]);
-      span.blue  = ChanToFixed(vert->color[2]);
-      span.alpha = ChanToFixed(vert->color[3]);
-      span.redStep = 0;
-      span.greenStep = 0;
-      span.blueStep = 0;
-      span.alphaStep = 0;
-   }
+   span.interpMask = SPAN_Z | SPAN_RGBA;
+   span.red   = ChanToFixed(vert->color[0]);
+   span.green = ChanToFixed(vert->color[1]);
+   span.blue  = ChanToFixed(vert->color[2]);
+   span.alpha = ChanToFixed(vert->color[3]);
+   span.redStep = 0;
+   span.greenStep = 0;
+   span.blueStep = 0;
+   span.alphaStep = 0;
 
    /* need these for fragment programs */
-   span.attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F;
-   span.attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
-   span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
+   span.attrStart[VARYING_SLOT_POS][3] = 1.0F;
+   span.attrStepX[VARYING_SLOT_POS][3] = 0.0F;
+   span.attrStepY[VARYING_SLOT_POS][3] = 0.0F;
 
    ATTRIB_LOOP_BEGIN
       COPY_4V(span.attrStart[attr], vert->attrib[attr]);
@@ -422,8 +404,8 @@ large_point(GLcontext *ctx, const SWvertex *vert)
 
    /* compute pos, bounds and render */
    {
-      const GLfloat x = vert->attrib[FRAG_ATTRIB_WPOS][0];
-      const GLfloat y = vert->attrib[FRAG_ATTRIB_WPOS][1];
+      const GLfloat x = vert->attrib[VARYING_SLOT_POS][0];
+      const GLfloat y = vert->attrib[VARYING_SLOT_POS][1];
       GLint iSize = (GLint) (size + 0.5F);
       GLint xmin, xmax, ymin, ymax, ix, iy;
       GLint iRadius;
@@ -441,9 +423,9 @@ large_point(GLcontext *ctx, const SWvertex *vert)
       else {
          /* even size */
          /* 0.501 factor allows conformance to pass */
-         xmin = (GLint) (x + 0.501) - iRadius;
+         xmin = (GLint) (x + 0.501F) - iRadius;
          xmax = xmin + iSize - 1;
-         ymin = (GLint) (y + 0.501) - iRadius;
+         ymin = (GLint) (y + 0.501F) - iRadius;
          ymax = ymin + iSize - 1;
       }
 
@@ -456,7 +438,7 @@ large_point(GLcontext *ctx, const SWvertex *vert)
             span.end++;
          }
       }
-      assert(span.end <= MAX_WIDTH);
+      assert(span.end <= SWRAST_MAX_WIDTH);
       _swrast_write_rgba_span(ctx, &span);
    }
 }
@@ -466,10 +448,9 @@ large_point(GLcontext *ctx, const SWvertex *vert)
  * Draw size=1, single-pixel point
  */
 static void
-pixel_point(GLcontext *ctx, const SWvertex *vert)
+pixel_point(struct gl_context *ctx, const SWvertex *vert)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   const GLboolean ciMode = !ctx->Visual.rgbMode;
    /*
     * Note that unlike the other functions, we put single-pixel points
     * into a special span array in order to render as many points as
@@ -483,27 +464,21 @@ pixel_point(GLcontext *ctx, const SWvertex *vert)
    /* Span init */
    span->interpMask = 0;
    span->arrayMask = SPAN_XY | SPAN_Z;
-   if (ciMode)
-      span->arrayMask |= SPAN_INDEX;
-   else
-      span->arrayMask |= SPAN_RGBA;
+   span->arrayMask |= SPAN_RGBA;
    /*span->arrayMask |= SPAN_LAMBDA;*/
    span->arrayAttribs = swrast->_ActiveAttribMask; /* we'll produce these vals */
 
    /* need these for fragment programs */
-   span->attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F;
-   span->attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
-   span->attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
+   span->attrStart[VARYING_SLOT_POS][3] = 1.0F;
+   span->attrStepX[VARYING_SLOT_POS][3] = 0.0F;
+   span->attrStepY[VARYING_SLOT_POS][3] = 0.0F;
 
    /* check if we need to flush */
-   if (span->end >= MAX_WIDTH ||
+   if (span->end >= SWRAST_MAX_WIDTH ||
        (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT)) ||
        span->facing != swrast->PointLineFacing) {
       if (span->end > 0) {
-         if (ciMode)
-            _swrast_write_index_span(ctx, span);
-         else
-            _swrast_write_rgba_span(ctx, span);
+        _swrast_write_rgba_span(ctx, span);
          span->end = 0;
       }
    }
@@ -513,26 +488,22 @@ pixel_point(GLcontext *ctx, const SWvertex *vert)
    span->facing = swrast->PointLineFacing;
 
    /* fragment attributes */
-   if (ciMode) {
-      span->array->index[count] = (GLuint) vert->attrib[FRAG_ATTRIB_CI][0];
-   }
-   else {
-      span->array->rgba[count][RCOMP] = vert->color[0];
-      span->array->rgba[count][GCOMP] = vert->color[1];
-      span->array->rgba[count][BCOMP] = vert->color[2];
-      span->array->rgba[count][ACOMP] = vert->color[3];
-   }
+   span->array->rgba[count][RCOMP] = vert->color[0];
+   span->array->rgba[count][GCOMP] = vert->color[1];
+   span->array->rgba[count][BCOMP] = vert->color[2];
+   span->array->rgba[count][ACOMP] = vert->color[3];
+
    ATTRIB_LOOP_BEGIN
       COPY_4V(span->array->attribs[attr][count], vert->attrib[attr]);
    ATTRIB_LOOP_END
 
    /* fragment position */
-   span->array->x[count] = (GLint) vert->attrib[FRAG_ATTRIB_WPOS][0];
-   span->array->y[count] = (GLint) vert->attrib[FRAG_ATTRIB_WPOS][1];
-   span->array->z[count] = (GLint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+   span->array->x[count] = (GLint) vert->attrib[VARYING_SLOT_POS][0];
+   span->array->y[count] = (GLint) vert->attrib[VARYING_SLOT_POS][1];
+   span->array->z[count] = (GLint) (vert->attrib[VARYING_SLOT_POS][2] + 0.5F);
 
    span->end = count + 1;
-   ASSERT(span->end <= MAX_WIDTH);
+   assert(span->end <= SWRAST_MAX_WIDTH);
 }
 
 
@@ -541,7 +512,7 @@ pixel_point(GLcontext *ctx, const SWvertex *vert)
  * primary color.
  */
 void
-_swrast_add_spec_terms_point(GLcontext *ctx, const SWvertex *v0)
+_swrast_add_spec_terms_point(struct gl_context *ctx, const SWvertex *v0)
 {
    SWvertex *ncv0 = (SWvertex *) v0; /* cast away const */
    GLfloat rSum, gSum, bSum;
@@ -550,9 +521,9 @@ _swrast_add_spec_terms_point(GLcontext *ctx, const SWvertex *v0)
    /* save */
    COPY_CHAN4(cSave, ncv0->color);
    /* sum */
-   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);
@@ -567,9 +538,12 @@ _swrast_add_spec_terms_point(GLcontext *ctx, const SWvertex *v0)
  * Examine current state to determine which point drawing function to use.
  */
 void
-_swrast_choose_point(GLcontext *ctx)
+_swrast_choose_point(struct gl_context *ctx)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   const GLfloat size = CLAMP(ctx->Point.Size,
+                              ctx->Point.MinSize,
+                              ctx->Point.MaxSize);
 
    if (ctx->RenderMode == GL_RENDER) {
       if (ctx->Point.PointSprite) {
@@ -578,7 +552,7 @@ _swrast_choose_point(GLcontext *ctx)
       else if (ctx->Point.SmoothFlag) {
          swrast->Point = smooth_point;
       }
-      else if (ctx->Point.Size > 1.0 ||
+      else if (size > 1.0F ||
                ctx->Point._Attenuated ||
                ctx->VertexProgram.PointSizeEnabled) {
          swrast->Point = large_point;