summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast_setup
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-05-20 12:27:39 -0600
committerBrian <[email protected]>2007-05-20 12:27:39 -0600
commit9e8a961dd7d7b717a9fb4ecdea1c1b60ea355efe (patch)
tree60c87644ec38f4693ceecbf440b120b02e2d07e6 /src/mesa/swrast_setup
parentaa133a9dae53bc6aa50b88ee43deb8b34e8d0029 (diff)
Overhaul/simplify SWvertex and SWspan attribute handling.
Instead of separate fog/specular/texcoord/varying code, just treat all of them as generic attributes. Simplifies the point/line/triangle functions.
Diffstat (limited to 'src/mesa/swrast_setup')
-rw-r--r--src/mesa/swrast_setup/ss_context.c42
-rw-r--r--src/mesa/swrast_setup/ss_triangle.c52
-rw-r--r--src/mesa/swrast_setup/ss_tritmp.h88
3 files changed, 99 insertions, 83 deletions
diff --git a/src/mesa/swrast_setup/ss_context.c b/src/mesa/swrast_setup/ss_context.c
index 3f6d29403cc..9f83fde1f56 100644
--- a/src/mesa/swrast_setup/ss_context.c
+++ b/src/mesa/swrast_setup/ss_context.c
@@ -120,16 +120,25 @@ setup_vertex_format(GLcontext *ctx)
RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );
- EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, win );
-
- if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR0 ))
- EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color );
+ EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, attrib[FRAG_ATTRIB_WPOS] );
+
+ if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR0 )) {
+ if (ctx->FragmentProgram._Current
+ || ctx->ATIFragmentShader._Enabled
+ || CHAN_TYPE == GL_FLOAT)
+ EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4F, attrib[FRAG_ATTRIB_COL0]);
+ else
+ EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color );
+ }
- if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ))
- EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4CHAN_4F_RGBA, specular);
+ if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
+ EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4F, attrib[FRAG_ATTRIB_COL1]);
+ }
- if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR_INDEX ))
- EMIT_ATTR( _TNL_ATTRIB_COLOR_INDEX, EMIT_1F, index );
+ if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR_INDEX )) {
+ EMIT_ATTR( _TNL_ATTRIB_COLOR_INDEX, EMIT_1F,
+ attrib[FRAG_ATTRIB_CI][0] );
+ }
if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {
const GLint emit = ctx->FragmentProgram._Current ? EMIT_4F : EMIT_1F;
@@ -184,6 +193,10 @@ _swsetup_RenderStart( GLcontext *ctx )
_swsetup_choose_trifuncs(ctx);
}
+ if (swsetup->NewState & _NEW_PROGRAM) {
+ RENDERINPUTS_ZERO( swsetup->last_index_bitset );
+ }
+
swsetup->NewState = 0;
_swrast_render_start(ctx);
@@ -258,10 +271,10 @@ _swsetup_Translate( GLcontext *ctx, const void *vertex, SWvertex *dest )
_tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POS, tmp );
- dest->win[0] = m[0] * tmp[0] + m[12];
- dest->win[1] = m[5] * tmp[1] + m[13];
- dest->win[2] = m[10] * tmp[2] + m[14];
- dest->win[3] = tmp[3];
+ dest->attrib[FRAG_ATTRIB_WPOS][0] = m[0] * tmp[0] + m[12];
+ dest->attrib[FRAG_ATTRIB_WPOS][1] = m[5] * tmp[1] + m[13];
+ dest->attrib[FRAG_ATTRIB_WPOS][2] = m[10] * tmp[2] + m[14];
+ dest->attrib[FRAG_ATTRIB_WPOS][3] = tmp[3];
/** XXX try to limit these loops someday */
for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
@@ -276,13 +289,16 @@ _swsetup_Translate( GLcontext *ctx, const void *vertex, SWvertex *dest )
UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest->color, tmp );
_tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR1, tmp );
+ COPY_4V(dest->attrib[FRAG_ATTRIB_COL1], tmp);
+ /*
UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest->specular, tmp );
+ */
_tnl_get_attr( ctx, vertex, _TNL_ATTRIB_FOG, tmp );
dest->attrib[FRAG_ATTRIB_FOGC][0] = tmp[0];
_tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR_INDEX, tmp );
- dest->index = tmp[0];
+ dest->attrib[FRAG_ATTRIB_CI][0] = tmp[0];
/* XXX See _tnl_get_attr about pointsize ... */
_tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POINTSIZE, tmp );
diff --git a/src/mesa/swrast_setup/ss_triangle.c b/src/mesa/swrast_setup/ss_triangle.c
index 628e9288e87..b4207f2c64a 100644
--- a/src/mesa/swrast_setup/ss_triangle.c
+++ b/src/mesa/swrast_setup/ss_triangle.c
@@ -57,7 +57,7 @@ static void _swsetup_render_line_tri( GLcontext *ctx,
SWvertex *v1 = &verts[e1];
SWvertex *v2 = &verts[e2];
GLchan c[2][4];
- GLchan s[2][4];
+ GLfloat s[2][4];
GLfloat i[2];
/* cull testing */
@@ -71,17 +71,17 @@ static void _swsetup_render_line_tri( GLcontext *ctx,
if (ctx->Light.ShadeModel == GL_FLAT) {
COPY_CHAN4(c[0], v0->color);
COPY_CHAN4(c[1], v1->color);
- COPY_CHAN4(s[0], v0->specular);
- COPY_CHAN4(s[1], v1->specular);
- i[0] = v0->index;
- i[1] = v1->index;
+ COPY_4V(s[0], v0->attrib[FRAG_ATTRIB_COL1]);
+ COPY_4V(s[1], v1->attrib[FRAG_ATTRIB_COL1]);
+ i[0] = v0->attrib[FRAG_ATTRIB_CI][0];
+ i[1] = v1->attrib[FRAG_ATTRIB_CI][0];
COPY_CHAN4(v0->color, v2->color);
COPY_CHAN4(v1->color, v2->color);
- COPY_CHAN4(v0->specular, v2->specular);
- COPY_CHAN4(v1->specular, v2->specular);
- v0->index = v2->index;
- v1->index = v2->index;
+ COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
+ COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
+ v0->attrib[FRAG_ATTRIB_CI][0] = v2->attrib[FRAG_ATTRIB_CI][0];
+ v1->attrib[FRAG_ATTRIB_CI][0] = v2->attrib[FRAG_ATTRIB_CI][0];
}
if (swsetup->render_prim == GL_POLYGON) {
@@ -97,10 +97,10 @@ static void _swsetup_render_line_tri( GLcontext *ctx,
if (ctx->Light.ShadeModel == GL_FLAT) {
COPY_CHAN4(v0->color, c[0]);
COPY_CHAN4(v1->color, c[1]);
- COPY_CHAN4(v0->specular, s[0]);
- COPY_CHAN4(v1->specular, s[1]);
- v0->index = i[0];
- v1->index = i[1];
+ COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], s[0]);
+ COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], s[1]);
+ v0->attrib[FRAG_ATTRIB_CI][0] = i[0];
+ v1->attrib[FRAG_ATTRIB_CI][0] = i[1];
}
}
@@ -116,7 +116,7 @@ static void _swsetup_render_point_tri( GLcontext *ctx,
SWvertex *v1 = &verts[e1];
SWvertex *v2 = &verts[e2];
GLchan c[2][4];
- GLchan s[2][4];
+ GLfloat s[2][4];
GLfloat i[2];
/* cull testing */
@@ -131,18 +131,18 @@ static void _swsetup_render_point_tri( GLcontext *ctx,
/* save colors/indexes for v0, v1 vertices */
COPY_CHAN4(c[0], v0->color);
COPY_CHAN4(c[1], v1->color);
- COPY_CHAN4(s[0], v0->specular);
- COPY_CHAN4(s[1], v1->specular);
- i[0] = v0->index;
- i[1] = v1->index;
+ COPY_4V(s[0], v0->attrib[FRAG_ATTRIB_COL1]);
+ COPY_4V(s[1], v1->attrib[FRAG_ATTRIB_COL1]);
+ i[0] = v0->attrib[FRAG_ATTRIB_CI][0];
+ i[1] = v1->attrib[FRAG_ATTRIB_CI][0];
/* copy v2 color/indexes to v0, v1 indexes */
COPY_CHAN4(v0->color, v2->color);
COPY_CHAN4(v1->color, v2->color);
- COPY_CHAN4(v0->specular, v2->specular);
- COPY_CHAN4(v1->specular, v2->specular);
- v0->index = v2->index;
- v1->index = v2->index;
+ COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
+ COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
+ v0->attrib[FRAG_ATTRIB_CI][0] = v2->attrib[FRAG_ATTRIB_CI][0];
+ v1->attrib[FRAG_ATTRIB_CI][0] = v2->attrib[FRAG_ATTRIB_CI][0];
}
if (ef[e0]) _swrast_Point( ctx, v0 );
@@ -153,10 +153,10 @@ static void _swsetup_render_point_tri( GLcontext *ctx,
/* restore v0, v1 colores/indexes */
COPY_CHAN4(v0->color, c[0]);
COPY_CHAN4(v1->color, c[1]);
- COPY_CHAN4(v0->specular, s[0]);
- COPY_CHAN4(v1->specular, s[1]);
- v0->index = i[0];
- v1->index = i[1];
+ COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], s[0]);
+ COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], s[1]);
+ v0->attrib[FRAG_ATTRIB_CI][0] = i[0];
+ v1->attrib[FRAG_ATTRIB_CI][0] = i[1];
}
_swrast_flush(ctx);
}
diff --git a/src/mesa/swrast_setup/ss_tritmp.h b/src/mesa/swrast_setup/ss_tritmp.h
index 1fdf0cb5999..9fcde31644d 100644
--- a/src/mesa/swrast_setup/ss_tritmp.h
+++ b/src/mesa/swrast_setup/ss_tritmp.h
@@ -36,7 +36,7 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
GLenum mode = GL_FILL;
GLuint facing = 0;
GLchan saved_color[3][4];
- GLchan saved_spec[3][4];
+ GLfloat saved_spec[3][4];
GLfloat saved_index[3];
v[0] = &verts[e0];
@@ -46,10 +46,10 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
if (IND & (SS_TWOSIDE_BIT | SS_OFFSET_BIT | SS_UNFILLED_BIT))
{
- GLfloat ex = v[0]->win[0] - v[2]->win[0];
- GLfloat ey = v[0]->win[1] - v[2]->win[1];
- GLfloat fx = v[1]->win[0] - v[2]->win[0];
- GLfloat fy = v[1]->win[1] - v[2]->win[1];
+ GLfloat ex = v[0]->attrib[FRAG_ATTRIB_WPOS][0] - v[2]->attrib[FRAG_ATTRIB_WPOS][0];
+ GLfloat ey = v[0]->attrib[FRAG_ATTRIB_WPOS][1] - v[2]->attrib[FRAG_ATTRIB_WPOS][1];
+ GLfloat fx = v[1]->attrib[FRAG_ATTRIB_WPOS][0] - v[2]->attrib[FRAG_ATTRIB_WPOS][0];
+ GLfloat fy = v[1]->attrib[FRAG_ATTRIB_WPOS][1] - v[2]->attrib[FRAG_ATTRIB_WPOS][1];
GLfloat cc = ex*fy - ey*fx;
if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT))
@@ -85,30 +85,30 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
if (VB->SecondaryColorPtr[1]) {
GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
- COPY_CHAN4(saved_spec[0], v[0]->specular);
- COPY_CHAN4(saved_spec[1], v[1]->specular);
- COPY_CHAN4(saved_spec[2], v[2]->specular);
+ COPY_4V(saved_spec[0], v[0]->attrib[FRAG_ATTRIB_COL1]);
+ COPY_4V(saved_spec[1], v[1]->attrib[FRAG_ATTRIB_COL1]);
+ COPY_4V(saved_spec[2], v[2]->attrib[FRAG_ATTRIB_COL1]);
if (VB->SecondaryColorPtr[1]->stride) {
- SS_SPEC(v[0]->specular, vbspec[e0]);
- SS_SPEC(v[1]->specular, vbspec[e1]);
- SS_SPEC(v[2]->specular, vbspec[e2]);
+ SS_SPEC(v[0]->attrib[FRAG_ATTRIB_COL1], vbspec[e0]);
+ SS_SPEC(v[1]->attrib[FRAG_ATTRIB_COL1], vbspec[e1]);
+ SS_SPEC(v[2]->attrib[FRAG_ATTRIB_COL1], vbspec[e2]);
}
else {
- SS_SPEC(v[0]->specular, vbspec[0]);
- SS_SPEC(v[1]->specular, vbspec[0]);
- SS_SPEC(v[2]->specular, vbspec[0]);
+ SS_SPEC(v[0]->attrib[FRAG_ATTRIB_COL1], vbspec[0]);
+ SS_SPEC(v[1]->attrib[FRAG_ATTRIB_COL1], vbspec[0]);
+ SS_SPEC(v[2]->attrib[FRAG_ATTRIB_COL1], vbspec[0]);
}
}
} else {
GLfloat *vbindex = (GLfloat *)VB->IndexPtr[1]->data;
- saved_index[0] = v[0]->index;
- saved_index[1] = v[1]->index;
- saved_index[2] = v[2]->index;
+ saved_index[0] = v[0]->attrib[FRAG_ATTRIB_CI][0];
+ saved_index[1] = v[1]->attrib[FRAG_ATTRIB_CI][0];
+ saved_index[2] = v[2]->attrib[FRAG_ATTRIB_CI][0];
- SS_IND(v[0]->index, (GLuint) vbindex[e0]);
- SS_IND(v[1]->index, (GLuint) vbindex[e1]);
- SS_IND(v[2]->index, (GLuint) vbindex[e2]);
+ SS_IND(v[0]->attrib[FRAG_ATTRIB_CI][0], (GLuint) vbindex[e0]);
+ SS_IND(v[1]->attrib[FRAG_ATTRIB_CI][0], (GLuint) vbindex[e1]);
+ SS_IND(v[2]->attrib[FRAG_ATTRIB_CI][0], (GLuint) vbindex[e2]);
}
}
}
@@ -117,9 +117,9 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
if (IND & SS_OFFSET_BIT)
{
offset = ctx->Polygon.OffsetUnits * ctx->DrawBuffer->_MRD;
- z[0] = v[0]->win[2];
- z[1] = v[1]->win[2];
- z[2] = v[2]->win[2];
+ z[0] = v[0]->attrib[FRAG_ATTRIB_WPOS][2];
+ z[1] = v[1]->attrib[FRAG_ATTRIB_WPOS][2];
+ z[2] = v[2]->attrib[FRAG_ATTRIB_WPOS][2];
if (cc * cc > 1e-16) {
const GLfloat ez = z[0] - z[2];
const GLfloat fz = z[1] - z[2];
@@ -130,40 +130,40 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
/* Unfortunately, we need to clamp to prevent negative Zs below.
* Technically, we should do the clamping per-fragment.
*/
- offset = MAX2(offset, -v[0]->win[2]);
- offset = MAX2(offset, -v[1]->win[2]);
- offset = MAX2(offset, -v[2]->win[2]);
+ offset = MAX2(offset, -v[0]->attrib[FRAG_ATTRIB_WPOS][2]);
+ offset = MAX2(offset, -v[1]->attrib[FRAG_ATTRIB_WPOS][2]);
+ offset = MAX2(offset, -v[2]->attrib[FRAG_ATTRIB_WPOS][2]);
}
}
}
if (mode == GL_POINT) {
if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetPoint) {
- v[0]->win[2] += offset;
- v[1]->win[2] += offset;
- v[2]->win[2] += offset;
+ v[0]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
+ v[1]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
+ v[2]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
}
_swsetup_render_point_tri( ctx, e0, e1, e2, facing );
} else if (mode == GL_LINE) {
if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) {
- v[0]->win[2] += offset;
- v[1]->win[2] += offset;
- v[2]->win[2] += offset;
+ v[0]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
+ v[1]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
+ v[2]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
}
_swsetup_render_line_tri( ctx, e0, e1, e2, facing );
} else {
if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetFill) {
- v[0]->win[2] += offset;
- v[1]->win[2] += offset;
- v[2]->win[2] += offset;
+ v[0]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
+ v[1]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
+ v[2]->attrib[FRAG_ATTRIB_WPOS][2] += offset;
}
_swrast_Triangle( ctx, v[0], v[1], v[2] );
}
if (IND & SS_OFFSET_BIT) {
- v[0]->win[2] = z[0];
- v[1]->win[2] = z[1];
- v[2]->win[2] = z[2];
+ v[0]->attrib[FRAG_ATTRIB_WPOS][2] = z[0];
+ v[1]->attrib[FRAG_ATTRIB_WPOS][2] = z[1];
+ v[2]->attrib[FRAG_ATTRIB_WPOS][2] = z[2];
}
if (IND & SS_TWOSIDE_BIT) {
@@ -176,14 +176,14 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
}
if (VB->SecondaryColorPtr[1]) {
- COPY_CHAN4(v[0]->specular, saved_spec[0]);
- COPY_CHAN4(v[1]->specular, saved_spec[1]);
- COPY_CHAN4(v[2]->specular, saved_spec[2]);
+ COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL1], saved_spec[0]);
+ COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL1], saved_spec[1]);
+ COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL1], saved_spec[2]);
}
} else {
- v[0]->index = saved_index[0];
- v[1]->index = saved_index[1];
- v[2]->index = saved_index[2];
+ v[0]->attrib[FRAG_ATTRIB_CI][0] = saved_index[0];
+ v[1]->attrib[FRAG_ATTRIB_CI][0] = saved_index[1];
+ v[2]->attrib[FRAG_ATTRIB_CI][0] = saved_index[2];
}
}
}