summaryrefslogtreecommitdiff
path: root/src/mesa/swrast/s_span.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/swrast/s_span.c')
-rw-r--r--src/mesa/swrast/s_span.c600
1 files changed, 258 insertions, 342 deletions
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index cca1864ea4..a2044d0042 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -39,14 +39,13 @@
#include "s_atifragshader.h"
#include "s_alpha.h"
-#include "s_arbshader.h"
#include "s_blend.h"
#include "s_context.h"
#include "s_depth.h"
#include "s_fog.h"
#include "s_logic.h"
#include "s_masking.h"
-#include "s_nvfragprog.h"
+#include "s_fragprog.h"
#include "s_span.h"
#include "s_stencil.h"
#include "s_texcombine.h"
@@ -76,8 +75,10 @@ _swrast_span_default_z( GLcontext *ctx, SWspan *span )
void
_swrast_span_default_fog( GLcontext *ctx, SWspan *span )
{
- span->fog = _swrast_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
- span->fogStep = span->dfogdx = span->dfogdy = 0.0F;
+ span->attrStart[FRAG_ATTRIB_FOGC][0]
+ = _swrast_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ span->attrStepX[FRAG_ATTRIB_FOGC][0] = 0.0;
+ span->attrStepY[FRAG_ATTRIB_FOGC][0] = 0.0;
span->interpMask |= SPAN_FOG;
}
@@ -129,22 +130,23 @@ _swrast_span_default_texcoords( GLcontext *ctx, SWspan *span )
{
GLuint i;
for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
+ const GLuint attr = FRAG_ATTRIB_TEX0 + i;
const GLfloat *tc = ctx->Current.RasterTexCoords[i];
- if (ctx->FragmentProgram._Enabled || ctx->ATIFragmentShader._Enabled) {
- COPY_4V(span->tex[i], tc);
+ if (ctx->FragmentProgram._Current || ctx->ATIFragmentShader._Enabled) {
+ COPY_4V(span->attrStart[attr], tc);
}
else if (tc[3] > 0.0F) {
/* use (s/q, t/q, r/q, 1) */
- span->tex[i][0] = tc[0] / tc[3];
- span->tex[i][1] = tc[1] / tc[3];
- span->tex[i][2] = tc[2] / tc[3];
- span->tex[i][3] = 1.0;
+ span->attrStart[attr][0] = tc[0] / tc[3];
+ span->attrStart[attr][1] = tc[1] / tc[3];
+ span->attrStart[attr][2] = tc[2] / tc[3];
+ span->attrStart[attr][3] = 1.0;
}
else {
- ASSIGN_4V(span->tex[i], 0.0F, 0.0F, 0.0F, 1.0F);
+ ASSIGN_4V(span->attrStart[attr], 0.0F, 0.0F, 0.0F, 1.0F);
}
- ASSIGN_4V(span->texStepX[i], 0.0F, 0.0F, 0.0F, 0.0F);
- ASSIGN_4V(span->texStepY[i], 0.0F, 0.0F, 0.0F, 0.0F);
+ ASSIGN_4V(span->attrStepX[attr], 0.0F, 0.0F, 0.0F, 0.0F);
+ ASSIGN_4V(span->attrStepY[attr], 0.0F, 0.0F, 0.0F, 0.0F);
}
span->interpMask |= SPAN_TEXTURE;
}
@@ -240,7 +242,7 @@ interpolate_colors(SWspan *span)
#endif
case GL_FLOAT:
{
- GLfloat (*rgba)[4] = span->array->color.sz4.rgba;
+ GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0];
GLfloat r, g, b, a, dr, dg, db, da;
r = span->red;
g = span->green;
@@ -352,7 +354,7 @@ interpolate_specular(SWspan *span)
#endif
case GL_FLOAT:
{
- GLfloat (*spec)[4] = span->array->color.sz4.spec;
+ GLfloat (*spec)[4] = span->array->attribs[FRAG_ATTRIB_COL1];
#if CHAN_BITS <= 16
GLfloat r = CHAN_TO_FLOAT(FixedToChan(span->specRed));
GLfloat g = CHAN_TO_FLOAT(FixedToChan(span->specGreen));
@@ -431,15 +433,15 @@ interpolate_indexes(GLcontext *ctx, SWspan *span)
static INLINE void
interpolate_fog(const GLcontext *ctx, SWspan *span)
{
- GLfloat *fog = span->array->fog;
- const GLfloat fogStep = span->fogStep;
- GLfloat fogCoord = span->fog;
+ GLfloat (*fog)[4] = span->array->attribs[FRAG_ATTRIB_FOGC];
+ const GLfloat fogStep = span->attrStepX[FRAG_ATTRIB_FOGC][0];
+ GLfloat fogCoord = span->attrStart[FRAG_ATTRIB_FOGC][0];
const GLuint haveW = (span->interpMask & SPAN_W);
- const GLfloat wStep = haveW ? span->dwdx : 0.0F;
- GLfloat w = haveW ? span->w : 1.0F;
+ const GLfloat wStep = haveW ? span->attrStepX[FRAG_ATTRIB_WPOS][3] : 0.0F;
+ GLfloat w = haveW ? span->attrStart[FRAG_ATTRIB_WPOS][3] : 1.0F;
GLuint i;
for (i = 0; i < span->end; i++) {
- fog[i] = fogCoord / w;
+ fog[i][0] = fogCoord / w;
fogCoord += fogStep;
w += wStep;
}
@@ -539,309 +541,188 @@ _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
static void
interpolate_texcoords(GLcontext *ctx, SWspan *span)
{
+ const GLuint maxUnit
+ = (ctx->Texture._EnabledCoordUnits > 1) ? ctx->Const.MaxTextureUnits : 1;
+ GLuint u;
+
ASSERT(span->interpMask & SPAN_TEXTURE);
ASSERT(!(span->arrayMask & SPAN_TEXTURE));
- if (ctx->Texture._EnabledCoordUnits > 1) {
- /* multitexture */
- GLuint u;
- span->arrayMask |= SPAN_TEXTURE;
- /* XXX CoordUnits vs. ImageUnits */
- for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
- if (ctx->Texture._EnabledCoordUnits & (1 << u)) {
- const struct gl_texture_object *obj =ctx->Texture.Unit[u]._Current;
- GLfloat texW, texH;
- GLboolean needLambda;
- if (obj) {
- const struct gl_texture_image *img = obj->Image[0][obj->BaseLevel];
- needLambda = (obj->MinFilter != obj->MagFilter)
- || ctx->FragmentProgram._Enabled;
- texW = img->WidthScale;
- texH = img->HeightScale;
- }
- else {
- /* using a fragment program */
- texW = 1.0;
- texH = 1.0;
- needLambda = GL_FALSE;
- }
- if (needLambda) {
- GLfloat (*texcoord)[4] = span->array->texcoords[u];
- GLfloat *lambda = span->array->lambda[u];
- const GLfloat dsdx = span->texStepX[u][0];
- const GLfloat dsdy = span->texStepY[u][0];
- const GLfloat dtdx = span->texStepX[u][1];
- const GLfloat dtdy = span->texStepY[u][1];
- const GLfloat drdx = span->texStepX[u][2];
- const GLfloat dqdx = span->texStepX[u][3];
- const GLfloat dqdy = span->texStepY[u][3];
- GLfloat s = span->tex[u][0];
- GLfloat t = span->tex[u][1];
- GLfloat r = span->tex[u][2];
- GLfloat q = span->tex[u][3];
- GLuint i;
- if (ctx->FragmentProgram._Enabled || ctx->ATIFragmentShader._Enabled ||
- ctx->ShaderObjects._FragmentShaderPresent) {
- /* do perspective correction but don't divide s, t, r by q */
- const GLfloat dwdx = span->dwdx;
- GLfloat w = span->w;
- for (i = 0; i < span->end; i++) {
- const GLfloat invW = 1.0F / w;
- texcoord[i][0] = s * invW;
- texcoord[i][1] = t * invW;
- texcoord[i][2] = r * invW;
- texcoord[i][3] = q * invW;
- lambda[i] = _swrast_compute_lambda(dsdx, dsdy, dtdx, dtdy,
- dqdx, dqdy, texW, texH,
- s, t, q, invW);
- s += dsdx;
- t += dtdx;
- r += drdx;
- q += dqdx;
- w += dwdx;
- }
+ span->arrayMask |= SPAN_TEXTURE;
+
+ /* XXX CoordUnits vs. ImageUnits */
+ for (u = 0; u < maxUnit; u++) {
+ if (ctx->Texture._EnabledCoordUnits & (1 << u)) {
+ const GLuint attr = FRAG_ATTRIB_TEX0 + u;
+ const struct gl_texture_object *obj =ctx->Texture.Unit[u]._Current;
+ GLfloat texW, texH;
+ GLboolean needLambda;
+ GLfloat (*texcoord)[4] = span->array->attribs[attr];
+ GLfloat *lambda = span->array->lambda[u];
+ const GLfloat dsdx = span->attrStepX[attr][0];
+ const GLfloat dsdy = span->attrStepY[attr][0];
+ const GLfloat dtdx = span->attrStepX[attr][1];
+ const GLfloat dtdy = span->attrStepY[attr][1];
+ const GLfloat drdx = span->attrStepX[attr][2];
+ const GLfloat dqdx = span->attrStepX[attr][3];
+ const GLfloat dqdy = span->attrStepY[attr][3];
+ GLfloat s = span->attrStart[attr][0];
+ GLfloat t = span->attrStart[attr][1];
+ GLfloat r = span->attrStart[attr][2];
+ GLfloat q = span->attrStart[attr][3];
+
+ if (obj) {
+ const struct gl_texture_image *img = obj->Image[0][obj->BaseLevel];
+ needLambda = (obj->MinFilter != obj->MagFilter)
+ || ctx->FragmentProgram._Current;
+ texW = img->WidthScale;
+ texH = img->HeightScale;
+ }
+ else {
+ /* using a fragment program */
+ texW = 1.0;
+ texH = 1.0;
+ needLambda = GL_FALSE;
+ }
+ if (needLambda) {
+ GLuint i;
+ if (ctx->FragmentProgram._Current
+ || ctx->ATIFragmentShader._Enabled) {
+ /* do perspective correction but don't divide s, t, r by q */
+ const GLfloat dwdx = span->attrStepX[FRAG_ATTRIB_WPOS][3];
+ GLfloat w = span->attrStart[FRAG_ATTRIB_WPOS][3];
+ for (i = 0; i < span->end; i++) {
+ const GLfloat invW = 1.0F / w;
+ texcoord[i][0] = s * invW;
+ texcoord[i][1] = t * invW;
+ texcoord[i][2] = r * invW;
+ texcoord[i][3] = q * invW;
+ lambda[i] = _swrast_compute_lambda(dsdx, dsdy, dtdx, dtdy,
+ dqdx, dqdy, texW, texH,
+ s, t, q, invW);
+ s += dsdx;
+ t += dtdx;
+ r += drdx;
+ q += dqdx;
+ w += dwdx;
}
- else {
- for (i = 0; i < span->end; i++) {
- const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
- texcoord[i][0] = s * invQ;
- texcoord[i][1] = t * invQ;
- texcoord[i][2] = r * invQ;
- texcoord[i][3] = q;
- lambda[i] = _swrast_compute_lambda(dsdx, dsdy, dtdx, dtdy,
- dqdx, dqdy, texW, texH,
- s, t, q, invQ);
- s += dsdx;
- t += dtdx;
- r += drdx;
- q += dqdx;
- }
- }
- span->arrayMask |= SPAN_LAMBDA;
}
else {
- GLfloat (*texcoord)[4] = span->array->texcoords[u];
- GLfloat *lambda = span->array->lambda[u];
- const GLfloat dsdx = span->texStepX[u][0];
- const GLfloat dtdx = span->texStepX[u][1];
- const GLfloat drdx = span->texStepX[u][2];
- const GLfloat dqdx = span->texStepX[u][3];
- GLfloat s = span->tex[u][0];
- GLfloat t = span->tex[u][1];
- GLfloat r = span->tex[u][2];
- GLfloat q = span->tex[u][3];
- GLuint i;
- if (ctx->FragmentProgram._Enabled || ctx->ATIFragmentShader._Enabled ||
- ctx->ShaderObjects._FragmentShaderPresent) {
- /* do perspective correction but don't divide s, t, r by q */
- const GLfloat dwdx = span->dwdx;
- GLfloat w = span->w;
- for (i = 0; i < span->end; i++) {
- const GLfloat invW = 1.0F / w;
- texcoord[i][0] = s * invW;
- texcoord[i][1] = t * invW;
- texcoord[i][2] = r * invW;
- texcoord[i][3] = q * invW;
- lambda[i] = 0.0;
- s += dsdx;
- t += dtdx;
- r += drdx;
- q += dqdx;
- w += dwdx;
- }
- }
- else if (dqdx == 0.0F) {
- /* Ortho projection or polygon's parallel to window X axis */
+ for (i = 0; i < span->end; i++) {
const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
- for (i = 0; i < span->end; i++) {
- texcoord[i][0] = s * invQ;
- texcoord[i][1] = t * invQ;
- texcoord[i][2] = r * invQ;
- texcoord[i][3] = q;
- lambda[i] = 0.0;
- s += dsdx;
- t += dtdx;
- r += drdx;
- }
- }
- else {
- for (i = 0; i < span->end; i++) {
- const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
- texcoord[i][0] = s * invQ;
- texcoord[i][1] = t * invQ;
- texcoord[i][2] = r * invQ;
- texcoord[i][3] = q;
- lambda[i] = 0.0;
- s += dsdx;
- t += dtdx;
- r += drdx;
- q += dqdx;
- }
+ texcoord[i][0] = s * invQ;
+ texcoord[i][1] = t * invQ;
+ texcoord[i][2] = r * invQ;
+ texcoord[i][3] = q;
+ lambda[i] = _swrast_compute_lambda(dsdx, dsdy, dtdx, dtdy,
+ dqdx, dqdy, texW, texH,
+ s, t, q, invQ);
+ s += dsdx;
+ t += dtdx;
+ r += drdx;
+ q += dqdx;
}
- } /* lambda */
- } /* if */
- } /* for */
- }
- else {
- /* single texture */
- const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current;
- GLfloat texW, texH;
- GLboolean needLambda;
- if (obj) {
- const struct gl_texture_image *img = obj->Image[0][obj->BaseLevel];
- needLambda = (obj->MinFilter != obj->MagFilter)
- || ctx->FragmentProgram._Enabled;
- texW = (GLfloat) img->WidthScale;
- texH = (GLfloat) img->HeightScale;
- }
- else {
- needLambda = GL_FALSE;
- texW = texH = 1.0;
- }
- span->arrayMask |= SPAN_TEXTURE;
- if (needLambda) {
- /* just texture unit 0, with lambda */
- GLfloat (*texcoord)[4] = span->array->texcoords[0];
- GLfloat *lambda = span->array->lambda[0];
- const GLfloat dsdx = span->texStepX[0][0];
- const GLfloat dsdy = span->texStepY[0][0];
- const GLfloat dtdx = span->texStepX[0][1];
- const GLfloat dtdy = span->texStepY[0][1];
- const GLfloat drdx = span->texStepX[0][2];
- const GLfloat dqdx = span->texStepX[0][3];
- const GLfloat dqdy = span->texStepY[0][3];
- GLfloat s = span->tex[0][0];
- GLfloat t = span->tex[0][1];
- GLfloat r = span->tex[0][2];
- GLfloat q = span->tex[0][3];
- GLuint i;
- if (ctx->FragmentProgram._Enabled || ctx->ATIFragmentShader._Enabled ||
- ctx->ShaderObjects._FragmentShaderPresent) {
- /* do perspective correction but don't divide s, t, r by q */
- const GLfloat dwdx = span->dwdx;
- GLfloat w = span->w;
- for (i = 0; i < span->end; i++) {
- const GLfloat invW = 1.0F / w;
- texcoord[i][0] = s * invW;
- texcoord[i][1] = t * invW;
- texcoord[i][2] = r * invW;
- texcoord[i][3] = q * invW;
- lambda[i] = _swrast_compute_lambda(dsdx, dsdy, dtdx, dtdy,
- dqdx, dqdy, texW, texH,
- s, t, q, invW);
- s += dsdx;
- t += dtdx;
- r += drdx;
- q += dqdx;
- w += dwdx;
}
+ span->arrayMask |= SPAN_LAMBDA;
}
else {
- /* tex.c */
- for (i = 0; i < span->end; i++) {
- const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
- lambda[i] = _swrast_compute_lambda(dsdx, dsdy, dtdx, dtdy,
- dqdx, dqdy, texW, texH,
- s, t, q, invQ);
- texcoord[i][0] = s * invQ;
- texcoord[i][1] = t * invQ;
- texcoord[i][2] = r * invQ;
- texcoord[i][3] = q;
- s += dsdx;
- t += dtdx;
- r += drdx;
- q += dqdx;
- }
- }
- span->arrayMask |= SPAN_LAMBDA;
- }
- else {
- /* just texture 0, without lambda */
- GLfloat (*texcoord)[4] = span->array->texcoords[0];
- const GLfloat dsdx = span->texStepX[0][0];
- const GLfloat dtdx = span->texStepX[0][1];
- const GLfloat drdx = span->texStepX[0][2];
- const GLfloat dqdx = span->texStepX[0][3];
- GLfloat s = span->tex[0][0];
- GLfloat t = span->tex[0][1];
- GLfloat r = span->tex[0][2];
- GLfloat q = span->tex[0][3];
- GLuint i;
- if (ctx->FragmentProgram._Enabled || ctx->ATIFragmentShader._Enabled ||
- ctx->ShaderObjects._FragmentShaderPresent) {
- /* do perspective correction but don't divide s, t, r by q */
- const GLfloat dwdx = span->dwdx;
- GLfloat w = span->w;
- for (i = 0; i < span->end; i++) {
- const GLfloat invW = 1.0F / w;
- texcoord[i][0] = s * invW;
- texcoord[i][1] = t * invW;
- texcoord[i][2] = r * invW;
- texcoord[i][3] = q * invW;
- s += dsdx;
- t += dtdx;
- r += drdx;
- q += dqdx;
- w += dwdx;
- }
- }
- else if (dqdx == 0.0F) {
- /* Ortho projection or polygon's parallel to window X axis */
- const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
- for (i = 0; i < span->end; i++) {
- texcoord[i][0] = s * invQ;
- texcoord[i][1] = t * invQ;
- texcoord[i][2] = r * invQ;
- texcoord[i][3] = q;
- s += dsdx;
- t += dtdx;
- r += drdx;
+ GLuint i;
+ if (ctx->FragmentProgram._Current ||
+ ctx->ATIFragmentShader._Enabled) {
+ /* do perspective correction but don't divide s, t, r by q */
+ const GLfloat dwdx = span->attrStepX[FRAG_ATTRIB_WPOS][3];
+ GLfloat w = span->attrStart[FRAG_ATTRIB_WPOS][3];
+ for (i = 0; i < span->end; i++) {
+ const GLfloat invW = 1.0F / w;
+ texcoord[i][0] = s * invW;
+ texcoord[i][1] = t * invW;
+ texcoord[i][2] = r * invW;
+ texcoord[i][3] = q * invW;
+ lambda[i] = 0.0;
+ s += dsdx;
+ t += dtdx;
+ r += drdx;
+ q += dqdx;
+ w += dwdx;
+ }
}
- }
- else {
- for (i = 0; i < span->end; i++) {
+ else if (dqdx == 0.0F) {
+ /* Ortho projection or polygon's parallel to window X axis */
const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
- texcoord[i][0] = s * invQ;
- texcoord[i][1] = t * invQ;
- texcoord[i][2] = r * invQ;
- texcoord[i][3] = q;
- s += dsdx;
- t += dtdx;
- r += drdx;
- q += dqdx;
+ for (i = 0; i < span->end; i++) {
+ texcoord[i][0] = s * invQ;
+ texcoord[i][1] = t * invQ;
+ texcoord[i][2] = r * invQ;
+ texcoord[i][3] = q;
+ lambda[i] = 0.0;
+ s += dsdx;
+ t += dtdx;
+ r += drdx;
+ }
}
- }
- }
- }
+ else {
+ for (i = 0; i < span->end; i++) {
+ const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q);
+ texcoord[i][0] = s * invQ;
+ texcoord[i][1] = t * invQ;
+ texcoord[i][2] = r * invQ;
+ texcoord[i][3] = q;
+ lambda[i] = 0.0;
+ s += dsdx;
+ t += dtdx;
+ r += drdx;
+ q += dqdx;
+ }
+ }
+ } /* lambda */
+ } /* if */
+ } /* for */
}
+
/**
- * Fill in the span.varying array from the interpolation values.
+ * Fill in the arrays->attribs[FRAG_ATTRIB_VARx] arrays from the
+ * interpolation values.
+ * XXX since interpolants/arrays are getting uniformed, we might merge
+ * this with interpolate_texcoords(), interpolate_Fog(), etc. someday.
*/
static INLINE void
interpolate_varying(GLcontext *ctx, SWspan *span)
{
- GLuint i, j;
+ GLuint var;
+ const GLbitfield inputsUsed = ctx->FragmentProgram._Current->Base.InputsRead;
ASSERT(span->interpMask & SPAN_VARYING);
ASSERT(!(span->arrayMask & SPAN_VARYING));
span->arrayMask |= SPAN_VARYING;
- for (i = 0; i < MAX_VARYING_VECTORS; i++) {
- for (j = 0; j < VARYINGS_PER_VECTOR; j++) {
- const GLfloat dvdx = span->varStepX[i][j];
- GLfloat v = span->var[i][j];
- const GLfloat dwdx = span->dwdx;
- GLfloat w = span->w;
+ for (var = 0; var < MAX_VARYING; var++) {
+ if (inputsUsed & FRAG_BIT_VAR(var)) {
+ const GLuint attr = FRAG_ATTRIB_VAR0 + var;
+ const GLfloat dwdx = span->attrStepX[FRAG_ATTRIB_WPOS][3];
+ GLfloat w = span->attrStart[FRAG_ATTRIB_WPOS][3];
+ const GLfloat dv0dx = span->attrStepX[attr][0];
+ const GLfloat dv1dx = span->attrStepX[attr][1];
+ const GLfloat dv2dx = span->attrStepX[attr][2];
+ const GLfloat dv3dx = span->attrStepX[attr][3];
+ GLfloat v0 = span->attrStart[attr][0];
+ GLfloat v1 = span->attrStart[attr][1];
+ GLfloat v2 = span->attrStart[attr][2];
+ GLfloat v3 = span->attrStart[attr][3];
GLuint k;
-
for (k = 0; k < span->end; k++) {
GLfloat invW = 1.0f / w;
- span->array->varying[k][i][j] = v * invW;
- v += dvdx;
+ span->array->attribs[attr][k][0] = v0 * invW;
+ span->array->attribs[attr][k][1] = v1 * invW;
+ span->array->attribs[attr][k][2] = v2 * invW;
+ span->array->attribs[attr][k][3] = v3 * invW;
+ v0 += dv0dx;
+ v1 += dv1dx;
+ v2 += dv2dx;
+ v3 += dv3dx;
w += dwdx;
}
}
@@ -850,28 +731,68 @@ interpolate_varying(GLcontext *ctx, SWspan *span)
/**
+ * Fill in the arrays->attribs[FRAG_ATTRIB_WPOS] array.
+ */
+static INLINE void
+interpolate_wpos(GLcontext *ctx, SWspan *span)
+{
+ GLfloat (*wpos)[4] = span->array->attribs[FRAG_ATTRIB_WPOS];
+ GLuint i;
+ if (span->arrayMask & SPAN_XY) {
+ for (i = 0; i < span->end; i++) {
+ wpos[i][0] = (GLfloat) span->array->x[i];
+ wpos[i][1] = (GLfloat) span->array->y[i];
+ }
+ }
+ else {
+ for (i = 0; i < span->end; i++) {
+ wpos[i][0] = (GLfloat) span->x + i;
+ wpos[i][1] = (GLfloat) span->y;
+ }
+ }
+ for (i = 0; i < span->end; i++) {
+ wpos[i][2] = (GLfloat) span->array->z[i] / ctx->DrawBuffer->_DepthMaxF;
+ wpos[i][3] = span->attrStart[FRAG_ATTRIB_WPOS][3]
+ + i * span->attrStepX[FRAG_ATTRIB_WPOS][3];
+ }
+}
+
+
+/**
* Apply the current polygon stipple pattern to a span of pixels.
*/
static INLINE void
-stipple_polygon_span( GLcontext *ctx, SWspan *span )
+stipple_polygon_span(GLcontext *ctx, SWspan *span)
{
- const GLuint highbit = 0x80000000;
- const GLuint stipple = ctx->PolygonStipple[span->y % 32];
GLubyte *mask = span->array->mask;
- GLuint i, m;
ASSERT(ctx->Polygon.StippleFlag);
- ASSERT((span->arrayMask & SPAN_XY) == 0);
- m = highbit >> (GLuint) (span->x % 32);
-
- for (i = 0; i < span->end; i++) {
- if ((m & stipple) == 0) {
- mask[i] = 0;
+ if (span->arrayMask & SPAN_XY) {
+ /* arrays of x/y pixel coords */
+ GLuint i;
+ for (i = 0; i < span->end; i++) {
+ const GLint col = span->array->x[i] % 32;
+ const GLint row = span->array->y[i] % 32;
+ const GLuint stipple = ctx->PolygonStipple[row];
+ if (((1 << col) & stipple) == 0) {
+ mask[i] = 0;
+ }
}
- m = m >> 1;
- if (m == 0) {
- m = highbit;
+ }
+ else {
+ /* horizontal span of pixels */
+ const GLuint highBit = 1 << 31;
+ const GLuint stipple = ctx->PolygonStipple[span->y % 32];
+ GLuint i, m = highBit >> (GLuint) (span->x % 32);
+ for (i = 0; i < span->end; i++) {
+ if ((m & stipple) == 0) {
+ mask[i] = 0;
+ }
+ m = m >> 1;
+ if (m == 0) {
+ m = highBit;
+ }
}
}
span->writeAll = GL_FALSE;
@@ -1224,8 +1145,8 @@ add_specular(GLcontext *ctx, SWspan *span)
break;
case GL_FLOAT:
{
- GLfloat (*rgba)[4] = span->array->color.sz4.rgba;
- GLfloat (*spec)[4] = span->array->color.sz4.spec;
+ GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0];
+ GLfloat (*spec)[4] = span->array->attribs[FRAG_ATTRIB_COL1];
GLuint i;
for (i = 0; i < span->end; i++) {
rgba[i][RCOMP] += spec[i][RCOMP];
@@ -1266,7 +1187,7 @@ apply_aa_coverage(SWspan *span)
}
}
else {
- GLfloat (*rgba)[4] = span->array->color.sz4.rgba;
+ GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0];
for (i = 0; i < span->end; i++) {
rgba[i][ACOMP] = rgba[i][ACOMP] * coverage[i];
}
@@ -1280,7 +1201,7 @@ apply_aa_coverage(SWspan *span)
static INLINE void
clamp_colors(SWspan *span)
{
- GLfloat (*rgba)[4] = span->array->color.sz4.rgba;
+ GLfloat (*rgba)[4] = span->array->attribs[FRAG_ATTRIB_COL0];
GLuint i;
ASSERT(span->array->ChanType == GL_FLOAT);
for (i = 0; i < span->end; i++) {
@@ -1296,7 +1217,7 @@ clamp_colors(SWspan *span)
* Convert the span's color arrays to the given type.
*/
static INLINE void
-convert_color_type(GLcontext *ctx, SWspan *span, GLenum newType)
+convert_color_type(SWspan *span, GLenum newType)
{
GLvoid *src, *dst;
if (span->array->ChanType == GL_UNSIGNED_BYTE) {
@@ -1306,7 +1227,7 @@ convert_color_type(GLcontext *ctx, SWspan *span, GLenum newType)
src = span->array->color.sz2.rgba;
}
else {
- src = span->array->color.sz4.rgba;
+ src = span->array->attribs[FRAG_ATTRIB_COL0];
}
if (newType == GL_UNSIGNED_BYTE) {
dst = span->array->color.sz1.rgba;
@@ -1315,7 +1236,7 @@ convert_color_type(GLcontext *ctx, SWspan *span, GLenum newType)
dst = span->array->color.sz2.rgba;
}
else {
- dst = span->array->color.sz4.rgba;
+ dst = span->array->attribs[FRAG_ATTRIB_COL0];
}
_mesa_convert_colors(span->array->ChanType, src,
@@ -1340,8 +1261,7 @@ shade_texture_span(GLcontext *ctx, SWspan *span)
if (ctx->Texture._EnabledCoordUnits && (span->interpMask & SPAN_TEXTURE))
interpolate_texcoords(ctx, span);
- if (ctx->ShaderObjects._FragmentShaderPresent ||
- ctx->FragmentProgram._Enabled ||
+ if (ctx->FragmentProgram._Current ||
ctx->ATIFragmentShader._Enabled) {
/* use float colors if running a fragment program or shader */
@@ -1352,7 +1272,7 @@ shade_texture_span(GLcontext *ctx, SWspan *span)
? (GLvoid *) span->array->color.sz1.rgba
: (GLvoid *) span->array->color.sz2.rgba;
_mesa_convert_colors(oldType, src,
- newType, span->array->color.sz4.rgba,
+ newType, span->array->attribs[FRAG_ATTRIB_COL0],
span->end, span->array->mask);
span->array->ChanType = newType;
}
@@ -1367,12 +1287,15 @@ shade_texture_span(GLcontext *ctx, SWspan *span)
if (span->interpMask & SPAN_Z)
_swrast_span_interpolate_z (ctx, span);
- /* Run fragment program/shader now */
- if (ctx->ShaderObjects._FragmentShaderPresent) {
+ if (ctx->Shader.CurrentProgram && span->interpMask & SPAN_VARYING)
interpolate_varying(ctx, span);
- _swrast_exec_arbshader(ctx, span);
- }
- else if (ctx->FragmentProgram._Enabled) {
+
+ if (ctx->FragmentProgram._Current &&
+ (ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_WPOS))
+ interpolate_wpos(ctx, span);
+
+ /* Run fragment program/shader now */
+ if (ctx->FragmentProgram._Current) {
_swrast_exec_fragment_program(ctx, span);
}
else {
@@ -1403,10 +1326,8 @@ _swrast_write_rgba_span( GLcontext *ctx, SWspan *span)
const GLbitfield origInterpMask = span->interpMask;
const GLbitfield origArrayMask = span->arrayMask;
const GLenum chanType = span->array->ChanType;
- const GLboolean shader
- = ctx->FragmentProgram._Enabled
- || ctx->ShaderObjects._FragmentShaderPresent
- || ctx->ATIFragmentShader._Enabled;
+ const GLboolean shader = (ctx->FragmentProgram._Current
+ || ctx->ATIFragmentShader._Enabled);
const GLboolean shaderOrTexture = shader || ctx->Texture._EnabledUnits;
GLboolean deferredTexture;
@@ -1429,20 +1350,16 @@ _swrast_write_rgba_span( GLcontext *ctx, SWspan *span)
deferredTexture = GL_FALSE;
}
else if (shaderOrTexture) {
- if (ctx->FragmentProgram._Enabled) {
- if (ctx->FragmentProgram.Current->Base.OutputsWritten
+ if (ctx->FragmentProgram._Current) {
+ if (ctx->FragmentProgram._Current->Base.OutputsWritten
& (1 << FRAG_RESULT_DEPR)) {
- /* Z comes from fragment program */
+ /* Z comes from fragment program/shader */
deferredTexture = GL_FALSE;
}
else {
deferredTexture = GL_TRUE;
}
}
- else if (ctx->ShaderObjects._FragmentShaderPresent) {
- /* XXX how do we test if Z is written by shader? */
- deferredTexture = GL_FALSE; /* never defer to be safe */
- }
else {
/* ATI frag shader or conventional texturing */
deferredTexture = GL_TRUE;
@@ -1607,7 +1524,7 @@ _swrast_write_rgba_span( GLcontext *ctx, SWspan *span)
if (numDrawBuffers > 0) {
if (fb->_ColorDrawBuffers[output][0]->DataType
!= span->array->ChanType) {
- convert_color_type(ctx, span,
+ convert_color_type(span,
fb->_ColorDrawBuffers[output][0]->DataType);
}
}
@@ -1665,9 +1582,9 @@ end:
/**
- * Read RGBA pixels from frame buffer. Clipping will be done to prevent
+ * Read RGBA pixels from a renderbuffer. Clipping will be done to prevent
* reading ouside the buffer's boundaries.
- * \param type datatype for returned colors
+ * \param dstType datatype for returned colors
* \param rgba the returned colors
*/
void
@@ -1732,7 +1649,7 @@ _swrast_read_rgba_span( GLcontext *ctx, struct gl_renderbuffer *rb,
/**
- * Read CI pixels from frame buffer. Clipping will be done to prevent
+ * Read CI pixels from a renderbuffer. Clipping will be done to prevent
* reading ouside the buffer's boundaries.
*/
void
@@ -1815,8 +1732,7 @@ _swrast_get_values(GLcontext *ctx, struct gl_renderbuffer *rb,
for (i = 0; i < count; i++) {
if (x[i] >= 0 && y[i] >= 0 &&
- x[i] < (GLint) rb->Width &&
- y[i] < (GLint) rb->Height) {
+ x[i] < (GLint) rb->Width && y[i] < (GLint) rb->Height) {
/* inside */
if (inCount == 0)
inStart = i;
@@ -1850,13 +1766,13 @@ _swrast_put_row(GLcontext *ctx, struct gl_renderbuffer *rb,
{
GLint skip = 0;
- if (y < 0 || (GLint) y >= rb->Height)
+ if (y < 0 || y >= (GLint) rb->Height)
return; /* above or below */
if (x + (GLint) count <= 0 || x >= (GLint) rb->Width)
return; /* entirely left or right */
- if (x + count > rb->Width) {
+ if ((GLint) (x + count) > (GLint) rb->Width) {
/* right clip */
GLint clip = x + count - rb->Width;
count -= clip;
@@ -1885,10 +1801,10 @@ _swrast_get_row(GLcontext *ctx, struct gl_renderbuffer *rb,
{
GLint skip = 0;
- if (y < 0 || y >= rb->Height)
+ if (y < 0 || y >= (GLint) rb->Height)
return; /* above or below */
- if (x + (GLint) count <= 0 || x >= rb->Width)
+ if (x + (GLint) count <= 0 || x >= (GLint) rb->Width)
return; /* entirely left or right */
if (x + count > rb->Width) {
@@ -1933,7 +1849,7 @@ _swrast_get_dest_rgba(GLcontext *ctx, struct gl_renderbuffer *rb,
rbPixels = span->array->color.sz2.spec;
}
else {
- rbPixels = span->array->color.sz4.spec;
+ rbPixels = span->array->attribs[FRAG_ATTRIB_COL1];
}
/* Get destination values from renderbuffer */