summaryrefslogtreecommitdiffstats
path: root/src/mesa/pipe
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/pipe')
-rw-r--r--src/mesa/pipe/Makefile2
-rw-r--r--src/mesa/pipe/p_context.h89
-rw-r--r--src/mesa/pipe/p_defines.h121
-rw-r--r--src/mesa/pipe/p_state.h184
-rw-r--r--src/mesa/pipe/softpipe/Makefile3
-rw-r--r--src/mesa/pipe/softpipe/g_context.c135
-rw-r--r--src/mesa/pipe/softpipe/g_context.h149
-rw-r--r--src/mesa/pipe/softpipe/g_draw.c696
-rw-r--r--src/mesa/pipe/softpipe/g_draw.h56
-rw-r--r--src/mesa/pipe/softpipe/g_headers.h116
-rw-r--r--src/mesa/pipe/softpipe/g_prim.h90
-rw-r--r--src/mesa/pipe/softpipe/g_prim_clip.c429
-rw-r--r--src/mesa/pipe/softpipe/g_prim_cull.c119
-rw-r--r--src/mesa/pipe/softpipe/g_prim_flatshade.c149
-rw-r--r--src/mesa/pipe/softpipe/g_prim_offset.c157
-rw-r--r--src/mesa/pipe/softpipe/g_prim_setup.c888
-rw-r--r--src/mesa/pipe/softpipe/g_prim_setup.h121
-rw-r--r--src/mesa/pipe/softpipe/g_prim_twoside.c149
-rw-r--r--src/mesa/pipe/softpipe/g_prim_unfilled.c165
-rw-r--r--src/mesa/pipe/softpipe/g_state.h61
-rw-r--r--src/mesa/pipe/softpipe/g_state_clip.c69
-rw-r--r--src/mesa/pipe/softpipe/g_state_derived.c136
-rw-r--r--src/mesa/pipe/softpipe/g_state_fs.c50
-rw-r--r--src/mesa/pipe/softpipe/g_state_setup.c122
-rw-r--r--src/mesa/pipe/softpipe/g_state_surface.c53
-rw-r--r--src/mesa/pipe/softpipe/g_surface.c153
-rw-r--r--src/mesa/pipe/softpipe/g_surface.h115
-rw-r--r--src/mesa/pipe/softpipe/g_tile.h42
-rw-r--r--src/mesa/pipe/softpipe/g_tile_fs.c203
-rw-r--r--src/mesa/pipe/softpipe/g_tile_output.c92
-rw-r--r--src/mesa/pipe/softpipe/sp_context.c135
-rw-r--r--src/mesa/pipe/softpipe/sp_context.h149
-rw-r--r--src/mesa/pipe/softpipe/sp_draw.c696
-rw-r--r--src/mesa/pipe/softpipe/sp_draw.h56
-rw-r--r--src/mesa/pipe/softpipe/sp_headers.h116
-rw-r--r--src/mesa/pipe/softpipe/sp_prim.h90
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_clip.c429
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_cull.c119
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_flatshade.c149
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_offset.c157
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_setup.c888
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_setup.h121
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_twoside.c149
-rw-r--r--src/mesa/pipe/softpipe/sp_prim_unfilled.c165
-rw-r--r--src/mesa/pipe/softpipe/sp_state.h61
-rw-r--r--src/mesa/pipe/softpipe/sp_state_clip.c69
-rw-r--r--src/mesa/pipe/softpipe/sp_state_derived.c136
-rw-r--r--src/mesa/pipe/softpipe/sp_state_fs.c50
-rw-r--r--src/mesa/pipe/softpipe/sp_state_setup.c122
-rw-r--r--src/mesa/pipe/softpipe/sp_state_surface.c53
-rw-r--r--src/mesa/pipe/softpipe/sp_surface.c153
-rw-r--r--src/mesa/pipe/softpipe/sp_surface.h115
-rw-r--r--src/mesa/pipe/softpipe/sp_tile.h42
-rw-r--r--src/mesa/pipe/softpipe/sp_tile_fs.c203
-rw-r--r--src/mesa/pipe/softpipe/sp_tile_output.c92
55 files changed, 9429 insertions, 0 deletions
diff --git a/src/mesa/pipe/Makefile b/src/mesa/pipe/Makefile
new file mode 100644
index 00000000000..451911a3545
--- /dev/null
+++ b/src/mesa/pipe/Makefile
@@ -0,0 +1,2 @@
+default:
+ cd .. ; make
diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h
new file mode 100644
index 00000000000..716ddd27a97
--- /dev/null
+++ b/src/mesa/pipe/p_context.h
@@ -0,0 +1,89 @@
+/**************************************************************************
+ *
+ * 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"
+
+extern struct softpipe_context *generic_create( void );
+
+/* Drawing currently kludged up via the existing tnl/ module.
+ */
+struct vertex_buffer;
+
+
+/**
+ * Software pipeline rendering context. Basically a collection of
+ * state setting functions, plus VBO drawing entrypoint.
+ */
+struct softpipe_context {
+
+ void (*destroy)( struct softpipe_context * );
+
+ /*
+ * Drawing
+ */
+ void (*draw_vb)( struct softpipe_context *softpipe,
+ struct vertex_buffer *VB );
+
+ /*
+ * State functions
+ */
+ void (*set_blend_state)( struct softpipe_context *,
+ const struct softpipe_blend_state * );
+
+ void (*set_cbuf_state)( struct softpipe_context *,
+ const struct softpipe_surface * );
+
+ void (*set_clip_state)( struct softpipe_context *,
+ const struct softpipe_clip_state * );
+
+ void (*set_depth_state)( struct softpipe_context *,
+ const struct softpipe_depth_state * );
+
+ 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_setup_state)( struct softpipe_context *,
+ const struct softpipe_setup_state * );
+
+ void (*set_scissor_rect)( struct softpipe_context *,
+ const struct softpipe_scissor_rect * );
+
+ void (*set_stencil_state)( struct softpipe_context *,
+ const struct softpipe_stencil_state * );
+
+ void (*set_viewport)( struct softpipe_context *,
+ const struct softpipe_viewport * );
+};
+
+
+#endif
diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h
new file mode 100644
index 00000000000..c381865dab5
--- /dev/null
+++ b/src/mesa/pipe/p_defines.h
@@ -0,0 +1,121 @@
+/**************************************************************************
+ *
+ * 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_DEFINES_H
+#define SP_DEFINES_H
+
+#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
+
+#define SP_STENCIL_FUNC_NEVER 0
+#define SP_STENCIL_FUNC_LESS 1
+#define SP_STENCIL_FUNC_EQUAL 2
+#define SP_STENCIL_FUNC_LEQUAL 3
+#define SP_STENCIL_FUNC_GREATER 4
+#define SP_STENCIL_FUNC_NOTEQUAL 5
+#define SP_STENCIL_FUNC_GEQUAL 6
+#define SP_STENCIL_FUNC_ALWAYS 7
+
+#define SP_STENCIL_OP_KEEP 0
+#define SP_STENCIL_OP_ZERO 1
+#define SP_STENCIL_OP_REPLACE 2
+#define SP_STENCIL_OP_INCR 3
+#define SP_STENCIL_OP_DECR 4
+#define SP_STENCIL_OP_INCR_WRAP 5
+#define SP_STENCIL_OP_DECR_WRAP 6
+#define SP_STENCIL_OP_INVERT 7
+
+/* Note: same as stencil funcs. Also used for shadow/depth compare */
+#define SP_DEPTH_FUNC_NEVER 0
+#define SP_DEPTH_FUNC_LESS 1
+#define SP_DEPTH_FUNC_EQUAL 2
+#define SP_DEPTH_FUNC_LEQUAL 3
+#define SP_DEPTH_FUNC_GREATER 4
+#define SP_DEPTH_FUNC_NOTEQUAL 5
+#define SP_DEPTH_FUNC_GEQUAL 6
+#define SP_DEPTH_FUNC_ALWAYS 7
+
+#define SP_TEX_WRAP_REPEAT 0
+#define SP_TEX_WRAP_CLAMP 1
+#define SP_TEX_WRAP_CLAMP_TO_EDGE 2
+#define SP_TEX_WRAP_CLAMP_TO_BORDER 3
+#define SP_TEX_WRAP_MIRROR_REPEAT 4
+#define SP_TEX_WRAP_MIRROR_CLAMP 5
+#define SP_TEX_WRAP_MIRROR_CLAMP_TO_EDGE 6
+#define SP_TEX_WRAP_MIRROR_CLAMP_TO_BORDER 7
+
+#define SP_TEX_FILTER_NEAREST 0
+#define SP_TEX_FILTER_LINEAR 1
+#define SP_TEX_FILTER_NEAREST_MIPMAP_NEAREST 2
+#define SP_TEX_FILTER_NEAREST_MIPMAP_LINEAR 3
+#define SP_TEX_FILTER_LINEAR_MIPMAP_NEAREST 4
+#define SP_TEX_FILTER_LINEAR_MIPMAP_LINEAR 5
+
+#define SP_TEX_COMPARE_NONE 0
+#define SP_TEX_COMPARE_R_TO_TEXTURE 1
+
+#endif
diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h
new file mode 100644
index 00000000000..150fa9fcadb
--- /dev/null
+++ b/src/mesa/pipe/p_state.h
@@ -0,0 +1,184 @@
+/**************************************************************************
+ *
+ * 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;
+};
+
+
+#define SP_MAX_CLIP_PLANES 6
+
+struct softpipe_clip_state {
+ GLfloat ucp[SP_MAX_CLIP_PLANES][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_depth_state
+{
+ GLuint enabled:1; /**< depth test enabled? */
+ GLuint writemask:1; /**< allow depth buffer writes? */
+ GLuint func:3; /**< depth test func */
+ GLfloat clear; /**< Clear value in [0,1] (XXX correct place?) */
+};
+
+
+struct softpipe_blend_state {
+ GLuint blend_enable:1;
+
+ GLuint rgb_func:3;
+ GLuint rgb_src_factor:5;
+ GLuint rgb_dst_factor:5;
+
+ GLuint alpha_func:3;
+ GLuint alpha_src_factor:5;
+ GLuint alpha_dst_factor:5;
+
+ GLuint logicop_enable:1;
+ GLuint logicop_func:4;
+};
+
+struct softpipe_blend_color {
+ GLfloat color[4];
+};
+
+
+struct softpipe_stencil_state {
+ GLuint front_enabled:1;
+ GLuint front_func:3; /**< SP_STENCIL_FUNC_x */
+ GLuint front_fail_op:3; /**< SP_STENCIL_OP_x */
+ GLuint front_zpass_op:3; /**< SP_STENCIL_OP_x */
+ GLuint front_zfail_op:3; /**< SP_STENCIL_OP_x */
+ GLuint back_enabled:1;
+ GLuint back_func:3;
+ GLuint back_fail_op:3;
+ GLuint back_zpass_op:3;
+ GLuint back_zfail_op:3;
+ GLubyte ref_value[2]; /**< [0] = front, [1] = back */
+ GLubyte value_mask[2];
+ GLubyte write_mask[2];
+ GLubyte clear_value;
+};
+
+
+/* This will change for hardware softpipes...
+ */
+struct softpipe_surface {
+ GLubyte *ptr;
+ GLint stride;
+ GLuint cpp;
+ GLuint format;
+};
+
+
+/**
+ * Texture sampler state.
+ */
+struct softpipe_sampler_state
+{
+ GLuint wrap_s:3; /**< SP_TEX_WRAP_x */
+ GLuint wrap_t:3; /**< SP_TEX_WRAP_x */
+ GLuint wrap_r:3; /**< SP_TEX_WRAP_x */
+ GLuint min_filter:3; /**< SP_TEX_FILTER_x */
+ GLuint mag_filter:1; /**< SP_TEX_FILTER_LINEAR or _NEAREST */
+ GLfloat min_lod;
+ GLfloat max_lod;
+ GLfloat lod_bias;
+#if 0 /* need these? */
+ GLint BaseLevel; /**< min mipmap level, OpenGL 1.2 */
+ GLint MaxLevel; /**< max mipmap level, OpenGL 1.2 */
+#endif
+ GLfloat max_anisotropy;
+ GLuint compare:1; /**< shadow/depth compare enabled? */
+ GLenum compare_mode:1; /**< SP_TEX_COMPARE_x */
+ GLenum compare_func:3; /**< SP_DEPTH_FUNC_x */
+ GLfloat shadow_ambient; /**< shadow test fail color/intensity */
+};
+
+#endif
diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile
new file mode 100644
index 00000000000..12a8bd0409e
--- /dev/null
+++ b/src/mesa/pipe/softpipe/Makefile
@@ -0,0 +1,3 @@
+default:
+ cd ../.. ; make
+
diff --git a/src/mesa/pipe/softpipe/g_context.c b/src/mesa/pipe/softpipe/g_context.c
new file mode 100644
index 00000000000..c3329b5c7da
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+
+#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/pipe/softpipe/g_context.h b/src/mesa/pipe/softpipe/g_context.h
new file mode 100644
index 00000000000..24d467f2c3b
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+
+#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/pipe/softpipe/g_draw.c b/src/mesa/pipe/softpipe/g_draw.c
new file mode 100644
index 00000000000..4e094c21a0a
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+
+#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/pipe/softpipe/g_draw.h b/src/mesa/pipe/softpipe/g_draw.h
new file mode 100644
index 00000000000..78c93b4df7a
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+
+#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/pipe/softpipe/g_headers.h b/src/mesa/pipe/softpipe/g_headers.h
new file mode 100644
index 00000000000..96ff52a453b
--- /dev/null
+++ b/src/mesa/pipe/softpipe/g_headers.h
@@ -0,0 +1,116 @@
+/**************************************************************************
+ *
+ * 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 <[email protected]>
+ */
+#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;
+ GLuint facing; /**< Front or back facing? */
+
+ 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/pipe/softpipe/g_prim.h b/src/mesa/pipe/softpipe/g_prim.h
new file mode 100644
index 00000000000..e3b2c5ea2f5
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+
+#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/pipe/softpipe/g_prim_clip.c b/src/mesa/pipe/softpipe/g_prim_clip.c
new file mode 100644
index 00000000000..742def9c7dd
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+
+#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/pipe/softpipe/g_prim_cull.c b/src/mesa/pipe/softpipe/g_prim_cull.c
new file mode 100644
index 00000000000..633fbcc4926
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+#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/pipe/softpipe/g_prim_flatshade.c b/src/mesa/pipe/softpipe/g_prim_flatshade.c
new file mode 100644
index 00000000000..1974a64fa80
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+#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/pipe/softpipe/g_prim_offset.c b/src/mesa/pipe/softpipe/g_prim_offset.c
new file mode 100644
index 00000000000..801ce9a441b
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+#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/pipe/softpipe/g_prim_setup.c b/src/mesa/pipe/softpipe/g_prim_setup.c
new file mode 100644
index 00000000000..41e1381a603
--- /dev/null
+++ b/src/mesa/pipe/softpipe/g_prim_setup.c
@@ -0,0 +1,888 @@
+/**************************************************************************
+ *
+ * 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 <[email protected]>
+ */
+
+#include "imports.h"
+#include "macros.h"
+
+#include "g_context.h"
+#include "g_prim.h"
+#include "g_tile.h"
+
+
+/**
+ * Triangle edge info
+ */
+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 */
+};
+
+
+/**
+ * Triangle setup info (derived from prim_stage).
+ * Also used for line drawing (taking some liberties).
+ */
+struct setup_stage {
+ struct prim_stage stage; /**< This must be first */
+
+ /* 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]; /**< [0] = row0, [1] = row1 */
+ GLint right[2];
+ GLint y;
+ GLuint y_flags;
+ GLuint mask; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */
+ } span;
+};
+
+
+
+/**
+ * Basically a cast wrapper.
+ */
+static inline struct setup_stage *setup_stage( struct prim_stage *stage )
+{
+ return (struct setup_stage *)stage;
+}
+
+
+/**
+ * Given an X or Y coordinate, return the block/quad coordinate that it
+ * belongs to.
+ */
+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;
+}
+
+
+/**
+ * Run shader on a quad/block.
+ */
+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 );
+}
+
+
+/**
+ * Compute mask which indicates which pixels in the 2x2 quad are actually inside
+ * the triangle's bounds.
+ *
+ * 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;
+}
+
+
+/**
+ * Render a horizontal span of quads
+ */
+static void flush_spans( struct setup_stage *setup )
+{
+ GLint minleft, maxright;
+ GLint x;
+
+ switch (setup->span.y_flags) {
+ case 3:
+ minleft = MIN2(setup->span.left[0], setup->span.left[1]);
+ maxright = MAX2(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 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;
+
+ /* 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;
+ }
+ }
+ else {
+ if (y0 <= y2) {
+ /* y1<=y0<=y2 */
+ setup->vmin = v1;
+ setup->vmid = v0;
+ setup->vmax = v2;
+ }
+ else if (y2 <= y1) {
+ /* y2<=y1<=y0 */
+ setup->vmin = v2;
+ setup->vmid = v1;
+ setup->vmax = v0;
+ }
+ 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;
+ }
+
+ /* XXX need to know if this is a front or back-facing triangle:
+ * - the GLSL gl_FrontFacing fragment attribute (bool)
+ * - two-sided stencil test
+ */
+ setup->quad.facing = 0;
+
+ _mesa_printf("%s one-over-area %f\n", __FUNCTION__, setup->oneoverarea );
+
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
+ */
+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];
+}
+
+
+/**
+ * Compute a0, dadx and dady for a linearly interpolated coefficient,
+ * for a triangle.
+ */
+static void tri_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]);
+}
+
+
+/**
+ * Compute a0, dadx and dady for a perspective-corrected interpolant,
+ * for a triangle.
+ */
+static void tri_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)));
+}
+
+
+
+/**
+ * Compute the setup->coef[] array dadx, dady, a0 values.
+ * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
+ */
+static void setup_tri_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:
+ */
+ tri_linear_coeff(setup, 0, 2);
+ tri_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++)
+ tri_linear_coeff(setup, slot, j);
+ break;
+
+ case INTERP_PERSPECTIVE:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ tri_persp_coeff(setup, slot, j);
+ break;
+ }
+ }
+}
+
+
+
+static void setup_tri_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;
+}
+
+
+/**
+ * Render the upper or lower half of a triangle.
+ * Scissoring is applied here too.
+ */
+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;
+}
+
+
+/**
+ * Do setup for triangle rasterization, then render the triangle.
+ */
+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_tri_coefficients( setup );
+ setup_tri_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 );
+}
+
+
+
+/**
+ * Compute a0, dadx and dady for a linearly interpolated coefficient,
+ * for a line.
+ */
+static void
+line_linear_coeff(struct setup_stage *setup, GLuint slot, GLuint i)
+{
+ const GLfloat dz = setup->vmax->data[slot][i] - setup->vmin->data[slot][i];
+ const GLfloat dadx = dz * setup->emaj.dx * setup->oneoverarea;
+ const GLfloat dady = dz * setup->emaj.dy * setup->oneoverarea;
+ setup->coef[slot].dadx[i] = dadx;
+ setup->coef[slot].dady[i] = dady;
+ setup->coef[slot].a0[i]
+ = (setup->vmin->data[slot][i] -
+ (dadx * (setup->vmin->data[0][0] - 0.5) +
+ dady * (setup->vmin->data[0][1] - 0.5)));
+}
+
+
+/**
+ * Compute a0, dadx and dady for a perspective-corrected interpolant,
+ * for a line.
+ */
+static void
+line_persp_coeff(struct setup_stage *setup, GLuint slot, GLuint i)
+{
+ /* XXX to do */
+ line_linear_coeff(setup, slot, i); /* XXX temporary */
+}
+
+
+/**
+ * Compute the setup->coef[] array dadx, dady, a0 values.
+ * Must be called after setup->vmin,vmax are initialized.
+ */
+static INLINE void
+setup_line_coefficients(struct setup_stage *setup, struct prim_header *prim)
+{
+ const enum interp_mode *interp = setup->stage.generic->interp;
+ GLuint slot, j;
+
+ /* use setup->vmin, vmax to point to vertices */
+ setup->vprovoke = prim->v[1];
+ setup->vmin = prim->v[0];
+ setup->vmax = prim->v[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];
+ /* NOTE: this is not really 1/area */
+ setup->oneoverarea = 1.0 / (setup->emaj.dx * setup->emaj.dx +
+ setup->emaj.dy * setup->emaj.dy);
+
+ /* z and w are done by linear interpolation:
+ */
+ line_linear_coeff(setup, 0, 2);
+ line_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++)
+ line_linear_coeff(setup, slot, j);
+ break;
+
+ case INTERP_PERSPECTIVE:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ line_persp_coeff(setup, slot, j);
+ break;
+ }
+ }
+}
+
+
+/**
+ * Plot a pixel in a line segment.
+ */
+static INLINE void
+plot(struct setup_stage *setup, GLint x, GLint y)
+{
+ const GLint iy = y & 1;
+ const GLint ix = x & 1;
+ const GLint quadX = x - ix;
+ const GLint quadY = y - iy;
+ const GLint mask = (1 << ix) << (2 * iy);
+
+ if (quadX != setup->quad.x0 ||
+ quadY != setup->quad.y0)
+ {
+ /* flush prev quad, start new quad */
+
+ if (setup->quad.x0 != -1)
+ quad_shade(setup->stage.generic, &setup->quad);
+
+ setup->quad.x0 = quadX;
+ setup->quad.y0 = quadY;
+ setup->quad.mask = 0x0;
+ }
+
+ setup->quad.mask |= mask;
+}
+
+
+
+/**
+ * Do setup for line rasterization, then render the line.
+ * XXX single-pixel width, no stipple, etc
+ * XXX no scissoring yet.
+ */
+static void
+setup_line(struct prim_stage *stage, struct prim_header *prim)
+{
+ const struct vertex_header *v0 = prim->v[0];
+ const struct vertex_header *v1 = prim->v[1];
+ struct setup_stage *setup = setup_stage( stage );
+
+ GLint x0 = (GLint) v0->data[0][0];
+ GLint x1 = (GLint) v1->data[0][0];
+ GLint y0 = (GLint) v0->data[0][1];
+ GLint y1 = (GLint) v1->data[0][1];
+ GLint dx = x1 - x0;
+ GLint dy = y1 - y0;
+ GLint xstep, ystep;
+
+ if (dx == 0 && dy == 0)
+ return;
+
+ setup_line_coefficients(setup, prim);
+
+ if (dx < 0) {
+ dx = -dx; /* make positive */
+ xstep = -1;
+ }
+ else {
+ xstep = 1;
+ }
+
+ if (dy < 0) {
+ dy = -dy; /* make positive */
+ ystep = -1;
+ }
+ else {
+ ystep = 1;
+ }
+
+ assert(dx >= 0);
+ assert(dy >= 0);
+
+ setup->quad.x0 = setup->quad.y0 = -1;
+ setup->quad.mask = 0x0;
+
+ if (dx > dy) {
+ /*** X-major line ***/
+ GLint i;
+ const GLint errorInc = dy + dy;
+ GLint error = errorInc - dx;
+ const GLint errorDec = error - dx;
+
+ for (i = 0; i < dx; i++) {
+ plot(setup, x0, y0);
+
+ x0 += xstep;
+ if (error < 0) {
+ error += errorInc;
+ }
+ else {
+ error += errorDec;
+ y0 += ystep;
+ }
+ }
+ }
+ else {
+ /*** Y-major line ***/
+ GLint i;
+ const GLint errorInc = dx + dx;
+ GLint error = errorInc - dy;
+ const GLint errorDec = error - dy;
+
+ for (i = 0; i < dy; i++) {
+ plot(setup, x0, y0);
+
+ y0 += ystep;
+
+ if (error < 0) {
+ error += errorInc;
+ }
+ else {
+ error += errorDec;
+ x0 += xstep;
+ }
+ }
+ }
+
+ /* draw final quad */
+ if (setup->quad.mask) {
+ quad_shade(setup->stage.generic, &setup->quad);
+ }
+}
+
+
+/**
+ * Do setup for point rasterization, then render the point.
+ * Round or square points...
+ * XXX could optimize a lot for 1-pixel points.
+ */
+static void
+setup_point(struct prim_stage *stage, struct prim_header *prim)
+{
+ struct setup_stage *setup = setup_stage( stage );
+ GLfloat halfSize = 7.3; /*XXX this is a vertex attrib */
+ GLfloat halfSizeSquared = halfSize * halfSize;
+ const struct vertex_header *v0 = prim->v[0];
+ const GLfloat x = v0->data[FRAG_ATTRIB_WPOS][0];
+ const GLfloat y = v0->data[FRAG_ATTRIB_WPOS][1];
+ const GLint ixmin = block((GLint) (x - halfSize));
+ const GLint ixmax = block((GLint) (x + halfSize));
+ const GLint iymin = block((GLint) (y - halfSize));
+ const GLint iymax = block((GLint) (y + halfSize));
+ GLboolean round = GL_TRUE;
+ GLint ix, iy;
+ GLuint slot, j;
+
+ /* For points, all interpolants are constant-valued.
+ * However, for point sprites, we'll need to setup texcoords appropriately.
+ * XXX: which coefficients are the texcoords???
+ * We may do point sprites as textured quads...
+ *
+ * KW: We don't know which coefficients are texcoords - ultimately
+ * the choice of what interpolation mode to use for each attribute
+ * should be determined by the fragment program, using
+ * per-attribute declaration statements that include interpolation
+ * mode as a parameter. So either the fragment program will have
+ * to be adjusted for pointsprite vs normal point behaviour, or
+ * otherwise a special interpolation mode will have to be defined
+ * which matches the required behaviour for point sprites. But -
+ * the latter is not a feature of normal hardware, and as such
+ * probably should be ruled out on that basis.
+ */
+ setup->vprovoke = prim->v[0];
+ const_coeff(setup, 0, 2);
+ const_coeff(setup, 0, 3);
+ for (slot = 1; slot < setup->quad.nr_attrs; slot++) {
+ for (j = 0; j < NUM_CHANNELS; j++)
+ const_coeff(setup, slot, j);
+ }
+
+ /* XXX need to clip against scissor bounds too */
+
+ for (iy = iymin; iy <= iymax; iy += 2) {
+ for (ix = ixmin; ix <= ixmax; ix += 2) {
+
+ if (round) {
+ /* rounded points */
+ /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */
+ GLfloat dx, dy;
+
+ setup->quad.mask = 0x0;
+
+ dx = (ix + 0.5) - x;
+ dy = (iy + 0.5) - y;
+ if (dx * dx + dy * dy <= halfSizeSquared)
+ setup->quad.mask |= MASK_BOTTOM_LEFT;
+
+ dx = (ix + 1.5) - x;
+ dy = (iy + 0.5) - y;
+ if (dx * dx + dy * dy <= halfSizeSquared)
+ setup->quad.mask |= MASK_BOTTOM_RIGHT;
+
+ dx = (ix + 0.5) - x;
+ dy = (iy + 1.5) - y;
+ if (dx * dx + dy * dy <= halfSizeSquared)
+ setup->quad.mask |= MASK_TOP_LEFT;
+
+ dx = (ix + 1.5) - x;
+ dy = (iy + 1.5) - y;
+ if (dx * dx + dy * dy <= halfSizeSquared)
+ setup->quad.mask |= MASK_TOP_RIGHT;
+ }
+ else {
+ /* square points */
+ setup->quad.mask = 0xf;
+
+ if (ix + 0.5 < x - halfSize)
+ setup->quad.mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT);
+
+ if (ix + 1.5 > x + halfSize)
+ setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT);
+
+ if (iy + 0.5 < y - halfSize)
+ setup->quad.mask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT);
+
+ if (iy + 1.5 > y + halfSize)
+ setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT);
+ }
+
+ if (setup->quad.mask) {
+ setup->quad.x0 = ix;
+ setup->quad.y0 = iy;
+ quad_shade( setup->stage.generic, &setup->quad );
+ }
+ }
+ }
+}
+
+
+
+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/pipe/softpipe/g_prim_setup.h b/src/mesa/pipe/softpipe/g_prim_setup.h
new file mode 100644
index 00000000000..40a70c543e6
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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/pipe/softpipe/g_prim_twoside.c b/src/mesa/pipe/softpipe/g_prim_twoside.c
new file mode 100644
index 00000000000..334ae2f5378
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+#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/pipe/softpipe/g_prim_unfilled.c b/src/mesa/pipe/softpipe/g_prim_unfilled.c
new file mode 100644
index 00000000000..7c6ee79f92a
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+#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/pipe/softpipe/g_state.h b/src/mesa/pipe/softpipe/g_state.h
new file mode 100644
index 00000000000..5077d37ab7b
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+
+#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/pipe/softpipe/g_state_clip.c b/src/mesa/pipe/softpipe/g_state_clip.c
new file mode 100644
index 00000000000..b90034e11e4
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+#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/pipe/softpipe/g_state_derived.c b/src/mesa/pipe/softpipe/g_state_derived.c
new file mode 100644
index 00000000000..678825afe13
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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/pipe/softpipe/g_state_fs.c b/src/mesa/pipe/softpipe/g_state_fs.c
new file mode 100644
index 00000000000..8a430c0c65a
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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/pipe/softpipe/g_state_setup.c b/src/mesa/pipe/softpipe/g_state_setup.c
new file mode 100644
index 00000000000..2a5176c5a1a
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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/pipe/softpipe/g_state_surface.c b/src/mesa/pipe/softpipe/g_state_surface.c
new file mode 100644
index 00000000000..c791ce4640a
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+#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/pipe/softpipe/g_surface.c b/src/mesa/pipe/softpipe/g_surface.c
new file mode 100644
index 00000000000..2df30cde705
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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/pipe/softpipe/g_surface.h b/src/mesa/pipe/softpipe/g_surface.h
new file mode 100644
index 00000000000..23c28f0bb40
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+
+#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/pipe/softpipe/g_tile.h b/src/mesa/pipe/softpipe/g_tile.h
new file mode 100644
index 00000000000..6ae52123560
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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 <[email protected]>
+ */
+#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/pipe/softpipe/g_tile_fs.c b/src/mesa/pipe/softpipe/g_tile_fs.c
new file mode 100644
index 00000000000..4c5e6efaed0
--- /dev/null
+++ b/src/mesa/pipe/softpipe/g_tile_fs.c
@@ -0,0 +1,203 @@
+/*
+ * 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];
+};
+
+
+/**
+ * Compute quad's attributes values, as constants (GL_FLAT shading).
+ */
+static INLINE void 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];
+ }
+}
+
+
+/**
+ * Compute quad's attribute values by linear interpolation.
+ *
+ * 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++) {
+ const GLfloat x = exec->attr[FRAG_ATTRIB_WPOS][0][j];
+ const GLfloat y = exec->attr[FRAG_ATTRIB_WPOS][1][j];
+ exec->attr[attrib][i][j] = (exec->coef[attrib].a0[i] +
+ exec->coef[attrib].dadx[i] * x +
+ exec->coef[attrib].dady[i] * y);
+ }
+}
+
+
+/**
+ * Compute quad's attribute values by linear interpolation with
+ * perspective correction.
+ *
+ * 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++) {
+ const GLfloat x = exec->attr[FRAG_ATTRIB_WPOS][0][j];
+ const GLfloat y = exec->attr[FRAG_ATTRIB_WPOS][1][j];
+ const GLfloat invW = exec->attr[FRAG_ATTRIB_WPOS][3][j];
+ exec->attr[attrib][i][j] = ((exec->coef[attrib].a0[i] +
+ exec->coef[attrib].dadx[i] * x +
+ exec->coef[attrib].dady[i] * y) * invW);
+ }
+}
+
+
+
+/* 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:
+ * XXX we'll probably have to use integers for Z
+ */
+ 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/pipe/softpipe/g_tile_output.c b/src/mesa/pipe/softpipe/g_tile_output.c
new file mode 100644
index 00000000000..058ca301931
--- /dev/null
+++ b/src/mesa/pipe/softpipe/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/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c
new file mode 100644
index 00000000000..8e547cbdc39
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+
+#include "imports.h"
+#include "macros.h"
+
+#include "tnl/t_context.h"
+#include "vf/vf.h"
+
+#include "sp_context.h"
+#include "sp_prim.h"
+#include "sp_state.h"
+#include "sp_draw.h"
+
+static void softpipe_destroy( struct pipe_context *pipe )
+{
+ struct softpipe_context *softpipe = softpipe_context( pipe );
+
+ draw_destroy( softpipe->draw );
+
+ FREE( softpipe );
+}
+
+
+static void softpipe_draw_vb( struct pipe_context *pipe,
+ struct vertex_buffer *VB )
+{
+ struct softpipe_context *softpipe = softpipe_context( pipe );
+
+ if (softpipe->dirty)
+ softpipe_update_derived( softpipe );
+
+ draw_vb( softpipe->draw, VB );
+}
+
+struct pipe_context *softpipe_create( void )
+{
+ struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
+
+ softpipe->pipe.destroy = softpipe_destroy;
+ softpipe->pipe.set_clip_state = softpipe_set_clip_state;
+ softpipe->pipe.set_viewport = softpipe_set_viewport;
+ softpipe->pipe.set_setup_state = softpipe_set_setup_state;
+ softpipe->pipe.set_scissor_rect = softpipe_set_scissor_rect;
+ softpipe->pipe.set_fs_state = softpipe_set_fs_state;
+ softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
+ softpipe->pipe.set_cbuf_state = softpipe_set_cbuf_state;
+ softpipe->pipe.draw_vb = softpipe_draw_vb;
+
+
+
+ softpipe->prim.setup = prim_setup( softpipe );
+ softpipe->prim.unfilled = prim_unfilled( softpipe );
+ softpipe->prim.twoside = prim_twoside( softpipe );
+ softpipe->prim.offset = prim_offset( softpipe );
+ softpipe->prim.clip = prim_clip( softpipe );
+ softpipe->prim.flatshade = prim_flatshade( softpipe );
+ softpipe->prim.cull = prim_cull( softpipe );
+
+
+ softpipe->draw = draw_create( softpipe );
+
+ ASSIGN_4V( softpipe->plane[0], -1, 0, 0, 1 );
+ ASSIGN_4V( softpipe->plane[1], 1, 0, 0, 1 );
+ ASSIGN_4V( softpipe->plane[2], 0, -1, 0, 1 );
+ ASSIGN_4V( softpipe->plane[3], 0, 1, 0, 1 );
+ ASSIGN_4V( softpipe->plane[4], 0, 0, 1, 1 ); /* yes these are correct */
+ ASSIGN_4V( softpipe->plane[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */
+ softpipe->nr_planes = 6;
+
+ return &softpipe->pipe;
+}
+
+
+
+
+
+
+#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/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h
new file mode 100644
index 00000000000..da6c17aaf6e
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+
+#ifndef G_CONTEXT_H
+#define G_CONTEXT_H
+
+#include "glheader.h"
+
+#include "pipe/p_state.h"
+#include "pipe/p_context.h"
+
+
+
+struct softpipe_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 softpipe_context {
+ struct pipe_context pipe;
+
+
+ /* The most recent drawing state as set by the driver:
+ */
+ struct pipe_viewport viewport;
+ struct pipe_setup_state setup;
+ struct pipe_fs_state fs;
+ struct pipe_blend_state blend;
+ struct pipe_surface cbuf;
+ struct pipe_clip_state clip;
+ struct pipe_scissor_rect scissor;
+ struct pipe_poly_stipple poly_stipple;
+ GLuint dirty;
+
+
+ /* Cbuf derived state???
+ */
+ struct softpipe_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 softpipe_context *
+softpipe_context( struct pipe_context *pipe )
+{
+ return (struct softpipe_context *)pipe;
+}
+
+
+
+
+#endif
diff --git a/src/mesa/pipe/softpipe/sp_draw.c b/src/mesa/pipe/softpipe/sp_draw.c
new file mode 100644
index 00000000000..5813e377762
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+
+#include "imports.h"
+
+#include "tnl/t_context.h"
+
+#include "sp_context.h"
+#include "sp_prim.h"
+#include "sp_headers.h"
+#include "sp_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 pipe.
+ */
+
+
+struct draw_context
+{
+ struct softpipe_context *softpipe;
+
+ 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->softpipe->prim.first->begin( draw->softpipe->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->softpipe->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->softpipe->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->softpipe->prim.first->end( draw->softpipe->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 softpipe_context *softpipe )
+{
+ struct draw_context *draw = CALLOC_STRUCT( draw_context );
+ draw->softpipe = softpipe;
+ 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/pipe/softpipe/sp_draw.h b/src/mesa/pipe/softpipe/sp_draw.h
new file mode 100644
index 00000000000..a138f812fa4
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+
+#ifndef G_DRAW_H
+#define G_DRAW_H
+
+#include "glheader.h"
+#include "pipe/p_state.h"
+
+
+struct draw_context;
+
+struct draw_context *draw_create( struct softpipe_context *softpipe );
+
+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/pipe/softpipe/sp_headers.h b/src/mesa/pipe/softpipe/sp_headers.h
new file mode 100644
index 00000000000..96ff52a453b
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_headers.h
@@ -0,0 +1,116 @@
+/**************************************************************************
+ *
+ * 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 <[email protected]>
+ */
+#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;
+ GLuint facing; /**< Front or back facing? */
+
+ 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/pipe/softpipe/sp_prim.h b/src/mesa/pipe/softpipe/sp_prim.h
new file mode 100644
index 00000000000..b6cbaae085d
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+
+#ifndef G_PRIM_H
+#define G_PRIM_H
+
+#include "glheader.h"
+#include "sp_headers.h"
+
+struct softpipe_context;
+
+struct prim_stage *prim_setup( struct softpipe_context *context );
+struct prim_stage *prim_unfilled( struct softpipe_context *context );
+struct prim_stage *prim_twoside( struct softpipe_context *context );
+struct prim_stage *prim_offset( struct softpipe_context *context );
+struct prim_stage *prim_clip( struct softpipe_context *context );
+struct prim_stage *prim_flatshade( struct softpipe_context *context );
+struct prim_stage *prim_cull( struct softpipe_context *context );
+
+
+/* Internal structs and helpers for the primitive clip/setup pipeline:
+ */
+struct prim_stage {
+ struct softpipe_context *softpipe;
+
+ 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->softpipe->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/pipe/softpipe/sp_prim_clip.c b/src/mesa/pipe/softpipe/sp_prim_clip.c
new file mode 100644
index 00000000000..304c43c3f48
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+
+#include "imports.h"
+#include "macros.h"
+
+#include "sp_context.h"
+#include "sp_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.softpipe->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.softpipe->viewport.scale;
+ const GLfloat *trans = clip->stage.softpipe->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.softpipe->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.softpipe->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->softpipe->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 softpipe_context *softpipe )
+{
+ struct clipper *clipper = CALLOC_STRUCT(clipper);
+
+ prim_alloc_tmps( &clipper->stage, MAX_CLIPPED_VERTICES );
+
+ clipper->stage.softpipe = softpipe;
+ 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/pipe/softpipe/sp_prim_cull.c b/src/mesa/pipe/softpipe/sp_prim_cull.c
new file mode 100644
index 00000000000..16920d478aa
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+#include "imports.h"
+
+#include "sp_context.h"
+#include "sp_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->softpipe->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 softpipe_context *softpipe )
+{
+ struct cull_stage *cull = CALLOC_STRUCT(cull_stage);
+
+ prim_alloc_tmps( &cull->stage, 0 );
+
+ cull->stage.softpipe = softpipe;
+ 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/pipe/softpipe/sp_prim_flatshade.c b/src/mesa/pipe/softpipe/sp_prim_flatshade.c
new file mode 100644
index 00000000000..0e9de5faeb1
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+#include "imports.h"
+
+#include "sp_context.h"
+#include "sp_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 softpipe_context *softpipe )
+{
+ struct flatshade_stage *flatshade = CALLOC_STRUCT(flatshade_stage);
+
+ prim_alloc_tmps( &flatshade->stage, 2 );
+
+ flatshade->stage.softpipe = softpipe;
+ 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 = softpipe->vf_attr_to_slot;
+
+ return &flatshade->stage;
+}
+
+
diff --git a/src/mesa/pipe/softpipe/sp_prim_offset.c b/src/mesa/pipe/softpipe/sp_prim_offset.c
new file mode 100644
index 00000000000..5fd6ac911a5
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+#include "imports.h"
+#include "macros.h"
+
+#include "sp_context.h"
+#include "sp_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->softpipe->setup.offset_units;
+ offset->scale = stage->softpipe->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 softpipe_context *softpipe )
+{
+ struct offset_stage *offset = CALLOC_STRUCT(offset_stage);
+
+ prim_alloc_tmps( &offset->stage, 3 );
+
+ offset->stage.softpipe = softpipe;
+ 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/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c
new file mode 100644
index 00000000000..a1addc4ee17
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_prim_setup.c
@@ -0,0 +1,888 @@
+/**************************************************************************
+ *
+ * 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 <[email protected]>
+ */
+
+#include "imports.h"
+#include "macros.h"
+
+#include "sp_context.h"
+#include "sp_prim.h"
+#include "sp_tile.h"
+
+
+/**
+ * Triangle edge info
+ */
+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 */
+};
+
+
+/**
+ * Triangle setup info (derived from prim_stage).
+ * Also used for line drawing (taking some liberties).
+ */
+struct setup_stage {
+ struct prim_stage stage; /**< This must be first */
+
+ /* 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]; /**< [0] = row0, [1] = row1 */
+ GLint right[2];
+ GLint y;
+ GLuint y_flags;
+ GLuint mask; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */
+ } span;
+};
+
+
+
+/**
+ * Basically a cast wrapper.
+ */
+static inline struct setup_stage *setup_stage( struct prim_stage *stage )
+{
+ return (struct setup_stage *)stage;
+}
+
+
+/**
+ * Given an X or Y coordinate, return the block/quad coordinate that it
+ * belongs to.
+ */
+static inline GLint block( GLint x )
+{
+ return x & ~1;
+}
+
+
+
+static void setup_begin( struct prim_stage *stage )
+{
+ setup_stage(stage)->quad.nr_attrs = stage->softpipe->nr_frag_attrs;
+}
+
+
+/**
+ * Run shader on a quad/block.
+ */
+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.softpipe, &setup->quad );
+}
+
+
+/**
+ * Compute mask which indicates which pixels in the 2x2 quad are actually inside
+ * the triangle's bounds.
+ *
+ * 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;
+}
+
+
+/**
+ * Render a horizontal span of quads
+ */
+static void flush_spans( struct setup_stage *setup )
+{
+ GLint minleft, maxright;
+ GLint x;
+
+ switch (setup->span.y_flags) {
+ case 3:
+ minleft = MIN2(setup->span.left[0], setup->span.left[1]);
+ maxright = MAX2(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 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;
+
+ /* 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;
+ }
+ }
+ else {
+ if (y0 <= y2) {
+ /* y1<=y0<=y2 */
+ setup->vmin = v1;
+ setup->vmid = v0;
+ setup->vmax = v2;
+ }
+ else if (y2 <= y1) {
+ /* y2<=y1<=y0 */
+ setup->vmin = v2;
+ setup->vmid = v1;
+ setup->vmax = v0;
+ }
+ 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;
+ }
+
+ /* XXX need to know if this is a front or back-facing triangle:
+ * - the GLSL gl_FrontFacing fragment attribute (bool)
+ * - two-sided stencil test
+ */
+ setup->quad.facing = 0;
+
+ _mesa_printf("%s one-over-area %f\n", __FUNCTION__, setup->oneoverarea );
+
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
+ */
+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];
+}
+
+
+/**
+ * Compute a0, dadx and dady for a linearly interpolated coefficient,
+ * for a triangle.
+ */
+static void tri_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]);
+}
+
+
+/**
+ * Compute a0, dadx and dady for a perspective-corrected interpolant,
+ * for a triangle.
+ */
+static void tri_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)));
+}
+
+
+
+/**
+ * Compute the setup->coef[] array dadx, dady, a0 values.
+ * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
+ */
+static void setup_tri_coefficients( struct setup_stage *setup )
+{
+ const enum interp_mode *interp = setup->stage.softpipe->interp;
+ GLuint slot, j;
+
+ /* z and w are done by linear interpolation:
+ */
+ tri_linear_coeff(setup, 0, 2);
+ tri_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++)
+ tri_linear_coeff(setup, slot, j);
+ break;
+
+ case INTERP_PERSPECTIVE:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ tri_persp_coeff(setup, slot, j);
+ break;
+ }
+ }
+}
+
+
+
+static void setup_tri_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;
+}
+
+
+/**
+ * Render the upper or lower half of a triangle.
+ * Scissoring is applied here too.
+ */
+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.softpipe->setup.scissor) {
+ start_y = sy;
+ finish_y = start_y + lines;
+
+ if (start_y < setup->stage.softpipe->scissor.miny)
+ start_y = setup->stage.softpipe->scissor.miny;
+
+ if (finish_y > setup->stage.softpipe->scissor.maxy)
+ finish_y = setup->stage.softpipe->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.softpipe->setup.scissor) {
+ if (left < setup->stage.softpipe->scissor.minx)
+ left = setup->stage.softpipe->scissor.minx;
+
+ if (right > setup->stage.softpipe->scissor.maxx)
+ right = setup->stage.softpipe->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;
+}
+
+
+/**
+ * Do setup for triangle rasterization, then render the triangle.
+ */
+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_tri_coefficients( setup );
+ setup_tri_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 );
+}
+
+
+
+/**
+ * Compute a0, dadx and dady for a linearly interpolated coefficient,
+ * for a line.
+ */
+static void
+line_linear_coeff(struct setup_stage *setup, GLuint slot, GLuint i)
+{
+ const GLfloat dz = setup->vmax->data[slot][i] - setup->vmin->data[slot][i];
+ const GLfloat dadx = dz * setup->emaj.dx * setup->oneoverarea;
+ const GLfloat dady = dz * setup->emaj.dy * setup->oneoverarea;
+ setup->coef[slot].dadx[i] = dadx;
+ setup->coef[slot].dady[i] = dady;
+ setup->coef[slot].a0[i]
+ = (setup->vmin->data[slot][i] -
+ (dadx * (setup->vmin->data[0][0] - 0.5) +
+ dady * (setup->vmin->data[0][1] - 0.5)));
+}
+
+
+/**
+ * Compute a0, dadx and dady for a perspective-corrected interpolant,
+ * for a line.
+ */
+static void
+line_persp_coeff(struct setup_stage *setup, GLuint slot, GLuint i)
+{
+ /* XXX to do */
+ line_linear_coeff(setup, slot, i); /* XXX temporary */
+}
+
+
+/**
+ * Compute the setup->coef[] array dadx, dady, a0 values.
+ * Must be called after setup->vmin,vmax are initialized.
+ */
+static INLINE void
+setup_line_coefficients(struct setup_stage *setup, struct prim_header *prim)
+{
+ const enum interp_mode *interp = setup->stage.softpipe->interp;
+ GLuint slot, j;
+
+ /* use setup->vmin, vmax to point to vertices */
+ setup->vprovoke = prim->v[1];
+ setup->vmin = prim->v[0];
+ setup->vmax = prim->v[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];
+ /* NOTE: this is not really 1/area */
+ setup->oneoverarea = 1.0 / (setup->emaj.dx * setup->emaj.dx +
+ setup->emaj.dy * setup->emaj.dy);
+
+ /* z and w are done by linear interpolation:
+ */
+ line_linear_coeff(setup, 0, 2);
+ line_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++)
+ line_linear_coeff(setup, slot, j);
+ break;
+
+ case INTERP_PERSPECTIVE:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ line_persp_coeff(setup, slot, j);
+ break;
+ }
+ }
+}
+
+
+/**
+ * Plot a pixel in a line segment.
+ */
+static INLINE void
+plot(struct setup_stage *setup, GLint x, GLint y)
+{
+ const GLint iy = y & 1;
+ const GLint ix = x & 1;
+ const GLint quadX = x - ix;
+ const GLint quadY = y - iy;
+ const GLint mask = (1 << ix) << (2 * iy);
+
+ if (quadX != setup->quad.x0 ||
+ quadY != setup->quad.y0)
+ {
+ /* flush prev quad, start new quad */
+
+ if (setup->quad.x0 != -1)
+ quad_shade(setup->stage.softpipe, &setup->quad);
+
+ setup->quad.x0 = quadX;
+ setup->quad.y0 = quadY;
+ setup->quad.mask = 0x0;
+ }
+
+ setup->quad.mask |= mask;
+}
+
+
+
+/**
+ * Do setup for line rasterization, then render the line.
+ * XXX single-pixel width, no stipple, etc
+ * XXX no scissoring yet.
+ */
+static void
+setup_line(struct prim_stage *stage, struct prim_header *prim)
+{
+ const struct vertex_header *v0 = prim->v[0];
+ const struct vertex_header *v1 = prim->v[1];
+ struct setup_stage *setup = setup_stage( stage );
+
+ GLint x0 = (GLint) v0->data[0][0];
+ GLint x1 = (GLint) v1->data[0][0];
+ GLint y0 = (GLint) v0->data[0][1];
+ GLint y1 = (GLint) v1->data[0][1];
+ GLint dx = x1 - x0;
+ GLint dy = y1 - y0;
+ GLint xstep, ystep;
+
+ if (dx == 0 && dy == 0)
+ return;
+
+ setup_line_coefficients(setup, prim);
+
+ if (dx < 0) {
+ dx = -dx; /* make positive */
+ xstep = -1;
+ }
+ else {
+ xstep = 1;
+ }
+
+ if (dy < 0) {
+ dy = -dy; /* make positive */
+ ystep = -1;
+ }
+ else {
+ ystep = 1;
+ }
+
+ assert(dx >= 0);
+ assert(dy >= 0);
+
+ setup->quad.x0 = setup->quad.y0 = -1;
+ setup->quad.mask = 0x0;
+
+ if (dx > dy) {
+ /*** X-major line ***/
+ GLint i;
+ const GLint errorInc = dy + dy;
+ GLint error = errorInc - dx;
+ const GLint errorDec = error - dx;
+
+ for (i = 0; i < dx; i++) {
+ plot(setup, x0, y0);
+
+ x0 += xstep;
+ if (error < 0) {
+ error += errorInc;
+ }
+ else {
+ error += errorDec;
+ y0 += ystep;
+ }
+ }
+ }
+ else {
+ /*** Y-major line ***/
+ GLint i;
+ const GLint errorInc = dx + dx;
+ GLint error = errorInc - dy;
+ const GLint errorDec = error - dy;
+
+ for (i = 0; i < dy; i++) {
+ plot(setup, x0, y0);
+
+ y0 += ystep;
+
+ if (error < 0) {
+ error += errorInc;
+ }
+ else {
+ error += errorDec;
+ x0 += xstep;
+ }
+ }
+ }
+
+ /* draw final quad */
+ if (setup->quad.mask) {
+ quad_shade(setup->stage.softpipe, &setup->quad);
+ }
+}
+
+
+/**
+ * Do setup for point rasterization, then render the point.
+ * Round or square points...
+ * XXX could optimize a lot for 1-pixel points.
+ */
+static void
+setup_point(struct prim_stage *stage, struct prim_header *prim)
+{
+ struct setup_stage *setup = setup_stage( stage );
+ GLfloat halfSize = 7.3; /*XXX this is a vertex attrib */
+ GLfloat halfSizeSquared = halfSize * halfSize;
+ const struct vertex_header *v0 = prim->v[0];
+ const GLfloat x = v0->data[FRAG_ATTRIB_WPOS][0];
+ const GLfloat y = v0->data[FRAG_ATTRIB_WPOS][1];
+ const GLint ixmin = block((GLint) (x - halfSize));
+ const GLint ixmax = block((GLint) (x + halfSize));
+ const GLint iymin = block((GLint) (y - halfSize));
+ const GLint iymax = block((GLint) (y + halfSize));
+ GLboolean round = GL_TRUE;
+ GLint ix, iy;
+ GLuint slot, j;
+
+ /* For points, all interpolants are constant-valued.
+ * However, for point sprites, we'll need to setup texcoords appropriately.
+ * XXX: which coefficients are the texcoords???
+ * We may do point sprites as textured quads...
+ *
+ * KW: We don't know which coefficients are texcoords - ultimately
+ * the choice of what interpolation mode to use for each attribute
+ * should be determined by the fragment program, using
+ * per-attribute declaration statements that include interpolation
+ * mode as a parameter. So either the fragment program will have
+ * to be adjusted for pointsprite vs normal point behaviour, or
+ * otherwise a special interpolation mode will have to be defined
+ * which matches the required behaviour for point sprites. But -
+ * the latter is not a feature of normal hardware, and as such
+ * probably should be ruled out on that basis.
+ */
+ setup->vprovoke = prim->v[0];
+ const_coeff(setup, 0, 2);
+ const_coeff(setup, 0, 3);
+ for (slot = 1; slot < setup->quad.nr_attrs; slot++) {
+ for (j = 0; j < NUM_CHANNELS; j++)
+ const_coeff(setup, slot, j);
+ }
+
+ /* XXX need to clip against scissor bounds too */
+
+ for (iy = iymin; iy <= iymax; iy += 2) {
+ for (ix = ixmin; ix <= ixmax; ix += 2) {
+
+ if (round) {
+ /* rounded points */
+ /* XXX for GL_SMOOTH, need to compute per-fragment coverage too */
+ GLfloat dx, dy;
+
+ setup->quad.mask = 0x0;
+
+ dx = (ix + 0.5) - x;
+ dy = (iy + 0.5) - y;
+ if (dx * dx + dy * dy <= halfSizeSquared)
+ setup->quad.mask |= MASK_BOTTOM_LEFT;
+
+ dx = (ix + 1.5) - x;
+ dy = (iy + 0.5) - y;
+ if (dx * dx + dy * dy <= halfSizeSquared)
+ setup->quad.mask |= MASK_BOTTOM_RIGHT;
+
+ dx = (ix + 0.5) - x;
+ dy = (iy + 1.5) - y;
+ if (dx * dx + dy * dy <= halfSizeSquared)
+ setup->quad.mask |= MASK_TOP_LEFT;
+
+ dx = (ix + 1.5) - x;
+ dy = (iy + 1.5) - y;
+ if (dx * dx + dy * dy <= halfSizeSquared)
+ setup->quad.mask |= MASK_TOP_RIGHT;
+ }
+ else {
+ /* square points */
+ setup->quad.mask = 0xf;
+
+ if (ix + 0.5 < x - halfSize)
+ setup->quad.mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT);
+
+ if (ix + 1.5 > x + halfSize)
+ setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT);
+
+ if (iy + 0.5 < y - halfSize)
+ setup->quad.mask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT);
+
+ if (iy + 1.5 > y + halfSize)
+ setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT);
+ }
+
+ if (setup->quad.mask) {
+ setup->quad.x0 = ix;
+ setup->quad.y0 = iy;
+ quad_shade( setup->stage.softpipe, &setup->quad );
+ }
+ }
+ }
+}
+
+
+
+static void setup_end( struct prim_stage *stage )
+{
+}
+
+
+struct prim_stage *prim_setup( struct softpipe_context *softpipe )
+{
+ struct setup_stage *setup = CALLOC_STRUCT(setup_stage);
+
+ setup->stage.softpipe = softpipe;
+ 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/pipe/softpipe/sp_prim_setup.h b/src/mesa/pipe/softpipe/sp_prim_setup.h
new file mode 100644
index 00000000000..40a70c543e6
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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/pipe/softpipe/sp_prim_twoside.c b/src/mesa/pipe/softpipe/sp_prim_twoside.c
new file mode 100644
index 00000000000..6eee1de5888
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+#include "imports.h"
+#include "sp_context.h"
+#include "sp_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->softpipe->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 softpipe_context *softpipe )
+{
+ struct twoside_stage *twoside = CALLOC_STRUCT(twoside_stage);
+
+ prim_alloc_tmps( &twoside->stage, 3 );
+
+ twoside->stage.softpipe = softpipe;
+ 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 = softpipe->vf_attr_to_slot;
+
+ return &twoside->stage;
+}
diff --git a/src/mesa/pipe/softpipe/sp_prim_unfilled.c b/src/mesa/pipe/softpipe/sp_prim_unfilled.c
new file mode 100644
index 00000000000..73147337fd5
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+#include "imports.h"
+
+#include "sp_context.h"
+#include "sp_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->softpipe->setup.fill_ccw;
+ unfilled->mode[1] = stage->softpipe->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 softpipe_context *softpipe )
+{
+ struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
+
+ prim_alloc_tmps( &unfilled->stage, 0 );
+
+ unfilled->stage.softpipe = softpipe;
+ 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/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h
new file mode 100644
index 00000000000..2abefc60372
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+
+#ifndef PRIM_H
+#define PRIM_H
+
+#include "glheader.h"
+#include "pipe/p_state.h"
+
+
+void softpipe_set_clip_state( struct pipe_context *,
+ const struct pipe_clip_state * );
+
+void softpipe_set_viewport( struct pipe_context *,
+ const struct pipe_viewport * );
+
+void softpipe_set_setup_state( struct pipe_context *,
+ const struct pipe_setup_state * );
+
+void softpipe_set_scissor_rect( struct pipe_context *,
+ const struct pipe_scissor_rect * );
+
+void softpipe_set_fs_state( struct pipe_context *,
+ const struct pipe_fs_state * );
+
+void softpipe_set_polygon_stipple( struct pipe_context *,
+ const struct pipe_poly_stipple * );
+
+void softpipe_set_cbuf_state( struct pipe_context *,
+ const struct pipe_surface * );
+
+void softpipe_update_derived( struct softpipe_context *softpipe );
+
+#endif
diff --git a/src/mesa/pipe/softpipe/sp_state_clip.c b/src/mesa/pipe/softpipe/sp_state_clip.c
new file mode 100644
index 00000000000..6e83b055fbc
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+#include "imports.h"
+
+#include "sp_context.h"
+#include "sp_state.h"
+#include "sp_draw.h"
+
+
+
+void softpipe_set_clip_state( struct pipe_context *pipe,
+ const struct pipe_clip_state *clip )
+{
+ struct softpipe_context *softpipe = softpipe_context(pipe);
+
+ memcpy(&softpipe->plane[6], clip->ucp, clip->nr * sizeof(clip->ucp[0]));
+
+ softpipe->nr_planes = 6 + clip->nr;
+ softpipe->dirty |= G_NEW_CLIP;
+}
+
+
+
+/* Called when driver state tracker notices changes to the viewport
+ * matrix:
+ */
+void softpipe_set_viewport( struct pipe_context *pipe,
+ const struct pipe_viewport *viewport )
+{
+ struct softpipe_context *softpipe = softpipe_context(pipe);
+
+ memcpy(&softpipe->viewport, viewport, sizeof(viewport));
+
+ /* Using tnl/ and vf/ modules is temporary while getting started.
+ * Full pipe will have vertex shader, vertex fetch of its own.
+ */
+ draw_set_viewport( softpipe->draw, viewport->scale, viewport->translate );
+ softpipe->dirty |= G_NEW_VIEWPORT;
+}
+
+
+
diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c
new file mode 100644
index 00000000000..1f7329600ab
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 "sp_context.h"
+#include "sp_draw.h"
+#include "sp_state.h"
+
+#define EMIT_ATTR( ATTR, FRAG_ATTR, INTERP ) \
+do { \
+ slot_to_vf_attr[softpipe->nr_attrs] = ATTR; \
+ softpipe->vf_attr_to_slot[ATTR] = softpipe->nr_attrs; \
+ softpipe->fp_attr_to_slot[FRAG_ATTR] = softpipe->nr_attrs; \
+ softpipe->interp[softpipe->nr_attrs] = INTERP; \
+ softpipe->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 softpipe_context *softpipe )
+{
+ struct gl_fragment_program *fp = softpipe->fs.fp;
+ const GLuint inputsRead = fp->Base.InputsRead;
+ GLuint slot_to_vf_attr[VF_ATTRIB_MAX];
+ GLuint attr_mask = 0;
+ GLuint i;
+
+ softpipe->nr_attrs = 0;
+ memset(slot_to_vf_attr, 0, sizeof(slot_to_vf_attr));
+
+ memset(softpipe->fp_attr_to_slot, 0, sizeof(softpipe->vf_attr_to_slot));
+ memset(softpipe->vf_attr_to_slot, 0, sizeof(softpipe->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);
+ }
+ }
+
+ softpipe->nr_frag_attrs = softpipe->nr_attrs;
+
+ /* Additional attributes required for setup: Just twosided
+ * lighting. Edgeflag is dealt with specially by setting bits in
+ * the vertex header.
+ */
+ if (softpipe->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 != softpipe->attr_mask) {
+ softpipe->attr_mask = attr_mask;
+
+ draw_set_vertex_attributes( softpipe->draw,
+ slot_to_vf_attr,
+ softpipe->nr_attrs );
+ }
+}
+
+
+/* Hopefully this will remain quite simple, otherwise need to pull in
+ * something like the state tracker mechanism.
+ */
+void softpipe_update_derived( struct softpipe_context *softpipe )
+{
+ if (softpipe->dirty & (G_NEW_SETUP | G_NEW_FS))
+ calculate_vertex_layout( softpipe );
+
+ softpipe->dirty = 0;
+}
diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c
new file mode 100644
index 00000000000..29f965e50e2
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 "sp_context.h"
+#include "sp_state.h"
+
+
+
+void softpipe_set_fs_state( struct pipe_context *pipe,
+ const struct pipe_fs_state *fs )
+{
+ struct softpipe_context *softpipe = softpipe_context(pipe);
+
+ memcpy(&softpipe->fs, fs, sizeof(*fs));
+
+ softpipe->dirty |= G_NEW_FS;
+}
+
+
+
+
+
+
+
+
+
diff --git a/src/mesa/pipe/softpipe/sp_state_setup.c b/src/mesa/pipe/softpipe/sp_state_setup.c
new file mode 100644
index 00000000000..7be7d7fe40d
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 "sp_context.h"
+#include "sp_state.h"
+#include "sp_prim.h"
+
+
+
+
+static void validate_prim_pipe( struct softpipe_context *softpipe )
+{
+ struct prim_stage *next = softpipe->prim.setup;
+
+ /* TODO: make the current primitive part of the state and build
+ * shorter pipelines for lines & points.
+ */
+ if (softpipe->setup.fill_cw != FILL_TRI ||
+ softpipe->setup.fill_ccw != FILL_TRI) {
+
+ softpipe->prim.unfilled->next = next;
+ next = softpipe->prim.unfilled;
+ }
+
+ if (softpipe->setup.offset_cw ||
+ softpipe->setup.offset_ccw) {
+ softpipe->prim.offset->next = next;
+ next = softpipe->prim.offset;
+ }
+
+ if (softpipe->setup.light_twoside) {
+ softpipe->prim.twoside->next = next;
+ next = softpipe->prim.twoside;
+ }
+
+ /* Always run the cull stage as we calculate determinant there
+ * also. Fix this..
+ */
+ {
+ softpipe->prim.cull->next = next;
+ next = softpipe->prim.cull;
+ }
+
+
+ /* Clip stage
+ */
+ {
+ softpipe->prim.clip->next = next;
+ next = softpipe->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 (softpipe->setup.flatshade) {
+ softpipe->prim.flatshade->next = next;
+ next = softpipe->prim.flatshade;
+ }
+
+
+ softpipe->prim.first = next;
+}
+
+
+
+
+void softpipe_set_setup_state( struct pipe_context *pipe,
+ const struct pipe_setup_state *setup )
+{
+ struct softpipe_context *softpipe = softpipe_context(pipe);
+
+ memcpy( &softpipe->setup, setup, sizeof(*setup) );
+
+ validate_prim_pipe( softpipe );
+ softpipe->dirty |= G_NEW_SETUP;
+}
+
+
+
+void softpipe_set_scissor_rect( struct pipe_context *pipe,
+ const struct pipe_scissor_rect *scissor )
+{
+ struct softpipe_context *softpipe = softpipe_context(pipe);
+
+ memcpy( &softpipe->scissor, scissor, sizeof(*scissor) );
+ softpipe->dirty |= G_NEW_SCISSOR;
+}
+
+
+void softpipe_set_polygon_stipple( struct pipe_context *pipe,
+ const struct pipe_poly_stipple *stipple )
+{
+ struct softpipe_context *softpipe = softpipe_context(pipe);
+
+ memcpy( &softpipe->poly_stipple, stipple, sizeof(*stipple) );
+ softpipe->dirty |= G_NEW_STIPPLE;
+}
diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c
new file mode 100644
index 00000000000..989f2e29d8c
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+#include "imports.h"
+
+#include "sp_context.h"
+#include "sp_state.h"
+#include "sp_surface.h"
+
+
+/* This is all a total hack.
+ */
+void softpipe_set_cbuf_state( struct pipe_context *pipe,
+ const struct pipe_surface *surface )
+{
+ struct softpipe_context *softpipe = softpipe_context(pipe);
+
+ if (softpipe->cbuf_surface == NULL) {
+ softpipe->cbuf_surface = CALLOC_STRUCT(softpipe_surface);
+ softpipe->cbuf_surface->type = &gs_rgba8;
+ }
+
+ softpipe->cbuf_surface->surface = *surface;
+ softpipe->dirty |= G_NEW_CBUF;
+}
+
+
diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c
new file mode 100644
index 00000000000..16bbacb12b9
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 "sp_context.h"
+#include "sp_state.h"
+#include "sp_surface.h"
+#include "sp_headers.h"
+
+static void rgba8_read_quad_f( struct softpipe_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 softpipe_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 softpipe_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 softpipe_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 softpipe_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 softpipe_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 softpipe_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/pipe/softpipe/sp_surface.h b/src/mesa/pipe/softpipe/sp_surface.h
new file mode 100644
index 00000000000..08b6889257a
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+
+#ifndef G_SURFACE_H
+#define G_SURFACE_H
+
+#include "glheader.h"
+#include "sp_headers.h"
+
+struct softpipe_surface;
+
+#define G_SURFACE_RGBA_8888 0x1
+
+/* Internal structs and helpers for the primitive clip/setup pipeline:
+ */
+struct softpipe_surface_type {
+
+ GLuint format;
+
+ void (*read_quad_f)( struct softpipe_surface *,
+ GLint x, GLint y,
+ GLfloat (*rgba)[NUM_CHANNELS] );
+
+ void (*read_quad_f_swz)( struct softpipe_surface *,
+ GLint x, GLint y,
+ GLfloat (*rrrr)[QUAD_SIZE] );
+
+ void (*read_quad_ub)( struct softpipe_surface *,
+ GLint x, GLint y,
+ GLubyte (*rgba)[NUM_CHANNELS] );
+
+
+ void (*write_quad_f)( struct softpipe_surface *,
+ GLint x, GLint y,
+ GLfloat (*rgba)[NUM_CHANNELS] );
+
+ void (*write_quad_f_swz)( struct softpipe_surface *,
+ GLint x, GLint y,
+ GLfloat (*rrrr)[QUAD_SIZE] );
+
+
+ void (*write_quad_ub)( struct softpipe_surface *,
+ GLint x, GLint y,
+ GLubyte (*rgba)[NUM_CHANNELS] );
+
+
+};
+
+
+struct softpipe_surface {
+ struct softpipe_surface_type *type;
+ struct pipe_surface surface;
+};
+
+
+static INLINE void gs_read_quad_f( struct softpipe_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 softpipe_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 softpipe_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 softpipe_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 softpipe_surface_type gs_rgba8;
+
+#endif
diff --git a/src/mesa/pipe/softpipe/sp_tile.h b/src/mesa/pipe/softpipe/sp_tile.h
new file mode 100644
index 00000000000..f4808b99d29
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 <[email protected]>
+ */
+#ifndef G_TILE_H
+#define G_TILE_H
+
+struct softpipe_context;
+struct quad_header;
+
+void quad_shade( struct softpipe_context *softpipe,
+ struct quad_header *quad );
+
+void quad_output( struct softpipe_context *softpipe,
+ struct quad_header *quad );
+
+#endif
diff --git a/src/mesa/pipe/softpipe/sp_tile_fs.c b/src/mesa/pipe/softpipe/sp_tile_fs.c
new file mode 100644
index 00000000000..c145fcf089a
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_tile_fs.c
@@ -0,0 +1,203 @@
+/*
+ * 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 "sp_context.h"
+#include "sp_headers.h"
+#include "sp_tile.h"
+
+struct exec_machine {
+ const struct setup_coefficient *coef;
+
+ GLfloat attr[FRAG_ATTRIB_MAX][4][QUAD_SIZE];
+};
+
+
+/**
+ * Compute quad's attributes values, as constants (GL_FLAT shading).
+ */
+static INLINE void 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];
+ }
+}
+
+
+/**
+ * Compute quad's attribute values by linear interpolation.
+ *
+ * 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++) {
+ const GLfloat x = exec->attr[FRAG_ATTRIB_WPOS][0][j];
+ const GLfloat y = exec->attr[FRAG_ATTRIB_WPOS][1][j];
+ exec->attr[attrib][i][j] = (exec->coef[attrib].a0[i] +
+ exec->coef[attrib].dadx[i] * x +
+ exec->coef[attrib].dady[i] * y);
+ }
+}
+
+
+/**
+ * Compute quad's attribute values by linear interpolation with
+ * perspective correction.
+ *
+ * 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++) {
+ const GLfloat x = exec->attr[FRAG_ATTRIB_WPOS][0][j];
+ const GLfloat y = exec->attr[FRAG_ATTRIB_WPOS][1][j];
+ const GLfloat invW = exec->attr[FRAG_ATTRIB_WPOS][3][j];
+ exec->attr[attrib][i][j] = ((exec->coef[attrib].a0[i] +
+ exec->coef[attrib].dadx[i] * x +
+ exec->coef[attrib].dady[i] * y) * invW);
+ }
+}
+
+
+
+/* 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 softpipe_context *softpipe,
+ 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:
+ * XXX we'll probably have to use integers for Z
+ */
+ if (softpipe->need_z) {
+ linterp(&exec, 0, 2);
+ }
+
+ if (softpipe->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
+ softpipe->run_fs( tri->fp, quad, &tri->outputs );
+#else
+ {
+ GLuint attr = softpipe->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( softpipe, quad );
+}
+
+
+
+
+
+
+
diff --git a/src/mesa/pipe/softpipe/sp_tile_output.c b/src/mesa/pipe/softpipe/sp_tile_output.c
new file mode 100644
index 00000000000..b1eb9e8c9ff
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_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 "sp_context.h"
+#include "sp_headers.h"
+#include "sp_surface.h"
+#include "sp_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 softpipe_context *softpipe,
+ 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( softpipe->cbuf_surface,
+ quad->x0,
+ quad->y0,
+ tmp );
+
+ mask_copy( tmp, quad->outputs.color, quad->mask );
+
+ gs_write_quad_f_swz( softpipe->cbuf_surface,
+ quad->x0,
+ quad->y0,
+ tmp );
+ }
+ else
+ {
+ gs_write_quad_f_swz( softpipe->cbuf_surface,
+ quad->x0,
+ quad->y0,
+ quad->outputs.color );
+ }
+}