summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast/s_fragprog.c
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-02-02 11:20:08 -0700
committerBrian <[email protected]>2007-02-02 11:20:08 -0700
commit531348e814359a262eb1fe0a294749ab1b88045f (patch)
tree455b2167a73f860fec5789ceaada0741e4a0a22e /src/mesa/swrast/s_fragprog.c
parente4f976b8b9d74a74b5816146cb11880c3a493929 (diff)
simplify derivative-related code
Diffstat (limited to 'src/mesa/swrast/s_fragprog.c')
-rw-r--r--src/mesa/swrast/s_fragprog.c131
1 files changed, 41 insertions, 90 deletions
diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index 090fd6dd97d..343cdf5bc53 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -274,31 +274,18 @@ fetch_vector4_deriv( GLcontext *ctx,
}
break;
case FRAG_ATTRIB_COL0:
- if (xOrY == 'X') {
- src[0] = span->attrStepX[FRAG_ATTRIB_COL0][0] * (1.0F / CHAN_MAXF);
- src[1] = span->attrStepX[FRAG_ATTRIB_COL0][1] * (1.0F / CHAN_MAXF);
- src[2] = span->attrStepX[FRAG_ATTRIB_COL0][2] * (1.0F / CHAN_MAXF);
- src[3] = span->attrStepX[FRAG_ATTRIB_COL0][3] * (1.0F / CHAN_MAXF);
- }
- else {
- src[0] = span->attrStepY[FRAG_ATTRIB_COL0][0] * (1.0F / CHAN_MAXF);
- src[1] = span->attrStepY[FRAG_ATTRIB_COL0][1] * (1.0F / CHAN_MAXF);
- src[2] = span->attrStepY[FRAG_ATTRIB_COL0][2] * (1.0F / CHAN_MAXF);
- src[3] = span->attrStepY[FRAG_ATTRIB_COL0][3] * (1.0F / CHAN_MAXF);
- }
- break;
case FRAG_ATTRIB_COL1:
if (xOrY == 'X') {
- src[0] = span->attrStepX[FRAG_ATTRIB_COL1][0] * (1.0F / CHAN_MAXF);
- src[1] = span->attrStepX[FRAG_ATTRIB_COL1][1] * (1.0F / CHAN_MAXF);
- src[2] = span->attrStepX[FRAG_ATTRIB_COL1][2] * (1.0F / CHAN_MAXF);
- src[3] = span->attrStepX[FRAG_ATTRIB_COL1][3] * (1.0F / CHAN_MAXF);
+ src[0] = span->attrStepX[source->Index][0] * (1.0F / CHAN_MAXF);
+ src[1] = span->attrStepX[source->Index][1] * (1.0F / CHAN_MAXF);
+ src[2] = span->attrStepX[source->Index][2] * (1.0F / CHAN_MAXF);
+ src[3] = span->attrStepX[source->Index][3] * (1.0F / CHAN_MAXF);
}
else {
- src[0] = span->attrStepY[FRAG_ATTRIB_COL1][0] * (1.0F / CHAN_MAXF);
- src[1] = span->attrStepY[FRAG_ATTRIB_COL1][1] * (1.0F / CHAN_MAXF);
- src[2] = span->attrStepY[FRAG_ATTRIB_COL1][2] * (1.0F / CHAN_MAXF);
- src[3] = span->attrStepY[FRAG_ATTRIB_COL1][3] * (1.0F / CHAN_MAXF);
+ src[0] = span->attrStepY[source->Index][0] * (1.0F / CHAN_MAXF);
+ src[1] = span->attrStepY[source->Index][1] * (1.0F / CHAN_MAXF);
+ src[2] = span->attrStepY[source->Index][2] * (1.0F / CHAN_MAXF);
+ src[3] = span->attrStepY[source->Index][3] * (1.0F / CHAN_MAXF);
}
break;
case FRAG_ATTRIB_FOGC:
@@ -315,14 +302,9 @@ fetch_vector4_deriv( GLcontext *ctx,
src[3] = 0.0;
}
break;
- case FRAG_ATTRIB_TEX0:
- case FRAG_ATTRIB_TEX1:
- case FRAG_ATTRIB_TEX2:
- case FRAG_ATTRIB_TEX3:
- case FRAG_ATTRIB_TEX4:
- case FRAG_ATTRIB_TEX5:
- case FRAG_ATTRIB_TEX6:
- case FRAG_ATTRIB_TEX7:
+ default:
+ assert(source->Index < FRAG_ATTRIB_MAX);
+ /* texcoord or varying */
if (xOrY == 'X') {
/* this is a little tricky - I think I've got it right */
const GLfloat invQ = 1.0f / (span->attrStart[source->Index][3]
@@ -342,8 +324,6 @@ fetch_vector4_deriv( GLcontext *ctx,
src[3] = span->attrStepY[source->Index][3] * invQ;
}
break;
- default:
- return GL_FALSE;
}
result[0] = src[GET_SWZ(source->Swizzle, 0)];
@@ -543,7 +523,7 @@ init_machine_deriv( GLcontext *ctx,
const SWspan *span, char xOrY,
struct fp_machine *dMachine )
{
- GLuint u, v;
+ GLuint attr;
ASSERT(xOrY == 'X' || xOrY == 'Y');
@@ -572,34 +552,23 @@ init_machine_deriv( GLcontext *ctx,
wpos[3] += span->attrStepY[FRAG_ATTRIB_WPOS][3];
}
}
- if (program->Base.InputsRead & FRAG_BIT_COL0) {
- GLfloat *col0 = machine->Attribs[FRAG_ATTRIB_COL0][machine->CurFrag];
- if (xOrY == 'X') {
- col0[0] += span->attrStepX[FRAG_ATTRIB_COL0][0] * (1.0F / CHAN_MAXF);
- col0[1] += span->attrStepX[FRAG_ATTRIB_COL0][1] * (1.0F / CHAN_MAXF);
- col0[2] += span->attrStepX[FRAG_ATTRIB_COL0][2] * (1.0F / CHAN_MAXF);
- col0[3] += span->attrStepX[FRAG_ATTRIB_COL0][3] * (1.0F / CHAN_MAXF);
- }
- else {
- col0[0] += span->attrStepY[FRAG_ATTRIB_COL0][0] * (1.0F / CHAN_MAXF);
- col0[1] += span->attrStepY[FRAG_ATTRIB_COL0][1] * (1.0F / CHAN_MAXF);
- col0[2] += span->attrStepY[FRAG_ATTRIB_COL0][2] * (1.0F / CHAN_MAXF);
- col0[3] += span->attrStepY[FRAG_ATTRIB_COL0][3] * (1.0F / CHAN_MAXF);
- }
- }
- if (program->Base.InputsRead & FRAG_BIT_COL1) {
- GLfloat *col1 = machine->Attribs[FRAG_ATTRIB_COL1][machine->CurFrag];
- if (xOrY == 'X') {
- col1[0] += span->attrStepX[FRAG_ATTRIB_COL1][0] * (1.0F / CHAN_MAXF);
- col1[1] += span->attrStepX[FRAG_ATTRIB_COL1][1] * (1.0F / CHAN_MAXF);
- col1[2] += span->attrStepX[FRAG_ATTRIB_COL1][2] * (1.0F / CHAN_MAXF);
- col1[3] += span->attrStepX[FRAG_ATTRIB_COL1][3] * (1.0F / CHAN_MAXF);
- }
- else {
- col1[0] += span->attrStepY[FRAG_ATTRIB_COL1][0] * (1.0F / CHAN_MAXF);
- col1[1] += span->attrStepY[FRAG_ATTRIB_COL1][1] * (1.0F / CHAN_MAXF);
- col1[2] += span->attrStepY[FRAG_ATTRIB_COL1][2] * (1.0F / CHAN_MAXF);
- col1[3] += span->attrStepY[FRAG_ATTRIB_COL1][3] * (1.0F / CHAN_MAXF);
+
+ /* primary, secondary colors */
+ for (attr = FRAG_ATTRIB_COL0; attr <= FRAG_ATTRIB_COL1; attr++) {
+ if (program->Base.InputsRead & (1 << attr)) {
+ GLfloat *col = machine->Attribs[attr][machine->CurFrag];
+ if (xOrY == 'X') {
+ col[0] += span->attrStepX[attr][0] * (1.0F / CHAN_MAXF);
+ col[1] += span->attrStepX[attr][1] * (1.0F / CHAN_MAXF);
+ col[2] += span->attrStepX[attr][2] * (1.0F / CHAN_MAXF);
+ col[3] += span->attrStepX[attr][3] * (1.0F / CHAN_MAXF);
+ }
+ else {
+ col[0] += span->attrStepY[attr][0] * (1.0F / CHAN_MAXF);
+ col[1] += span->attrStepY[attr][1] * (1.0F / CHAN_MAXF);
+ col[2] += span->attrStepY[attr][2] * (1.0F / CHAN_MAXF);
+ col[3] += span->attrStepY[attr][3] * (1.0F / CHAN_MAXF);
+ }
}
}
if (program->Base.InputsRead & FRAG_BIT_FOGC) {
@@ -611,40 +580,22 @@ init_machine_deriv( GLcontext *ctx,
fogc[0] += span->attrStepY[FRAG_ATTRIB_FOGC][0];
}
}
- for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
- if (program->Base.InputsRead & FRAG_BIT_TEX(u)) {
- GLfloat *tex = machine->Attribs[FRAG_ATTRIB_TEX0 + u][machine->CurFrag];
+ /* texcoord and varying vars */
+ for (attr = FRAG_ATTRIB_TEX0; attr < FRAG_ATTRIB_MAX; attr++) {
+ if (program->Base.InputsRead & (1 << attr)) {
+ GLfloat *val = machine->Attribs[attr][machine->CurFrag];
/* XXX perspective-correct interpolation */
if (xOrY == 'X') {
- tex[0] += span->attrStepX[FRAG_ATTRIB_TEX0 + u][0];
- tex[1] += span->attrStepX[FRAG_ATTRIB_TEX0 + u][1];
- tex[2] += span->attrStepX[FRAG_ATTRIB_TEX0 + u][2];
- tex[3] += span->attrStepX[FRAG_ATTRIB_TEX0 + u][3];
- }
- else {
- tex[0] += span->attrStepY[FRAG_ATTRIB_TEX0 + u][0];
- tex[1] += span->attrStepY[FRAG_ATTRIB_TEX0 + u][1];
- tex[2] += span->attrStepY[FRAG_ATTRIB_TEX0 + u][2];
- tex[3] += span->attrStepY[FRAG_ATTRIB_TEX0 + u][3];
- }
- }
- }
-
- for (v = 0; v < ctx->Const.MaxVarying; v++) {
- if (program->Base.InputsRead & FRAG_BIT_VAR(v)) {
- GLfloat *var = machine->Attribs[FRAG_ATTRIB_VAR0 + v][machine->CurFrag];
- GLuint attr = FRAG_ATTRIB_VAR0 + v;
- if (xOrY == 'X') {
- var[0] += span->attrStepX[attr][0];
- var[1] += span->attrStepX[attr][1];
- var[2] += span->attrStepX[attr][2];
- var[3] += span->attrStepX[attr][3];
+ val[0] += span->attrStepX[attr][0];
+ val[1] += span->attrStepX[attr][1];
+ val[2] += span->attrStepX[attr][2];
+ val[3] += span->attrStepX[attr][3];
}
else {
- var[0] += span->attrStepY[attr][0];
- var[1] += span->attrStepY[attr][1];
- var[2] += span->attrStepY[attr][2];
- var[3] += span->attrStepY[attr][3];
+ val[0] += span->attrStepY[attr][0];
+ val[1] += span->attrStepY[attr][1];
+ val[2] += span->attrStepY[attr][2];
+ val[3] += span->attrStepY[attr][3];
}
}
}