summaryrefslogtreecommitdiff
path: root/src/mesa/swrast_setup
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/swrast_setup')
-rw-r--r--src/mesa/swrast_setup/ss_context.c138
-rw-r--r--src/mesa/swrast_setup/ss_context.h1
-rw-r--r--src/mesa/swrast_setup/ss_triangle.c95
-rw-r--r--src/mesa/swrast_setup/ss_tritmp.h10
-rw-r--r--src/mesa/swrast_setup/swrast_setup.h12
5 files changed, 148 insertions, 108 deletions
diff --git a/src/mesa/swrast_setup/ss_context.c b/src/mesa/swrast_setup/ss_context.c
index de3f36288a..a6c7aa8740 100644
--- a/src/mesa/swrast_setup/ss_context.c
+++ b/src/mesa/swrast_setup/ss_context.c
@@ -1,4 +1,4 @@
-/* $Id: ss_context.c,v 1.7 2001/01/08 04:09:41 keithw Exp $ */
+/* $Id: ss_context.c,v 1.8 2001/01/16 05:29:43 keithw Exp $ */
/*
* Mesa 3-D graphics library
@@ -27,64 +27,17 @@
* Keith Whitwell <keithw@valinux.com>
*/
-
#include "glheader.h"
#include "mem.h"
-
-
#include "ss_context.h"
#include "ss_triangle.h"
#include "ss_vb.h"
-
#include "swrast_setup.h"
-
#include "tnl/t_context.h"
-/* Stub for swsetup->Triangle to select a true triangle function
- * after a state change.
- */
-static void
-_swsetup_validate_quad( GLcontext *ctx, GLuint v0, GLuint v1,
- GLuint v2, GLuint v3 )
-{
- _swsetup_choose_trifuncs( ctx );
- SWSETUP_CONTEXT(ctx)->Quad( ctx, v0, v1, v2, v3 );
-}
-
-static void
-_swsetup_validate_triangle( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2 )
-{
- _swsetup_choose_trifuncs( ctx );
- SWSETUP_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2 );
-}
-
-static void
-_swsetup_validate_line( GLcontext *ctx, GLuint v0, GLuint v1 )
-{
- _swsetup_choose_trifuncs( ctx );
- SWSETUP_CONTEXT(ctx)->Line( ctx, v0, v1 );
-}
-
-
-static void
-_swsetup_validate_points( GLcontext *ctx, GLuint first, GLuint last )
-{
- _swsetup_choose_trifuncs( ctx );
- SWSETUP_CONTEXT(ctx)->Points( ctx, first, last );
-}
-
-
-
-static void
-_swsetup_validate_buildprojverts( GLcontext *ctx,
- GLuint start, GLuint end, GLuint new_inputs )
-{
- _swsetup_choose_rastersetup_func( ctx );
- SWSETUP_CONTEXT(ctx)->BuildProjVerts( ctx, start, end, new_inputs );
-}
-
-
+
#define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
+ _NEW_LIGHT| \
_NEW_TEXTURE| \
_NEW_COLOR| \
_NEW_FOG| \
@@ -93,38 +46,13 @@ _swsetup_validate_buildprojverts( GLcontext *ctx,
#define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
-#if 0
-/* TODO: sleep/wakeup mechanism
- */
-static void
-_swsetup_sleep( GLcontext *ctx, GLuint new_state )
-{
-}
-#endif
-
-static void
-_swsetup_invalidate_state( GLcontext *ctx, GLuint new_state )
-{
- SScontext *swsetup = SWSETUP_CONTEXT(ctx);
-
- swsetup->NewState |= new_state;
-
- if (new_state & _SWSETUP_NEW_RENDERINDEX) {
- swsetup->Triangle = _swsetup_validate_triangle;
- swsetup->Line = _swsetup_validate_line;
- swsetup->Points = _swsetup_validate_points;
- swsetup->Quad = _swsetup_validate_quad;
- }
-
- if (new_state & _SWSETUP_NEW_VERTS) {
- swsetup->BuildProjVerts = _swsetup_validate_buildprojverts;
- }
-}
-
-
-
/* Dispatch from these fixed entrypoints to the state-dependent
- * functions:
+ * functions.
+ *
+ * The design of swsetup suggests that we could really program
+ * ctx->Driver.TriangleFunc directly from _swsetup_RenderStart, and
+ * avoid this second level of indirection. However, this is more
+ * convient for fallback cases in hardware rasterization drivers.
*/
void
_swsetup_Quad( GLcontext *ctx, GLuint v0, GLuint v1,
@@ -146,7 +74,6 @@ _swsetup_Line( GLcontext *ctx, GLuint v0, GLuint v1 )
SWSETUP_CONTEXT(ctx)->Line( ctx, v0, v1 );
}
-
void
_swsetup_Points( GLcontext *ctx, GLuint first, GLuint last )
{
@@ -160,12 +87,6 @@ _swsetup_BuildProjectedVertices( GLcontext *ctx, GLuint start, GLuint end,
SWSETUP_CONTEXT(ctx)->BuildProjVerts( ctx, start, end, new_inputs );
}
-void
-_swsetup_InvalidateState( GLcontext *ctx, GLuint new_state )
-{
- SWSETUP_CONTEXT(ctx)->InvalidateState( ctx, new_state );
-}
-
GLboolean
_swsetup_CreateContext( GLcontext *ctx )
@@ -185,13 +106,6 @@ _swsetup_CreateContext( GLcontext *ctx )
ctx->swsetup_context = swsetup;
swsetup->NewState = ~0;
- swsetup->InvalidateState = _swsetup_invalidate_state;
- swsetup->Quad = _swsetup_validate_quad;
- swsetup->Triangle = _swsetup_validate_triangle;
- swsetup->Line = _swsetup_validate_line;
- swsetup->Points = _swsetup_validate_points;
- swsetup->BuildProjVerts = _swsetup_validate_buildprojverts;
-
_swsetup_vb_init( ctx );
_swsetup_trifuncs_init( ctx );
@@ -210,10 +124,38 @@ _swsetup_DestroyContext( GLcontext *ctx )
}
}
+void
+_swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode )
+{
+ SWSETUP_CONTEXT(ctx)->render_prim = mode;
+}
+
+void
+_swsetup_RenderStart( GLcontext *ctx )
+{
+ SScontext *swsetup = SWSETUP_CONTEXT(ctx);
+ GLuint new_state = swsetup->NewState;
+
+ if (new_state & _SWSETUP_NEW_RENDERINDEX) {
+ _swsetup_choose_trifuncs( ctx );
+ }
+
+ if (new_state & _SWSETUP_NEW_VERTS) {
+ _swsetup_choose_rastersetup_func( ctx );
+ }
+
+ swsetup->NewState = 0;
+}
+
+void
+_swsetup_RenderFinish( GLcontext *ctx )
+{
+ _swrast_flush( ctx );
+}
void
-_swsetup_RenderPrimNoop( GLcontext *ctx, GLenum mode )
+_swsetup_InvalidateState( GLcontext *ctx, GLuint new_state )
{
- (void) ctx;
- (void) mode;
+ SWSETUP_CONTEXT(ctx)->NewState |= new_state;
}
+
diff --git a/src/mesa/swrast_setup/ss_context.h b/src/mesa/swrast_setup/ss_context.h
index 601ae9eb34..957a8fc3fc 100644
--- a/src/mesa/swrast_setup/ss_context.h
+++ b/src/mesa/swrast_setup/ss_context.h
@@ -54,6 +54,7 @@ typedef struct {
void (*Points)( GLcontext *ctx, GLuint first, GLuint last );
SWvertex *verts;
+ GLenum render_prim;
} SScontext;
diff --git a/src/mesa/swrast_setup/ss_triangle.c b/src/mesa/swrast_setup/ss_triangle.c
index 73a19ad38a..337a45acc5 100644
--- a/src/mesa/swrast_setup/ss_triangle.c
+++ b/src/mesa/swrast_setup/ss_triangle.c
@@ -26,6 +26,7 @@
*/
#include "glheader.h"
+#include "colormac.h"
#include "macros.h"
#include "mtypes.h"
@@ -44,6 +45,100 @@ static triangle_func tri_tab[SS_MAX_TRIFUNC];
static quad_func quad_tab[SS_MAX_TRIFUNC];
+static void _swsetup_render_line_tri( GLcontext *ctx,
+ GLuint e0, GLuint e1, GLuint e2 )
+{
+ SScontext *swsetup = SWSETUP_CONTEXT(ctx);
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+ GLubyte *ef = VB->EdgeFlag;
+ SWvertex *verts = swsetup->verts;
+ SWvertex *v0 = &verts[e0];
+ SWvertex *v1 = &verts[e1];
+ SWvertex *v2 = &verts[e2];
+ GLchan c[2][4];
+ GLchan s[2][4];
+ GLuint i[2];
+
+ if (ctx->_TriangleCaps & DD_FLATSHADE) {
+ 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_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;
+ }
+
+ if (swsetup->render_prim == GL_POLYGON) {
+ if (ef[e2]) _swrast_Line( ctx, v2, v0 );
+ if (ef[e0]) _swrast_Line( ctx, v0, v1 );
+ if (ef[e1]) _swrast_Line( ctx, v1, v2 );
+ } else {
+ if (ef[e0]) _swrast_Line( ctx, v0, v1 );
+ if (ef[e1]) _swrast_Line( ctx, v1, v2 );
+ if (ef[e2]) _swrast_Line( ctx, v2, v0 );
+ }
+
+ if (ctx->_TriangleCaps & DD_FLATSHADE) {
+ 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];
+ }
+}
+
+static void _swsetup_render_point_tri( GLcontext *ctx,
+ GLuint e0, GLuint e1, GLuint e2 )
+{
+ SScontext *swsetup = SWSETUP_CONTEXT(ctx);
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+ GLubyte *ef = VB->EdgeFlag;
+ SWvertex *verts = swsetup->verts;
+ SWvertex *v0 = &verts[e0];
+ SWvertex *v1 = &verts[e1];
+ SWvertex *v2 = &verts[e2];
+ GLchan c[2][4];
+ GLchan s[2][4];
+ GLuint i[2];
+
+ if (ctx->_TriangleCaps & DD_FLATSHADE) {
+ 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_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;
+ }
+
+ if (ef[e0]) _swrast_Point( ctx, v0 );
+ if (ef[e1]) _swrast_Point( ctx, v1 );
+ if (ef[e2]) _swrast_Point( ctx, v2 );
+
+ if (ctx->_TriangleCaps & DD_FLATSHADE) {
+ 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];
+ }
+}
+
#define SS_COLOR(a,b) COPY_4UBV(a,b)
#define SS_SPEC(a,b) COPY_4UBV(a,b)
#define SS_IND(a,b) (a = b)
diff --git a/src/mesa/swrast_setup/ss_tritmp.h b/src/mesa/swrast_setup/ss_tritmp.h
index 936774aba4..cc0c511c35 100644
--- a/src/mesa/swrast_setup/ss_tritmp.h
+++ b/src/mesa/swrast_setup/ss_tritmp.h
@@ -99,25 +99,19 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
}
if (mode == GL_POINT) {
- GLubyte *ef = VB->EdgeFlag;
if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetPoint) {
v[0]->win[2] += offset;
v[1]->win[2] += offset;
v[2]->win[2] += offset;
}
- if (ef[e0]) _swrast_Point( ctx, v[0] );
- if (ef[e1]) _swrast_Point( ctx, v[1] );
- if (ef[e2]) _swrast_Point( ctx, v[2] );
+ _swsetup_render_point_tri( ctx, e0, e1, e2 );
} else if (mode == GL_LINE) {
- GLubyte *ef = VB->EdgeFlag;
if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) {
v[0]->win[2] += offset;
v[1]->win[2] += offset;
v[2]->win[2] += offset;
}
- if (ef[e0]) _swrast_Line( ctx, v[0], v[1] );
- if (ef[e1]) _swrast_Line( ctx, v[1], v[2] );
- if (ef[e2]) _swrast_Line( ctx, v[2], v[0] );
+ _swsetup_render_line_tri( ctx, e0, e1, e2 );
} else {
if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetFill) {
v[0]->win[2] += offset;
diff --git a/src/mesa/swrast_setup/swrast_setup.h b/src/mesa/swrast_setup/swrast_setup.h
index 70b1113c90..f3607c75e9 100644
--- a/src/mesa/swrast_setup/swrast_setup.h
+++ b/src/mesa/swrast_setup/swrast_setup.h
@@ -25,7 +25,9 @@
* Keith Whitwell <keithw@valinux.com>
*/
-/* Public interface to the swrast_setup module.
+/* Public interface to the swrast_setup module. This module provides
+ * an implementation of the driver interface to t_vb_render.c, and uses
+ * the software rasterizer (swrast) to perform actual rasterization.
*/
#ifndef SWRAST_SETUP_H
@@ -59,6 +61,12 @@ extern void
_swsetup_Points( GLcontext *ctx, GLuint first, GLuint last );
extern void
-_swsetup_RenderPrimNoop( GLcontext *ctx, GLenum mode );
+_swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode );
+
+extern void
+_swsetup_RenderStart( GLcontext *ctx );
+
+extern void
+_swsetup_RenderFinish( GLcontext *ctx );
#endif