summaryrefslogtreecommitdiff
path: root/src/mesa
diff options
context:
space:
mode:
authorKeith Whitwell <keith@tungstengraphics.com>2007-05-24 10:41:34 +0100
committerKeith Whitwell <keith@tungstengraphics.com>2007-05-24 10:41:34 +0100
commit8e4a95a93d15a6707a29454cd47e10b08314cda2 (patch)
tree91d8156591f89cd8e345250342719c515efb31fa /src/mesa
parent572dc0864e044776618b0b9e8b808b9584cd1ef6 (diff)
First version of the softpipe rasterizer.
This will flesh out to hopefully acheive 3 things: - New software rasterizer for mesa - New driver model for mesa & dri with much smaller drivers - The basis for the cell driver. It's got a long way to go yet, but will at least run trivial/tri.c.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/softpipe/Makefile2
-rw-r--r--src/mesa/softpipe/generic/Makefile3
-rw-r--r--src/mesa/softpipe/generic/g_context.c135
-rw-r--r--src/mesa/softpipe/generic/g_context.h149
-rw-r--r--src/mesa/softpipe/generic/g_draw.c696
-rw-r--r--src/mesa/softpipe/generic/g_draw.h56
-rw-r--r--src/mesa/softpipe/generic/g_headers.h115
-rw-r--r--src/mesa/softpipe/generic/g_prim.h90
-rw-r--r--src/mesa/softpipe/generic/g_prim_clip.c429
-rw-r--r--src/mesa/softpipe/generic/g_prim_cull.c119
-rw-r--r--src/mesa/softpipe/generic/g_prim_flatshade.c149
-rw-r--r--src/mesa/softpipe/generic/g_prim_offset.c157
-rw-r--r--src/mesa/softpipe/generic/g_prim_setup.c568
-rw-r--r--src/mesa/softpipe/generic/g_prim_setup.h121
-rw-r--r--src/mesa/softpipe/generic/g_prim_twoside.c149
-rw-r--r--src/mesa/softpipe/generic/g_prim_unfilled.c165
-rw-r--r--src/mesa/softpipe/generic/g_state.h61
-rw-r--r--src/mesa/softpipe/generic/g_state_clip.c69
-rw-r--r--src/mesa/softpipe/generic/g_state_derived.c136
-rw-r--r--src/mesa/softpipe/generic/g_state_fs.c50
-rw-r--r--src/mesa/softpipe/generic/g_state_setup.c122
-rw-r--r--src/mesa/softpipe/generic/g_state_surface.c53
-rw-r--r--src/mesa/softpipe/generic/g_surface.c153
-rw-r--r--src/mesa/softpipe/generic/g_surface.h115
-rw-r--r--src/mesa/softpipe/generic/g_tile.h42
-rw-r--r--src/mesa/softpipe/generic/g_tile_fs.c188
-rw-r--r--src/mesa/softpipe/generic/g_tile_output.c92
-rw-r--r--src/mesa/softpipe/sp_context.h72
-rw-r--r--src/mesa/softpipe/sp_defines.h45
-rw-r--r--src/mesa/softpipe/sp_state.h132
-rw-r--r--src/mesa/softpipe/state_tracker/Makefile2
-rw-r--r--src/mesa/softpipe/state_tracker/st_atom.c168
-rw-r--r--src/mesa/softpipe/state_tracker/st_atom.h55
-rw-r--r--src/mesa/softpipe/state_tracker/st_atom_cbuf.c72
-rw-r--r--src/mesa/softpipe/state_tracker/st_atom_clip.c75
-rw-r--r--src/mesa/softpipe/state_tracker/st_atom_fs.c56
-rw-r--r--src/mesa/softpipe/state_tracker/st_atom_setup.c175
-rw-r--r--src/mesa/softpipe/state_tracker/st_atom_viewport.c117
-rw-r--r--src/mesa/softpipe/state_tracker/st_cb_program.c165
-rw-r--r--src/mesa/softpipe/state_tracker/st_context.c76
-rw-r--r--src/mesa/softpipe/state_tracker/st_context.h109
-rw-r--r--src/mesa/softpipe/state_tracker/st_draw.c107
-rw-r--r--src/mesa/softpipe/state_tracker/st_draw.h40
-rw-r--r--src/mesa/softpipe/state_tracker/st_program.h68
-rw-r--r--src/mesa/softpipe/state_tracker/st_public.h43
45 files changed, 5761 insertions, 0 deletions
diff --git a/src/mesa/softpipe/Makefile b/src/mesa/softpipe/Makefile
new file mode 100644
index 0000000000..451911a354
--- /dev/null
+++ b/src/mesa/softpipe/Makefile
@@ -0,0 +1,2 @@
+default:
+ cd .. ; make
diff --git a/src/mesa/softpipe/generic/Makefile b/src/mesa/softpipe/generic/Makefile
new file mode 100644
index 0000000000..12a8bd0409
--- /dev/null
+++ b/src/mesa/softpipe/generic/Makefile
@@ -0,0 +1,3 @@
+default:
+ cd ../.. ; make
+
diff --git a/src/mesa/softpipe/generic/g_context.c b/src/mesa/softpipe/generic/g_context.c
new file mode 100644
index 0000000000..c3329b5c7d
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_context.c
@@ -0,0 +1,135 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Author:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "imports.h"
+#include "macros.h"
+
+#include "tnl/t_context.h"
+#include "vf/vf.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+#include "g_state.h"
+#include "g_draw.h"
+
+static void generic_destroy( struct softpipe_context *softpipe )
+{
+ struct generic_context *generic = generic_context( softpipe );
+
+ draw_destroy( generic->draw );
+
+ FREE( generic );
+}
+
+
+static void generic_draw_vb( struct softpipe_context *softpipe,
+ struct vertex_buffer *VB )
+{
+ struct generic_context *generic = generic_context( softpipe );
+
+ if (generic->dirty)
+ generic_update_derived( generic );
+
+ draw_vb( generic->draw, VB );
+}
+
+struct softpipe_context *generic_create( void )
+{
+ struct generic_context *generic = CALLOC_STRUCT(generic_context);
+
+ generic->softpipe.destroy = generic_destroy;
+ generic->softpipe.set_clip_state = generic_set_clip_state;
+ generic->softpipe.set_viewport = generic_set_viewport;
+ generic->softpipe.set_setup_state = generic_set_setup_state;
+ generic->softpipe.set_scissor_rect = generic_set_scissor_rect;
+ generic->softpipe.set_fs_state = generic_set_fs_state;
+ generic->softpipe.set_polygon_stipple = generic_set_polygon_stipple;
+ generic->softpipe.set_cbuf_state = generic_set_cbuf_state;
+ generic->softpipe.draw_vb = generic_draw_vb;
+
+
+
+ generic->prim.setup = prim_setup( generic );
+ generic->prim.unfilled = prim_unfilled( generic );
+ generic->prim.twoside = prim_twoside( generic );
+ generic->prim.offset = prim_offset( generic );
+ generic->prim.clip = prim_clip( generic );
+ generic->prim.flatshade = prim_flatshade( generic );
+ generic->prim.cull = prim_cull( generic );
+
+
+ generic->draw = draw_create( generic );
+
+ ASSIGN_4V( generic->plane[0], -1, 0, 0, 1 );
+ ASSIGN_4V( generic->plane[1], 1, 0, 0, 1 );
+ ASSIGN_4V( generic->plane[2], 0, -1, 0, 1 );
+ ASSIGN_4V( generic->plane[3], 0, 1, 0, 1 );
+ ASSIGN_4V( generic->plane[4], 0, 0, 1, 1 ); /* yes these are correct */
+ ASSIGN_4V( generic->plane[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */
+ generic->nr_planes = 6;
+
+ return &generic->softpipe;
+}
+
+
+
+
+
+
+#define MAX_VERTEX_SIZE ((2 + FRAG_ATTRIB_MAX) * 4 * sizeof(GLfloat))
+
+void prim_alloc_tmps( struct prim_stage *stage, GLuint nr )
+{
+ stage->nr_tmps = nr;
+
+ if (nr) {
+ GLubyte *store = MALLOC(MAX_VERTEX_SIZE * nr);
+ GLuint i;
+
+ stage->tmp = MALLOC(sizeof(struct vertex_header *) * nr);
+
+ for (i = 0; i < nr; i++)
+ stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);
+ }
+}
+
+void prim_free_tmps( struct prim_stage *stage )
+{
+ if (stage->tmp) {
+ FREE(stage->tmp[0]);
+ FREE(stage->tmp);
+ }
+}
+
+
+
+
+
diff --git a/src/mesa/softpipe/generic/g_context.h b/src/mesa/softpipe/generic/g_context.h
new file mode 100644
index 0000000000..24d467f2c3
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_context.h
@@ -0,0 +1,149 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#ifndef G_CONTEXT_H
+#define G_CONTEXT_H
+
+#include "glheader.h"
+
+#include "softpipe/sp_state.h"
+#include "softpipe/sp_context.h"
+
+
+
+struct generic_surface;
+struct draw_context;
+struct prim_stage;
+
+
+enum interp_mode {
+ INTERP_CONSTANT,
+ INTERP_LINEAR,
+ INTERP_PERSPECTIVE
+};
+
+
+#define G_NEW_VIEWPORT 0x1
+#define G_NEW_SETUP 0x2
+#define G_NEW_FS 0x4
+#define G_NEW_BLEND 0x8
+#define G_NEW_CBUF 0x10
+#define G_NEW_CLIP 0x20
+#define G_NEW_SCISSOR 0x40
+#define G_NEW_STIPPLE 0x80
+
+
+
+struct generic_context {
+ struct softpipe_context softpipe;
+
+
+ /* The most recent drawing state as set by the driver:
+ */
+ struct softpipe_viewport viewport;
+ struct softpipe_setup_state setup;
+ struct softpipe_fs_state fs;
+ struct softpipe_blend_state blend;
+ struct softpipe_surface cbuf;
+ struct softpipe_clip_state clip;
+ struct softpipe_scissor_rect scissor;
+ struct softpipe_poly_stipple poly_stipple;
+ GLuint dirty;
+
+
+ /* Cbuf derived state???
+ */
+ struct generic_surface *cbuf_surface;
+
+ /* Clip derived state:
+ */
+ GLfloat plane[12][4];
+ GLuint nr_planes;
+
+ /* Setup derived state. TODO: this should be passed in the program
+ * tokens as parameters to DECL instructions.
+ *
+ * For now we just set colors to CONST on flatshade, textures to
+ * perspective always and everything else to linear.
+ */
+ enum interp_mode interp[VF_ATTRIB_MAX];
+
+
+ /* FS + setup derived state:
+ */
+ GLuint fp_attr_to_slot[VF_ATTRIB_MAX];
+ GLuint vf_attr_to_slot[VF_ATTRIB_MAX];
+ GLuint nr_attrs;
+ GLuint nr_frag_attrs;
+ GLuint attr_mask;
+
+ GLboolean need_z;
+ GLboolean need_w;
+
+ /* Stipple derived state:
+ */
+ GLubyte stipple_masks[16][16];
+
+
+ /* The software clipper/setup engine.
+ */
+ struct {
+ struct prim_stage *setup;
+ struct prim_stage *unfilled;
+ struct prim_stage *twoside;
+ struct prim_stage *clip;
+ struct prim_stage *flatshade;
+ struct prim_stage *offset;
+ struct prim_stage *cull;
+
+ struct prim_stage *first;
+
+ GLenum prim;
+ GLuint vertex_size;
+ } prim;
+
+ /* Temp kludge:
+ */
+ struct draw_context *draw;
+};
+
+
+
+
+static INLINE struct generic_context *
+generic_context( struct softpipe_context *softpipe )
+{
+ return (struct generic_context *)softpipe;
+}
+
+
+
+
+#endif
diff --git a/src/mesa/softpipe/generic/g_draw.c b/src/mesa/softpipe/generic/g_draw.c
new file mode 100644
index 0000000000..4e094c21a0
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_draw.c
@@ -0,0 +1,696 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "imports.h"
+
+#include "tnl/t_context.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+#include "g_headers.h"
+#include "g_draw.h"
+
+/* This file is a temporary set of hooks to allow us to use the tnl/
+ * and vf/ modules until we have replacements in softpipe.
+ */
+
+
+struct draw_context
+{
+ struct generic_context *generic;
+
+ struct vf_attr_map attrs[VF_ATTRIB_MAX];
+ GLuint nr_attrs;
+ GLuint vertex_size;
+ struct vertex_fetch *vf;
+
+ GLubyte *verts;
+ GLuint nr_vertices;
+ GLboolean in_vb;
+
+ GLenum prim;
+
+ /* Helper for tnl:
+ */
+ GLvector4f header;
+};
+
+
+static struct vertex_header *get_vertex( struct draw_context *pipe,
+ GLuint i )
+{
+ return (struct vertex_header *)(pipe->verts + i * pipe->vertex_size);
+}
+
+
+
+static void draw_allocate_vertices( struct draw_context *draw,
+ GLuint nr_vertices )
+{
+ draw->nr_vertices = nr_vertices;
+ draw->verts = MALLOC( nr_vertices * draw->vertex_size );
+
+ draw->generic->prim.first->begin( draw->generic->prim.first );
+}
+
+static void draw_set_prim( struct draw_context *draw,
+ GLenum prim )
+{
+ draw->prim = prim;
+
+ /* Not done yet - need to force edgeflags to 1 in strip/fan
+ * primitives.
+ */
+#if 0
+ switch (prim) {
+ case GL_TRIANGLES:
+ case GL_POLYGON:
+ case GL_QUADS:
+ case GL_QUAD_STRIP: /* yes, we need this */
+ respect_edgeflags( pipe, GL_TRUE );
+ break;
+
+ default:
+ respect_edgeflags( pipe, GL_FALSE );
+ break;
+ }
+#endif
+}
+
+
+
+static void do_quad( struct prim_stage *first,
+ struct vertex_header *v0,
+ struct vertex_header *v1,
+ struct vertex_header *v2,
+ struct vertex_header *v3 )
+{
+ struct prim_header prim;
+
+ {
+ GLuint tmp = v1->edgeflag;
+ v1->edgeflag = 0;
+
+ prim.v[0] = v0;
+ prim.v[1] = v1;
+ prim.v[2] = v3;
+ first->tri( first, &prim );
+
+ v1->edgeflag = tmp;
+ }
+
+ {
+ GLuint tmp = v3->edgeflag;
+ v3->edgeflag = 0;
+
+ prim.v[0] = v1;
+ prim.v[1] = v2;
+ prim.v[2] = v3;
+ first->tri( first, &prim );
+
+ v3->edgeflag = tmp;
+ }
+}
+
+
+
+
+static void draw_indexed_prim( struct draw_context *draw,
+ const GLuint *elts,
+ GLuint count )
+{
+ struct prim_stage * const first = draw->generic->prim.first;
+ struct prim_header prim;
+ GLuint i;
+
+ prim.det = 0; /* valid from cull stage onwards */
+ prim.v[0] = 0;
+ prim.v[1] = 0;
+ prim.v[2] = 0;
+
+ switch (draw->prim) {
+ case GL_POINTS:
+ for (i = 0; i < count; i ++) {
+ prim.v[0] = get_vertex( draw, elts[i] );
+
+ first->point( first, &prim );
+ }
+ break;
+
+ case GL_LINES:
+ for (i = 0; i+1 < count; i += 2) {
+ prim.v[0] = get_vertex( draw, elts[i + 0] );
+ prim.v[1] = get_vertex( draw, elts[i + 1] );
+
+ first->line( first, &prim );
+ }
+ break;
+
+ case GL_LINE_LOOP:
+ if (count >= 2) {
+ for (i = 1; i < count; i++) {
+ prim.v[0] = get_vertex( draw, elts[i-1] );
+ prim.v[1] = get_vertex( draw, elts[i] );
+ first->line( first, &prim );
+ }
+
+ prim.v[0] = get_vertex( draw, elts[count-1] );
+ prim.v[1] = get_vertex( draw, elts[0] );
+ first->line( first, &prim );
+ }
+ break;
+
+ case GL_LINE_STRIP:
+ /* I'm guessing it will be necessary to have something like a
+ * render->reset_line_stipple() method to properly support
+ * splitting strips into primitives like this. Alternately we
+ * could just scan ahead to find individual clipped lines and
+ * otherwise leave the strip intact - that might be better, but
+ * require more complex code here.
+ */
+ if (count >= 2) {
+ prim.v[0] = 0;
+ prim.v[1] = get_vertex( draw, elts[0] );
+
+ for (i = 1; i < count; i++) {
+ prim.v[0] = prim.v[1];
+ prim.v[1] = get_vertex( draw, elts[i] );
+
+ first->line( first, &prim );
+ }
+ }
+ break;
+
+ case GL_TRIANGLES:
+ for (i = 0; i+2 < count; i += 3) {
+ prim.v[0] = get_vertex( draw, elts[i + 0] );
+ prim.v[1] = get_vertex( draw, elts[i + 1] );
+ prim.v[2] = get_vertex( draw, elts[i + 2] );
+
+ first->tri( first, &prim );
+ }
+ break;
+
+ case GL_TRIANGLE_STRIP:
+ for (i = 0; i+2 < count; i++) {
+ if (i & 1) {
+ prim.v[0] = get_vertex( draw, elts[i + 1] );
+ prim.v[1] = get_vertex( draw, elts[i + 0] );
+ prim.v[2] = get_vertex( draw, elts[i + 2] );
+ }
+ else {
+ prim.v[0] = get_vertex( draw, elts[i + 0] );
+ prim.v[1] = get_vertex( draw, elts[i + 1] );
+ prim.v[2] = get_vertex( draw, elts[i + 2] );
+ }
+
+ first->tri( first, &prim );
+ }
+ break;
+
+ case GL_TRIANGLE_FAN:
+ if (count >= 3) {
+ prim.v[0] = get_vertex( draw, elts[0] );
+ prim.v[1] = 0;
+ prim.v[2] = get_vertex( draw, elts[1] );
+
+ for (i = 0; i+2 < count; i++) {
+ prim.v[1] = prim.v[2];
+ prim.v[2] = get_vertex( draw, elts[i+2] );
+
+ first->tri( first, &prim );
+ }
+ }
+ break;
+
+ case GL_QUADS:
+ for (i = 0; i+3 < count; i += 4) {
+ do_quad( first,
+ get_vertex( draw, elts[i + 0] ),
+ get_vertex( draw, elts[i + 1] ),
+ get_vertex( draw, elts[i + 2] ),
+ get_vertex( draw, elts[i + 3] ));
+ }
+ break;
+
+ case GL_QUAD_STRIP:
+ for (i = 0; i+3 < count; i += 2) {
+ do_quad( first,
+ get_vertex( draw, elts[i + 2] ),
+ get_vertex( draw, elts[i + 0] ),
+ get_vertex( draw, elts[i + 1] ),
+ get_vertex( draw, elts[i + 3] ));
+ }
+ break;
+
+
+ case GL_POLYGON:
+ if (count >= 3) {
+ prim.v[0] = 0;
+ prim.v[1] = get_vertex( draw, elts[1] );
+ prim.v[2] = get_vertex( draw, elts[0] );
+
+ for (i = 0; i+2 < count; i++) {
+ prim.v[0] = prim.v[1];
+ prim.v[1] = get_vertex( draw, elts[i+2] );
+
+ first->tri( first, &prim );
+ }
+ }
+ break;
+
+ default:
+ assert(0);
+ break;
+ }
+}
+
+static void draw_prim( struct draw_context *draw,
+ GLuint start,
+ GLuint count )
+{
+ struct prim_stage * const first = draw->generic->prim.first;
+ struct prim_header prim;
+ GLuint i;
+
+// _mesa_printf("%s (%d) %d/%d\n", __FUNCTION__, draw->prim, start, count );
+
+ prim.det = 0; /* valid from cull stage onwards */
+ prim.v[0] = 0;
+ prim.v[1] = 0;
+ prim.v[2] = 0;
+
+ switch (draw->prim) {
+ case GL_POINTS:
+ for (i = 0; i < count; i ++) {
+ prim.v[0] = get_vertex( draw, start + i );
+ first->point( first, &prim );
+ }
+ break;
+
+ case GL_LINES:
+ for (i = 0; i+1 < count; i += 2) {
+ prim.v[0] = get_vertex( draw, start + i + 0 );
+ prim.v[1] = get_vertex( draw, start + i + 1 );
+
+ first->line( first, &prim );
+ }
+ break;
+
+ case GL_LINE_LOOP:
+ if (count >= 2) {
+ for (i = 1; i < count; i++) {
+ prim.v[0] = get_vertex( draw, start + i - 1 );
+ prim.v[1] = get_vertex( draw, start + i );
+ first->line( first, &prim );
+ }
+
+ prim.v[0] = get_vertex( draw, start + count - 1 );
+ prim.v[1] = get_vertex( draw, start + 0 );
+ first->line( first, &prim );
+ }
+ break;
+
+ case GL_LINE_STRIP:
+ if (count >= 2) {
+ prim.v[0] = 0;
+ prim.v[1] = get_vertex( draw, start + 0 );
+
+ for (i = 1; i < count; i++) {
+ prim.v[0] = prim.v[1];
+ prim.v[1] = get_vertex( draw, start + i );
+
+ first->line( first, &prim );
+ }
+ }
+ break;
+
+ case GL_TRIANGLES:
+ for (i = 0; i+2 < count; i += 3) {
+ prim.v[0] = get_vertex( draw, start + i + 0 );
+ prim.v[1] = get_vertex( draw, start + i + 1 );
+ prim.v[2] = get_vertex( draw, start + i + 2 );
+
+ first->tri( first, &prim );
+ }
+ break;
+
+ case GL_TRIANGLE_STRIP:
+ for (i = 0; i+2 < count; i++) {
+ if (i & 1) {
+ prim.v[0] = get_vertex( draw, start + i + 1 );
+ prim.v[1] = get_vertex( draw, start + i + 0 );
+ prim.v[2] = get_vertex( draw, start + i + 2 );
+ }
+ else {
+ prim.v[0] = get_vertex( draw, start + i + 0 );
+ prim.v[1] = get_vertex( draw, start + i + 1 );
+ prim.v[2] = get_vertex( draw, start + i + 2 );
+ }
+
+ first->tri( first, &prim );
+ }
+ break;
+
+ case GL_TRIANGLE_FAN:
+ if (count >= 3) {
+ prim.v[0] = get_vertex( draw, start + 0 );
+ prim.v[1] = 0;
+ prim.v[2] = get_vertex( draw, start + 1 );
+
+ for (i = 0; i+2 < count; i++) {
+ prim.v[1] = prim.v[2];
+ prim.v[2] = get_vertex( draw, start + i + 2 );
+
+ first->tri( first, &prim );
+ }
+ }
+ break;
+
+
+ case GL_QUADS:
+ for (i = 0; i+3 < count; i += 4) {
+ do_quad( first,
+ get_vertex( draw, start + i + 0 ),
+ get_vertex( draw, start + i + 1 ),
+ get_vertex( draw, start + i + 2 ),
+ get_vertex( draw, start + i + 3 ));
+ }
+ break;
+
+ case GL_QUAD_STRIP:
+ for (i = 0; i+3 < count; i += 2) {
+ do_quad( first,
+ get_vertex( draw, start + i + 2 ),
+ get_vertex( draw, start + i + 0 ),
+ get_vertex( draw, start + i + 1 ),
+ get_vertex( draw, start + i + 3 ));
+ }
+ break;
+
+ case GL_POLYGON:
+ if (count >= 3) {
+ prim.v[0] = 0;
+ prim.v[1] = get_vertex( draw, start + 1 );
+ prim.v[2] = get_vertex( draw, start + 0 );
+
+ for (i = 0; i+2 < count; i++) {
+ prim.v[0] = prim.v[1];
+ prim.v[1] = get_vertex( draw, start + i + 2 );
+
+ first->tri( first, &prim );
+ }
+ }
+ break;
+
+ default:
+ assert(0);
+ break;
+ }
+}
+
+
+static void draw_release_vertices( struct draw_context *draw )
+{
+ draw->generic->prim.first->end( draw->generic->prim.first );
+
+ FREE(draw->verts);
+ draw->verts = NULL;
+}
+
+
+struct header_dword {
+ GLuint clipmask:12;
+ GLuint edgeflag:1;
+ GLuint pad:19;
+};
+
+
+static void
+build_vertex_headers( struct draw_context *draw,
+ struct vertex_buffer *VB )
+{
+ if (draw->header.storage == NULL) {
+ draw->header.stride = sizeof(GLfloat);
+ draw->header.size = 1;
+ draw->header.storage = ALIGN_MALLOC( VB->Size * sizeof(GLfloat), 32 );
+ draw->header.data = draw->header.storage;
+ draw->header.count = 0;
+ draw->header.flags = VEC_SIZE_1 | VEC_MALLOC;
+ }
+
+ /* Build vertex header attribute.
+ *
+ */
+
+ {
+ GLuint i;
+ struct header_dword *header = (struct header_dword *)draw->header.storage;
+
+ /* yes its a hack
+ */
+ assert(sizeof(*header) == sizeof(GLfloat));
+
+ draw->header.count = VB->Count;
+
+ if (VB->EdgeFlag) {
+ for (i = 0; i < VB->Count; i++) {
+ header[i].clipmask = VB->ClipMask[i];
+ header[i].edgeflag = VB->EdgeFlag[i];
+ header[i].pad = 0;
+ }
+ }
+ else if (VB->ClipOrMask) {
+ for (i = 0; i < VB->Count; i++) {
+ header[i].clipmask = VB->ClipMask[i];
+ header[i].edgeflag = 0;
+ header[i].pad = 0;
+ }
+ }
+ else {
+ for (i = 0; i < VB->Count; i++) {
+ header[i].clipmask = 0;
+ header[i].edgeflag = 0;
+ header[i].pad = 0;
+ }
+ }
+ }
+
+ VB->AttribPtr[VF_ATTRIB_VERTEX_HEADER] = &draw->header;
+}
+
+
+
+
+
+static GLuint draw_prim_info(GLenum mode, GLuint *first, GLuint *incr)
+{
+ switch (mode) {
+ case GL_POINTS:
+ *first = 1;
+ *incr = 1;
+ return 0;
+ case GL_LINES:
+ *first = 2;
+ *incr = 2;
+ return 0;
+ case GL_LINE_STRIP:
+ *first = 2;
+ *incr = 1;
+ return 0;
+ case GL_LINE_LOOP:
+ *first = 2;
+ *incr = 1;
+ return 1;
+ case GL_TRIANGLES:
+ *first = 3;
+ *incr = 3;
+ return 0;
+ case GL_TRIANGLE_STRIP:
+ *first = 3;
+ *incr = 1;
+ return 0;
+ case GL_TRIANGLE_FAN:
+ case GL_POLYGON:
+ *first = 3;
+ *incr = 1;
+ return 1;
+ case GL_QUADS:
+ *first = 4;
+ *incr = 4;
+ return 0;
+ case GL_QUAD_STRIP:
+ *first = 4;
+ *incr = 2;
+ return 0;
+ default:
+ assert(0);
+ *first = 1;
+ *incr = 1;
+ return 0;
+ }
+}
+
+
+static GLuint trim( GLuint count, GLuint first, GLuint incr )
+{
+ if (count < first)
+ return 0;
+ else
+ return count - (count - first) % incr;
+}
+
+
+/* This is a hack & will all go away.
+ */
+void draw_vb(struct draw_context *draw,
+ struct vertex_buffer *VB )
+{
+ GLuint i;
+
+ VB->AttribPtr[VF_ATTRIB_POS] = VB->NdcPtr;
+ VB->AttribPtr[VF_ATTRIB_BFC0] = VB->ColorPtr[1];
+ VB->AttribPtr[VF_ATTRIB_BFC1] = VB->SecondaryColorPtr[1];
+ VB->AttribPtr[VF_ATTRIB_CLIP_POS] = VB->ClipPtr;
+
+ /* Build vertex headers:
+ */
+ build_vertex_headers( draw, VB );
+
+ draw->in_vb = 1;
+
+ /* Allocate the vertices:
+ */
+ draw_allocate_vertices( draw, VB->Count );
+
+ /* Bind the vb outputs:
+ */
+ vf_set_sources( draw->vf, VB->AttribPtr, 0 );
+
+ /* Build the hardware or prim-pipe vertices:
+ */
+ vf_emit_vertices( draw->vf, VB->Count, draw->verts );
+
+
+ for (i = 0; i < VB->PrimitiveCount; i++) {
+
+ GLenum mode = VB->Primitive[i].mode;
+ GLuint start = VB->Primitive[i].start;
+ GLuint length, first, incr;
+
+ /* Trim the primitive down to a legal size.
+ */
+ draw_prim_info( mode, &first, &incr );
+ length = trim( VB->Primitive[i].count, first, incr );
+
+ if (!length)
+ continue;
+
+ if (draw->prim != mode)
+ draw_set_prim( draw, mode );
+
+ if (VB->Elts) {
+ draw_indexed_prim( draw,
+ VB->Elts + start,
+ length );
+ }
+ else {
+ draw_prim( draw,
+ start,
+ length );
+ }
+ }
+
+ draw_release_vertices( draw );
+ draw->verts = NULL;
+ draw->in_vb = 0;
+}
+
+void draw_set_viewport( struct draw_context *draw,
+ const GLfloat *scale,
+ const GLfloat *translate )
+{
+ assert(!draw->in_vb);
+ vf_set_vp_scale_translate( draw->vf, scale, translate );
+}
+
+
+
+struct draw_context *draw_create( struct generic_context *generic )
+{
+ struct draw_context *draw = CALLOC_STRUCT( draw_context );
+ draw->generic = generic;
+ draw->vf = vf_create( GL_TRUE );
+
+ return draw;
+}
+
+
+void draw_destroy( struct draw_context *draw )
+{
+ if (draw->header.storage)
+ ALIGN_FREE( draw->header.storage );
+
+ vf_destroy( draw->vf );
+
+ FREE( draw );
+}
+
+#define EMIT_ATTR( ATTR, STYLE ) \
+do { \
+ draw->attrs[draw->nr_attrs].attrib = ATTR; \
+ draw->attrs[draw->nr_attrs].format = STYLE; \
+ draw->nr_attrs++; \
+} while (0)
+
+
+void draw_set_vertex_attributes( struct draw_context *draw,
+ const GLuint *attrs,
+ GLuint nr_attrs )
+{
+ GLuint i;
+
+ draw->nr_attrs = 0;
+
+ EMIT_ATTR(VF_ATTRIB_VERTEX_HEADER, EMIT_1F);
+ EMIT_ATTR(VF_ATTRIB_CLIP_POS, EMIT_4F);
+
+ assert(attrs[0] == VF_ATTRIB_POS);
+ EMIT_ATTR(attrs[0], EMIT_4F_VIEWPORT);
+
+ for (i = 1; i < nr_attrs; i++)
+ EMIT_ATTR(attrs[i], EMIT_4F);
+
+ draw->vertex_size = vf_set_vertex_attributes( draw->vf, draw->attrs, draw->nr_attrs, 0 );
+}
+
+
diff --git a/src/mesa/softpipe/generic/g_draw.h b/src/mesa/softpipe/generic/g_draw.h
new file mode 100644
index 0000000000..78c93b4df7
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_draw.h
@@ -0,0 +1,56 @@
+
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#ifndef G_DRAW_H
+#define G_DRAW_H
+
+#include "glheader.h"
+#include "softpipe/sp_state.h"
+
+
+struct draw_context;
+
+struct draw_context *draw_create( struct generic_context *generic );
+
+void draw_destroy( struct draw_context *draw );
+
+void draw_set_viewport( struct draw_context *draw,
+ const GLfloat *scale,
+ const GLfloat *translate );
+
+void draw_set_vertex_attributes( struct draw_context *draw,
+ const GLuint *attrs,
+ GLuint nr_attrs );
+
+void draw_vb(struct draw_context *draw,
+ struct vertex_buffer *VB );
+
+#endif
diff --git a/src/mesa/softpipe/generic/g_headers.h b/src/mesa/softpipe/generic/g_headers.h
new file mode 100644
index 0000000000..1db325a4ab
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_headers.h
@@ -0,0 +1,115 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#ifndef G_HEADERS_H
+#define G_HEADERS_H
+
+#define PRIM_POINT 1
+#define PRIM_LINE 2
+#define PRIM_TRI 3
+
+struct prim_header {
+ GLfloat det;
+ struct vertex_header *v[3];
+};
+
+/* Carry some useful information around with the vertices in the prim
+ * pipe.
+ */
+struct vertex_header {
+ GLuint clipmask:12;
+ GLuint edgeflag:1;
+ GLuint pad:19;
+
+ GLfloat clip[4];
+
+ GLfloat data[][4]; /* Note variable size */
+};
+
+
+
+
+
+/* The rasterizer generates 2x2 quads of fragment and feeds them to
+ * the current fp_machine (see below).
+ */
+#define QUAD_BOTTOM_LEFT 0
+#define QUAD_BOTTOM_RIGHT 1
+#define QUAD_TOP_LEFT 2
+#define QUAD_TOP_RIGHT 3
+#define QUAD_SIZE (2*2)
+
+#define MASK_BOTTOM_LEFT 0x1
+#define MASK_BOTTOM_RIGHT 0x2
+#define MASK_TOP_LEFT 0x4
+#define MASK_TOP_RIGHT 0x8
+#define MASK_ALL 0xf
+
+
+#define NUM_CHANNELS 4 /* avoid confusion between 4 pixels and 4 channels */
+
+
+struct setup_coefficient {
+ GLfloat a0[NUM_CHANNELS]; /* in an xyzw layout */
+ GLfloat dadx[NUM_CHANNELS];
+ GLfloat dady[NUM_CHANNELS];
+};
+
+
+
+/* Encodes everything we need to know about a 2x2 pixel block. Uses
+ * "Channel-Serial" or "SoA" layout.
+ *
+ * Will expand to include non-attribute things like AA coverage and
+ * maybe prefetched depth from the depth buffer.
+ */
+struct quad_header {
+ GLint x0;
+ GLint y0;
+ GLuint mask;
+
+ struct {
+ GLfloat color[4][QUAD_SIZE]; /* rrrr, gggg, bbbb, aaaa */
+ GLfloat depth[QUAD_SIZE];
+ } outputs;
+
+ const struct setup_coefficient *coef;
+
+ const enum interp_mode *interp; /* XXX: this information should be
+ * encoded in fragment program DECL
+ * statements. */
+
+ GLuint nr_attrs;
+};
+
+
+
+
+
+#endif
diff --git a/src/mesa/softpipe/generic/g_prim.h b/src/mesa/softpipe/generic/g_prim.h
new file mode 100644
index 0000000000..e3b2c5ea2f
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim.h
@@ -0,0 +1,90 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#ifndef G_PRIM_H
+#define G_PRIM_H
+
+#include "glheader.h"
+#include "g_headers.h"
+
+struct generic_context;
+
+struct prim_stage *prim_setup( struct generic_context *context );
+struct prim_stage *prim_unfilled( struct generic_context *context );
+struct prim_stage *prim_twoside( struct generic_context *context );
+struct prim_stage *prim_offset( struct generic_context *context );
+struct prim_stage *prim_clip( struct generic_context *context );
+struct prim_stage *prim_flatshade( struct generic_context *context );
+struct prim_stage *prim_cull( struct generic_context *context );
+
+
+/* Internal structs and helpers for the primitive clip/setup pipeline:
+ */
+struct prim_stage {
+ struct generic_context *generic;
+
+ struct prim_stage *next;
+
+ struct vertex_header **tmp;
+ GLuint nr_tmps;
+
+ void (*begin)( struct prim_stage * );
+
+ void (*point)( struct prim_stage *,
+ struct prim_header * );
+
+ void (*line)( struct prim_stage *,
+ struct prim_header * );
+
+ void (*tri)( struct prim_stage *,
+ struct prim_header * );
+
+ void (*end)( struct prim_stage * );
+};
+
+
+
+/* Get a writeable copy of a vertex:
+ */
+static INLINE struct vertex_header *
+dup_vert( struct prim_stage *stage,
+ const struct vertex_header *vert,
+ GLuint idx )
+{
+ struct vertex_header *tmp = stage->tmp[idx];
+ memcpy(tmp, vert, stage->generic->prim.vertex_size );
+ return tmp;
+}
+
+void prim_free_tmps( struct prim_stage *stage );
+void prim_alloc_tmps( struct prim_stage *stage, GLuint nr );
+
+
+#endif
diff --git a/src/mesa/softpipe/generic/g_prim_clip.c b/src/mesa/softpipe/generic/g_prim_clip.c
new file mode 100644
index 0000000000..742def9c7d
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim_clip.c
@@ -0,0 +1,429 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "imports.h"
+#include "macros.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+
+struct clipper {
+ struct prim_stage stage;
+
+ GLuint active_user_planes;
+};
+
+/* This is a bit confusing:
+ */
+static INLINE struct clipper *clipper_stage( struct prim_stage *stage )
+{
+ return (struct clipper *)stage;
+}
+
+
+#define LINTERP(T, OUT, IN) ((OUT) + (T) * ((IN) - (OUT)))
+
+
+/* All attributes are float[4], so this is easy:
+ */
+static void interp_attr( GLfloat *fdst,
+ GLfloat t,
+ const GLfloat *fin,
+ const GLfloat *fout )
+{
+ fdst[0] = LINTERP( t, fout[0], fin[0] );
+ fdst[1] = LINTERP( t, fout[1], fin[1] );
+ fdst[2] = LINTERP( t, fout[2], fin[2] );
+ fdst[3] = LINTERP( t, fout[3], fin[3] );
+}
+
+
+
+
+/* Interpolate between two vertices to produce a third.
+ */
+static void interp( struct clipper *clip,
+ struct vertex_header *dst,
+ GLfloat t,
+ const struct vertex_header *out,
+ const struct vertex_header *in )
+{
+ const GLuint nr_attrs = clip->stage.generic->nr_attrs;
+ GLuint j;
+
+ /* Vertex header.
+ */
+ {
+ dst->clipmask = 0;
+ dst->edgeflag = 0;
+ dst->pad = 0;
+ }
+
+ /* Clip coordinates: interpolate normally
+ */
+ {
+ interp_attr(dst->clip, t, in->clip, out->clip);
+ }
+
+ /* Do the projective divide and insert window coordinates:
+ */
+ {
+ const GLfloat *pos = dst->clip;
+ const GLfloat *scale = clip->stage.generic->viewport.scale;
+ const GLfloat *trans = clip->stage.generic->viewport.translate;
+ GLfloat oow;
+
+ oow = 1.0 / pos[3];
+
+ dst->data[0][0] = pos[0] * oow * scale[0] + trans[0];
+ dst->data[0][1] = pos[1] * oow * scale[1] + trans[1];
+ dst->data[0][2] = pos[2] * oow * scale[2] + trans[2];
+ dst->data[0][3] = oow;
+ }
+
+
+ /* Other attributes
+ */
+ for (j = 1; j < nr_attrs-1; j++) {
+ interp_attr(dst->data[j], t, in->data[j], out->data[j]);
+ }
+}
+
+
+#define CLIP_USER_BIT 0x40
+#define CLIP_CULL_BIT 0x80
+
+
+static INLINE GLfloat dot4( const GLfloat *a,
+ const GLfloat *b )
+{
+ GLfloat result = (a[0]*b[0] +
+ a[1]*b[1] +
+ a[2]*b[2] +
+ a[3]*b[3]);
+
+ return result;
+}
+
+
+#if 0
+static INLINE void do_tri( struct prim_stage *next,
+ struct prim_header *header )
+{
+ GLuint i;
+ for (i = 0; i < 3; i++) {
+ GLfloat *ndc = header->v[i]->data[0];
+ _mesa_printf("ndc %f %f %f\n", ndc[0], ndc[1], ndc[2]);
+ assert(ndc[0] >= -1 && ndc[0] <= 641);
+ assert(ndc[1] >= 30 && ndc[1] <= 481);
+ }
+ _mesa_printf("\n");
+ next->tri(next, header);
+}
+#endif
+
+
+static void emit_poly( struct prim_stage *stage,
+ struct vertex_header **inlist,
+ GLuint n )
+{
+ struct prim_header header;
+ GLuint i;
+
+ for (i = 2; i < n; i++) {
+ header.v[0] = inlist[0];
+ header.v[1] = inlist[i-1];
+ header.v[2] = inlist[i];
+
+ {
+ GLuint tmp0 = header.v[0]->edgeflag;
+ GLuint tmp2 = header.v[2]->edgeflag;
+
+ if (i != 2) header.v[0]->edgeflag = 0;
+ if (i != n-1) header.v[2]->edgeflag = 0;
+
+ stage->next->tri( stage->next, &header );
+
+ header.v[0]->edgeflag = tmp0;
+ header.v[2]->edgeflag = tmp2;
+ }
+ }
+}
+
+
+#if 0
+static void emit_poly( struct prim_stage *stage )
+{
+ GLuint i;
+
+ for (i = 2; i < n; i++) {
+ header->v[0] = inlist[0];
+ header->v[1] = inlist[i-1];
+ header->v[2] = inlist[i];
+
+ stage->next->tri( stage->next, header );
+ }
+}
+#endif
+
+
+/* Clip a triangle against the viewport and user clip planes.
+ */
+static void
+do_clip_tri( struct prim_stage *stage,
+ struct prim_header *header,
+ GLuint clipmask )
+{
+ struct clipper *clipper = clipper_stage( stage );
+ struct vertex_header *a[MAX_CLIPPED_VERTICES];
+ struct vertex_header *b[MAX_CLIPPED_VERTICES];
+ struct vertex_header **inlist = a;
+ struct vertex_header **outlist = b;
+ GLuint tmpnr = 0;
+ GLuint n = 3;
+ GLuint i;
+
+ inlist[0] = header->v[0];
+ inlist[1] = header->v[1];
+ inlist[2] = header->v[2];
+
+ /* XXX: Note stupid hack to deal with tnl's 8-bit clipmask. Remove
+ * this once we correctly use 16bit masks for userclip planes.
+ */
+ clipmask &= ~CLIP_CULL_BIT;
+ if (clipmask & CLIP_USER_BIT) {
+ clipmask &= ~CLIP_USER_BIT;
+ clipmask |= clipper->active_user_planes;
+ }
+
+ while (clipmask && n >= 3) {
+ GLuint plane_idx = ffs(clipmask)-1;
+ const GLfloat *plane = clipper->stage.generic->plane[plane_idx];
+ struct vertex_header *vert_prev = inlist[0];
+ GLfloat dp_prev = dot4( vert_prev->clip, plane );
+ GLuint outcount = 0;
+
+ clipmask &= ~(1<<plane_idx);
+
+ inlist[n] = inlist[0]; /* prevent rotation of vertices */
+
+ for (i = 1; i <= n; i++) {
+ struct vertex_header *vert = inlist[i];
+
+ GLfloat dp = dot4( vert->clip, plane );
+
+ if (!IS_NEGATIVE(dp_prev)) {
+ outlist[outcount++] = vert_prev;
+ }
+
+ if (DIFFERENT_SIGNS(dp, dp_prev)) {
+ struct vertex_header *new_vert = clipper->stage.tmp[tmpnr++];
+ outlist[outcount++] = new_vert;
+
+ if (IS_NEGATIVE(dp)) {
+ /* Going out of bounds. Avoid division by zero as we
+ * know dp != dp_prev from DIFFERENT_SIGNS, above.
+ */
+ GLfloat t = dp / (dp - dp_prev);
+ interp( clipper, new_vert, t, vert, vert_prev );
+
+ /* Force edgeflag true in this case:
+ */
+ new_vert->edgeflag = 1;
+ } else {
+ /* Coming back in.
+ */
+ GLfloat t = dp_prev / (dp_prev - dp);
+ interp( clipper, new_vert, t, vert_prev, vert );
+
+ /* Copy starting vert's edgeflag:
+ */
+ new_vert->edgeflag = vert_prev->edgeflag;
+ }
+ }
+
+ vert_prev = vert;
+ dp_prev = dp;
+ }
+
+ {
+ struct vertex_header **tmp = inlist;
+ inlist = outlist;
+ outlist = tmp;
+ n = outcount;
+ }
+ }
+
+ /* Emit the polygon as triangles to the setup stage:
+ */
+ if (n >= 3)
+ emit_poly( stage, inlist, n );
+}
+
+
+/* Clip a line against the viewport and user clip planes.
+ */
+static void
+do_clip_line( struct prim_stage *stage,
+ struct prim_header *header,
+ GLuint clipmask )
+{
+ struct clipper *clipper = clipper_stage( stage );
+ struct vertex_header *v0 = header->v[0];
+ struct vertex_header *v1 = header->v[1];
+ const GLfloat *pos0 = v0->clip;
+ const GLfloat *pos1 = v1->clip;
+ GLfloat t0 = 0;
+ GLfloat t1 = 0;
+
+ /* XXX: Note stupid hack to deal with tnl's 8-bit clipmask. Remove
+ * this once we correctly use 16bit masks for userclip planes.
+ */
+ clipmask &= ~CLIP_CULL_BIT;
+ if (clipmask & CLIP_USER_BIT) {
+ clipmask &= ~CLIP_USER_BIT;
+ clipmask |= clipper->active_user_planes;
+ }
+
+ while (clipmask) {
+ GLuint plane_idx = ffs(clipmask)-1;
+ const GLfloat *plane = clipper->stage.generic->plane[plane_idx];
+
+ clipmask &= ~(1<<plane_idx);
+
+ const GLfloat dp0 = dot4( pos0, plane );
+ const GLfloat dp1 = dot4( pos1, plane );
+
+ if (dp1 < 0) {
+ GLfloat t = dp1 / (dp1 - dp0);
+ if (t > t1) t1 = t;
+ }
+
+ if (dp0 < 0) {
+ GLfloat t = dp0 / (dp0 - dp1);
+ if (t > t0) t0 = t;
+ }
+
+ if (t0 + t1 >= 1.0)
+ return; /* discard */
+ }
+
+ if (v0->clipmask) {
+ interp( clipper, stage->tmp[0], t0, v0, v1 );
+ header->v[0] = stage->tmp[0];
+ }
+
+ if (v1->clipmask) {
+ interp( clipper, stage->tmp[1], t1, v1, v0 );
+ header->v[1] = stage->tmp[1];
+ }
+
+ stage->next->line( stage->next, header );
+}
+
+
+
+static void clip_begin( struct prim_stage *stage )
+{
+ struct clipper *clipper = clipper_stage(stage);
+ GLuint nr = stage->generic->nr_planes;
+
+ /* Hacky bitmask to use when we hit CLIP_USER_BIT:
+ */
+ clipper->active_user_planes = ((1<<nr)-1) & ~((1<<6)-1);
+
+ stage->next->begin( stage->next );
+}
+
+static void
+clip_point( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ if (header->v[0]->clipmask == 0)
+ stage->next->point( stage->next, header );
+}
+
+
+static void
+clip_line( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ GLuint clipmask = (header->v[0]->clipmask |
+ header->v[1]->clipmask);
+
+ if (clipmask == 0) {
+ stage->next->line( stage->next, header );
+ }
+ else if ((header->v[0]->clipmask &
+ header->v[1]->clipmask) == 0) {
+ do_clip_line(stage, header, clipmask);
+ }
+}
+
+
+static void
+clip_tri( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ GLuint clipmask = (header->v[0]->clipmask |
+ header->v[1]->clipmask |
+ header->v[2]->clipmask);
+
+ if (clipmask == 0) {
+ stage->next->tri( stage->next, header );
+ }
+ else if ((header->v[0]->clipmask &
+ header->v[1]->clipmask &
+ header->v[2]->clipmask) == 0) {
+ do_clip_tri(stage, header, clipmask);
+ }
+}
+
+static void clip_end( struct prim_stage *stage )
+{
+ stage->next->end( stage->next );
+}
+
+
+struct prim_stage *prim_clip( struct generic_context *generic )
+{
+ struct clipper *clipper = CALLOC_STRUCT(clipper);
+
+ prim_alloc_tmps( &clipper->stage, MAX_CLIPPED_VERTICES );
+
+ clipper->stage.generic = generic;
+ clipper->stage.begin = clip_begin;
+ clipper->stage.point = clip_point;
+ clipper->stage.line = clip_line;
+ clipper->stage.tri = clip_tri;
+ clipper->stage.end = clip_end;
+
+ return &clipper->stage;
+}
diff --git a/src/mesa/softpipe/generic/g_prim_cull.c b/src/mesa/softpipe/generic/g_prim_cull.c
new file mode 100644
index 0000000000..633fbcc492
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim_cull.c
@@ -0,0 +1,119 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#include "imports.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+
+
+
+struct cull_stage {
+ struct prim_stage stage;
+ GLuint mode;
+};
+
+
+
+static INLINE struct cull_stage *cull_stage( struct prim_stage *stage )
+{
+ return (struct cull_stage *)stage;
+}
+
+
+static void cull_begin( struct prim_stage *stage )
+{
+ struct cull_stage *cull = cull_stage(stage);
+
+ cull->mode = stage->generic->setup.cull_mode;
+
+ stage->next->begin( stage->next );
+}
+
+
+static void cull_tri( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ /* Window coords: */
+ GLfloat *v0 = (GLfloat *)&(header->v[0]->data[0]);
+ GLfloat *v1 = (GLfloat *)&(header->v[1]->data[0]);
+ GLfloat *v2 = (GLfloat *)&(header->v[2]->data[0]);
+
+ GLfloat ex = v0[0] - v2[0];
+ GLfloat ey = v0[1] - v2[1];
+ GLfloat fx = v1[0] - v2[0];
+ GLfloat fy = v1[1] - v2[1];
+
+ header->det = ex * fy - ey * fx;
+
+ _mesa_printf("%s %f\n", __FUNCTION__, header->det );
+
+ if (header->det != 0) {
+ GLuint mode = (header->det < 0) ? WINDING_CW : WINDING_CCW;
+
+ if ((mode & cull_stage(stage)->mode) == 0)
+ stage->next->tri( stage->next, header );
+ }
+}
+
+
+static void cull_line( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->line( stage->next, header );
+}
+
+
+static void cull_point( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->point( stage->next, header );
+}
+
+static void cull_end( struct prim_stage *stage )
+{
+ stage->next->end( stage->next );
+}
+
+struct prim_stage *prim_cull( struct generic_context *generic )
+{
+ struct cull_stage *cull = CALLOC_STRUCT(cull_stage);
+
+ prim_alloc_tmps( &cull->stage, 0 );
+
+ cull->stage.generic = generic;
+ cull->stage.next = NULL;
+ cull->stage.begin = cull_begin;
+ cull->stage.point = cull_point;
+ cull->stage.line = cull_line;
+ cull->stage.tri = cull_tri;
+ cull->stage.end = cull_end;
+
+ return &cull->stage;
+}
diff --git a/src/mesa/softpipe/generic/g_prim_flatshade.c b/src/mesa/softpipe/generic/g_prim_flatshade.c
new file mode 100644
index 0000000000..1974a64fa8
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim_flatshade.c
@@ -0,0 +1,149 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#include "imports.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+
+
+struct flatshade_stage {
+ struct prim_stage stage;
+
+ const GLuint *lookup;
+};
+
+
+
+static INLINE struct flatshade_stage *flatshade_stage( struct prim_stage *stage )
+{
+ return (struct flatshade_stage *)stage;
+}
+
+
+static void flatshade_begin( struct prim_stage *stage )
+{
+ stage->next->begin( stage->next );
+}
+
+
+
+static INLINE void copy_attr( GLuint attr,
+ struct vertex_header *dst,
+ const struct vertex_header *src )
+{
+ if (attr) {
+ memcpy( dst->data[attr],
+ src->data[attr],
+ sizeof(src->data[0]) );
+ }
+}
+
+static void copy_colors( struct prim_stage *stage,
+ struct vertex_header *dst,
+ const struct vertex_header *src )
+{
+ struct flatshade_stage *flatshade = flatshade_stage(stage);
+ const GLuint *lookup = flatshade->lookup;
+
+ copy_attr( lookup[VF_ATTRIB_COLOR0], dst, src );
+ copy_attr( lookup[VF_ATTRIB_COLOR1], dst, src );
+ copy_attr( lookup[VF_ATTRIB_BFC0], dst, src );
+ copy_attr( lookup[VF_ATTRIB_BFC1], dst, src );
+}
+
+
+
+/* Flatshade tri. Required for clipping and when unfilled tris are
+ * active, otherwise handled by hardware.
+ */
+static void flatshade_tri( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ struct prim_header tmp;
+
+ tmp.det = header->det;
+ tmp.v[0] = dup_vert(stage, header->v[0], 0);
+ tmp.v[1] = dup_vert(stage, header->v[1], 1);
+ tmp.v[2] = header->v[2];
+
+ copy_colors(stage, tmp.v[0], tmp.v[2]);
+ copy_colors(stage, tmp.v[1], tmp.v[2]);
+
+ stage->next->tri( stage->next, &tmp );
+}
+
+
+/* Flatshade line. Required for clipping.
+ */
+static void flatshade_line( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ struct prim_header tmp;
+
+ tmp.v[0] = dup_vert(stage, header->v[0], 0);
+ tmp.v[1] = header->v[1];
+
+ copy_colors(stage, tmp.v[0], tmp.v[1]);
+
+ stage->next->line( stage->next, &tmp );
+}
+
+
+static void flatshade_point( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->point( stage->next, header );
+}
+
+static void flatshade_end( struct prim_stage *stage )
+{
+ stage->next->end( stage->next );
+}
+
+struct prim_stage *prim_flatshade( struct generic_context *generic )
+{
+ struct flatshade_stage *flatshade = CALLOC_STRUCT(flatshade_stage);
+
+ prim_alloc_tmps( &flatshade->stage, 2 );
+
+ flatshade->stage.generic = generic;
+ flatshade->stage.next = NULL;
+ flatshade->stage.begin = flatshade_begin;
+ flatshade->stage.point = flatshade_point;
+ flatshade->stage.line = flatshade_line;
+ flatshade->stage.tri = flatshade_tri;
+ flatshade->stage.end = flatshade_end;
+
+ flatshade->lookup = generic->vf_attr_to_slot;
+
+ return &flatshade->stage;
+}
+
+
diff --git a/src/mesa/softpipe/generic/g_prim_offset.c b/src/mesa/softpipe/generic/g_prim_offset.c
new file mode 100644
index 0000000000..801ce9a441
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim_offset.c
@@ -0,0 +1,157 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#include "imports.h"
+#include "macros.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+
+
+
+struct offset_stage {
+ struct prim_stage stage;
+
+ GLuint hw_data_offset;
+
+ GLfloat scale;
+ GLfloat units;
+};
+
+
+
+static INLINE struct offset_stage *offset_stage( struct prim_stage *stage )
+{
+ return (struct offset_stage *)stage;
+}
+
+
+static void offset_begin( struct prim_stage *stage )
+{
+ struct offset_stage *offset = offset_stage(stage);
+
+ offset->units = stage->generic->setup.offset_units;
+ offset->scale = stage->generic->setup.offset_scale;
+
+ stage->next->begin( stage->next );
+}
+
+
+/* Offset tri. Some hardware can handle this, but not usually when
+ * doing unfilled rendering.
+ */
+static void do_offset_tri( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ struct offset_stage *offset = offset_stage(stage);
+ GLfloat inv_det = 1.0 / header->det;
+
+ /* Window coords:
+ */
+ GLfloat *v0 = (GLfloat *)&(header->v[0]->data[0]);
+ GLfloat *v1 = (GLfloat *)&(header->v[1]->data[0]);
+ GLfloat *v2 = (GLfloat *)&(header->v[2]->data[0]);
+
+ GLfloat ex = v0[0] - v2[2];
+ GLfloat fx = v1[0] - v2[2];
+ GLfloat ey = v0[1] - v2[2];
+ GLfloat fy = v1[1] - v2[2];
+ GLfloat ez = v0[2] - v2[2];
+ GLfloat fz = v1[2] - v2[2];
+
+ GLfloat a = ey*fz - ez*fy;
+ GLfloat b = ez*fx - ex*fz;
+
+ GLfloat ac = a * inv_det;
+ GLfloat bc = b * inv_det;
+ GLfloat zoffset;
+
+ if ( ac < 0.0f ) ac = -ac;
+ if ( bc < 0.0f ) bc = -bc;
+
+ zoffset = offset->units + MAX2( ac, bc ) * offset->scale;
+
+ v0[2] += zoffset;
+ v1[2] += zoffset;
+ v2[2] += zoffset;
+
+ stage->next->tri( stage->next, header );
+}
+
+
+static void offset_tri( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ struct prim_header tmp;
+
+ tmp.det = header->det;
+ tmp.v[0] = dup_vert(stage, header->v[0], 0);
+ tmp.v[1] = dup_vert(stage, header->v[1], 1);
+ tmp.v[2] = dup_vert(stage, header->v[2], 2);
+
+ do_offset_tri( stage->next, &tmp );
+}
+
+
+
+static void offset_line( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->line( stage->next, header );
+}
+
+
+static void offset_point( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->point( stage->next, header );
+}
+
+
+static void offset_end( struct prim_stage *stage )
+{
+ stage->next->end( stage->next );
+}
+
+struct prim_stage *prim_offset( struct generic_context *generic )
+{
+ struct offset_stage *offset = CALLOC_STRUCT(offset_stage);
+
+ prim_alloc_tmps( &offset->stage, 3 );
+
+ offset->stage.generic = generic;
+ offset->stage.next = NULL;
+ offset->stage.begin = offset_begin;
+ offset->stage.point = offset_point;
+ offset->stage.line = offset_line;
+ offset->stage.tri = offset_tri;
+ offset->stage.end = offset_end;
+
+ return &offset->stage;
+}
diff --git a/src/mesa/softpipe/generic/g_prim_setup.c b/src/mesa/softpipe/generic/g_prim_setup.c
new file mode 100644
index 0000000000..3e9639f7bc
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim_setup.c
@@ -0,0 +1,568 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "imports.h"
+#include "macros.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+#include "g_tile.h"
+
+
+struct edge {
+ GLfloat dx; /* X(v1) - X(v0), used only during setup */
+ GLfloat dy; /* Y(v1) - Y(v0), used only during setup */
+ GLfloat dxdy; /* dx/dy */
+ GLfloat sx; /* first sample point x coord */
+ GLfloat sy;
+ GLint lines; /* number of lines on this edge */
+};
+
+
+struct setup_stage {
+ struct prim_stage stage;
+
+ /* Vertices are just an array of floats making up each attribute in
+ * turn. Currently fixed at 4 floats, but should change in time.
+ * Codegen will help cope with this.
+ */
+ const struct vertex_header *vmax;
+ const struct vertex_header *vmid;
+ const struct vertex_header *vmin;
+ const struct vertex_header *vprovoke;
+
+ struct edge ebot;
+ struct edge etop;
+ struct edge emaj;
+
+ GLfloat oneoverarea;
+
+ struct setup_coefficient coef[FRAG_ATTRIB_MAX];
+ struct quad_header quad;
+
+ struct {
+ GLint left[2];
+ GLint right[2];
+ GLint y;
+ GLuint y_flags;
+ GLuint mask;
+ } span;
+
+};
+
+
+
+
+static inline struct setup_stage *setup_stage( struct prim_stage *stage )
+{
+ return (struct setup_stage *)stage;
+}
+
+
+
+static inline GLint _min(GLint x, GLint y)
+{
+ return x < y ? x : y;
+}
+
+static inline GLint _max(GLint x, GLint y)
+{
+ return x > y ? x : y;
+}
+
+static inline GLint block( GLint x )
+{
+ return x & ~1;
+}
+
+
+
+static void setup_begin( struct prim_stage *stage )
+{
+ setup_stage(stage)->quad.nr_attrs = stage->generic->nr_frag_attrs;
+}
+
+
+
+static void run_shader_block( struct setup_stage *setup,
+ GLint x, GLint y, GLuint mask )
+{
+ setup->quad.x0 = x;
+ setup->quad.y0 = y;
+ setup->quad.mask = mask;
+
+ quad_shade( setup->stage.generic, &setup->quad );
+}
+
+
+/* this is pretty nasty... may need to rework flush_spans again to
+ * fix it, if possible.
+ */
+static GLuint calculate_mask( struct setup_stage *setup,
+ GLint x )
+{
+ GLuint mask = 0;
+
+ if (x >= setup->span.left[0] && x < setup->span.right[0])
+ mask |= MASK_BOTTOM_LEFT;
+
+ if (x >= setup->span.left[1] && x < setup->span.right[1])
+ mask |= MASK_TOP_LEFT;
+
+ if (x+1 >= setup->span.left[0] && x+1 < setup->span.right[0])
+ mask |= MASK_BOTTOM_RIGHT;
+
+ if (x+1 >= setup->span.left[1] && x+1 < setup->span.right[1])
+ mask |= MASK_TOP_RIGHT;
+
+ return mask;
+}
+
+
+static void flush_spans( struct setup_stage *setup )
+{
+ GLint minleft, maxright;
+ GLint x;
+
+ switch (setup->span.y_flags) {
+ case 3:
+ minleft = _min(setup->span.left[0],
+ setup->span.left[1]);
+ maxright = _max(setup->span.right[0],
+ setup->span.right[1]);
+ break;
+
+ case 1:
+ minleft = setup->span.left[0];
+ maxright = setup->span.right[0];
+ break;
+
+ case 2:
+ minleft = setup->span.left[1];
+ maxright = setup->span.right[1];
+ break;
+
+ default:
+ return;
+ }
+
+
+ for (x = block(minleft); x <= block(maxright); )
+ {
+ run_shader_block( setup, x,
+ setup->span.y,
+ calculate_mask( setup, x ) );
+ x += 2;
+ }
+
+ setup->span.y = 0;
+ setup->span.y_flags = 0;
+ setup->span.right[0] = 0;
+ setup->span.right[1] = 0;
+}
+
+
+
+static void
+setup_point( struct prim_stage *stage,
+ struct prim_header *header )
+{
+}
+
+
+static void
+setup_line( struct prim_stage *stage,
+ struct prim_header *header )
+{
+}
+
+
+
+
+
+
+static GLboolean setup_sort_vertices( struct setup_stage *setup,
+ const struct prim_header *prim )
+{
+
+ const struct vertex_header *v0 = prim->v[0];
+ const struct vertex_header *v1 = prim->v[1];
+ const struct vertex_header *v2 = prim->v[2];
+
+ setup->vprovoke = v2;
+// setup->oneoverarea = -1.0 / prim->det;
+
+ /* determine bottom to top order of vertices */
+ {
+ GLfloat y0 = v0->data[0][1];
+ GLfloat y1 = v1->data[0][1];
+ GLfloat y2 = v2->data[0][1];
+ if (y0 <= y1) {
+ if (y1 <= y2) {
+ /* y0<=y1<=y2 */
+ setup->vmin = v0;
+ setup->vmid = v1;
+ setup->vmax = v2;
+ }
+ else if (y2 <= y0) {
+ /* y2<=y0<=y1 */
+ setup->vmin = v2;
+ setup->vmid = v0;
+ setup->vmax = v1;
+ }
+ else {
+ /* y0<=y2<=y1 */
+ setup->vmin = v0;
+ setup->vmid = v2;
+ setup->vmax = v1;
+// setup->oneoverarea = -setup->oneoverarea;
+ }
+ }
+ else {
+ if (y0 <= y2) {
+ /* y1<=y0<=y2 */
+ setup->vmin = v1;
+ setup->vmid = v0;
+ setup->vmax = v2;
+// setup->oneoverarea = -setup->oneoverarea;
+ }
+ else if (y2 <= y1) {
+ /* y2<=y1<=y0 */
+ setup->vmin = v2;
+ setup->vmid = v1;
+ setup->vmax = v0;
+// setup->oneoverarea = -setup->oneoverarea;
+ }
+ else {
+ /* y1<=y2<=y0 */
+ setup->vmin = v1;
+ setup->vmid = v2;
+ setup->vmax = v0;
+ }
+ }
+ }
+
+ setup->ebot.dx = setup->vmid->data[0][0] - setup->vmin->data[0][0];
+ setup->ebot.dy = setup->vmid->data[0][1] - setup->vmin->data[0][1];
+ setup->emaj.dx = setup->vmax->data[0][0] - setup->vmin->data[0][0];
+ setup->emaj.dy = setup->vmax->data[0][1] - setup->vmin->data[0][1];
+ setup->etop.dx = setup->vmax->data[0][0] - setup->vmid->data[0][0];
+ setup->etop.dy = setup->vmax->data[0][1] - setup->vmid->data[0][1];
+
+ /* xxx: may need to adjust this sign according to the if-tree
+ * above:
+ *
+ * XXX: this is like 'det', but calculated from screen coords??
+ */
+ {
+ const GLfloat area = (setup->emaj.dx * setup->ebot.dy -
+ setup->ebot.dx * setup->emaj.dy);
+
+ setup->oneoverarea = 1.0 / area;
+ }
+
+
+ _mesa_printf("%s one-over-area %f\n", __FUNCTION__, setup->oneoverarea );
+
+
+ return GL_TRUE;
+}
+
+
+static void const_coeff( struct setup_stage *setup,
+ GLuint slot,
+ GLuint i )
+{
+ setup->coef[slot].dadx[i] = 0;
+ setup->coef[slot].dady[i] = 0;
+
+ /* need provoking vertex info!
+ */
+ setup->coef[slot].a0[i] = setup->vprovoke->data[slot][i];
+}
+
+
+static void linear_coeff( struct setup_stage *setup,
+ GLuint slot,
+ GLuint i)
+{
+ GLfloat botda = setup->vmid->data[slot][i] - setup->vmin->data[slot][i];
+ GLfloat majda = setup->vmax->data[slot][i] - setup->vmin->data[slot][i];
+ GLfloat a = setup->ebot.dy * majda - botda * setup->emaj.dy;
+ GLfloat b = setup->emaj.dx * botda - majda * setup->ebot.dx;
+
+ setup->coef[slot].dadx[i] = a * setup->oneoverarea;
+ setup->coef[slot].dady[i] = b * setup->oneoverarea;
+
+ /* calculate a0 as the value which would be sampled for the
+ * fragment at (0,0), taking into account that we want to sample at
+ * pixel centers, in other words (0.5, 0.5).
+ *
+ * this is neat but unfortunately not a good way to do things for
+ * triangles with very large values of dadx or dady as it will
+ * result in the subtraction and re-addition from a0 of a very
+ * large number, which means we'll end up loosing a lot of the
+ * fractional bits and precision from a0. the way to fix this is
+ * to define a0 as the sample at a pixel center somewhere near vmin
+ * instead - i'll switch to this later.
+ */
+ setup->coef[slot].a0[i] = (setup->vmin->data[slot][i] -
+ (setup->coef[slot].dadx[i] * (setup->vmin->data[0][0] - 0.5) +
+ setup->coef[slot].dady[i] * (setup->vmin->data[0][1] - 0.5)));
+
+ _mesa_printf("attr[%d].%c: %f dx:%f dy:%f\n",
+ slot, "xyzw"[i],
+ setup->coef[slot].a0[i],
+ setup->coef[slot].dadx[i],
+ setup->coef[slot].dady[i]);
+}
+
+
+static void persp_coeff( struct setup_stage *setup,
+ GLuint slot,
+ GLuint i )
+{
+ /* premultiply by 1/w:
+ */
+ GLfloat mina = setup->vmin->data[slot][i] * setup->vmin->data[0][3];
+ GLfloat mida = setup->vmid->data[slot][i] * setup->vmid->data[0][3];
+ GLfloat maxa = setup->vmax->data[slot][i] * setup->vmax->data[0][3];
+
+ GLfloat botda = mida - mina;
+ GLfloat majda = maxa - mina;
+ GLfloat a = setup->ebot.dy * majda - botda * setup->emaj.dy;
+ GLfloat b = setup->emaj.dx * botda - majda * setup->ebot.dx;
+
+ setup->coef[slot].dadx[i] = a * setup->oneoverarea;
+ setup->coef[slot].dady[i] = b * setup->oneoverarea;
+ setup->coef[slot].a0[i] = (mina -
+ (setup->coef[slot].dadx[i] * (setup->vmin->data[0][0] - 0.5) +
+ setup->coef[slot].dady[i] * (setup->vmin->data[0][1] - 0.5)));
+}
+
+
+
+
+static void setup_coefficients( struct setup_stage *setup )
+{
+ const enum interp_mode *interp = setup->stage.generic->interp;
+ GLuint slot, j;
+
+ /* z and w are done by linear interpolation:
+ */
+ linear_coeff(setup, 0, 2);
+ linear_coeff(setup, 0, 3);
+
+ /* setup interpolation for all the remaining attributes:
+ */
+ for (slot = 1; slot < setup->quad.nr_attrs; slot++) {
+ switch (interp[slot]) {
+ case INTERP_CONSTANT:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ const_coeff(setup, slot, j);
+ break;
+
+ case INTERP_LINEAR:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ linear_coeff(setup, slot, j);
+ break;
+
+ case INTERP_PERSPECTIVE:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ persp_coeff(setup, slot, j);
+ break;
+ }
+ }
+}
+
+
+
+static void setup_edges( struct setup_stage *setup )
+{
+ GLfloat vmin_x = setup->vmin->data[0][0] + 0.5;
+ GLfloat vmid_x = setup->vmid->data[0][0] + 0.5;
+
+ GLfloat vmin_y = setup->vmin->data[0][1] - 0.5;
+ GLfloat vmid_y = setup->vmid->data[0][1] - 0.5;
+ GLfloat vmax_y = setup->vmax->data[0][1] - 0.5;
+
+ setup->emaj.sy = ceilf(vmin_y);
+ setup->emaj.lines = (GLint) ceilf(vmax_y - setup->emaj.sy);
+ setup->emaj.dxdy = setup->emaj.dx / setup->emaj.dy;
+ setup->emaj.sx = vmin_x + (setup->emaj.sy - vmin_y) * setup->emaj.dxdy;
+
+ setup->etop.sy = ceilf(vmid_y);
+ setup->etop.lines = (GLint) ceilf(vmax_y - setup->etop.sy);
+ setup->etop.dxdy = setup->etop.dx / setup->etop.dy;
+ setup->etop.sx = vmid_x + (setup->etop.sy - vmid_y) * setup->etop.dxdy;
+
+ setup->ebot.sy = ceilf(vmin_y);
+ setup->ebot.lines = (GLint) ceilf(vmid_y - setup->ebot.sy);
+ setup->ebot.dxdy = setup->ebot.dx / setup->ebot.dy;
+ setup->ebot.sx = vmin_x + (setup->ebot.sy - vmin_y) * setup->ebot.dxdy;
+}
+
+
+
+
+
+
+static void subtriangle( struct setup_stage *setup,
+ struct edge *eleft,
+ struct edge *eright,
+ GLuint lines )
+{
+ GLint y, start_y, finish_y;
+ GLint sy = (GLint)eleft->sy;
+
+ assert((GLint)eleft->sy == (GLint) eright->sy);
+ assert((GLint)eleft->sy >= 0); /* catch bug in x64? */
+
+ /* scissor y:
+ */
+ if (setup->stage.generic->setup.scissor) {
+ start_y = sy;
+ finish_y = start_y + lines;
+
+ if (start_y < setup->stage.generic->scissor.miny)
+ start_y = setup->stage.generic->scissor.miny;
+
+ if (finish_y > setup->stage.generic->scissor.maxy)
+ finish_y = setup->stage.generic->scissor.maxy;
+
+ start_y -= sy;
+ finish_y -= sy;
+ }
+ else {
+ start_y = 0;
+ finish_y = lines;
+ }
+
+ _mesa_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y);
+
+ for (y = start_y; y < finish_y; y++) {
+
+ /* avoid accumulating adds as floats don't have the precision to
+ * accurately iterate large triangle edges that way. luckily we
+ * can just multiply these days.
+ *
+ * this is all drowned out by the attribute interpolation anyway.
+ */
+ GLint left = (GLint)(eleft->sx + y * eleft->dxdy);
+ GLint right = (GLint)(eright->sx + y * eright->dxdy);
+
+ /* scissor x:
+ */
+ if (setup->stage.generic->setup.scissor) {
+ if (left < setup->stage.generic->scissor.minx)
+ left = setup->stage.generic->scissor.minx;
+
+ if (right > setup->stage.generic->scissor.maxx)
+ right = setup->stage.generic->scissor.maxx;
+ }
+
+ if (left < right) {
+ GLint _y = sy+y;
+ if (block(_y) != setup->span.y) {
+ flush_spans(setup);
+ setup->span.y = block(_y);
+ }
+
+ setup->span.left[_y&1] = left;
+ setup->span.right[_y&1] = right;
+ setup->span.y_flags |= 1<<(_y&1);
+ }
+ }
+
+
+ /* save the values so that emaj can be restarted:
+ */
+ eleft->sx += lines * eleft->dxdy;
+ eright->sx += lines * eright->dxdy;
+ eleft->sy += lines;
+ eright->sy += lines;
+}
+
+
+static void setup_tri( struct prim_stage *stage,
+ struct prim_header *prim )
+{
+ struct setup_stage *setup = setup_stage( stage );
+
+ _mesa_printf("%s\n", __FUNCTION__ );
+
+ setup_sort_vertices( setup, prim );
+ setup_coefficients( setup );
+ setup_edges( setup );
+
+ setup->span.y = 0;
+ setup->span.y_flags = 0;
+ setup->span.right[0] = 0;
+ setup->span.right[1] = 0;
+// setup->span.z_mode = tri_z_mode( setup->ctx );
+
+// init_constant_attribs( setup );
+
+ if (setup->oneoverarea < 0.0) {
+ /* emaj on left:
+ */
+ subtriangle( setup, &setup->emaj, &setup->ebot, setup->ebot.lines );
+ subtriangle( setup, &setup->emaj, &setup->etop, setup->etop.lines );
+ }
+ else {
+ /* emaj on right:
+ */
+ subtriangle( setup, &setup->ebot, &setup->emaj, setup->ebot.lines );
+ subtriangle( setup, &setup->etop, &setup->emaj, setup->etop.lines );
+ }
+
+ flush_spans( setup );
+}
+
+static void setup_end( struct prim_stage *stage )
+{
+}
+
+
+struct prim_stage *prim_setup( struct generic_context *generic )
+{
+ struct setup_stage *setup = CALLOC_STRUCT(setup_stage);
+
+ setup->stage.generic = generic;
+ setup->stage.begin = setup_begin;
+ setup->stage.point = setup_point;
+ setup->stage.line = setup_line;
+ setup->stage.tri = setup_tri;
+ setup->stage.end = setup_end;
+
+ setup->quad.coef = setup->coef;
+
+ return &setup->stage;
+}
diff --git a/src/mesa/softpipe/generic/g_prim_setup.h b/src/mesa/softpipe/generic/g_prim_setup.h
new file mode 100644
index 0000000000..40a70c543e
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim_setup.h
@@ -0,0 +1,121 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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.
+ */
+
+#ifndef S_TRI_H
+#define S_TRI_H
+
+/* Vertices are just an array of floats, with all the attributes
+ * packed. We currently assume a layout like:
+ *
+ * attr[0][0..3] - window position
+ * attr[1..n][0..3] - remaining attributes.
+ *
+ * Attributes are assumed to be 4 floats wide but are packed so that
+ * all the enabled attributes run contiguously.
+ */
+
+#include "glheader.h"
+#include "imports.h"
+#include "s_tri_public.h"
+#include "s_context.h"
+
+
+
+struct tri_context;
+struct fp_context;
+struct be_context;
+
+/* Note the rasterizer does not take a GLcontext argument. This is
+ * deliberate.
+ */
+struct tri_context *tri_create_context( GLcontext *ctx );
+
+void tri_destroy_context( struct tri_context *tri );
+
+void tri_set_fp_context( struct tri_context *tri,
+ struct fp_context *fp,
+ void (*fp_run)( struct fp_context *fp,
+ const struct fp_inputs *,
+ struct fp_outputs * ));
+
+
+void tri_set_be_context( struct tri_context *tri,
+ struct be_context *be,
+ void (*be_run)( struct be_context *be,
+ const struct fp_outputs * ));
+
+void tri_set_attribs( struct tri_context *tri,
+ const struct attr_info *info,
+ GLuint nr_attrib );
+
+void tri_set_backface( struct tri_context *tri,
+ GLfloat backface );
+
+void tri_set_scissor( struct tri_context *tri,
+ GLint x,
+ GLint y,
+ GLuint width,
+ GLuint height,
+ GLboolean enabled );
+
+void tri_set_stipple( struct tri_context *tri,
+ const GLuint *pattern,
+ GLboolean enabled );
+
+/* Unfilled triangles will be handled elsewhere (higher in the
+ * pipeline), as will things like stipple (lower in the pipeline).
+ */
+
+void tri_triangle( struct tri_context *tri,
+ const struct vertex *v0,
+ const struct vertex *v1,
+ const struct vertex *v2 );
+
+/* TODO: rasterize_line, rasterize_point??
+ * How will linestipple work?
+ */
+
+
+#ifdef SETUP_PRIVATE
+
+
+
+
+
+
+GLboolean tri_setup( struct tri_context *tri,
+ const struct vertex *v0,
+ const struct vertex *v1,
+ const struct vertex *v2 );
+
+void tri_rasterize( struct tri_context *tri );
+void tri_rasterize_spans( struct tri_context *tri );
+
+
+
+
+
+
+#endif
+#endif
diff --git a/src/mesa/softpipe/generic/g_prim_twoside.c b/src/mesa/softpipe/generic/g_prim_twoside.c
new file mode 100644
index 0000000000..334ae2f537
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim_twoside.c
@@ -0,0 +1,149 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#include "imports.h"
+#include "g_context.h"
+#include "g_prim.h"
+
+
+struct twoside_stage {
+ struct prim_stage stage;
+
+ GLfloat facing;
+ const GLuint *lookup;
+};
+
+
+static INLINE struct twoside_stage *twoside_stage( struct prim_stage *stage )
+{
+ return (struct twoside_stage *)stage;
+}
+
+
+static void twoside_begin( struct prim_stage *stage )
+{
+ struct twoside_stage *twoside = twoside_stage(stage);
+
+ twoside->facing = (stage->generic->setup.front_winding == WINDING_CW) ? -1 : 1;
+
+ stage->next->begin( stage->next );
+}
+
+
+static INLINE void copy_color( GLuint attr_dst,
+ GLuint attr_src,
+ struct vertex_header *v )
+{
+ if (attr_dst && attr_src) {
+ memcpy( v->data[attr_dst],
+ v->data[attr_src],
+ sizeof(v->data[0]) );
+ }
+}
+
+
+static struct vertex_header *copy_bfc( struct twoside_stage *twoside,
+ const struct vertex_header *v,
+ GLuint idx )
+{
+ struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx );
+
+ copy_color( twoside->lookup[VF_ATTRIB_COLOR0],
+ twoside->lookup[VF_ATTRIB_BFC0],
+ tmp );
+
+ copy_color( twoside->lookup[VF_ATTRIB_COLOR1],
+ twoside->lookup[VF_ATTRIB_BFC1],
+ tmp );
+
+ return tmp;
+}
+
+
+/* Twoside tri:
+ */
+static void twoside_tri( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ struct twoside_stage *twoside = twoside_stage(stage);
+
+ if (header->det * twoside->facing < 0) {
+ struct prim_header tmp;
+
+ tmp.det = header->det;
+ tmp.v[0] = copy_bfc(twoside, header->v[0], 0);
+ tmp.v[1] = copy_bfc(twoside, header->v[1], 1);
+ tmp.v[2] = copy_bfc(twoside, header->v[2], 2);
+
+ stage->next->tri( stage->next, &tmp );
+ }
+ else {
+ stage->next->tri( stage->next, header );
+ }
+}
+
+
+static void twoside_line( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->line( stage->next, header );
+}
+
+
+static void twoside_point( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->point( stage->next, header );
+}
+
+static void twoside_end( struct prim_stage *stage )
+{
+ stage->next->end( stage->next );
+}
+
+
+
+struct prim_stage *prim_twoside( struct generic_context *generic )
+{
+ struct twoside_stage *twoside = CALLOC_STRUCT(twoside_stage);
+
+ prim_alloc_tmps( &twoside->stage, 3 );
+
+ twoside->stage.generic = generic;
+ twoside->stage.next = NULL;
+ twoside->stage.begin = twoside_begin;
+ twoside->stage.point = twoside_point;
+ twoside->stage.line = twoside_line;
+ twoside->stage.tri = twoside_tri;
+ twoside->stage.end = twoside_end;
+
+ twoside->lookup = generic->vf_attr_to_slot;
+
+ return &twoside->stage;
+}
diff --git a/src/mesa/softpipe/generic/g_prim_unfilled.c b/src/mesa/softpipe/generic/g_prim_unfilled.c
new file mode 100644
index 0000000000..7c6ee79f92
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_prim_unfilled.c
@@ -0,0 +1,165 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#include "imports.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+
+
+
+struct unfilled_stage {
+ struct prim_stage stage;
+
+ GLuint mode[2];
+};
+
+
+static INLINE struct unfilled_stage *unfilled_stage( struct prim_stage *stage )
+{
+ return (struct unfilled_stage *)stage;
+}
+
+
+static void unfilled_begin( struct prim_stage *stage )
+{
+ struct unfilled_stage *unfilled = unfilled_stage(stage);
+
+ unfilled->mode[0] = stage->generic->setup.fill_ccw;
+ unfilled->mode[1] = stage->generic->setup.fill_cw;
+
+ stage->next->begin( stage->next );
+}
+
+static void point( struct prim_stage *stage,
+ struct vertex_header *v0 )
+{
+ struct prim_header tmp;
+ tmp.v[0] = v0;
+ stage->next->point( stage->next, &tmp );
+}
+
+static void line( struct prim_stage *stage,
+ struct vertex_header *v0,
+ struct vertex_header *v1 )
+{
+ struct prim_header tmp;
+ tmp.v[0] = v0;
+ tmp.v[1] = v1;
+ stage->next->line( stage->next, &tmp );
+}
+
+
+static void points( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ struct vertex_header *v0 = header->v[0];
+ struct vertex_header *v1 = header->v[1];
+ struct vertex_header *v2 = header->v[2];
+
+ if (v0->edgeflag) point( stage, v0 );
+ if (v1->edgeflag) point( stage, v1 );
+ if (v2->edgeflag) point( stage, v2 );
+}
+
+static void lines( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ struct vertex_header *v0 = header->v[0];
+ struct vertex_header *v1 = header->v[1];
+ struct vertex_header *v2 = header->v[2];
+
+ if (v0->edgeflag) line( stage, v0, v1 );
+ if (v1->edgeflag) line( stage, v1, v2 );
+ if (v2->edgeflag) line( stage, v2, v0 );
+}
+
+
+/* Unfilled tri:
+ *
+ * Note edgeflags in the vertex struct is not sufficient as we will
+ * need to manipulate them when decomposing primitives???
+ */
+static void unfilled_tri( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ struct unfilled_stage *unfilled = unfilled_stage(stage);
+ GLuint mode = unfilled->mode[header->det < 0];
+
+ switch (mode) {
+ case FILL_TRI:
+ stage->next->tri( stage->next, header );
+ break;
+
+ case FILL_LINE:
+ lines( stage, header );
+ break;
+
+ case GL_POINT:
+ points( stage, header );
+ break;
+ }
+}
+
+static void unfilled_line( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->line( stage->next, header );
+}
+
+
+static void unfilled_point( struct prim_stage *stage,
+ struct prim_header *header )
+{
+ stage->next->point( stage->next, header );
+}
+
+
+static void unfilled_end( struct prim_stage *stage )
+{
+ stage->next->end( stage->next );
+}
+
+struct prim_stage *prim_unfilled( struct generic_context *generic )
+{
+ struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
+
+ prim_alloc_tmps( &unfilled->stage, 0 );
+
+ unfilled->stage.generic = generic;
+ unfilled->stage.next = NULL;
+ unfilled->stage.tmp = NULL;
+ unfilled->stage.begin = unfilled_begin;
+ unfilled->stage.point = unfilled_point;
+ unfilled->stage.line = unfilled_line;
+ unfilled->stage.tri = unfilled_tri;
+ unfilled->stage.end = unfilled_end;
+
+ return &unfilled->stage;
+}
diff --git a/src/mesa/softpipe/generic/g_state.h b/src/mesa/softpipe/generic/g_state.h
new file mode 100644
index 0000000000..5077d37ab7
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_state.h
@@ -0,0 +1,61 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#ifndef PRIM_H
+#define PRIM_H
+
+#include "glheader.h"
+#include "softpipe/sp_state.h"
+
+
+void generic_set_clip_state( struct softpipe_context *,
+ const struct softpipe_clip_state * );
+
+void generic_set_viewport( struct softpipe_context *,
+ const struct softpipe_viewport * );
+
+void generic_set_setup_state( struct softpipe_context *,
+ const struct softpipe_setup_state * );
+
+void generic_set_scissor_rect( struct softpipe_context *,
+ const struct softpipe_scissor_rect * );
+
+void generic_set_fs_state( struct softpipe_context *,
+ const struct softpipe_fs_state * );
+
+void generic_set_polygon_stipple( struct softpipe_context *,
+ const struct softpipe_poly_stipple * );
+
+void generic_set_cbuf_state( struct softpipe_context *,
+ const struct softpipe_surface * );
+
+void generic_update_derived( struct generic_context *generic );
+
+#endif
diff --git a/src/mesa/softpipe/generic/g_state_clip.c b/src/mesa/softpipe/generic/g_state_clip.c
new file mode 100644
index 0000000000..b90034e11e
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_state_clip.c
@@ -0,0 +1,69 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#include "imports.h"
+
+#include "g_context.h"
+#include "g_state.h"
+#include "g_draw.h"
+
+
+
+void generic_set_clip_state( struct softpipe_context *softpipe,
+ const struct softpipe_clip_state *clip )
+{
+ struct generic_context *generic = generic_context(softpipe);
+
+ memcpy(&generic->plane[6], clip->ucp, clip->nr * sizeof(clip->ucp[0]));
+
+ generic->nr_planes = 6 + clip->nr;
+ generic->dirty |= G_NEW_CLIP;
+}
+
+
+
+/* Called when driver state tracker notices changes to the viewport
+ * matrix:
+ */
+void generic_set_viewport( struct softpipe_context *softpipe,
+ const struct softpipe_viewport *viewport )
+{
+ struct generic_context *generic = generic_context(softpipe);
+
+ memcpy(&generic->viewport, viewport, sizeof(viewport));
+
+ /* Using tnl/ and vf/ modules is temporary while getting started.
+ * Full softpipe will have vertex shader, vertex fetch of its own.
+ */
+ draw_set_viewport( generic->draw, viewport->scale, viewport->translate );
+ generic->dirty |= G_NEW_VIEWPORT;
+}
+
+
+
diff --git a/src/mesa/softpipe/generic/g_state_derived.c b/src/mesa/softpipe/generic/g_state_derived.c
new file mode 100644
index 0000000000..678825afe1
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_state_derived.c
@@ -0,0 +1,136 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 "glheader.h"
+#include "macros.h"
+#include "enums.h"
+#include "program.h"
+
+#include "g_context.h"
+#include "g_draw.h"
+#include "g_state.h"
+
+#define EMIT_ATTR( ATTR, FRAG_ATTR, INTERP ) \
+do { \
+ slot_to_vf_attr[generic->nr_attrs] = ATTR; \
+ generic->vf_attr_to_slot[ATTR] = generic->nr_attrs; \
+ generic->fp_attr_to_slot[FRAG_ATTR] = generic->nr_attrs; \
+ generic->interp[generic->nr_attrs] = INTERP; \
+ generic->nr_attrs++; \
+ attr_mask |= (1<<ATTR); \
+} while (0)
+
+
+static GLuint frag_to_vf[FRAG_ATTRIB_MAX] =
+{
+ VF_ATTRIB_POS,
+ VF_ATTRIB_COLOR0,
+ VF_ATTRIB_COLOR1,
+ VF_ATTRIB_FOG,
+ VF_ATTRIB_TEX0,
+ VF_ATTRIB_TEX1,
+ VF_ATTRIB_TEX2,
+ VF_ATTRIB_TEX3,
+ VF_ATTRIB_TEX4,
+ VF_ATTRIB_TEX5,
+ VF_ATTRIB_TEX6,
+ VF_ATTRIB_TEX7,
+};
+
+
+/* Derived from: fs, setup states.
+ */
+static void calculate_vertex_layout( struct generic_context *generic )
+{
+ struct gl_fragment_program *fp = generic->fs.fp;
+ const GLuint inputsRead = fp->Base.InputsRead;
+ GLuint slot_to_vf_attr[VF_ATTRIB_MAX];
+ GLuint attr_mask = 0;
+ GLuint i;
+
+ generic->nr_attrs = 0;
+ memset(slot_to_vf_attr, 0, sizeof(slot_to_vf_attr));
+
+ memset(generic->fp_attr_to_slot, 0, sizeof(generic->vf_attr_to_slot));
+ memset(generic->vf_attr_to_slot, 0, sizeof(generic->fp_attr_to_slot));
+
+ /* TODO - Figure out if we need to do perspective divide, etc.
+ */
+ EMIT_ATTR(VF_ATTRIB_POS, FRAG_ATTRIB_WPOS, INTERP_LINEAR);
+
+ /* Pull in the rest of the attributes. They are all in float4
+ * format. Future optimizations could be to keep some attributes
+ * as fixed point or ubyte format.
+ */
+ for (i = 1; i < FRAG_ATTRIB_TEX0; i++) {
+ if (inputsRead & (i << i)) {
+ EMIT_ATTR(frag_to_vf[i], i, INTERP_LINEAR);
+ }
+ }
+
+ for (i = FRAG_ATTRIB_TEX0; i < FRAG_ATTRIB_MAX; i++) {
+ if (inputsRead & (i << i)) {
+ EMIT_ATTR(frag_to_vf[i], i, INTERP_PERSPECTIVE);
+ }
+ }
+
+ generic->nr_frag_attrs = generic->nr_attrs;
+
+ /* Additional attributes required for setup: Just twosided
+ * lighting. Edgeflag is dealt with specially by setting bits in
+ * the vertex header.
+ */
+ if (generic->setup.light_twoside) {
+ if (inputsRead & FRAG_BIT_COL0) {
+ EMIT_ATTR(VF_ATTRIB_BFC0, FRAG_ATTRIB_MAX, 0); /* XXX: mark as discarded after setup */
+ }
+
+ if (inputsRead & FRAG_BIT_COL1) {
+ EMIT_ATTR(VF_ATTRIB_BFC1, FRAG_ATTRIB_MAX, 0); /* XXX: discard after setup */
+ }
+ }
+
+ if (attr_mask != generic->attr_mask) {
+ generic->attr_mask = attr_mask;
+
+ draw_set_vertex_attributes( generic->draw,
+ slot_to_vf_attr,
+ generic->nr_attrs );
+ }
+}
+
+
+/* Hopefully this will remain quite simple, otherwise need to pull in
+ * something like the state tracker mechanism.
+ */
+void generic_update_derived( struct generic_context *generic )
+{
+ if (generic->dirty & (G_NEW_SETUP | G_NEW_FS))
+ calculate_vertex_layout( generic );
+
+ generic->dirty = 0;
+}
diff --git a/src/mesa/softpipe/generic/g_state_fs.c b/src/mesa/softpipe/generic/g_state_fs.c
new file mode 100644
index 0000000000..8a430c0c65
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_state_fs.c
@@ -0,0 +1,50 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 "g_context.h"
+#include "g_state.h"
+
+
+
+void generic_set_fs_state( struct softpipe_context *softpipe,
+ const struct softpipe_fs_state *fs )
+{
+ struct generic_context *generic = generic_context(softpipe);
+
+ memcpy(&generic->fs, fs, sizeof(*fs));
+
+ generic->dirty |= G_NEW_FS;
+}
+
+
+
+
+
+
+
+
+
diff --git a/src/mesa/softpipe/generic/g_state_setup.c b/src/mesa/softpipe/generic/g_state_setup.c
new file mode 100644
index 0000000000..2a5176c5a1
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_state_setup.c
@@ -0,0 +1,122 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 "g_context.h"
+#include "g_state.h"
+#include "g_prim.h"
+
+
+
+
+static void validate_prim_pipe( struct generic_context *generic )
+{
+ struct prim_stage *next = generic->prim.setup;
+
+ /* TODO: make the current primitive part of the state and build
+ * shorter pipelines for lines & points.
+ */
+ if (generic->setup.fill_cw != FILL_TRI ||
+ generic->setup.fill_ccw != FILL_TRI) {
+
+ generic->prim.unfilled->next = next;
+ next = generic->prim.unfilled;
+ }
+
+ if (generic->setup.offset_cw ||
+ generic->setup.offset_ccw) {
+ generic->prim.offset->next = next;
+ next = generic->prim.offset;
+ }
+
+ if (generic->setup.light_twoside) {
+ generic->prim.twoside->next = next;
+ next = generic->prim.twoside;
+ }
+
+ /* Always run the cull stage as we calculate determinant there
+ * also. Fix this..
+ */
+ {
+ generic->prim.cull->next = next;
+ next = generic->prim.cull;
+ }
+
+
+ /* Clip stage
+ */
+ {
+ generic->prim.clip->next = next;
+ next = generic->prim.clip;
+ }
+
+ /* Do software flatshading prior to clipping. XXX: should only do
+ * this for clipped primitives, ie it is a part of the clip
+ * routine.
+ */
+ if (generic->setup.flatshade) {
+ generic->prim.flatshade->next = next;
+ next = generic->prim.flatshade;
+ }
+
+
+ generic->prim.first = next;
+}
+
+
+
+
+void generic_set_setup_state( struct softpipe_context *softpipe,
+ const struct softpipe_setup_state *setup )
+{
+ struct generic_context *generic = generic_context(softpipe);
+
+ memcpy( &generic->setup, setup, sizeof(*setup) );
+
+ validate_prim_pipe( generic );
+ generic->dirty |= G_NEW_SETUP;
+}
+
+
+
+void generic_set_scissor_rect( struct softpipe_context *softpipe,
+ const struct softpipe_scissor_rect *scissor )
+{
+ struct generic_context *generic = generic_context(softpipe);
+
+ memcpy( &generic->scissor, scissor, sizeof(*scissor) );
+ generic->dirty |= G_NEW_SCISSOR;
+}
+
+
+void generic_set_polygon_stipple( struct softpipe_context *softpipe,
+ const struct softpipe_poly_stipple *stipple )
+{
+ struct generic_context *generic = generic_context(softpipe);
+
+ memcpy( &generic->poly_stipple, stipple, sizeof(*stipple) );
+ generic->dirty |= G_NEW_STIPPLE;
+}
diff --git a/src/mesa/softpipe/generic/g_state_surface.c b/src/mesa/softpipe/generic/g_state_surface.c
new file mode 100644
index 0000000000..c791ce4640
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_state_surface.c
@@ -0,0 +1,53 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#include "imports.h"
+
+#include "g_context.h"
+#include "g_state.h"
+#include "g_surface.h"
+
+
+/* This is all a total hack.
+ */
+void generic_set_cbuf_state( struct softpipe_context *softpipe,
+ const struct softpipe_surface *surface )
+{
+ struct generic_context *generic = generic_context(softpipe);
+
+ if (generic->cbuf_surface == NULL) {
+ generic->cbuf_surface = CALLOC_STRUCT(generic_surface);
+ generic->cbuf_surface->type = &gs_rgba8;
+ }
+
+ generic->cbuf_surface->surface = *surface;
+ generic->dirty |= G_NEW_CBUF;
+}
+
+
diff --git a/src/mesa/softpipe/generic/g_surface.c b/src/mesa/softpipe/generic/g_surface.c
new file mode 100644
index 0000000000..2df30cde70
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_surface.c
@@ -0,0 +1,153 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 "g_context.h"
+#include "g_state.h"
+#include "g_surface.h"
+#include "g_headers.h"
+
+static void rgba8_read_quad_f( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLfloat (*rgba)[NUM_CHANNELS] )
+{
+ GLuint i, j, k = 0;
+
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < 2; j++, k++) {
+ GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4;
+ rgba[k][0] = ptr[0] * (1.0 / 255.0);
+ rgba[k][1] = ptr[1] * (1.0 / 255.0);
+ rgba[k][2] = ptr[2] * (1.0 / 255.0);
+ rgba[k][3] = ptr[3] * (1.0 / 255.0);
+ }
+ }
+}
+
+static void rgba8_read_quad_f_swz( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLfloat (*rrrr)[QUAD_SIZE] )
+{
+ GLuint i, j, k = 0;
+
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < 2; j++, k++) {
+ GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4;
+ rrrr[0][k] = ptr[0] * (1.0 / 255.0);
+ rrrr[1][k] = ptr[1] * (1.0 / 255.0);
+ rrrr[2][k] = ptr[2] * (1.0 / 255.0);
+ rrrr[3][k] = ptr[3] * (1.0 / 255.0);
+ }
+ }
+}
+
+static void rgba8_write_quad_f( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLfloat (*rgba)[NUM_CHANNELS] )
+{
+ GLuint i, j, k = 0;
+
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < 2; j++, k++) {
+ GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4;
+ ptr[0] = rgba[k][0] * 255.0;
+ ptr[1] = rgba[k][1] * 255.0;
+ ptr[2] = rgba[k][2] * 255.0;
+ ptr[3] = rgba[k][3] * 255.0;
+ }
+ }
+}
+
+static void rgba8_write_quad_f_swz( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLfloat (*rrrr)[QUAD_SIZE] )
+{
+ GLuint i, j, k = 0;
+
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < 2; j++, k++) {
+ GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4;
+ ptr[0] = rrrr[0][k] * 255.0;
+ ptr[1] = rrrr[1][k] * 255.0;
+ ptr[2] = rrrr[2][k] * 255.0;
+ ptr[3] = rrrr[3][k] * 255.0;
+ }
+ }
+}
+
+
+
+
+static void rgba8_read_quad_ub( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLubyte (*rgba)[NUM_CHANNELS] )
+{
+ GLuint i, j, k = 0;
+
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < 2; j++, k++) {
+ GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4;
+ rgba[k][0] = ptr[0];
+ rgba[k][1] = ptr[1];
+ rgba[k][2] = ptr[2];
+ rgba[k][3] = ptr[3];
+ }
+ }
+}
+
+
+static void rgba8_write_quad_ub( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLubyte (*rgba)[NUM_CHANNELS] )
+{
+ GLuint i, j, k = 0;
+
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < 2; j++, k++) {
+ GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4;
+ ptr[0] = rgba[k][0];
+ ptr[1] = rgba[k][1];
+ ptr[2] = rgba[k][2];
+ ptr[3] = rgba[k][3];
+ }
+ }
+}
+
+
+
+
+struct generic_surface_type gs_rgba8 = {
+ G_SURFACE_RGBA_8888,
+ rgba8_read_quad_f,
+ rgba8_read_quad_f_swz,
+ rgba8_read_quad_ub,
+ rgba8_write_quad_f,
+ rgba8_write_quad_f_swz,
+ rgba8_write_quad_ub,
+};
+
+
+
diff --git a/src/mesa/softpipe/generic/g_surface.h b/src/mesa/softpipe/generic/g_surface.h
new file mode 100644
index 0000000000..23c28f0bb4
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_surface.h
@@ -0,0 +1,115 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#ifndef G_SURFACE_H
+#define G_SURFACE_H
+
+#include "glheader.h"
+#include "g_headers.h"
+
+struct generic_surface;
+
+#define G_SURFACE_RGBA_8888 0x1
+
+/* Internal structs and helpers for the primitive clip/setup pipeline:
+ */
+struct generic_surface_type {
+
+ GLuint format;
+
+ void (*read_quad_f)( struct generic_surface *,
+ GLint x, GLint y,
+ GLfloat (*rgba)[NUM_CHANNELS] );
+
+ void (*read_quad_f_swz)( struct generic_surface *,
+ GLint x, GLint y,
+ GLfloat (*rrrr)[QUAD_SIZE] );
+
+ void (*read_quad_ub)( struct generic_surface *,
+ GLint x, GLint y,
+ GLubyte (*rgba)[NUM_CHANNELS] );
+
+
+ void (*write_quad_f)( struct generic_surface *,
+ GLint x, GLint y,
+ GLfloat (*rgba)[NUM_CHANNELS] );
+
+ void (*write_quad_f_swz)( struct generic_surface *,
+ GLint x, GLint y,
+ GLfloat (*rrrr)[QUAD_SIZE] );
+
+
+ void (*write_quad_ub)( struct generic_surface *,
+ GLint x, GLint y,
+ GLubyte (*rgba)[NUM_CHANNELS] );
+
+
+};
+
+
+struct generic_surface {
+ struct generic_surface_type *type;
+ struct softpipe_surface surface;
+};
+
+
+static INLINE void gs_read_quad_f( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLfloat (*rgba)[NUM_CHANNELS] )
+{
+ gs->type->read_quad_f(gs, x, y, rgba);
+}
+
+static INLINE void gs_read_quad_f_swz( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLfloat (*rrrr)[QUAD_SIZE] )
+{
+ gs->type->read_quad_f_swz(gs, x, y, rrrr);
+}
+
+static INLINE void gs_write_quad_f( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLfloat (*rgba)[NUM_CHANNELS] )
+{
+ gs->type->write_quad_f(gs, x, y, rgba);
+}
+
+static INLINE void gs_write_quad_f_swz( struct generic_surface *gs,
+ GLint x, GLint y,
+ GLfloat (*rrrr)[QUAD_SIZE] )
+{
+ gs->type->write_quad_f_swz(gs, x, y, rrrr);
+}
+
+/* Like this, or hidden?
+ */
+struct generic_surface_type gs_rgba8;
+
+#endif
diff --git a/src/mesa/softpipe/generic/g_tile.h b/src/mesa/softpipe/generic/g_tile.h
new file mode 100644
index 0000000000..6ae5212356
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_tile.h
@@ -0,0 +1,42 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+/* Authors: Keith Whitwell <keith@tungstengraphics.com>
+ */
+#ifndef G_TILE_H
+#define G_TILE_H
+
+struct generic_context;
+struct quad_header;
+
+void quad_shade( struct generic_context *generic,
+ struct quad_header *quad );
+
+void quad_output( struct generic_context *generic,
+ struct quad_header *quad );
+
+#endif
diff --git a/src/mesa/softpipe/generic/g_tile_fs.c b/src/mesa/softpipe/generic/g_tile_fs.c
new file mode 100644
index 0000000000..35e1ab63de
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_tile_fs.c
@@ -0,0 +1,188 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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.
+ */
+
+/* Vertices are just an array of floats, with all the attributes
+ * packed. We currently assume a layout like:
+ *
+ * attr[0][0..3] - window position
+ * attr[1..n][0..3] - remaining attributes.
+ *
+ * Attributes are assumed to be 4 floats wide but are packed so that
+ * all the enabled attributes run contiguously.
+ */
+
+#include "glheader.h"
+#include "g_context.h"
+#include "g_headers.h"
+#include "g_tile.h"
+
+struct exec_machine {
+ const struct setup_coefficient *coef;
+
+ GLfloat attr[FRAG_ATTRIB_MAX][4][QUAD_SIZE];
+};
+
+
+static void INLINE cinterp( struct exec_machine *exec,
+ GLuint attrib,
+ GLuint i )
+{
+ GLuint j;
+
+ for (j = 0; j < QUAD_SIZE; j++) {
+ exec->attr[attrib][i][j] = exec->coef[attrib].a0[i];
+ }
+}
+
+
+/* Push into the fp:
+ *
+ * INPUT[attr] = MAD COEF_A0[attr], COEF_DADX[attr], INPUT_WPOS.xxxx
+ * INPUT[attr] = MAD INPUT[attr], COEF_DADY[attr], INPUT_WPOS.yyyy
+ */
+static INLINE void linterp( struct exec_machine *exec,
+ GLuint attrib,
+ GLuint i )
+{
+ GLuint j;
+
+ for (j = 0; j < QUAD_SIZE; j++) {
+ exec->attr[attrib][i][j] = (exec->coef[attrib].a0[i] +
+ exec->coef[attrib].dadx[i] * exec->attr[0][0][j] +
+ exec->coef[attrib].dady[i] * exec->attr[0][1][j]);
+ }
+}
+
+
+/* Push into the fp:
+ *
+ * INPUT[attr] = MAD COEF_A0[attr], COEF_DADX[attr], INPUT_WPOS.xxxx
+ * INPUT[attr] = MAD INPUT[attr], COEF_DADY[attr], INPUT_WPOS.yyyy
+ * INPUT[attr] = MUL INPUT[attr], INPUT_WPOS.wwww
+ *
+ * (Or should that be 1/w ???)
+ */
+static INLINE void pinterp( struct exec_machine *exec,
+ GLuint attrib,
+ GLuint i )
+{
+ GLuint j;
+
+ for (j = 0; j < QUAD_SIZE; j++) {
+ exec->attr[attrib][i][j] = ((exec->coef[attrib].a0[i] +
+ exec->coef[attrib].dadx[i] * exec->attr[0][0][j] +
+ exec->coef[attrib].dady[i] * exec->attr[0][1][j]) *
+ exec->attr[0][3][j]);
+ }
+}
+
+
+
+/* This should be done by the fragment shader execution unit (code
+ * generated from the decl instructions). Do it here for now.
+ */
+void quad_shade( struct generic_context *generic,
+ struct quad_header *quad )
+{
+ struct exec_machine exec;
+ GLfloat fx = quad->x0;
+ GLfloat fy = quad->y0;
+ GLuint i, j;
+
+ exec.coef = quad->coef;
+
+ /* Position:
+ */
+ exec.attr[FRAG_ATTRIB_WPOS][0][0] = fx;
+ exec.attr[FRAG_ATTRIB_WPOS][0][1] = fx + 1.0;
+ exec.attr[FRAG_ATTRIB_WPOS][0][2] = fx;
+ exec.attr[FRAG_ATTRIB_WPOS][0][3] = fx + 1.0;
+
+ exec.attr[FRAG_ATTRIB_WPOS][1][0] = fy;
+ exec.attr[FRAG_ATTRIB_WPOS][1][1] = fy;
+ exec.attr[FRAG_ATTRIB_WPOS][1][2] = fy + 1.0;
+ exec.attr[FRAG_ATTRIB_WPOS][1][3] = fy + 1.0;
+
+ /* Z and W are done by linear interpolation:
+ */
+ if (generic->need_z) {
+ linterp(&exec, 0, 2);
+ }
+
+ if (generic->need_w) {
+ linterp(&exec, 0, 3);
+// invert(&exec, 0, 3);
+ }
+
+ /* Interpolate all the remaining attributes. This will get pushed
+ * into the fragment program's responsibilities at some point.
+ */
+ for (i = 1; i < quad->nr_attrs; i++) {
+#if 1
+ for (j = 0; j < NUM_CHANNELS; j++)
+ linterp(&exec, i, j);
+#else
+ switch (quad->interp[i]) {
+ case INTERP_CONSTANT:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ cinterp(&exec, i, j);
+ break;
+
+ case INTERP_LINEAR:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ linterp(&exec, i, j);
+ break;
+
+ case INTERP_PERSPECTIVE:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ pinterp(&exec, i, j);
+ break;
+ }
+#endif
+ }
+
+#if 0
+ generic->run_fs( tri->fp, quad, &tri->outputs );
+#else
+ {
+ GLuint attr = generic->fp_attr_to_slot[FRAG_ATTRIB_COL0];
+ assert(attr);
+
+ memcpy(quad->outputs.color,
+ exec.attr[attr],
+ sizeof(quad->outputs.color));
+ }
+#endif
+
+
+ if (quad->mask)
+ quad_output( generic, quad );
+}
+
+
+
+
+
+
+
diff --git a/src/mesa/softpipe/generic/g_tile_output.c b/src/mesa/softpipe/generic/g_tile_output.c
new file mode 100644
index 0000000000..058ca30193
--- /dev/null
+++ b/src/mesa/softpipe/generic/g_tile_output.c
@@ -0,0 +1,92 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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.
+ */
+
+/* Vertices are just an array of floats, with all the attributes
+ * packed. We currently assume a layout like:
+ *
+ * attr[0][0..3] - window position
+ * attr[1..n][0..3] - remaining attributes.
+ *
+ * Attributes are assumed to be 4 floats wide but are packed so that
+ * all the enabled attributes run contiguously.
+ */
+
+#include "glheader.h"
+#include "g_context.h"
+#include "g_headers.h"
+#include "g_surface.h"
+#include "g_tile.h"
+
+
+static void mask_copy( GLfloat (*dest)[4],
+ GLfloat (*src)[4],
+ GLuint mask )
+{
+ GLuint i, j;
+
+ for (i = 0; i < 4; i++) {
+ if (mask & (1<<i)) {
+ for (j = 0; j < 4; j++) {
+ dest[j][i] = src[j][i];
+ }
+ }
+ }
+}
+
+
+/* Write to the output, taking mask into account.
+ *
+ * Note that surfaces support only full quad reads and writes.
+ */
+void quad_output( struct generic_context *generic,
+ struct quad_header *quad )
+{
+
+ if (quad->mask != MASK_ALL)
+ {
+ GLfloat tmp[4][QUAD_SIZE];
+
+ /* Yes, we'll probably have a masked write as well, but this is
+ * how blend will be done at least.
+ */
+ gs_read_quad_f_swz( generic->cbuf_surface,
+ quad->x0,
+ quad->y0,
+ tmp );
+
+ mask_copy( tmp, quad->outputs.color, quad->mask );
+
+ gs_write_quad_f_swz( generic->cbuf_surface,
+ quad->x0,
+ quad->y0,
+ tmp );
+ }
+ else
+ {
+ gs_write_quad_f_swz( generic->cbuf_surface,
+ quad->x0,
+ quad->y0,
+ quad->outputs.color );
+ }
+}
diff --git a/src/mesa/softpipe/sp_context.h b/src/mesa/softpipe/sp_context.h
new file mode 100644
index 0000000000..a11ad26018
--- /dev/null
+++ b/src/mesa/softpipe/sp_context.h
@@ -0,0 +1,72 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+#ifndef SP_CONTEXT_H
+#define SP_CONTEXT_H
+
+#include "mtypes.h"
+
+struct softpipe_context *generic_create( void );
+
+/* Drawing currently kludged up via the existing tnl/ module.
+ */
+struct vertex_buffer;
+
+struct softpipe_context {
+
+ void (*destroy)( struct softpipe_context * );
+
+ void (*set_clip_state)( struct softpipe_context *,
+ const struct softpipe_clip_state * );
+
+ void (*set_viewport)( struct softpipe_context *,
+ const struct softpipe_viewport * );
+
+ void (*set_setup_state)( struct softpipe_context *,
+ const struct softpipe_setup_state * );
+
+ void (*set_scissor_rect)( struct softpipe_context *,
+ const struct softpipe_scissor_rect * );
+
+ void (*set_fs_state)( struct softpipe_context *,
+ const struct softpipe_fs_state * );
+
+ void (*set_polygon_stipple)( struct softpipe_context *,
+ const struct softpipe_poly_stipple * );
+
+ void (*set_cbuf_state)( struct softpipe_context *,
+ const struct softpipe_surface * );
+
+
+ void (*draw_vb)( struct softpipe_context *softpipe,
+ struct vertex_buffer *VB );
+};
+
+
+
+
+#endif
diff --git a/src/mesa/softpipe/sp_defines.h b/src/mesa/softpipe/sp_defines.h
new file mode 100644
index 0000000000..d8ae8d4baf
--- /dev/null
+++ b/src/mesa/softpipe/sp_defines.h
@@ -0,0 +1,45 @@
+
+#define SP_BLENDFACTOR_ONE 0x1
+#define SP_BLENDFACTOR_SRC_COLOR 0x2
+#define SP_BLENDFACTOR_SRC_ALPHA 0x3
+#define SP_BLENDFACTOR_DST_ALPHA 0x4
+#define SP_BLENDFACTOR_DST_COLOR 0x5
+#define SP_BLENDFACTOR_SRC_ALPHA_SATURATE 0x6
+#define SP_BLENDFACTOR_CONST_COLOR 0x7
+#define SP_BLENDFACTOR_CONST_ALPHA 0x8
+#define SP_BLENDFACTOR_SRC1_COLOR 0x9
+#define SP_BLENDFACTOR_SRC1_ALPHA 0x0A
+#define SP_BLENDFACTOR_ZERO 0x11
+#define SP_BLENDFACTOR_INV_SRC_COLOR 0x12
+#define SP_BLENDFACTOR_INV_SRC_ALPHA 0x13
+#define SP_BLENDFACTOR_INV_DST_ALPHA 0x14
+#define SP_BLENDFACTOR_INV_DST_COLOR 0x15
+#define SP_BLENDFACTOR_INV_CONST_COLOR 0x17
+#define SP_BLENDFACTOR_INV_CONST_ALPHA 0x18
+#define SP_BLENDFACTOR_INV_SRC1_COLOR 0x19
+#define SP_BLENDFACTOR_INV_SRC1_ALPHA 0x1A
+
+#define SP_BLEND_ADD 0
+#define SP_BLEND_SUBTRACT 1
+#define SP_BLEND_REVERSE_SUBTRACT 2
+#define SP_BLEND_MIN 3
+#define SP_BLEND_MAX 4
+
+
+#define SP_LOGICOP_CLEAR 0
+#define SP_LOGICOP_NOR 1
+#define SP_LOGICOP_AND_INVERTED 2
+#define SP_LOGICOP_COPY_INVERTED 3
+#define SP_LOGICOP_AND_REVERSE 4
+#define SP_LOGICOP_INVERT 5
+#define SP_LOGICOP_XOR 6
+#define SP_LOGICOP_NAND 7
+#define SP_LOGICOP_AND 8
+#define SP_LOGICOP_EQUIV 9
+#define SP_LOGICOP_NOOP 10
+#define SP_LOGICOP_OR_INVERTED 11
+#define SP_LOGICOP_COPY 12
+#define SP_LOGICOP_OR_REVERSE 13
+#define SP_LOGICOP_OR 14
+#define SP_LOGICOP_SET 15
+
diff --git a/src/mesa/softpipe/sp_state.h b/src/mesa/softpipe/sp_state.h
new file mode 100644
index 0000000000..d69f9cd164
--- /dev/null
+++ b/src/mesa/softpipe/sp_state.h
@@ -0,0 +1,132 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+#ifndef SP_STATE_H
+#define SP_STATE_H
+
+#include "mtypes.h"
+#include "vf/vf.h"
+
+#define WINDING_NONE 0
+#define WINDING_CW 1
+#define WINDING_CCW 2
+#define WINDING_BOTH (WINDING_CW | WINDING_CCW)
+
+#define FILL_POINT 1
+#define FILL_LINE 2
+#define FILL_TRI 3
+
+struct softpipe_setup_state {
+ GLuint flatshade:1;
+ GLuint light_twoside:1;
+
+ GLuint front_winding:2;
+
+ GLuint cull_mode:2;
+
+ GLuint fill_cw:2;
+ GLuint fill_ccw:2;
+
+ GLuint offset_cw:1;
+ GLuint offset_ccw:1;
+
+ GLuint scissor:1;
+ GLuint poly_stipple:1;
+
+ GLuint pad:18;
+
+ GLfloat offset_units;
+ GLfloat offset_scale;
+};
+
+struct softpipe_poly_stipple {
+ GLuint stipple[32];
+};
+
+
+struct softpipe_viewport {
+ GLfloat scale[4];
+ GLfloat translate[4];
+};
+
+struct softpipe_scissor_rect {
+ GLshort minx;
+ GLshort miny;
+ GLshort maxx;
+ GLshort maxy;
+};
+
+
+struct softpipe_clip_state {
+ GLfloat ucp[6][4];
+ GLuint nr;
+};
+
+struct softpipe_fs_state {
+ struct gl_fragment_program *fp;
+};
+
+#define SP_MAX_CONSTANT 32
+
+struct softpipe_constant_buffer {
+ GLfloat constant[SP_MAX_CONSTANT][4];
+ GLuint nr_constants;
+};
+
+
+struct softpipe_blend_state {
+ GLuint blend_enable:1;
+ GLuint ia_blend_enable:1;
+
+ GLuint ia_dest_blend_factor:5;
+ GLuint ia_src_blend_factor:5;
+ GLuint ia_blend_function:3;
+
+ GLuint dest_blend_factor:5;
+ GLuint src_blend_factor:5;
+ GLuint blend_function:3;
+
+ GLuint logicop_enable:1;
+ GLuint logicop_func:4;
+};
+
+struct softpipe_blend_color {
+ GLfloat color[4];
+};
+
+
+/* This will change for hardware softpipes...
+ */
+struct softpipe_surface {
+ GLubyte *ptr;
+ GLint stride;
+ GLuint cpp;
+ GLuint format;
+};
+
+
+#endif
diff --git a/src/mesa/softpipe/state_tracker/Makefile b/src/mesa/softpipe/state_tracker/Makefile
new file mode 100644
index 0000000000..0ab1dc6e6b
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/Makefile
@@ -0,0 +1,2 @@
+default:
+ cd ../.. ; make \ No newline at end of file
diff --git a/src/mesa/softpipe/state_tracker/st_atom.c b/src/mesa/softpipe/state_tracker/st_atom.c
new file mode 100644
index 0000000000..99fba398bf
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_atom.c
@@ -0,0 +1,168 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 "glheader.h"
+#include "context.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+
+
+
+/* This is used to initialize st->atoms[]. We could use this list
+ * directly except for a single atom, st_update_constants, which has a
+ * .dirty value which changes according to the parameters of the
+ * current fragment and vertex programs, and so cannot be a static
+ * value.
+ */
+static const struct st_tracked_state *atoms[] =
+{
+ &st_update_cbuf,
+ &st_update_clip,
+ &st_update_fs,
+ &st_update_setup,
+ &st_update_viewport,
+ /* will be patched out at runtime */
+/* &st_update_constants */
+};
+
+
+void st_init_atoms( struct st_context *st )
+{
+ GLuint i;
+
+ st->atoms = _mesa_malloc(sizeof(atoms));
+ st->nr_atoms = sizeof(atoms)/sizeof(*atoms);
+ _mesa_memcpy(st->atoms, atoms, sizeof(atoms));
+
+ /* Patch in a pointer to the dynamic state atom:
+ */
+ for (i = 0; i < st->nr_atoms; i++)
+ if (st->atoms[i] == &st_update_constants)
+ st->atoms[i] = &st->constants.tracked_state;
+
+ _mesa_memcpy(&st->constants.tracked_state,
+ &st_update_constants,
+ sizeof(st_update_constants));
+}
+
+
+void st_destroy_atoms( struct st_context *st )
+{
+ if (st->atoms) {
+ _mesa_free(st->atoms);
+ st->atoms = NULL;
+ }
+}
+
+
+/***********************************************************************
+ */
+
+static GLboolean check_state( const struct st_state_flags *a,
+ const struct st_state_flags *b )
+{
+ return ((a->mesa & b->mesa) ||
+ (a->st & b->st));
+}
+
+static void accumulate_state( struct st_state_flags *a,
+ const struct st_state_flags *b )
+{
+ a->mesa |= b->mesa;
+ a->st |= b->st;
+}
+
+
+static void xor_states( struct st_state_flags *result,
+ const struct st_state_flags *a,
+ const struct st_state_flags *b )
+{
+ result->mesa = a->mesa ^ b->mesa;
+ result->st = a->st ^ b->st;
+}
+
+
+/***********************************************************************
+ * Update all derived state:
+ */
+
+void st_validate_state( struct st_context *st )
+{
+ struct st_state_flags *state = &st->dirty;
+ GLuint i;
+
+ if (state->st == 0)
+ return;
+
+ if (1) {
+ /* Debug version which enforces various sanity checks on the
+ * state flags which are generated and checked to help ensure
+ * state atoms are ordered correctly in the list.
+ */
+ struct st_state_flags examined, prev;
+ _mesa_memset(&examined, 0, sizeof(examined));
+ prev = *state;
+
+ for (i = 0; i < st->nr_atoms; i++) {
+ const struct st_tracked_state *atom = st->atoms[i];
+ struct st_state_flags generated;
+
+ assert(atom->dirty.mesa ||
+ atom->dirty.st);
+ assert(atom->update);
+
+ if (check_state(state, &atom->dirty)) {
+ st->atoms[i]->update( st );
+ }
+
+ accumulate_state(&examined, &atom->dirty);
+
+ /* generated = (prev ^ state)
+ * if (examined & generated)
+ * fail;
+ */
+ xor_states(&generated, &prev, state);
+ assert(!check_state(&examined, &generated));
+ prev = *state;
+ }
+ }
+ else {
+ const GLuint nr = st->nr_atoms;
+
+ for (i = 0; i < nr; i++) {
+ if (check_state(state, &st->atoms[i]->dirty))
+ st->atoms[i]->update( st );
+ }
+ }
+
+ memset(state, 0, sizeof(*state));
+}
+
+
+
diff --git a/src/mesa/softpipe/state_tracker/st_atom.h b/src/mesa/softpipe/state_tracker/st_atom.h
new file mode 100644
index 0000000000..87b72940b4
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_atom.h
@@ -0,0 +1,55 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#ifndef ST_ATOM_H
+#define ST_ATOM_H
+
+struct st_context;
+struct st_tracked_state;
+
+void st_init_atoms( struct st_context *st );
+void st_destroy_atoms( struct st_context *st );
+
+
+void st_validate_state( struct st_context *st );
+
+
+const struct st_tracked_state st_update_cbuf;
+const struct st_tracked_state st_update_clip;
+const struct st_tracked_state st_update_fs;
+const struct st_tracked_state st_update_setup;
+const struct st_tracked_state st_update_viewport;
+const struct st_tracked_state st_update_constants;
+
+
+#endif
diff --git a/src/mesa/softpipe/state_tracker/st_atom_cbuf.c b/src/mesa/softpipe/state_tracker/st_atom_cbuf.c
new file mode 100644
index 0000000000..cd707ec5ef
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_atom_cbuf.c
@@ -0,0 +1,72 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "st_context.h"
+#include "softpipe/sp_context.h"
+#include "st_atom.h"
+
+extern GLboolean xmesa_get_cbuf_details( GLcontext *ctx,
+ void **ptr,
+ GLuint *cpp,
+ GLint *stride,
+ GLuint *format );
+
+
+/* This is a hack to work with the X11 driver as a test harness
+ */
+static void update_cbuf_state( struct st_context *st )
+{
+ struct softpipe_surface cbuf;
+ GLboolean ok;
+
+ ok = xmesa_get_cbuf_details( st->ctx,
+ (void **)&cbuf.ptr,
+ &cbuf.cpp,
+ &cbuf.stride,
+ &cbuf.format );
+
+ assert(ok);
+
+ if (memcmp(&cbuf, &st->state.cbuf, sizeof(cbuf)) != 0) {
+ st->state.cbuf = cbuf;
+ st->softpipe->set_cbuf_state( st->softpipe, &cbuf );
+ }
+}
+
+const struct st_tracked_state st_update_cbuf = {
+ .dirty = {
+ .mesa = _NEW_BUFFERS,
+ .st = 0,
+ },
+ .update = update_cbuf_state
+};
+
diff --git a/src/mesa/softpipe/state_tracker/st_atom_clip.c b/src/mesa/softpipe/state_tracker/st_atom_clip.c
new file mode 100644
index 0000000000..1a0d2c4053
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_atom_clip.c
@@ -0,0 +1,75 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#include "st_context.h"
+#include "softpipe/sp_context.h"
+#include "st_atom.h"
+
+
+/* Second state atom for user clip planes:
+ */
+static void update_clip( struct st_context *st )
+{
+ struct softpipe_clip_state clip;
+ GLuint i;
+
+ memset(&clip, 0, sizeof(clip));
+
+ for (i = 0; i < 6; i++) {
+ if (st->ctx->Transform.ClipPlanesEnabled & (1 << i)) {
+ memcpy(clip.ucp[clip.nr],
+ st->ctx->Transform._ClipUserPlane[i],
+ sizeof(clip.ucp[0]));
+ clip.nr++;
+ }
+ }
+
+ if (memcmp(&clip, &st->state.clip, sizeof(clip)) != 0) {
+ st->state.clip = clip;
+ st->softpipe->set_clip_state(st->softpipe, &clip);
+ }
+}
+
+
+const struct st_tracked_state st_update_clip = {
+ .dirty = {
+ .mesa = (_NEW_TRANSFORM),
+ .st = 0,
+ },
+ .update = update_clip
+};
+
+
+
+
+
diff --git a/src/mesa/softpipe/state_tracker/st_atom_fs.c b/src/mesa/softpipe/state_tracker/st_atom_fs.c
new file mode 100644
index 0000000000..ca109d2d34
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_atom_fs.c
@@ -0,0 +1,56 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "st_context.h"
+#include "softpipe/sp_context.h"
+#include "st_atom.h"
+
+
+static void update_fs( struct st_context *st )
+{
+ struct softpipe_fs_state fs;
+
+ fs.fp = st->ctx->FragmentProgram._Current;
+
+ if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0) {
+ st->state.fs = fs;
+ st->softpipe->set_fs_state(st->softpipe, &fs);
+ }
+}
+
+
+const struct st_tracked_state st_update_fs = {
+ .dirty = {
+ .mesa = 0,
+ .st = ST_NEW_FRAGMENT_PROGRAM,
+ },
+ .update = update_fs
+};
diff --git a/src/mesa/softpipe/state_tracker/st_atom_setup.c b/src/mesa/softpipe/state_tracker/st_atom_setup.c
new file mode 100644
index 0000000000..2a582ea36c
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_atom_setup.c
@@ -0,0 +1,175 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#include "st_context.h"
+#include "softpipe/sp_context.h"
+#include "st_atom.h"
+
+static GLuint translate_fill( GLenum mode )
+{
+ switch (mode) {
+ case GL_POINT: return FILL_POINT;
+ case GL_LINE: return FILL_LINE;
+ case GL_FILL: return FILL_TRI;
+ default: assert(0); return 0;
+ }
+}
+
+static GLboolean get_offset_flag( GLuint fill_mode,
+ const struct gl_polygon_attrib *Polygon )
+{
+ switch (fill_mode) {
+ case FILL_POINT: return Polygon->OffsetPoint;
+ case FILL_LINE: return Polygon->OffsetLine;
+ case FILL_TRI: return Polygon->OffsetFill;
+ default: assert(0); return 0;
+ }
+}
+
+
+static void update_setup_state( struct st_context *st )
+{
+ GLcontext *ctx = st->ctx;
+ struct softpipe_setup_state setup;
+
+ memset(&setup, 0, sizeof(setup));
+
+ /* _NEW_POLYGON, _NEW_BUFFERS
+ */
+ {
+ setup.front_winding = WINDING_CW;
+
+ if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0)
+ setup.front_winding ^= WINDING_BOTH;
+
+ if (ctx->Polygon.FrontFace != GL_CCW)
+ setup.front_winding ^= WINDING_BOTH;
+ }
+
+ /* _NEW_LIGHT
+ */
+ if (ctx->Light.ShadeModel == GL_FLAT)
+ setup.flatshade = 1;
+
+ /* _NEW_LIGHT
+ *
+ * Not sure about the light->enabled requirement - does this still
+ * apply??
+ */
+ if (ctx->Light.Enabled &&
+ ctx->Light.Model.TwoSide)
+ setup.light_twoside = 1;
+
+
+ /* _NEW_POLYGON
+ */
+ if (ctx->Polygon.CullFlag) {
+ if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) {
+ setup.cull_mode = WINDING_BOTH;
+ }
+ else if (ctx->Polygon.CullFaceMode == GL_FRONT) {
+ setup.cull_mode = setup.front_winding;
+ }
+ else {
+ setup.cull_mode = setup.front_winding ^ WINDING_BOTH;
+ }
+ }
+
+ /* _NEW_POLYGON
+ */
+ {
+ GLuint fill_front = translate_fill( ctx->Polygon.FrontMode );
+ GLuint fill_back = translate_fill( ctx->Polygon.BackMode );
+
+ if (setup.front_winding == WINDING_CW) {
+ setup.fill_cw = fill_front;
+ setup.fill_ccw = fill_back;
+ }
+ else {
+ setup.fill_cw = fill_back;
+ setup.fill_ccw = fill_front;
+ }
+
+ /* Simplify when culling is active:
+ */
+ if (setup.cull_mode & WINDING_CW) {
+ setup.fill_cw = setup.fill_ccw;
+ }
+
+ if (setup.cull_mode & WINDING_CCW) {
+ setup.fill_ccw = setup.fill_cw;
+ }
+ }
+
+ /* Hardware does offset for filled prims, but need to do it in
+ * software for unfilled.
+ *
+ * _NEW_POLYGON
+ */
+ if (setup.fill_cw != FILL_TRI)
+ setup.offset_cw = get_offset_flag( setup.fill_cw,
+ &ctx->Polygon );
+
+ if (setup.fill_ccw != FILL_TRI)
+ setup.offset_ccw = get_offset_flag( setup.fill_ccw,
+ &ctx->Polygon );
+
+
+ /* _NEW_BUFFERS, _NEW_POLYGON
+ */
+ if (setup.fill_cw != FILL_TRI ||
+ setup.fill_ccw != FILL_TRI)
+ {
+ GLfloat mrd = (ctx->DrawBuffer ?
+ ctx->DrawBuffer->_MRD :
+ 1.0);
+
+ setup.offset_units = ctx->Polygon.OffsetFactor * mrd;
+ setup.offset_scale = (ctx->Polygon.OffsetUnits * mrd *
+ st->polygon_offset_scale);
+ }
+
+
+ if (memcmp(&setup, &st->state.setup, sizeof(setup)) != 0) {
+ st->state.setup = setup;
+ st->softpipe->set_setup_state( st->softpipe, &setup );
+ }
+}
+
+const struct st_tracked_state st_update_setup = {
+ .dirty = {
+ .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_BUFFERS),
+ .st = 0,
+ },
+ .update = update_setup_state
+};
diff --git a/src/mesa/softpipe/state_tracker/st_atom_viewport.c b/src/mesa/softpipe/state_tracker/st_atom_viewport.c
new file mode 100644
index 0000000000..af896e2e31
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_atom_viewport.c
@@ -0,0 +1,117 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 "context.h"
+#include "colormac.h"
+#include "st_context.h"
+#include "softpipe/sp_context.h"
+#include "st_atom.h"
+
+
+
+
+
+/**
+ * Update the viewport transformation matrix. Depends on:
+ * - viewport pos/size
+ * - depthrange
+ * - window pos/size or FBO size
+ */
+static void update_viewport( struct st_context *st )
+{
+ GLcontext *ctx = st->ctx;
+ const GLframebuffer *DrawBuffer = ctx->DrawBuffer;
+ GLfloat yScale = 1.0;
+ GLfloat yBias = 0.0;
+
+ /* _NEW_BUFFERS
+ */
+ if (DrawBuffer) {
+
+#if 0
+ if (DrawBuffer->Name) {
+ /* User created FBO */
+ struct st_renderbuffer *irb
+ = st_renderbuffer(DrawBuffer->_ColorDrawBuffers[0][0]);
+ if (irb && !irb->RenderToTexture) {
+ /* y=0=top */
+ yScale = -1.0;
+ yBias = irb->Base.Height;
+ }
+ else {
+ /* y=0=bottom */
+ yScale = 1.0;
+ yBias = 0.0;
+ }
+ }
+ else
+ {
+ /* window buffer, y=0=top */
+ yScale = -1.0;
+ yBias = DrawBuffer->Height;
+ }
+#endif
+ }
+
+ {
+ /* _NEW_VIEWPORT
+ */
+ GLfloat x = ctx->Viewport.X;
+ GLfloat y = ctx->Viewport.Y;
+ GLfloat z = ctx->Viewport.Near;
+ GLfloat half_width = ctx->Viewport.Width / 2.0;
+ GLfloat half_height = ctx->Viewport.Height / 2.0;
+ GLfloat half_depth = (ctx->Viewport.Far - ctx->Viewport.Near) / 2.0;
+
+ struct softpipe_viewport vp;
+
+ vp.scale[0] = half_width;
+ vp.scale[1] = half_height * yScale;
+ vp.scale[2] = half_depth;
+ vp.scale[3] = 1.0;
+
+ vp.translate[0] = (half_width + x);
+ vp.translate[1] = (half_height + y) * yScale + yBias;
+ vp.translate[2] = (half_depth + z);
+ vp.translate[3] = 0.0;
+
+ if (memcmp(&vp, &st->state.viewport, sizeof(vp)) != 0) {
+ st->state.viewport = vp;
+ st->softpipe->set_viewport(st->softpipe, &vp);
+ }
+ }
+}
+
+
+const struct st_tracked_state st_update_viewport = {
+ .dirty = {
+ .mesa = _NEW_BUFFERS | _NEW_VIEWPORT,
+ .st = 0,
+ },
+ .update = update_viewport
+};
diff --git a/src/mesa/softpipe/state_tracker/st_cb_program.c b/src/mesa/softpipe/state_tracker/st_cb_program.c
new file mode 100644
index 0000000000..67a589ca8d
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_cb_program.c
@@ -0,0 +1,165 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "st_context.h"
+#include "st_program.h"
+
+#include "glheader.h"
+#include "macros.h"
+#include "enums.h"
+#include "prog_instruction.h"
+#include "prog_parameter.h"
+#include "program.h"
+#include "programopt.h"
+#include "tnl/tnl.h"
+
+
+static void st_bind_program( GLcontext *ctx,
+ GLenum target,
+ struct gl_program *prog )
+{
+ struct st_context *st = st_context(ctx);
+
+ switch (target) {
+ case GL_VERTEX_PROGRAM_ARB:
+ break;
+ case GL_FRAGMENT_PROGRAM_ARB:
+ st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
+ break;
+ }
+}
+
+static struct gl_program *st_new_program( GLcontext *ctx,
+ GLenum target,
+ GLuint id )
+{
+ struct st_context *st = st_context(ctx);
+
+ switch (target) {
+ case GL_VERTEX_PROGRAM_ARB:
+ return _mesa_init_vertex_program(ctx,
+ CALLOC_STRUCT(gl_vertex_program),
+ target,
+ id);
+
+ case GL_FRAGMENT_PROGRAM_ARB: {
+ struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program);
+
+ prog->id = st->program_id++;
+
+ return _mesa_init_fragment_program( ctx,
+ &prog->Base,
+ target,
+ id );
+ }
+
+ default:
+ return _mesa_new_program(ctx, target, id);
+ }
+}
+
+static void st_delete_program( GLcontext *ctx,
+ struct gl_program *prog )
+{
+ _mesa_delete_program( ctx, prog );
+}
+
+
+static GLboolean st_is_program_native( GLcontext *ctx,
+ GLenum target,
+ struct gl_program *prog )
+{
+ return GL_TRUE;
+}
+
+static void st_program_string_notify( GLcontext *ctx,
+ GLenum target,
+ struct gl_program *prog )
+{
+ if (target == GL_FRAGMENT_PROGRAM_ARB) {
+ struct st_context *st = st_context(ctx);
+
+ if (prog == &st->ctx->FragmentProgram._Current->Base)
+ {
+ struct st_fragment_program *p =
+ (struct st_fragment_program *) prog;
+
+ st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
+
+ p->id = st->program_id++;
+#if 0
+ p->param_state = p->Base.Base.Parameters->StateFlags;
+ p->translated = 0;
+#endif
+
+ /* Gack! do this in the compiler:
+ */
+ if (p->Base.FogOption) {
+ /* add extra instructions to do fog, then turn off FogOption field */
+ _mesa_append_fog_code(ctx, &p->Base);
+ p->Base.FogOption = GL_NONE;
+ }
+ }
+ }
+ else if (target == GL_VERTEX_PROGRAM_ARB) {
+
+ /* Also tell tnl about it:
+ */
+ _tnl_program_string(ctx, target, prog);
+ }
+}
+
+
+
+void st_init_cb_program( struct st_context *st )
+{
+ struct dd_function_table *functions = &st->ctx->Driver;
+
+ /* Need these flags:
+ */
+ st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
+ st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE;
+
+
+ assert(functions->ProgramStringNotify == _tnl_program_string);
+ functions->BindProgram = st_bind_program;
+ functions->NewProgram = st_new_program;
+ functions->DeleteProgram = st_delete_program;
+ functions->IsProgramNative = st_is_program_native;
+ functions->ProgramStringNotify = st_program_string_notify;
+}
+
+
+void st_destroy_cb_program( struct st_context *st )
+{
+}
+
diff --git a/src/mesa/softpipe/state_tracker/st_context.c b/src/mesa/softpipe/state_tracker/st_context.c
new file mode 100644
index 0000000000..8a06dd88df
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_context.c
@@ -0,0 +1,76 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 "imports.h"
+#include "st_public.h"
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_draw.h"
+#include "st_program.h"
+#include "softpipe/sp_context.h"
+
+void st_invalidate_state(GLcontext * ctx, GLuint new_state)
+{
+ struct st_context *st = st_context(ctx);
+
+ st->dirty.mesa |= new_state;
+ st->dirty.st |= ST_NEW_MESA;
+}
+
+
+struct st_context *st_create_context( GLcontext *ctx,
+ struct softpipe_context *softpipe )
+{
+ struct st_context *st = CALLOC_STRUCT( st_context );
+
+ ctx->st = st;
+
+ st->ctx = ctx;
+ st->softpipe = softpipe;
+
+ st->dirty.mesa = ~0;
+ st->dirty.st = ~0;
+
+ st_init_atoms( st );
+ st_init_draw( st );
+ st_init_cb_program( st );
+
+ return st;
+}
+
+
+void st_destroy_context( struct st_context *st )
+{
+ st_destroy_atoms( st );
+ st_destroy_draw( st );
+ st_destroy_cb_program( st );
+ st->softpipe->destroy( st->softpipe );
+ FREE( st );
+}
+
+
+
diff --git a/src/mesa/softpipe/state_tracker/st_context.h b/src/mesa/softpipe/state_tracker/st_context.h
new file mode 100644
index 0000000000..08cee11797
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_context.h
@@ -0,0 +1,109 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+#ifndef ST_CONTEXT_H
+#define ST_CONTEXT_H
+
+#include "mtypes.h"
+#include "softpipe/sp_state.h"
+
+
+struct st_context;
+struct st_region;
+struct st_texture_object;
+struct st_texture_image;
+struct st_fragment_program;
+
+#define ST_NEW_MESA 0x1 /* Mesa state has changed */
+#define ST_NEW_FRAGMENT_PROGRAM 0x2
+
+struct st_state_flags {
+ GLuint mesa;
+ GLuint st;
+};
+
+struct st_tracked_state {
+ struct st_state_flags dirty;
+ void (*update)( struct st_context *st );
+};
+
+
+
+
+struct st_context
+{
+ GLcontext *ctx;
+
+ struct softpipe_context *softpipe;
+
+ /* Eventually will use a cache to feed the softpipe with
+ * create/bind/delete calls to constant state objects. Not yet
+ * though, we just shove random objects across the interface.
+ */
+ struct {
+ struct softpipe_viewport viewport;
+ struct softpipe_setup_state setup;
+ struct softpipe_fs_state fs;
+ struct softpipe_blend_state blend;
+ struct softpipe_surface cbuf;
+ struct softpipe_clip_state clip;
+ struct softpipe_scissor_rect scissor;
+ struct softpipe_poly_stipple poly_stipple;
+ } state;
+
+ struct {
+ struct st_tracked_state tracked_state;
+ } constants;
+
+ struct {
+ struct gl_fragment_program *fragment_program;
+ } cb;
+
+ /* State to be validated:
+ */
+ struct st_tracked_state **atoms;
+ GLuint nr_atoms;
+
+ struct st_state_flags dirty;
+
+ /* Counter to track program string changes:
+ */
+ GLuint program_id;
+
+ GLfloat polygon_offset_scale; /* ?? */
+};
+
+
+/* Need this so that we can implement Mesa callbacks in this module.
+ */
+static INLINE struct st_context *st_context(GLcontext *ctx)
+{
+ return ctx->st;
+}
+
+
+#endif
diff --git a/src/mesa/softpipe/state_tracker/st_draw.c b/src/mesa/softpipe/state_tracker/st_draw.c
new file mode 100644
index 0000000000..12646402ee
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_draw.c
@@ -0,0 +1,107 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "imports.h"
+
+#include "tnl/t_context.h"
+#include "tnl/t_pipeline.h"
+
+#include "st_context.h"
+#include "st_atom.h"
+#include "st_draw.h"
+#include "softpipe/sp_context.h"
+
+/*
+ * TNL stage which feedsinto the above.
+ *
+ * XXX: this needs to go into each driver using this code, because we
+ * cannot make the leap from ctx->draw_context in this file. The
+ * driver needs to customize tnl anyway, so this isn't a big deal.
+ */
+static GLboolean draw( GLcontext * ctx, struct tnl_pipeline_stage *stage )
+{
+ struct st_context *st = st_context(ctx);
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+
+ /* Validate driver and softpipe state:
+ */
+ st_validate_state( st );
+
+ /* Call into the new draw code to handle the VB:
+ */
+ st->softpipe->draw_vb( st->softpipe, VB );
+
+ /* Finished
+ */
+ return GL_FALSE;
+}
+
+const struct tnl_pipeline_stage st_draw = {
+ "check state and draw",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ draw
+};
+
+static const struct tnl_pipeline_stage *intel_pipeline[] = {
+ &_tnl_vertex_transform_stage,
+ &_tnl_vertex_cull_stage,
+ &_tnl_normal_transform_stage,
+ &_tnl_lighting_stage,
+ &_tnl_fog_coordinate_stage,
+ &_tnl_texgen_stage,
+ &_tnl_texture_transform_stage,
+ &_tnl_point_attenuation_stage,
+ &_tnl_vertex_program_stage,
+ &st_draw, /* ADD: escape to softpipe */
+ 0,
+};
+
+/* This is all a hack to keep using tnl until we have vertex programs
+ * up and running.
+ */
+void st_init_draw( struct st_context *st )
+{
+ GLcontext *ctx = st->ctx;
+
+ _tnl_destroy_pipeline( ctx );
+ _tnl_install_pipeline( ctx, intel_pipeline );
+}
+
+
+void st_destroy_draw( struct st_context *st )
+{
+ /* Nothing to do.
+ */
+}
diff --git a/src/mesa/softpipe/state_tracker/st_draw.h b/src/mesa/softpipe/state_tracker/st_draw.h
new file mode 100644
index 0000000000..f51059706a
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_draw.h
@@ -0,0 +1,40 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#ifndef ST_DRAW_H
+#define ST_DRAW_H
+
+void st_init_draw( struct st_context *st );
+void st_destroy_draw( struct st_context *st );
+
+#endif
diff --git a/src/mesa/softpipe/state_tracker/st_program.h b/src/mesa/softpipe/state_tracker/st_program.h
new file mode 100644
index 0000000000..a47059d7a6
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_program.h
@@ -0,0 +1,68 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#ifndef ST_PROGRAM_H
+#define ST_PROGRAM_H
+
+struct st_fragment_program
+{
+ struct gl_fragment_program Base;
+ GLboolean error; /* If program is malformed for any reason. */
+
+ GLuint id; /* String id, for tracking
+ * ProgramStringNotify changes.
+ */
+
+#if 0
+ GLfloat (*cbuffer)[4];
+ GLuint nr_constants;
+
+ /* Translate all the parameters, etc, into a constant buffer which
+ * we update on state changes.
+ */
+ struct
+ {
+ GLuint reg; /* Constant idx */
+ const GLfloat *values; /* Pointer to tracked values */
+ } *param;
+ GLuint nr_params;
+
+ GLuint param_state;
+#endif
+};
+
+
+void st_init_cb_program( struct st_context *st );
+void st_destroy_cb_program( struct st_context *st );
+
+#endif
diff --git a/src/mesa/softpipe/state_tracker/st_public.h b/src/mesa/softpipe/state_tracker/st_public.h
new file mode 100644
index 0000000000..8241dbd52d
--- /dev/null
+++ b/src/mesa/softpipe/state_tracker/st_public.h
@@ -0,0 +1,43 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+#ifndef ST_PUBLIC_H
+#define ST_PUBLIC_H
+
+#include "mtypes.h"
+
+struct st_context;
+struct softpipe_context;
+
+struct st_context *st_create_context( GLcontext *ctx,
+ struct softpipe_context *softpipe);
+
+void st_destroy_context( struct st_context *st );
+
+void st_invalidate_state(GLcontext * ctx, GLuint new_state);
+
+#endif