From: Keith Whitwell Date: Thu, 14 Jun 2007 17:11:48 +0000 (+0100) Subject: Renamed softpipe directories and files to something less confusing. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6393cda6766b707ef01e925d378239a66d143ae0;p=mesa.git Renamed softpipe directories and files to something less confusing. softpipe/state_tracker --> state_tracker/ softpipe/ --> pipe/ softpipe/generic --> pipe/softpipe/ I don't think pipe is a great name, but I disliked all the others too. Luckily it's fairly easy to rename with git, so this can be revisited later. --- 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 + */ + +#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 + */ + +#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 + */ + +#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 + */ + +#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 + */ +#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 + */ + +#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 + */ + +#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<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< 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<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 + */ +#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 + */ +#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 + */ +#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 + */ + +#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 + */ +#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 + */ +#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 + */ + +#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 + */ +#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<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 + */ +#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 + */ + +#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 + */ +#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<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 + */ + +#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 + */ + +#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 + */ + +#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 + */ + +#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 + */ +#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 + */ + +#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 + */ + +#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<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< 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<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 + */ +#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 + */ +#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 + */ +#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 + */ + +#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 + */ +#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 + */ +#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 + */ + +#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 + */ +#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<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 + */ +#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 + */ + +#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 + */ +#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<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 ); + } +} diff --git a/src/mesa/softpipe/Makefile b/src/mesa/softpipe/Makefile deleted file mode 100644 index 451911a3545..00000000000 --- a/src/mesa/softpipe/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -default: - cd .. ; make diff --git a/src/mesa/softpipe/generic/Makefile b/src/mesa/softpipe/generic/Makefile deleted file mode 100644 index 12a8bd0409e..00000000000 --- a/src/mesa/softpipe/generic/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -default: - cd ../.. ; make - diff --git a/src/mesa/softpipe/generic/g_context.c b/src/mesa/softpipe/generic/g_context.c deleted file mode 100644 index c3329b5c7da..00000000000 --- a/src/mesa/softpipe/generic/g_context.c +++ /dev/null @@ -1,135 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#include "imports.h" -#include "macros.h" - -#include "tnl/t_context.h" -#include "vf/vf.h" - -#include "g_context.h" -#include "g_prim.h" -#include "g_state.h" -#include "g_draw.h" - -static void generic_destroy( struct softpipe_context *softpipe ) -{ - struct generic_context *generic = generic_context( softpipe ); - - draw_destroy( generic->draw ); - - FREE( generic ); -} - - -static void generic_draw_vb( struct softpipe_context *softpipe, - struct vertex_buffer *VB ) -{ - struct generic_context *generic = generic_context( softpipe ); - - if (generic->dirty) - generic_update_derived( generic ); - - draw_vb( generic->draw, VB ); -} - -struct softpipe_context *generic_create( void ) -{ - struct generic_context *generic = CALLOC_STRUCT(generic_context); - - generic->softpipe.destroy = generic_destroy; - generic->softpipe.set_clip_state = generic_set_clip_state; - generic->softpipe.set_viewport = generic_set_viewport; - generic->softpipe.set_setup_state = generic_set_setup_state; - generic->softpipe.set_scissor_rect = generic_set_scissor_rect; - generic->softpipe.set_fs_state = generic_set_fs_state; - generic->softpipe.set_polygon_stipple = generic_set_polygon_stipple; - generic->softpipe.set_cbuf_state = generic_set_cbuf_state; - generic->softpipe.draw_vb = generic_draw_vb; - - - - generic->prim.setup = prim_setup( generic ); - generic->prim.unfilled = prim_unfilled( generic ); - generic->prim.twoside = prim_twoside( generic ); - generic->prim.offset = prim_offset( generic ); - generic->prim.clip = prim_clip( generic ); - generic->prim.flatshade = prim_flatshade( generic ); - generic->prim.cull = prim_cull( generic ); - - - generic->draw = draw_create( generic ); - - ASSIGN_4V( generic->plane[0], -1, 0, 0, 1 ); - ASSIGN_4V( generic->plane[1], 1, 0, 0, 1 ); - ASSIGN_4V( generic->plane[2], 0, -1, 0, 1 ); - ASSIGN_4V( generic->plane[3], 0, 1, 0, 1 ); - ASSIGN_4V( generic->plane[4], 0, 0, 1, 1 ); /* yes these are correct */ - ASSIGN_4V( generic->plane[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */ - generic->nr_planes = 6; - - return &generic->softpipe; -} - - - - - - -#define MAX_VERTEX_SIZE ((2 + FRAG_ATTRIB_MAX) * 4 * sizeof(GLfloat)) - -void prim_alloc_tmps( struct prim_stage *stage, GLuint nr ) -{ - stage->nr_tmps = nr; - - if (nr) { - GLubyte *store = MALLOC(MAX_VERTEX_SIZE * nr); - GLuint i; - - stage->tmp = MALLOC(sizeof(struct vertex_header *) * nr); - - for (i = 0; i < nr; i++) - stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE); - } -} - -void prim_free_tmps( struct prim_stage *stage ) -{ - if (stage->tmp) { - FREE(stage->tmp[0]); - FREE(stage->tmp); - } -} - - - - - diff --git a/src/mesa/softpipe/generic/g_context.h b/src/mesa/softpipe/generic/g_context.h deleted file mode 100644 index 24d467f2c3b..00000000000 --- a/src/mesa/softpipe/generic/g_context.h +++ /dev/null @@ -1,149 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#ifndef G_CONTEXT_H -#define G_CONTEXT_H - -#include "glheader.h" - -#include "softpipe/sp_state.h" -#include "softpipe/sp_context.h" - - - -struct generic_surface; -struct draw_context; -struct prim_stage; - - -enum interp_mode { - INTERP_CONSTANT, - INTERP_LINEAR, - INTERP_PERSPECTIVE -}; - - -#define G_NEW_VIEWPORT 0x1 -#define G_NEW_SETUP 0x2 -#define G_NEW_FS 0x4 -#define G_NEW_BLEND 0x8 -#define G_NEW_CBUF 0x10 -#define G_NEW_CLIP 0x20 -#define G_NEW_SCISSOR 0x40 -#define G_NEW_STIPPLE 0x80 - - - -struct generic_context { - struct softpipe_context softpipe; - - - /* The most recent drawing state as set by the driver: - */ - struct softpipe_viewport viewport; - struct softpipe_setup_state setup; - struct softpipe_fs_state fs; - struct softpipe_blend_state blend; - struct softpipe_surface cbuf; - struct softpipe_clip_state clip; - struct softpipe_scissor_rect scissor; - struct softpipe_poly_stipple poly_stipple; - GLuint dirty; - - - /* Cbuf derived state??? - */ - struct generic_surface *cbuf_surface; - - /* Clip derived state: - */ - GLfloat plane[12][4]; - GLuint nr_planes; - - /* Setup derived state. TODO: this should be passed in the program - * tokens as parameters to DECL instructions. - * - * For now we just set colors to CONST on flatshade, textures to - * perspective always and everything else to linear. - */ - enum interp_mode interp[VF_ATTRIB_MAX]; - - - /* FS + setup derived state: - */ - GLuint fp_attr_to_slot[VF_ATTRIB_MAX]; - GLuint vf_attr_to_slot[VF_ATTRIB_MAX]; - GLuint nr_attrs; - GLuint nr_frag_attrs; - GLuint attr_mask; - - GLboolean need_z; - GLboolean need_w; - - /* Stipple derived state: - */ - GLubyte stipple_masks[16][16]; - - - /* The software clipper/setup engine. - */ - struct { - struct prim_stage *setup; - struct prim_stage *unfilled; - struct prim_stage *twoside; - struct prim_stage *clip; - struct prim_stage *flatshade; - struct prim_stage *offset; - struct prim_stage *cull; - - struct prim_stage *first; - - GLenum prim; - GLuint vertex_size; - } prim; - - /* Temp kludge: - */ - struct draw_context *draw; -}; - - - - -static INLINE struct generic_context * -generic_context( struct softpipe_context *softpipe ) -{ - return (struct generic_context *)softpipe; -} - - - - -#endif diff --git a/src/mesa/softpipe/generic/g_draw.c b/src/mesa/softpipe/generic/g_draw.c deleted file mode 100644 index 4e094c21a0a..00000000000 --- a/src/mesa/softpipe/generic/g_draw.c +++ /dev/null @@ -1,696 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#include "imports.h" - -#include "tnl/t_context.h" - -#include "g_context.h" -#include "g_prim.h" -#include "g_headers.h" -#include "g_draw.h" - -/* This file is a temporary set of hooks to allow us to use the tnl/ - * and vf/ modules until we have replacements in softpipe. - */ - - -struct draw_context -{ - struct generic_context *generic; - - struct vf_attr_map attrs[VF_ATTRIB_MAX]; - GLuint nr_attrs; - GLuint vertex_size; - struct vertex_fetch *vf; - - GLubyte *verts; - GLuint nr_vertices; - GLboolean in_vb; - - GLenum prim; - - /* Helper for tnl: - */ - GLvector4f header; -}; - - -static struct vertex_header *get_vertex( struct draw_context *pipe, - GLuint i ) -{ - return (struct vertex_header *)(pipe->verts + i * pipe->vertex_size); -} - - - -static void draw_allocate_vertices( struct draw_context *draw, - GLuint nr_vertices ) -{ - draw->nr_vertices = nr_vertices; - draw->verts = MALLOC( nr_vertices * draw->vertex_size ); - - draw->generic->prim.first->begin( draw->generic->prim.first ); -} - -static void draw_set_prim( struct draw_context *draw, - GLenum prim ) -{ - draw->prim = prim; - - /* Not done yet - need to force edgeflags to 1 in strip/fan - * primitives. - */ -#if 0 - switch (prim) { - case GL_TRIANGLES: - case GL_POLYGON: - case GL_QUADS: - case GL_QUAD_STRIP: /* yes, we need this */ - respect_edgeflags( pipe, GL_TRUE ); - break; - - default: - respect_edgeflags( pipe, GL_FALSE ); - break; - } -#endif -} - - - -static void do_quad( struct prim_stage *first, - struct vertex_header *v0, - struct vertex_header *v1, - struct vertex_header *v2, - struct vertex_header *v3 ) -{ - struct prim_header prim; - - { - GLuint tmp = v1->edgeflag; - v1->edgeflag = 0; - - prim.v[0] = v0; - prim.v[1] = v1; - prim.v[2] = v3; - first->tri( first, &prim ); - - v1->edgeflag = tmp; - } - - { - GLuint tmp = v3->edgeflag; - v3->edgeflag = 0; - - prim.v[0] = v1; - prim.v[1] = v2; - prim.v[2] = v3; - first->tri( first, &prim ); - - v3->edgeflag = tmp; - } -} - - - - -static void draw_indexed_prim( struct draw_context *draw, - const GLuint *elts, - GLuint count ) -{ - struct prim_stage * const first = draw->generic->prim.first; - struct prim_header prim; - GLuint i; - - prim.det = 0; /* valid from cull stage onwards */ - prim.v[0] = 0; - prim.v[1] = 0; - prim.v[2] = 0; - - switch (draw->prim) { - case GL_POINTS: - for (i = 0; i < count; i ++) { - prim.v[0] = get_vertex( draw, elts[i] ); - - first->point( first, &prim ); - } - break; - - case GL_LINES: - for (i = 0; i+1 < count; i += 2) { - prim.v[0] = get_vertex( draw, elts[i + 0] ); - prim.v[1] = get_vertex( draw, elts[i + 1] ); - - first->line( first, &prim ); - } - break; - - case GL_LINE_LOOP: - if (count >= 2) { - for (i = 1; i < count; i++) { - prim.v[0] = get_vertex( draw, elts[i-1] ); - prim.v[1] = get_vertex( draw, elts[i] ); - first->line( first, &prim ); - } - - prim.v[0] = get_vertex( draw, elts[count-1] ); - prim.v[1] = get_vertex( draw, elts[0] ); - first->line( first, &prim ); - } - break; - - case GL_LINE_STRIP: - /* I'm guessing it will be necessary to have something like a - * render->reset_line_stipple() method to properly support - * splitting strips into primitives like this. Alternately we - * could just scan ahead to find individual clipped lines and - * otherwise leave the strip intact - that might be better, but - * require more complex code here. - */ - if (count >= 2) { - prim.v[0] = 0; - prim.v[1] = get_vertex( draw, elts[0] ); - - for (i = 1; i < count; i++) { - prim.v[0] = prim.v[1]; - prim.v[1] = get_vertex( draw, elts[i] ); - - first->line( first, &prim ); - } - } - break; - - case GL_TRIANGLES: - for (i = 0; i+2 < count; i += 3) { - prim.v[0] = get_vertex( draw, elts[i + 0] ); - prim.v[1] = get_vertex( draw, elts[i + 1] ); - prim.v[2] = get_vertex( draw, elts[i + 2] ); - - first->tri( first, &prim ); - } - break; - - case GL_TRIANGLE_STRIP: - for (i = 0; i+2 < count; i++) { - if (i & 1) { - prim.v[0] = get_vertex( draw, elts[i + 1] ); - prim.v[1] = get_vertex( draw, elts[i + 0] ); - prim.v[2] = get_vertex( draw, elts[i + 2] ); - } - else { - prim.v[0] = get_vertex( draw, elts[i + 0] ); - prim.v[1] = get_vertex( draw, elts[i + 1] ); - prim.v[2] = get_vertex( draw, elts[i + 2] ); - } - - first->tri( first, &prim ); - } - break; - - case GL_TRIANGLE_FAN: - if (count >= 3) { - prim.v[0] = get_vertex( draw, elts[0] ); - prim.v[1] = 0; - prim.v[2] = get_vertex( draw, elts[1] ); - - for (i = 0; i+2 < count; i++) { - prim.v[1] = prim.v[2]; - prim.v[2] = get_vertex( draw, elts[i+2] ); - - first->tri( first, &prim ); - } - } - break; - - case GL_QUADS: - for (i = 0; i+3 < count; i += 4) { - do_quad( first, - get_vertex( draw, elts[i + 0] ), - get_vertex( draw, elts[i + 1] ), - get_vertex( draw, elts[i + 2] ), - get_vertex( draw, elts[i + 3] )); - } - break; - - case GL_QUAD_STRIP: - for (i = 0; i+3 < count; i += 2) { - do_quad( first, - get_vertex( draw, elts[i + 2] ), - get_vertex( draw, elts[i + 0] ), - get_vertex( draw, elts[i + 1] ), - get_vertex( draw, elts[i + 3] )); - } - break; - - - case GL_POLYGON: - if (count >= 3) { - prim.v[0] = 0; - prim.v[1] = get_vertex( draw, elts[1] ); - prim.v[2] = get_vertex( draw, elts[0] ); - - for (i = 0; i+2 < count; i++) { - prim.v[0] = prim.v[1]; - prim.v[1] = get_vertex( draw, elts[i+2] ); - - first->tri( first, &prim ); - } - } - break; - - default: - assert(0); - break; - } -} - -static void draw_prim( struct draw_context *draw, - GLuint start, - GLuint count ) -{ - struct prim_stage * const first = draw->generic->prim.first; - struct prim_header prim; - GLuint i; - -// _mesa_printf("%s (%d) %d/%d\n", __FUNCTION__, draw->prim, start, count ); - - prim.det = 0; /* valid from cull stage onwards */ - prim.v[0] = 0; - prim.v[1] = 0; - prim.v[2] = 0; - - switch (draw->prim) { - case GL_POINTS: - for (i = 0; i < count; i ++) { - prim.v[0] = get_vertex( draw, start + i ); - first->point( first, &prim ); - } - break; - - case GL_LINES: - for (i = 0; i+1 < count; i += 2) { - prim.v[0] = get_vertex( draw, start + i + 0 ); - prim.v[1] = get_vertex( draw, start + i + 1 ); - - first->line( first, &prim ); - } - break; - - case GL_LINE_LOOP: - if (count >= 2) { - for (i = 1; i < count; i++) { - prim.v[0] = get_vertex( draw, start + i - 1 ); - prim.v[1] = get_vertex( draw, start + i ); - first->line( first, &prim ); - } - - prim.v[0] = get_vertex( draw, start + count - 1 ); - prim.v[1] = get_vertex( draw, start + 0 ); - first->line( first, &prim ); - } - break; - - case GL_LINE_STRIP: - if (count >= 2) { - prim.v[0] = 0; - prim.v[1] = get_vertex( draw, start + 0 ); - - for (i = 1; i < count; i++) { - prim.v[0] = prim.v[1]; - prim.v[1] = get_vertex( draw, start + i ); - - first->line( first, &prim ); - } - } - break; - - case GL_TRIANGLES: - for (i = 0; i+2 < count; i += 3) { - prim.v[0] = get_vertex( draw, start + i + 0 ); - prim.v[1] = get_vertex( draw, start + i + 1 ); - prim.v[2] = get_vertex( draw, start + i + 2 ); - - first->tri( first, &prim ); - } - break; - - case GL_TRIANGLE_STRIP: - for (i = 0; i+2 < count; i++) { - if (i & 1) { - prim.v[0] = get_vertex( draw, start + i + 1 ); - prim.v[1] = get_vertex( draw, start + i + 0 ); - prim.v[2] = get_vertex( draw, start + i + 2 ); - } - else { - prim.v[0] = get_vertex( draw, start + i + 0 ); - prim.v[1] = get_vertex( draw, start + i + 1 ); - prim.v[2] = get_vertex( draw, start + i + 2 ); - } - - first->tri( first, &prim ); - } - break; - - case GL_TRIANGLE_FAN: - if (count >= 3) { - prim.v[0] = get_vertex( draw, start + 0 ); - prim.v[1] = 0; - prim.v[2] = get_vertex( draw, start + 1 ); - - for (i = 0; i+2 < count; i++) { - prim.v[1] = prim.v[2]; - prim.v[2] = get_vertex( draw, start + i + 2 ); - - first->tri( first, &prim ); - } - } - break; - - - case GL_QUADS: - for (i = 0; i+3 < count; i += 4) { - do_quad( first, - get_vertex( draw, start + i + 0 ), - get_vertex( draw, start + i + 1 ), - get_vertex( draw, start + i + 2 ), - get_vertex( draw, start + i + 3 )); - } - break; - - case GL_QUAD_STRIP: - for (i = 0; i+3 < count; i += 2) { - do_quad( first, - get_vertex( draw, start + i + 2 ), - get_vertex( draw, start + i + 0 ), - get_vertex( draw, start + i + 1 ), - get_vertex( draw, start + i + 3 )); - } - break; - - case GL_POLYGON: - if (count >= 3) { - prim.v[0] = 0; - prim.v[1] = get_vertex( draw, start + 1 ); - prim.v[2] = get_vertex( draw, start + 0 ); - - for (i = 0; i+2 < count; i++) { - prim.v[0] = prim.v[1]; - prim.v[1] = get_vertex( draw, start + i + 2 ); - - first->tri( first, &prim ); - } - } - break; - - default: - assert(0); - break; - } -} - - -static void draw_release_vertices( struct draw_context *draw ) -{ - draw->generic->prim.first->end( draw->generic->prim.first ); - - FREE(draw->verts); - draw->verts = NULL; -} - - -struct header_dword { - GLuint clipmask:12; - GLuint edgeflag:1; - GLuint pad:19; -}; - - -static void -build_vertex_headers( struct draw_context *draw, - struct vertex_buffer *VB ) -{ - if (draw->header.storage == NULL) { - draw->header.stride = sizeof(GLfloat); - draw->header.size = 1; - draw->header.storage = ALIGN_MALLOC( VB->Size * sizeof(GLfloat), 32 ); - draw->header.data = draw->header.storage; - draw->header.count = 0; - draw->header.flags = VEC_SIZE_1 | VEC_MALLOC; - } - - /* Build vertex header attribute. - * - */ - - { - GLuint i; - struct header_dword *header = (struct header_dword *)draw->header.storage; - - /* yes its a hack - */ - assert(sizeof(*header) == sizeof(GLfloat)); - - draw->header.count = VB->Count; - - if (VB->EdgeFlag) { - for (i = 0; i < VB->Count; i++) { - header[i].clipmask = VB->ClipMask[i]; - header[i].edgeflag = VB->EdgeFlag[i]; - header[i].pad = 0; - } - } - else if (VB->ClipOrMask) { - for (i = 0; i < VB->Count; i++) { - header[i].clipmask = VB->ClipMask[i]; - header[i].edgeflag = 0; - header[i].pad = 0; - } - } - else { - for (i = 0; i < VB->Count; i++) { - header[i].clipmask = 0; - header[i].edgeflag = 0; - header[i].pad = 0; - } - } - } - - VB->AttribPtr[VF_ATTRIB_VERTEX_HEADER] = &draw->header; -} - - - - - -static GLuint draw_prim_info(GLenum mode, GLuint *first, GLuint *incr) -{ - switch (mode) { - case GL_POINTS: - *first = 1; - *incr = 1; - return 0; - case GL_LINES: - *first = 2; - *incr = 2; - return 0; - case GL_LINE_STRIP: - *first = 2; - *incr = 1; - return 0; - case GL_LINE_LOOP: - *first = 2; - *incr = 1; - return 1; - case GL_TRIANGLES: - *first = 3; - *incr = 3; - return 0; - case GL_TRIANGLE_STRIP: - *first = 3; - *incr = 1; - return 0; - case GL_TRIANGLE_FAN: - case GL_POLYGON: - *first = 3; - *incr = 1; - return 1; - case GL_QUADS: - *first = 4; - *incr = 4; - return 0; - case GL_QUAD_STRIP: - *first = 4; - *incr = 2; - return 0; - default: - assert(0); - *first = 1; - *incr = 1; - return 0; - } -} - - -static GLuint trim( GLuint count, GLuint first, GLuint incr ) -{ - if (count < first) - return 0; - else - return count - (count - first) % incr; -} - - -/* This is a hack & will all go away. - */ -void draw_vb(struct draw_context *draw, - struct vertex_buffer *VB ) -{ - GLuint i; - - VB->AttribPtr[VF_ATTRIB_POS] = VB->NdcPtr; - VB->AttribPtr[VF_ATTRIB_BFC0] = VB->ColorPtr[1]; - VB->AttribPtr[VF_ATTRIB_BFC1] = VB->SecondaryColorPtr[1]; - VB->AttribPtr[VF_ATTRIB_CLIP_POS] = VB->ClipPtr; - - /* Build vertex headers: - */ - build_vertex_headers( draw, VB ); - - draw->in_vb = 1; - - /* Allocate the vertices: - */ - draw_allocate_vertices( draw, VB->Count ); - - /* Bind the vb outputs: - */ - vf_set_sources( draw->vf, VB->AttribPtr, 0 ); - - /* Build the hardware or prim-pipe vertices: - */ - vf_emit_vertices( draw->vf, VB->Count, draw->verts ); - - - for (i = 0; i < VB->PrimitiveCount; i++) { - - GLenum mode = VB->Primitive[i].mode; - GLuint start = VB->Primitive[i].start; - GLuint length, first, incr; - - /* Trim the primitive down to a legal size. - */ - draw_prim_info( mode, &first, &incr ); - length = trim( VB->Primitive[i].count, first, incr ); - - if (!length) - continue; - - if (draw->prim != mode) - draw_set_prim( draw, mode ); - - if (VB->Elts) { - draw_indexed_prim( draw, - VB->Elts + start, - length ); - } - else { - draw_prim( draw, - start, - length ); - } - } - - draw_release_vertices( draw ); - draw->verts = NULL; - draw->in_vb = 0; -} - -void draw_set_viewport( struct draw_context *draw, - const GLfloat *scale, - const GLfloat *translate ) -{ - assert(!draw->in_vb); - vf_set_vp_scale_translate( draw->vf, scale, translate ); -} - - - -struct draw_context *draw_create( struct generic_context *generic ) -{ - struct draw_context *draw = CALLOC_STRUCT( draw_context ); - draw->generic = generic; - draw->vf = vf_create( GL_TRUE ); - - return draw; -} - - -void draw_destroy( struct draw_context *draw ) -{ - if (draw->header.storage) - ALIGN_FREE( draw->header.storage ); - - vf_destroy( draw->vf ); - - FREE( draw ); -} - -#define EMIT_ATTR( ATTR, STYLE ) \ -do { \ - draw->attrs[draw->nr_attrs].attrib = ATTR; \ - draw->attrs[draw->nr_attrs].format = STYLE; \ - draw->nr_attrs++; \ -} while (0) - - -void draw_set_vertex_attributes( struct draw_context *draw, - const GLuint *attrs, - GLuint nr_attrs ) -{ - GLuint i; - - draw->nr_attrs = 0; - - EMIT_ATTR(VF_ATTRIB_VERTEX_HEADER, EMIT_1F); - EMIT_ATTR(VF_ATTRIB_CLIP_POS, EMIT_4F); - - assert(attrs[0] == VF_ATTRIB_POS); - EMIT_ATTR(attrs[0], EMIT_4F_VIEWPORT); - - for (i = 1; i < nr_attrs; i++) - EMIT_ATTR(attrs[i], EMIT_4F); - - draw->vertex_size = vf_set_vertex_attributes( draw->vf, draw->attrs, draw->nr_attrs, 0 ); -} - - diff --git a/src/mesa/softpipe/generic/g_draw.h b/src/mesa/softpipe/generic/g_draw.h deleted file mode 100644 index 78c93b4df7a..00000000000 --- a/src/mesa/softpipe/generic/g_draw.h +++ /dev/null @@ -1,56 +0,0 @@ - -/************************************************************************** - * - * 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 - */ - -#ifndef G_DRAW_H -#define G_DRAW_H - -#include "glheader.h" -#include "softpipe/sp_state.h" - - -struct draw_context; - -struct draw_context *draw_create( struct generic_context *generic ); - -void draw_destroy( struct draw_context *draw ); - -void draw_set_viewport( struct draw_context *draw, - const GLfloat *scale, - const GLfloat *translate ); - -void draw_set_vertex_attributes( struct draw_context *draw, - const GLuint *attrs, - GLuint nr_attrs ); - -void draw_vb(struct draw_context *draw, - struct vertex_buffer *VB ); - -#endif diff --git a/src/mesa/softpipe/generic/g_headers.h b/src/mesa/softpipe/generic/g_headers.h deleted file mode 100644 index 96ff52a453b..00000000000 --- a/src/mesa/softpipe/generic/g_headers.h +++ /dev/null @@ -1,116 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#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/softpipe/generic/g_prim.h b/src/mesa/softpipe/generic/g_prim.h deleted file mode 100644 index e3b2c5ea2f5..00000000000 --- a/src/mesa/softpipe/generic/g_prim.h +++ /dev/null @@ -1,90 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#ifndef G_PRIM_H -#define G_PRIM_H - -#include "glheader.h" -#include "g_headers.h" - -struct generic_context; - -struct prim_stage *prim_setup( struct generic_context *context ); -struct prim_stage *prim_unfilled( struct generic_context *context ); -struct prim_stage *prim_twoside( struct generic_context *context ); -struct prim_stage *prim_offset( struct generic_context *context ); -struct prim_stage *prim_clip( struct generic_context *context ); -struct prim_stage *prim_flatshade( struct generic_context *context ); -struct prim_stage *prim_cull( struct generic_context *context ); - - -/* Internal structs and helpers for the primitive clip/setup pipeline: - */ -struct prim_stage { - struct generic_context *generic; - - struct prim_stage *next; - - struct vertex_header **tmp; - GLuint nr_tmps; - - void (*begin)( struct prim_stage * ); - - void (*point)( struct prim_stage *, - struct prim_header * ); - - void (*line)( struct prim_stage *, - struct prim_header * ); - - void (*tri)( struct prim_stage *, - struct prim_header * ); - - void (*end)( struct prim_stage * ); -}; - - - -/* Get a writeable copy of a vertex: - */ -static INLINE struct vertex_header * -dup_vert( struct prim_stage *stage, - const struct vertex_header *vert, - GLuint idx ) -{ - struct vertex_header *tmp = stage->tmp[idx]; - memcpy(tmp, vert, stage->generic->prim.vertex_size ); - return tmp; -} - -void prim_free_tmps( struct prim_stage *stage ); -void prim_alloc_tmps( struct prim_stage *stage, GLuint nr ); - - -#endif diff --git a/src/mesa/softpipe/generic/g_prim_clip.c b/src/mesa/softpipe/generic/g_prim_clip.c deleted file mode 100644 index 742def9c7dd..00000000000 --- a/src/mesa/softpipe/generic/g_prim_clip.c +++ /dev/null @@ -1,429 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#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<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< 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<next->begin( stage->next ); -} - -static void -clip_point( struct prim_stage *stage, - struct prim_header *header ) -{ - if (header->v[0]->clipmask == 0) - stage->next->point( stage->next, header ); -} - - -static void -clip_line( struct prim_stage *stage, - struct prim_header *header ) -{ - GLuint clipmask = (header->v[0]->clipmask | - header->v[1]->clipmask); - - if (clipmask == 0) { - stage->next->line( stage->next, header ); - } - else if ((header->v[0]->clipmask & - header->v[1]->clipmask) == 0) { - do_clip_line(stage, header, clipmask); - } -} - - -static void -clip_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - GLuint clipmask = (header->v[0]->clipmask | - header->v[1]->clipmask | - header->v[2]->clipmask); - - if (clipmask == 0) { - stage->next->tri( stage->next, header ); - } - else if ((header->v[0]->clipmask & - header->v[1]->clipmask & - header->v[2]->clipmask) == 0) { - do_clip_tri(stage, header, clipmask); - } -} - -static void clip_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - - -struct prim_stage *prim_clip( struct generic_context *generic ) -{ - struct clipper *clipper = CALLOC_STRUCT(clipper); - - prim_alloc_tmps( &clipper->stage, MAX_CLIPPED_VERTICES ); - - clipper->stage.generic = generic; - clipper->stage.begin = clip_begin; - clipper->stage.point = clip_point; - clipper->stage.line = clip_line; - clipper->stage.tri = clip_tri; - clipper->stage.end = clip_end; - - return &clipper->stage; -} diff --git a/src/mesa/softpipe/generic/g_prim_cull.c b/src/mesa/softpipe/generic/g_prim_cull.c deleted file mode 100644 index 633fbcc4926..00000000000 --- a/src/mesa/softpipe/generic/g_prim_cull.c +++ /dev/null @@ -1,119 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_prim.h" - - - -struct cull_stage { - struct prim_stage stage; - GLuint mode; -}; - - - -static INLINE struct cull_stage *cull_stage( struct prim_stage *stage ) -{ - return (struct cull_stage *)stage; -} - - -static void cull_begin( struct prim_stage *stage ) -{ - struct cull_stage *cull = cull_stage(stage); - - cull->mode = stage->generic->setup.cull_mode; - - stage->next->begin( stage->next ); -} - - -static void cull_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - /* Window coords: */ - GLfloat *v0 = (GLfloat *)&(header->v[0]->data[0]); - GLfloat *v1 = (GLfloat *)&(header->v[1]->data[0]); - GLfloat *v2 = (GLfloat *)&(header->v[2]->data[0]); - - GLfloat ex = v0[0] - v2[0]; - GLfloat ey = v0[1] - v2[1]; - GLfloat fx = v1[0] - v2[0]; - GLfloat fy = v1[1] - v2[1]; - - header->det = ex * fy - ey * fx; - - _mesa_printf("%s %f\n", __FUNCTION__, header->det ); - - if (header->det != 0) { - GLuint mode = (header->det < 0) ? WINDING_CW : WINDING_CCW; - - if ((mode & cull_stage(stage)->mode) == 0) - stage->next->tri( stage->next, header ); - } -} - - -static void cull_line( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->line( stage->next, header ); -} - - -static void cull_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - -static void cull_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - -struct prim_stage *prim_cull( struct generic_context *generic ) -{ - struct cull_stage *cull = CALLOC_STRUCT(cull_stage); - - prim_alloc_tmps( &cull->stage, 0 ); - - cull->stage.generic = generic; - cull->stage.next = NULL; - cull->stage.begin = cull_begin; - cull->stage.point = cull_point; - cull->stage.line = cull_line; - cull->stage.tri = cull_tri; - cull->stage.end = cull_end; - - return &cull->stage; -} diff --git a/src/mesa/softpipe/generic/g_prim_flatshade.c b/src/mesa/softpipe/generic/g_prim_flatshade.c deleted file mode 100644 index 1974a64fa80..00000000000 --- a/src/mesa/softpipe/generic/g_prim_flatshade.c +++ /dev/null @@ -1,149 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_prim.h" - - -struct flatshade_stage { - struct prim_stage stage; - - const GLuint *lookup; -}; - - - -static INLINE struct flatshade_stage *flatshade_stage( struct prim_stage *stage ) -{ - return (struct flatshade_stage *)stage; -} - - -static void flatshade_begin( struct prim_stage *stage ) -{ - stage->next->begin( stage->next ); -} - - - -static INLINE void copy_attr( GLuint attr, - struct vertex_header *dst, - const struct vertex_header *src ) -{ - if (attr) { - memcpy( dst->data[attr], - src->data[attr], - sizeof(src->data[0]) ); - } -} - -static void copy_colors( struct prim_stage *stage, - struct vertex_header *dst, - const struct vertex_header *src ) -{ - struct flatshade_stage *flatshade = flatshade_stage(stage); - const GLuint *lookup = flatshade->lookup; - - copy_attr( lookup[VF_ATTRIB_COLOR0], dst, src ); - copy_attr( lookup[VF_ATTRIB_COLOR1], dst, src ); - copy_attr( lookup[VF_ATTRIB_BFC0], dst, src ); - copy_attr( lookup[VF_ATTRIB_BFC1], dst, src ); -} - - - -/* Flatshade tri. Required for clipping and when unfilled tris are - * active, otherwise handled by hardware. - */ -static void flatshade_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct prim_header tmp; - - tmp.det = header->det; - tmp.v[0] = dup_vert(stage, header->v[0], 0); - tmp.v[1] = dup_vert(stage, header->v[1], 1); - tmp.v[2] = header->v[2]; - - copy_colors(stage, tmp.v[0], tmp.v[2]); - copy_colors(stage, tmp.v[1], tmp.v[2]); - - stage->next->tri( stage->next, &tmp ); -} - - -/* Flatshade line. Required for clipping. - */ -static void flatshade_line( struct prim_stage *stage, - struct prim_header *header ) -{ - struct prim_header tmp; - - tmp.v[0] = dup_vert(stage, header->v[0], 0); - tmp.v[1] = header->v[1]; - - copy_colors(stage, tmp.v[0], tmp.v[1]); - - stage->next->line( stage->next, &tmp ); -} - - -static void flatshade_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - -static void flatshade_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - -struct prim_stage *prim_flatshade( struct generic_context *generic ) -{ - struct flatshade_stage *flatshade = CALLOC_STRUCT(flatshade_stage); - - prim_alloc_tmps( &flatshade->stage, 2 ); - - flatshade->stage.generic = generic; - flatshade->stage.next = NULL; - flatshade->stage.begin = flatshade_begin; - flatshade->stage.point = flatshade_point; - flatshade->stage.line = flatshade_line; - flatshade->stage.tri = flatshade_tri; - flatshade->stage.end = flatshade_end; - - flatshade->lookup = generic->vf_attr_to_slot; - - return &flatshade->stage; -} - - diff --git a/src/mesa/softpipe/generic/g_prim_offset.c b/src/mesa/softpipe/generic/g_prim_offset.c deleted file mode 100644 index 801ce9a441b..00000000000 --- a/src/mesa/softpipe/generic/g_prim_offset.c +++ /dev/null @@ -1,157 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#include "imports.h" -#include "macros.h" - -#include "g_context.h" -#include "g_prim.h" - - - -struct offset_stage { - struct prim_stage stage; - - GLuint hw_data_offset; - - GLfloat scale; - GLfloat units; -}; - - - -static INLINE struct offset_stage *offset_stage( struct prim_stage *stage ) -{ - return (struct offset_stage *)stage; -} - - -static void offset_begin( struct prim_stage *stage ) -{ - struct offset_stage *offset = offset_stage(stage); - - offset->units = stage->generic->setup.offset_units; - offset->scale = stage->generic->setup.offset_scale; - - stage->next->begin( stage->next ); -} - - -/* Offset tri. Some hardware can handle this, but not usually when - * doing unfilled rendering. - */ -static void do_offset_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct offset_stage *offset = offset_stage(stage); - GLfloat inv_det = 1.0 / header->det; - - /* Window coords: - */ - GLfloat *v0 = (GLfloat *)&(header->v[0]->data[0]); - GLfloat *v1 = (GLfloat *)&(header->v[1]->data[0]); - GLfloat *v2 = (GLfloat *)&(header->v[2]->data[0]); - - GLfloat ex = v0[0] - v2[2]; - GLfloat fx = v1[0] - v2[2]; - GLfloat ey = v0[1] - v2[2]; - GLfloat fy = v1[1] - v2[2]; - GLfloat ez = v0[2] - v2[2]; - GLfloat fz = v1[2] - v2[2]; - - GLfloat a = ey*fz - ez*fy; - GLfloat b = ez*fx - ex*fz; - - GLfloat ac = a * inv_det; - GLfloat bc = b * inv_det; - GLfloat zoffset; - - if ( ac < 0.0f ) ac = -ac; - if ( bc < 0.0f ) bc = -bc; - - zoffset = offset->units + MAX2( ac, bc ) * offset->scale; - - v0[2] += zoffset; - v1[2] += zoffset; - v2[2] += zoffset; - - stage->next->tri( stage->next, header ); -} - - -static void offset_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct prim_header tmp; - - tmp.det = header->det; - tmp.v[0] = dup_vert(stage, header->v[0], 0); - tmp.v[1] = dup_vert(stage, header->v[1], 1); - tmp.v[2] = dup_vert(stage, header->v[2], 2); - - do_offset_tri( stage->next, &tmp ); -} - - - -static void offset_line( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->line( stage->next, header ); -} - - -static void offset_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - - -static void offset_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - -struct prim_stage *prim_offset( struct generic_context *generic ) -{ - struct offset_stage *offset = CALLOC_STRUCT(offset_stage); - - prim_alloc_tmps( &offset->stage, 3 ); - - offset->stage.generic = generic; - offset->stage.next = NULL; - offset->stage.begin = offset_begin; - offset->stage.point = offset_point; - offset->stage.line = offset_line; - offset->stage.tri = offset_tri; - offset->stage.end = offset_end; - - return &offset->stage; -} diff --git a/src/mesa/softpipe/generic/g_prim_setup.c b/src/mesa/softpipe/generic/g_prim_setup.c deleted file mode 100644 index 41e1381a603..00000000000 --- a/src/mesa/softpipe/generic/g_prim_setup.c +++ /dev/null @@ -1,888 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#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/softpipe/generic/g_prim_setup.h b/src/mesa/softpipe/generic/g_prim_setup.h deleted file mode 100644 index 40a70c543e6..00000000000 --- a/src/mesa/softpipe/generic/g_prim_setup.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5 - * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef S_TRI_H -#define S_TRI_H - -/* Vertices are just an array of floats, with all the attributes - * packed. We currently assume a layout like: - * - * attr[0][0..3] - window position - * attr[1..n][0..3] - remaining attributes. - * - * Attributes are assumed to be 4 floats wide but are packed so that - * all the enabled attributes run contiguously. - */ - -#include "glheader.h" -#include "imports.h" -#include "s_tri_public.h" -#include "s_context.h" - - - -struct tri_context; -struct fp_context; -struct be_context; - -/* Note the rasterizer does not take a GLcontext argument. This is - * deliberate. - */ -struct tri_context *tri_create_context( GLcontext *ctx ); - -void tri_destroy_context( struct tri_context *tri ); - -void tri_set_fp_context( struct tri_context *tri, - struct fp_context *fp, - void (*fp_run)( struct fp_context *fp, - const struct fp_inputs *, - struct fp_outputs * )); - - -void tri_set_be_context( struct tri_context *tri, - struct be_context *be, - void (*be_run)( struct be_context *be, - const struct fp_outputs * )); - -void tri_set_attribs( struct tri_context *tri, - const struct attr_info *info, - GLuint nr_attrib ); - -void tri_set_backface( struct tri_context *tri, - GLfloat backface ); - -void tri_set_scissor( struct tri_context *tri, - GLint x, - GLint y, - GLuint width, - GLuint height, - GLboolean enabled ); - -void tri_set_stipple( struct tri_context *tri, - const GLuint *pattern, - GLboolean enabled ); - -/* Unfilled triangles will be handled elsewhere (higher in the - * pipeline), as will things like stipple (lower in the pipeline). - */ - -void tri_triangle( struct tri_context *tri, - const struct vertex *v0, - const struct vertex *v1, - const struct vertex *v2 ); - -/* TODO: rasterize_line, rasterize_point?? - * How will linestipple work? - */ - - -#ifdef SETUP_PRIVATE - - - - - - -GLboolean tri_setup( struct tri_context *tri, - const struct vertex *v0, - const struct vertex *v1, - const struct vertex *v2 ); - -void tri_rasterize( struct tri_context *tri ); -void tri_rasterize_spans( struct tri_context *tri ); - - - - - - -#endif -#endif diff --git a/src/mesa/softpipe/generic/g_prim_twoside.c b/src/mesa/softpipe/generic/g_prim_twoside.c deleted file mode 100644 index 334ae2f5378..00000000000 --- a/src/mesa/softpipe/generic/g_prim_twoside.c +++ /dev/null @@ -1,149 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#include "imports.h" -#include "g_context.h" -#include "g_prim.h" - - -struct twoside_stage { - struct prim_stage stage; - - GLfloat facing; - const GLuint *lookup; -}; - - -static INLINE struct twoside_stage *twoside_stage( struct prim_stage *stage ) -{ - return (struct twoside_stage *)stage; -} - - -static void twoside_begin( struct prim_stage *stage ) -{ - struct twoside_stage *twoside = twoside_stage(stage); - - twoside->facing = (stage->generic->setup.front_winding == WINDING_CW) ? -1 : 1; - - stage->next->begin( stage->next ); -} - - -static INLINE void copy_color( GLuint attr_dst, - GLuint attr_src, - struct vertex_header *v ) -{ - if (attr_dst && attr_src) { - memcpy( v->data[attr_dst], - v->data[attr_src], - sizeof(v->data[0]) ); - } -} - - -static struct vertex_header *copy_bfc( struct twoside_stage *twoside, - const struct vertex_header *v, - GLuint idx ) -{ - struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx ); - - copy_color( twoside->lookup[VF_ATTRIB_COLOR0], - twoside->lookup[VF_ATTRIB_BFC0], - tmp ); - - copy_color( twoside->lookup[VF_ATTRIB_COLOR1], - twoside->lookup[VF_ATTRIB_BFC1], - tmp ); - - return tmp; -} - - -/* Twoside tri: - */ -static void twoside_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct twoside_stage *twoside = twoside_stage(stage); - - if (header->det * twoside->facing < 0) { - struct prim_header tmp; - - tmp.det = header->det; - tmp.v[0] = copy_bfc(twoside, header->v[0], 0); - tmp.v[1] = copy_bfc(twoside, header->v[1], 1); - tmp.v[2] = copy_bfc(twoside, header->v[2], 2); - - stage->next->tri( stage->next, &tmp ); - } - else { - stage->next->tri( stage->next, header ); - } -} - - -static void twoside_line( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->line( stage->next, header ); -} - - -static void twoside_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - -static void twoside_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - - - -struct prim_stage *prim_twoside( struct generic_context *generic ) -{ - struct twoside_stage *twoside = CALLOC_STRUCT(twoside_stage); - - prim_alloc_tmps( &twoside->stage, 3 ); - - twoside->stage.generic = generic; - twoside->stage.next = NULL; - twoside->stage.begin = twoside_begin; - twoside->stage.point = twoside_point; - twoside->stage.line = twoside_line; - twoside->stage.tri = twoside_tri; - twoside->stage.end = twoside_end; - - twoside->lookup = generic->vf_attr_to_slot; - - return &twoside->stage; -} diff --git a/src/mesa/softpipe/generic/g_prim_unfilled.c b/src/mesa/softpipe/generic/g_prim_unfilled.c deleted file mode 100644 index 7c6ee79f92a..00000000000 --- a/src/mesa/softpipe/generic/g_prim_unfilled.c +++ /dev/null @@ -1,165 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_prim.h" - - - -struct unfilled_stage { - struct prim_stage stage; - - GLuint mode[2]; -}; - - -static INLINE struct unfilled_stage *unfilled_stage( struct prim_stage *stage ) -{ - return (struct unfilled_stage *)stage; -} - - -static void unfilled_begin( struct prim_stage *stage ) -{ - struct unfilled_stage *unfilled = unfilled_stage(stage); - - unfilled->mode[0] = stage->generic->setup.fill_ccw; - unfilled->mode[1] = stage->generic->setup.fill_cw; - - stage->next->begin( stage->next ); -} - -static void point( struct prim_stage *stage, - struct vertex_header *v0 ) -{ - struct prim_header tmp; - tmp.v[0] = v0; - stage->next->point( stage->next, &tmp ); -} - -static void line( struct prim_stage *stage, - struct vertex_header *v0, - struct vertex_header *v1 ) -{ - struct prim_header tmp; - tmp.v[0] = v0; - tmp.v[1] = v1; - stage->next->line( stage->next, &tmp ); -} - - -static void points( struct prim_stage *stage, - struct prim_header *header ) -{ - struct vertex_header *v0 = header->v[0]; - struct vertex_header *v1 = header->v[1]; - struct vertex_header *v2 = header->v[2]; - - if (v0->edgeflag) point( stage, v0 ); - if (v1->edgeflag) point( stage, v1 ); - if (v2->edgeflag) point( stage, v2 ); -} - -static void lines( struct prim_stage *stage, - struct prim_header *header ) -{ - struct vertex_header *v0 = header->v[0]; - struct vertex_header *v1 = header->v[1]; - struct vertex_header *v2 = header->v[2]; - - if (v0->edgeflag) line( stage, v0, v1 ); - if (v1->edgeflag) line( stage, v1, v2 ); - if (v2->edgeflag) line( stage, v2, v0 ); -} - - -/* Unfilled tri: - * - * Note edgeflags in the vertex struct is not sufficient as we will - * need to manipulate them when decomposing primitives??? - */ -static void unfilled_tri( struct prim_stage *stage, - struct prim_header *header ) -{ - struct unfilled_stage *unfilled = unfilled_stage(stage); - GLuint mode = unfilled->mode[header->det < 0]; - - switch (mode) { - case FILL_TRI: - stage->next->tri( stage->next, header ); - break; - - case FILL_LINE: - lines( stage, header ); - break; - - case GL_POINT: - points( stage, header ); - break; - } -} - -static void unfilled_line( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->line( stage->next, header ); -} - - -static void unfilled_point( struct prim_stage *stage, - struct prim_header *header ) -{ - stage->next->point( stage->next, header ); -} - - -static void unfilled_end( struct prim_stage *stage ) -{ - stage->next->end( stage->next ); -} - -struct prim_stage *prim_unfilled( struct generic_context *generic ) -{ - struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage); - - prim_alloc_tmps( &unfilled->stage, 0 ); - - unfilled->stage.generic = generic; - unfilled->stage.next = NULL; - unfilled->stage.tmp = NULL; - unfilled->stage.begin = unfilled_begin; - unfilled->stage.point = unfilled_point; - unfilled->stage.line = unfilled_line; - unfilled->stage.tri = unfilled_tri; - unfilled->stage.end = unfilled_end; - - return &unfilled->stage; -} diff --git a/src/mesa/softpipe/generic/g_state.h b/src/mesa/softpipe/generic/g_state.h deleted file mode 100644 index 5077d37ab7b..00000000000 --- a/src/mesa/softpipe/generic/g_state.h +++ /dev/null @@ -1,61 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#ifndef PRIM_H -#define PRIM_H - -#include "glheader.h" -#include "softpipe/sp_state.h" - - -void generic_set_clip_state( struct softpipe_context *, - const struct softpipe_clip_state * ); - -void generic_set_viewport( struct softpipe_context *, - const struct softpipe_viewport * ); - -void generic_set_setup_state( struct softpipe_context *, - const struct softpipe_setup_state * ); - -void generic_set_scissor_rect( struct softpipe_context *, - const struct softpipe_scissor_rect * ); - -void generic_set_fs_state( struct softpipe_context *, - const struct softpipe_fs_state * ); - -void generic_set_polygon_stipple( struct softpipe_context *, - const struct softpipe_poly_stipple * ); - -void generic_set_cbuf_state( struct softpipe_context *, - const struct softpipe_surface * ); - -void generic_update_derived( struct generic_context *generic ); - -#endif diff --git a/src/mesa/softpipe/generic/g_state_clip.c b/src/mesa/softpipe/generic/g_state_clip.c deleted file mode 100644 index b90034e11e4..00000000000 --- a/src/mesa/softpipe/generic/g_state_clip.c +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_state.h" -#include "g_draw.h" - - - -void generic_set_clip_state( struct softpipe_context *softpipe, - const struct softpipe_clip_state *clip ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy(&generic->plane[6], clip->ucp, clip->nr * sizeof(clip->ucp[0])); - - generic->nr_planes = 6 + clip->nr; - generic->dirty |= G_NEW_CLIP; -} - - - -/* Called when driver state tracker notices changes to the viewport - * matrix: - */ -void generic_set_viewport( struct softpipe_context *softpipe, - const struct softpipe_viewport *viewport ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy(&generic->viewport, viewport, sizeof(viewport)); - - /* Using tnl/ and vf/ modules is temporary while getting started. - * Full softpipe will have vertex shader, vertex fetch of its own. - */ - draw_set_viewport( generic->draw, viewport->scale, viewport->translate ); - generic->dirty |= G_NEW_VIEWPORT; -} - - - diff --git a/src/mesa/softpipe/generic/g_state_derived.c b/src/mesa/softpipe/generic/g_state_derived.c deleted file mode 100644 index 678825afe13..00000000000 --- a/src/mesa/softpipe/generic/g_state_derived.c +++ /dev/null @@ -1,136 +0,0 @@ -/************************************************************************** - * - * 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<fs.fp; - const GLuint inputsRead = fp->Base.InputsRead; - GLuint slot_to_vf_attr[VF_ATTRIB_MAX]; - GLuint attr_mask = 0; - GLuint i; - - generic->nr_attrs = 0; - memset(slot_to_vf_attr, 0, sizeof(slot_to_vf_attr)); - - memset(generic->fp_attr_to_slot, 0, sizeof(generic->vf_attr_to_slot)); - memset(generic->vf_attr_to_slot, 0, sizeof(generic->fp_attr_to_slot)); - - /* TODO - Figure out if we need to do perspective divide, etc. - */ - EMIT_ATTR(VF_ATTRIB_POS, FRAG_ATTRIB_WPOS, INTERP_LINEAR); - - /* Pull in the rest of the attributes. They are all in float4 - * format. Future optimizations could be to keep some attributes - * as fixed point or ubyte format. - */ - for (i = 1; i < FRAG_ATTRIB_TEX0; i++) { - if (inputsRead & (i << i)) { - EMIT_ATTR(frag_to_vf[i], i, INTERP_LINEAR); - } - } - - for (i = FRAG_ATTRIB_TEX0; i < FRAG_ATTRIB_MAX; i++) { - if (inputsRead & (i << i)) { - EMIT_ATTR(frag_to_vf[i], i, INTERP_PERSPECTIVE); - } - } - - generic->nr_frag_attrs = generic->nr_attrs; - - /* Additional attributes required for setup: Just twosided - * lighting. Edgeflag is dealt with specially by setting bits in - * the vertex header. - */ - if (generic->setup.light_twoside) { - if (inputsRead & FRAG_BIT_COL0) { - EMIT_ATTR(VF_ATTRIB_BFC0, FRAG_ATTRIB_MAX, 0); /* XXX: mark as discarded after setup */ - } - - if (inputsRead & FRAG_BIT_COL1) { - EMIT_ATTR(VF_ATTRIB_BFC1, FRAG_ATTRIB_MAX, 0); /* XXX: discard after setup */ - } - } - - if (attr_mask != generic->attr_mask) { - generic->attr_mask = attr_mask; - - draw_set_vertex_attributes( generic->draw, - slot_to_vf_attr, - generic->nr_attrs ); - } -} - - -/* Hopefully this will remain quite simple, otherwise need to pull in - * something like the state tracker mechanism. - */ -void generic_update_derived( struct generic_context *generic ) -{ - if (generic->dirty & (G_NEW_SETUP | G_NEW_FS)) - calculate_vertex_layout( generic ); - - generic->dirty = 0; -} diff --git a/src/mesa/softpipe/generic/g_state_fs.c b/src/mesa/softpipe/generic/g_state_fs.c deleted file mode 100644 index 8a430c0c65a..00000000000 --- a/src/mesa/softpipe/generic/g_state_fs.c +++ /dev/null @@ -1,50 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "g_context.h" -#include "g_state.h" - - - -void generic_set_fs_state( struct softpipe_context *softpipe, - const struct softpipe_fs_state *fs ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy(&generic->fs, fs, sizeof(*fs)); - - generic->dirty |= G_NEW_FS; -} - - - - - - - - - diff --git a/src/mesa/softpipe/generic/g_state_setup.c b/src/mesa/softpipe/generic/g_state_setup.c deleted file mode 100644 index 2a5176c5a1a..00000000000 --- a/src/mesa/softpipe/generic/g_state_setup.c +++ /dev/null @@ -1,122 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "g_context.h" -#include "g_state.h" -#include "g_prim.h" - - - - -static void validate_prim_pipe( struct generic_context *generic ) -{ - struct prim_stage *next = generic->prim.setup; - - /* TODO: make the current primitive part of the state and build - * shorter pipelines for lines & points. - */ - if (generic->setup.fill_cw != FILL_TRI || - generic->setup.fill_ccw != FILL_TRI) { - - generic->prim.unfilled->next = next; - next = generic->prim.unfilled; - } - - if (generic->setup.offset_cw || - generic->setup.offset_ccw) { - generic->prim.offset->next = next; - next = generic->prim.offset; - } - - if (generic->setup.light_twoside) { - generic->prim.twoside->next = next; - next = generic->prim.twoside; - } - - /* Always run the cull stage as we calculate determinant there - * also. Fix this.. - */ - { - generic->prim.cull->next = next; - next = generic->prim.cull; - } - - - /* Clip stage - */ - { - generic->prim.clip->next = next; - next = generic->prim.clip; - } - - /* Do software flatshading prior to clipping. XXX: should only do - * this for clipped primitives, ie it is a part of the clip - * routine. - */ - if (generic->setup.flatshade) { - generic->prim.flatshade->next = next; - next = generic->prim.flatshade; - } - - - generic->prim.first = next; -} - - - - -void generic_set_setup_state( struct softpipe_context *softpipe, - const struct softpipe_setup_state *setup ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy( &generic->setup, setup, sizeof(*setup) ); - - validate_prim_pipe( generic ); - generic->dirty |= G_NEW_SETUP; -} - - - -void generic_set_scissor_rect( struct softpipe_context *softpipe, - const struct softpipe_scissor_rect *scissor ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy( &generic->scissor, scissor, sizeof(*scissor) ); - generic->dirty |= G_NEW_SCISSOR; -} - - -void generic_set_polygon_stipple( struct softpipe_context *softpipe, - const struct softpipe_poly_stipple *stipple ) -{ - struct generic_context *generic = generic_context(softpipe); - - memcpy( &generic->poly_stipple, stipple, sizeof(*stipple) ); - generic->dirty |= G_NEW_STIPPLE; -} diff --git a/src/mesa/softpipe/generic/g_state_surface.c b/src/mesa/softpipe/generic/g_state_surface.c deleted file mode 100644 index c791ce4640a..00000000000 --- a/src/mesa/softpipe/generic/g_state_surface.c +++ /dev/null @@ -1,53 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#include "imports.h" - -#include "g_context.h" -#include "g_state.h" -#include "g_surface.h" - - -/* This is all a total hack. - */ -void generic_set_cbuf_state( struct softpipe_context *softpipe, - const struct softpipe_surface *surface ) -{ - struct generic_context *generic = generic_context(softpipe); - - if (generic->cbuf_surface == NULL) { - generic->cbuf_surface = CALLOC_STRUCT(generic_surface); - generic->cbuf_surface->type = &gs_rgba8; - } - - generic->cbuf_surface->surface = *surface; - generic->dirty |= G_NEW_CBUF; -} - - diff --git a/src/mesa/softpipe/generic/g_surface.c b/src/mesa/softpipe/generic/g_surface.c deleted file mode 100644 index 2df30cde705..00000000000 --- a/src/mesa/softpipe/generic/g_surface.c +++ /dev/null @@ -1,153 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "g_context.h" -#include "g_state.h" -#include "g_surface.h" -#include "g_headers.h" - -static void rgba8_read_quad_f( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - rgba[k][0] = ptr[0] * (1.0 / 255.0); - rgba[k][1] = ptr[1] * (1.0 / 255.0); - rgba[k][2] = ptr[2] * (1.0 / 255.0); - rgba[k][3] = ptr[3] * (1.0 / 255.0); - } - } -} - -static void rgba8_read_quad_f_swz( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - rrrr[0][k] = ptr[0] * (1.0 / 255.0); - rrrr[1][k] = ptr[1] * (1.0 / 255.0); - rrrr[2][k] = ptr[2] * (1.0 / 255.0); - rrrr[3][k] = ptr[3] * (1.0 / 255.0); - } - } -} - -static void rgba8_write_quad_f( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - ptr[0] = rgba[k][0] * 255.0; - ptr[1] = rgba[k][1] * 255.0; - ptr[2] = rgba[k][2] * 255.0; - ptr[3] = rgba[k][3] * 255.0; - } - } -} - -static void rgba8_write_quad_f_swz( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - ptr[0] = rrrr[0][k] * 255.0; - ptr[1] = rrrr[1][k] * 255.0; - ptr[2] = rrrr[2][k] * 255.0; - ptr[3] = rrrr[3][k] * 255.0; - } - } -} - - - - -static void rgba8_read_quad_ub( struct generic_surface *gs, - GLint x, GLint y, - GLubyte (*rgba)[NUM_CHANNELS] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - rgba[k][0] = ptr[0]; - rgba[k][1] = ptr[1]; - rgba[k][2] = ptr[2]; - rgba[k][3] = ptr[3]; - } - } -} - - -static void rgba8_write_quad_ub( struct generic_surface *gs, - GLint x, GLint y, - GLubyte (*rgba)[NUM_CHANNELS] ) -{ - GLuint i, j, k = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++, k++) { - GLubyte *ptr = gs->surface.ptr + (y+i) * gs->surface.stride + (x+j) * 4; - ptr[0] = rgba[k][0]; - ptr[1] = rgba[k][1]; - ptr[2] = rgba[k][2]; - ptr[3] = rgba[k][3]; - } - } -} - - - - -struct generic_surface_type gs_rgba8 = { - G_SURFACE_RGBA_8888, - rgba8_read_quad_f, - rgba8_read_quad_f_swz, - rgba8_read_quad_ub, - rgba8_write_quad_f, - rgba8_write_quad_f_swz, - rgba8_write_quad_ub, -}; - - - diff --git a/src/mesa/softpipe/generic/g_surface.h b/src/mesa/softpipe/generic/g_surface.h deleted file mode 100644 index 23c28f0bb40..00000000000 --- a/src/mesa/softpipe/generic/g_surface.h +++ /dev/null @@ -1,115 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#ifndef G_SURFACE_H -#define G_SURFACE_H - -#include "glheader.h" -#include "g_headers.h" - -struct generic_surface; - -#define G_SURFACE_RGBA_8888 0x1 - -/* Internal structs and helpers for the primitive clip/setup pipeline: - */ -struct generic_surface_type { - - GLuint format; - - void (*read_quad_f)( struct generic_surface *, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ); - - void (*read_quad_f_swz)( struct generic_surface *, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ); - - void (*read_quad_ub)( struct generic_surface *, - GLint x, GLint y, - GLubyte (*rgba)[NUM_CHANNELS] ); - - - void (*write_quad_f)( struct generic_surface *, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ); - - void (*write_quad_f_swz)( struct generic_surface *, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ); - - - void (*write_quad_ub)( struct generic_surface *, - GLint x, GLint y, - GLubyte (*rgba)[NUM_CHANNELS] ); - - -}; - - -struct generic_surface { - struct generic_surface_type *type; - struct softpipe_surface surface; -}; - - -static INLINE void gs_read_quad_f( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ) -{ - gs->type->read_quad_f(gs, x, y, rgba); -} - -static INLINE void gs_read_quad_f_swz( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ) -{ - gs->type->read_quad_f_swz(gs, x, y, rrrr); -} - -static INLINE void gs_write_quad_f( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rgba)[NUM_CHANNELS] ) -{ - gs->type->write_quad_f(gs, x, y, rgba); -} - -static INLINE void gs_write_quad_f_swz( struct generic_surface *gs, - GLint x, GLint y, - GLfloat (*rrrr)[QUAD_SIZE] ) -{ - gs->type->write_quad_f_swz(gs, x, y, rrrr); -} - -/* Like this, or hidden? - */ -struct generic_surface_type gs_rgba8; - -#endif diff --git a/src/mesa/softpipe/generic/g_tile.h b/src/mesa/softpipe/generic/g_tile.h deleted file mode 100644 index 6ae52123560..00000000000 --- a/src/mesa/softpipe/generic/g_tile.h +++ /dev/null @@ -1,42 +0,0 @@ -/************************************************************************** - * - * 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 - */ -#ifndef G_TILE_H -#define G_TILE_H - -struct generic_context; -struct quad_header; - -void quad_shade( struct generic_context *generic, - struct quad_header *quad ); - -void quad_output( struct generic_context *generic, - struct quad_header *quad ); - -#endif diff --git a/src/mesa/softpipe/generic/g_tile_fs.c b/src/mesa/softpipe/generic/g_tile_fs.c deleted file mode 100644 index 4c5e6efaed0..00000000000 --- a/src/mesa/softpipe/generic/g_tile_fs.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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/softpipe/generic/g_tile_output.c b/src/mesa/softpipe/generic/g_tile_output.c deleted file mode 100644 index 058ca301931..00000000000 --- a/src/mesa/softpipe/generic/g_tile_output.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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<mask != MASK_ALL) - { - GLfloat tmp[4][QUAD_SIZE]; - - /* Yes, we'll probably have a masked write as well, but this is - * how blend will be done at least. - */ - gs_read_quad_f_swz( generic->cbuf_surface, - quad->x0, - quad->y0, - tmp ); - - mask_copy( tmp, quad->outputs.color, quad->mask ); - - gs_write_quad_f_swz( generic->cbuf_surface, - quad->x0, - quad->y0, - tmp ); - } - else - { - gs_write_quad_f_swz( generic->cbuf_surface, - quad->x0, - quad->y0, - quad->outputs.color ); - } -} diff --git a/src/mesa/softpipe/sp_context.h b/src/mesa/softpipe/sp_context.h deleted file mode 100644 index 716ddd27a97..00000000000 --- a/src/mesa/softpipe/sp_context.h +++ /dev/null @@ -1,89 +0,0 @@ -/************************************************************************** - * - * 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/softpipe/sp_defines.h b/src/mesa/softpipe/sp_defines.h deleted file mode 100644 index c381865dab5..00000000000 --- a/src/mesa/softpipe/sp_defines.h +++ /dev/null @@ -1,121 +0,0 @@ -/************************************************************************** - * - * 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/softpipe/sp_state.h b/src/mesa/softpipe/sp_state.h deleted file mode 100644 index 150fa9fcadb..00000000000 --- a/src/mesa/softpipe/sp_state.h +++ /dev/null @@ -1,184 +0,0 @@ -/************************************************************************** - * - * 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/softpipe/state_tracker/Makefile b/src/mesa/softpipe/state_tracker/Makefile deleted file mode 100644 index 0ab1dc6e6bd..00000000000 --- a/src/mesa/softpipe/state_tracker/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -default: - cd ../.. ; make \ No newline at end of file diff --git a/src/mesa/softpipe/state_tracker/st_atom.c b/src/mesa/softpipe/state_tracker/st_atom.c deleted file mode 100644 index fdbfb9021da..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom.c +++ /dev/null @@ -1,171 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include "glheader.h" -#include "context.h" - -#include "st_context.h" -#include "st_atom.h" - - - -/* This is used to initialize st->atoms[]. We could use this list - * directly except for a single atom, st_update_constants, which has a - * .dirty value which changes according to the parameters of the - * current fragment and vertex programs, and so cannot be a static - * value. - */ -static const struct st_tracked_state *atoms[] = -{ - &st_update_cbuf, - &st_update_clip, - &st_update_fs, - &st_update_setup, - &st_update_viewport, - &st_update_scissor, - &st_update_blend, - &st_update_stencil, - /* will be patched out at runtime */ -/* &st_update_constants */ -}; - - -void st_init_atoms( struct st_context *st ) -{ - GLuint i; - - st->atoms = _mesa_malloc(sizeof(atoms)); - st->nr_atoms = sizeof(atoms)/sizeof(*atoms); - memcpy(st->atoms, atoms, sizeof(atoms)); - - /* Patch in a pointer to the dynamic state atom: - */ - for (i = 0; i < st->nr_atoms; i++) - if (st->atoms[i] == &st_update_constants) - st->atoms[i] = &st->constants.tracked_state; - - memcpy(&st->constants.tracked_state, - &st_update_constants, - sizeof(st_update_constants)); -} - - -void st_destroy_atoms( struct st_context *st ) -{ - if (st->atoms) { - _mesa_free(st->atoms); - st->atoms = NULL; - } -} - - -/*********************************************************************** - */ - -static GLboolean check_state( const struct st_state_flags *a, - const struct st_state_flags *b ) -{ - return ((a->mesa & b->mesa) || - (a->st & b->st)); -} - -static void accumulate_state( struct st_state_flags *a, - const struct st_state_flags *b ) -{ - a->mesa |= b->mesa; - a->st |= b->st; -} - - -static void xor_states( struct st_state_flags *result, - const struct st_state_flags *a, - const struct st_state_flags *b ) -{ - result->mesa = a->mesa ^ b->mesa; - result->st = a->st ^ b->st; -} - - -/*********************************************************************** - * Update all derived state: - */ - -void st_validate_state( struct st_context *st ) -{ - struct st_state_flags *state = &st->dirty; - GLuint i; - - if (state->st == 0) - return; - - if (1) { - /* Debug version which enforces various sanity checks on the - * state flags which are generated and checked to help ensure - * state atoms are ordered correctly in the list. - */ - struct st_state_flags examined, prev; - _mesa_memset(&examined, 0, sizeof(examined)); - prev = *state; - - for (i = 0; i < st->nr_atoms; i++) { - const struct st_tracked_state *atom = st->atoms[i]; - struct st_state_flags generated; - - assert(atom->dirty.mesa || - atom->dirty.st); - assert(atom->update); - - if (check_state(state, &atom->dirty)) { - st->atoms[i]->update( st ); - } - - accumulate_state(&examined, &atom->dirty); - - /* generated = (prev ^ state) - * if (examined & generated) - * fail; - */ - xor_states(&generated, &prev, state); - assert(!check_state(&examined, &generated)); - prev = *state; - } - } - else { - const GLuint nr = st->nr_atoms; - - for (i = 0; i < nr; i++) { - if (check_state(state, &st->atoms[i]->dirty)) - st->atoms[i]->update( st ); - } - } - - memset(state, 0, sizeof(*state)); -} - - - diff --git a/src/mesa/softpipe/state_tracker/st_atom.h b/src/mesa/softpipe/state_tracker/st_atom.h deleted file mode 100644 index 1d8da463368..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom.h +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - /* - * Authors: - * Keith Whitwell - */ - - -#ifndef ST_ATOM_H -#define ST_ATOM_H - -struct st_context; -struct st_tracked_state; - -void st_init_atoms( struct st_context *st ); -void st_destroy_atoms( struct st_context *st ); - - -void st_validate_state( struct st_context *st ); - - -const struct st_tracked_state st_update_cbuf; -const struct st_tracked_state st_update_clip; -const struct st_tracked_state st_update_depth; -const struct st_tracked_state st_update_fs; -const struct st_tracked_state st_update_setup; -const struct st_tracked_state st_update_viewport; -const struct st_tracked_state st_update_constants; -const struct st_tracked_state st_update_scissor; -const struct st_tracked_state st_update_blend; -const struct st_tracked_state st_update_stencil; - - -#endif diff --git a/src/mesa/softpipe/state_tracker/st_atom_blend.c b/src/mesa/softpipe/state_tracker/st_atom_blend.c deleted file mode 100644 index eabb9172ba5..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_blend.c +++ /dev/null @@ -1,202 +0,0 @@ -/************************************************************************** - * - * 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 - * Brian Paul - */ - - -#include "st_context.h" -#include "st_atom.h" -#include "softpipe/sp_context.h" -#include "softpipe/sp_defines.h" - - -/** - * Convert GLenum blend tokens to softpipe tokens. - * Both blend factors and blend funcs are accepted. - */ -static GLuint -gl_blend_to_sp(GLenum blend) -{ - switch (blend) { - /* blend functions */ - case GL_FUNC_ADD: - return SP_BLEND_ADD; - case GL_FUNC_SUBTRACT: - return SP_BLEND_SUBTRACT; - case GL_FUNC_REVERSE_SUBTRACT: - return SP_BLEND_REVERSE_SUBTRACT; - case GL_MIN: - return SP_BLEND_MIN; - case GL_MAX: - return SP_BLEND_MAX; - - /* blend factors */ - case GL_ONE: - return SP_BLENDFACTOR_ONE; - case GL_SRC_COLOR: - return SP_BLENDFACTOR_SRC_COLOR; - case GL_SRC_ALPHA: - return SP_BLENDFACTOR_SRC_ALPHA; - case GL_DST_ALPHA: - return SP_BLENDFACTOR_DST_ALPHA; - case GL_DST_COLOR: - return SP_BLENDFACTOR_DST_COLOR; - case GL_SRC_ALPHA_SATURATE: - return SP_BLENDFACTOR_SRC_ALPHA_SATURATE; - case GL_CONSTANT_COLOR: - return SP_BLENDFACTOR_CONST_COLOR; - case GL_CONSTANT_ALPHA: - return SP_BLENDFACTOR_CONST_ALPHA; - /* - return SP_BLENDFACTOR_SRC1_COLOR; - return SP_BLENDFACTOR_SRC1_ALPHA; - */ - case GL_ZERO: - return SP_BLENDFACTOR_ZERO; - case GL_ONE_MINUS_SRC_COLOR: - return SP_BLENDFACTOR_INV_SRC_COLOR; - case GL_ONE_MINUS_SRC_ALPHA: - return SP_BLENDFACTOR_INV_SRC_ALPHA; - case GL_ONE_MINUS_DST_COLOR: - return SP_BLENDFACTOR_INV_DST_ALPHA; - case GL_ONE_MINUS_DST_ALPHA: - return SP_BLENDFACTOR_INV_DST_COLOR; - case GL_ONE_MINUS_CONSTANT_COLOR: - return SP_BLENDFACTOR_INV_CONST_COLOR; - case GL_ONE_MINUS_CONSTANT_ALPHA: - return SP_BLENDFACTOR_INV_CONST_ALPHA; - /* - return SP_BLENDFACTOR_INV_SRC1_COLOR; - return SP_BLENDFACTOR_INV_SRC1_ALPHA; - */ - default: - assert("invalid GL token in gl_blend_to_sp()" == NULL); - return 0; - } -} - - -/** - * Convert GLenum logicop tokens to softpipe tokens. - */ -static GLuint -gl_logicop_to_sp(GLenum logicop) -{ - switch (logicop) { - case GL_CLEAR: - return SP_LOGICOP_CLEAR; - case GL_NOR: - return SP_LOGICOP_NOR; - case GL_AND_INVERTED: - return SP_LOGICOP_AND_INVERTED; - case GL_COPY_INVERTED: - return SP_LOGICOP_COPY_INVERTED; - case GL_AND_REVERSE: - return SP_LOGICOP_AND_REVERSE; - case GL_INVERT: - return SP_LOGICOP_INVERT; - case GL_XOR: - return SP_LOGICOP_XOR; - case GL_NAND: - return SP_LOGICOP_NAND; - case GL_AND: - return SP_LOGICOP_AND; - case GL_EQUIV: - return SP_LOGICOP_EQUIV; - case GL_NOOP: - return SP_LOGICOP_NOOP; - case GL_OR_INVERTED: - return SP_LOGICOP_OR_INVERTED; - case GL_COPY: - return SP_LOGICOP_COPY; - case GL_OR_REVERSE: - return SP_LOGICOP_OR_REVERSE; - case GL_OR: - return SP_LOGICOP_OR; - case GL_SET: - return SP_LOGICOP_SET; - default: - assert("invalid GL token in gl_logicop_to_sp()" == NULL); - return 0; - } -} - - -static void -update_blend( struct st_context *st ) -{ - struct softpipe_blend_state blend; - - memset(&blend, 0, sizeof(blend)); - - if (st->ctx->Color.ColorLogicOpEnabled || - (st->ctx->Color.BlendEnabled && - st->ctx->Color.BlendEquationRGB == GL_LOGIC_OP)) { - /* logicop enabled */ - blend.logicop_enable = 1; - blend.logicop_func = gl_logicop_to_sp(st->ctx->Color.LogicOp); - } - else if (st->ctx->Color.BlendEnabled) { - /* blending enabled */ - blend.blend_enable = 1; - - blend.rgb_func = gl_blend_to_sp(st->ctx->Color.BlendEquationRGB); - blend.rgb_src_factor = gl_blend_to_sp(st->ctx->Color.BlendSrcRGB); - blend.rgb_dst_factor = gl_blend_to_sp(st->ctx->Color.BlendDstRGB); - - blend.alpha_func = gl_blend_to_sp(st->ctx->Color.BlendEquationA); - blend.alpha_src_factor = gl_blend_to_sp(st->ctx->Color.BlendSrcA); - blend.alpha_dst_factor = gl_blend_to_sp(st->ctx->Color.BlendDstA); - } - else { - /* no blending / logicop */ - } - - if (memcmp(&blend, &st->state.blend, sizeof(blend)) != 0) { - /* state has changed */ - st->state.blend = blend; /* struct copy */ - st->softpipe->set_blend_state(st->softpipe, &blend); /* set new state */ - } -} - - -const struct st_tracked_state st_update_blend = { - .dirty = { - .mesa = (_NEW_COLOR), /* XXX _NEW_BLEND someday? */ - .st = 0, - }, - .update = update_blend -}; - - - - - diff --git a/src/mesa/softpipe/state_tracker/st_atom_cbuf.c b/src/mesa/softpipe/state_tracker/st_atom_cbuf.c deleted file mode 100644 index cd707ec5ef5..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_cbuf.c +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#include "st_context.h" -#include "softpipe/sp_context.h" -#include "st_atom.h" - -extern GLboolean xmesa_get_cbuf_details( GLcontext *ctx, - void **ptr, - GLuint *cpp, - GLint *stride, - GLuint *format ); - - -/* This is a hack to work with the X11 driver as a test harness - */ -static void update_cbuf_state( struct st_context *st ) -{ - struct softpipe_surface cbuf; - GLboolean ok; - - ok = xmesa_get_cbuf_details( st->ctx, - (void **)&cbuf.ptr, - &cbuf.cpp, - &cbuf.stride, - &cbuf.format ); - - assert(ok); - - if (memcmp(&cbuf, &st->state.cbuf, sizeof(cbuf)) != 0) { - st->state.cbuf = cbuf; - st->softpipe->set_cbuf_state( st->softpipe, &cbuf ); - } -} - -const struct st_tracked_state st_update_cbuf = { - .dirty = { - .mesa = _NEW_BUFFERS, - .st = 0, - }, - .update = update_cbuf_state -}; - diff --git a/src/mesa/softpipe/state_tracker/st_atom_clip.c b/src/mesa/softpipe/state_tracker/st_atom_clip.c deleted file mode 100644 index 710d6ffc84f..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_clip.c +++ /dev/null @@ -1,75 +0,0 @@ -/************************************************************************** - * - * 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 - */ - - -#include "st_context.h" -#include "softpipe/sp_context.h" -#include "st_atom.h" - - -/* Second state atom for user clip planes: - */ -static void update_clip( struct st_context *st ) -{ - struct softpipe_clip_state clip; - GLuint i; - - memset(&clip, 0, sizeof(clip)); - - for (i = 0; i < SP_MAX_CLIP_PLANES; i++) { - if (st->ctx->Transform.ClipPlanesEnabled & (1 << i)) { - memcpy(clip.ucp[clip.nr], - st->ctx->Transform._ClipUserPlane[i], - sizeof(clip.ucp[0])); - clip.nr++; - } - } - - if (memcmp(&clip, &st->state.clip, sizeof(clip)) != 0) { - st->state.clip = clip; - st->softpipe->set_clip_state(st->softpipe, &clip); - } -} - - -const struct st_tracked_state st_update_clip = { - .dirty = { - .mesa = (_NEW_TRANSFORM), - .st = 0, - }, - .update = update_clip -}; - - - - - diff --git a/src/mesa/softpipe/state_tracker/st_atom_depth.c b/src/mesa/softpipe/state_tracker/st_atom_depth.c deleted file mode 100644 index 5532abc8fd7..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_depth.c +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************** - * - * 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 - * Brian Paul - */ - - -#include "st_context.h" -#include "st_atom.h" -#include "softpipe/sp_context.h" -#include "softpipe/sp_defines.h" - - -/** - * Convert GLenum depth func tokens to softpipe tokens. - */ -static GLuint -gl_depth_func_to_sp(GLenum func) -{ - /* Same values, just biased */ - assert(SP_DEPTH_FUNC_NEVER == GL_NEVER - GL_NEVER); - assert(SP_DEPTH_FUNC_LESS == GL_LESS - GL_NEVER); - assert(SP_DEPTH_FUNC_EQUAL == GL_EQUAL - GL_NEVER); - assert(SP_DEPTH_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); - assert(SP_DEPTH_FUNC_GREATER == GL_GREATER - GL_NEVER); - assert(SP_DEPTH_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); - assert(SP_DEPTH_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); - assert(SP_DEPTH_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); - assert(func >= GL_NEVER); - assert(func <= GL_ALWAYS); - return func - GL_NEVER; -} - - -static void -update_depth( struct st_context *st ) -{ - struct softpipe_depth_state depth; - - memset(&depth, 0, sizeof(depth)); - - depth.enabled = st->ctx->Depth.Test; - depth.writemask = st->ctx->Depth.Mask; - depth.func = gl_depth_func_to_sp(st->ctx->Depth.Func); - depth.clear = st->ctx->Depth.Clear; - - if (memcmp(&depth, &st->state.depth, sizeof(depth)) != 0) { - /* state has changed */ - st->state.depth = depth; /* struct copy */ - st->softpipe->set_depth_state(st->softpipe, &depth); /* set new state */ - } -} - - -const struct st_tracked_state st_update_depth = { - .dirty = { - .mesa = (_NEW_DEPTH), - .st = 0, - }, - .update = update_depth -}; diff --git a/src/mesa/softpipe/state_tracker/st_atom_fs.c b/src/mesa/softpipe/state_tracker/st_atom_fs.c deleted file mode 100644 index ca109d2d343..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_fs.c +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - /* - * Authors: - * Keith Whitwell - */ - -#include "st_context.h" -#include "softpipe/sp_context.h" -#include "st_atom.h" - - -static void update_fs( struct st_context *st ) -{ - struct softpipe_fs_state fs; - - fs.fp = st->ctx->FragmentProgram._Current; - - if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0) { - st->state.fs = fs; - st->softpipe->set_fs_state(st->softpipe, &fs); - } -} - - -const struct st_tracked_state st_update_fs = { - .dirty = { - .mesa = 0, - .st = ST_NEW_FRAGMENT_PROGRAM, - }, - .update = update_fs -}; diff --git a/src/mesa/softpipe/state_tracker/st_atom_scissor.c b/src/mesa/softpipe/state_tracker/st_atom_scissor.c deleted file mode 100644 index 105c2a6dd92..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_scissor.c +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************** - * - * 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 - */ - - -#include "st_context.h" -#include "softpipe/sp_context.h" -#include "st_atom.h" - - -/** - * Scissor depends on the scissor box, and the framebuffer dimensions. - */ -static void -update_scissor( struct st_context *st ) -{ - struct softpipe_scissor_rect scissor; - const struct gl_framebuffer *fb = st->ctx->DrawBuffer; - - scissor.minx = 0; - scissor.miny = 0; - scissor.maxx = fb->Width; - scissor.maxy = fb->Height; - - if (st->ctx->Scissor.Enabled) { - if (st->ctx->Scissor.X > scissor.minx) - scissor.minx = st->ctx->Scissor.X; - if (st->ctx->Scissor.Y > scissor.miny) - scissor.miny = st->ctx->Scissor.Y; - - if (st->ctx->Scissor.X + st->ctx->Scissor.Width < scissor.maxx) - scissor.maxx = st->ctx->Scissor.X + st->ctx->Scissor.Width; - if (st->ctx->Scissor.Y + st->ctx->Scissor.Height < scissor.maxy) - scissor.maxy = st->ctx->Scissor.Y + st->ctx->Scissor.Height; - - /* check for null space */ - if (scissor.minx >= scissor.maxx || scissor.miny >= scissor.maxy) - scissor.minx = scissor.miny = scissor.maxx = scissor.maxy = 0; - } - - if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) { - /* state has changed */ - st->state.scissor = scissor; /* struct copy */ - st->softpipe->set_scissor_rect(st->softpipe, &scissor); /* activate */ - } -} - - -const struct st_tracked_state st_update_scissor = { - .dirty = { - .mesa = (_NEW_SCISSOR | _NEW_BUFFERS), - .st = 0, - }, - .update = update_scissor -}; - - - - - diff --git a/src/mesa/softpipe/state_tracker/st_atom_setup.c b/src/mesa/softpipe/state_tracker/st_atom_setup.c deleted file mode 100644 index 2a582ea36ca..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_setup.c +++ /dev/null @@ -1,175 +0,0 @@ -/************************************************************************** - * - * 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 - */ - - -#include "st_context.h" -#include "softpipe/sp_context.h" -#include "st_atom.h" - -static GLuint translate_fill( GLenum mode ) -{ - switch (mode) { - case GL_POINT: return FILL_POINT; - case GL_LINE: return FILL_LINE; - case GL_FILL: return FILL_TRI; - default: assert(0); return 0; - } -} - -static GLboolean get_offset_flag( GLuint fill_mode, - const struct gl_polygon_attrib *Polygon ) -{ - switch (fill_mode) { - case FILL_POINT: return Polygon->OffsetPoint; - case FILL_LINE: return Polygon->OffsetLine; - case FILL_TRI: return Polygon->OffsetFill; - default: assert(0); return 0; - } -} - - -static void update_setup_state( struct st_context *st ) -{ - GLcontext *ctx = st->ctx; - struct softpipe_setup_state setup; - - memset(&setup, 0, sizeof(setup)); - - /* _NEW_POLYGON, _NEW_BUFFERS - */ - { - setup.front_winding = WINDING_CW; - - if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0) - setup.front_winding ^= WINDING_BOTH; - - if (ctx->Polygon.FrontFace != GL_CCW) - setup.front_winding ^= WINDING_BOTH; - } - - /* _NEW_LIGHT - */ - if (ctx->Light.ShadeModel == GL_FLAT) - setup.flatshade = 1; - - /* _NEW_LIGHT - * - * Not sure about the light->enabled requirement - does this still - * apply?? - */ - if (ctx->Light.Enabled && - ctx->Light.Model.TwoSide) - setup.light_twoside = 1; - - - /* _NEW_POLYGON - */ - if (ctx->Polygon.CullFlag) { - if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) { - setup.cull_mode = WINDING_BOTH; - } - else if (ctx->Polygon.CullFaceMode == GL_FRONT) { - setup.cull_mode = setup.front_winding; - } - else { - setup.cull_mode = setup.front_winding ^ WINDING_BOTH; - } - } - - /* _NEW_POLYGON - */ - { - GLuint fill_front = translate_fill( ctx->Polygon.FrontMode ); - GLuint fill_back = translate_fill( ctx->Polygon.BackMode ); - - if (setup.front_winding == WINDING_CW) { - setup.fill_cw = fill_front; - setup.fill_ccw = fill_back; - } - else { - setup.fill_cw = fill_back; - setup.fill_ccw = fill_front; - } - - /* Simplify when culling is active: - */ - if (setup.cull_mode & WINDING_CW) { - setup.fill_cw = setup.fill_ccw; - } - - if (setup.cull_mode & WINDING_CCW) { - setup.fill_ccw = setup.fill_cw; - } - } - - /* Hardware does offset for filled prims, but need to do it in - * software for unfilled. - * - * _NEW_POLYGON - */ - if (setup.fill_cw != FILL_TRI) - setup.offset_cw = get_offset_flag( setup.fill_cw, - &ctx->Polygon ); - - if (setup.fill_ccw != FILL_TRI) - setup.offset_ccw = get_offset_flag( setup.fill_ccw, - &ctx->Polygon ); - - - /* _NEW_BUFFERS, _NEW_POLYGON - */ - if (setup.fill_cw != FILL_TRI || - setup.fill_ccw != FILL_TRI) - { - GLfloat mrd = (ctx->DrawBuffer ? - ctx->DrawBuffer->_MRD : - 1.0); - - setup.offset_units = ctx->Polygon.OffsetFactor * mrd; - setup.offset_scale = (ctx->Polygon.OffsetUnits * mrd * - st->polygon_offset_scale); - } - - - if (memcmp(&setup, &st->state.setup, sizeof(setup)) != 0) { - st->state.setup = setup; - st->softpipe->set_setup_state( st->softpipe, &setup ); - } -} - -const struct st_tracked_state st_update_setup = { - .dirty = { - .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_BUFFERS), - .st = 0, - }, - .update = update_setup_state -}; diff --git a/src/mesa/softpipe/state_tracker/st_atom_stencil.c b/src/mesa/softpipe/state_tracker/st_atom_stencil.c deleted file mode 100644 index 32610c3d24d..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_stencil.c +++ /dev/null @@ -1,140 +0,0 @@ -/************************************************************************** - * - * 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 - * Brian Paul - */ - - -#include "st_context.h" -#include "st_atom.h" -#include "softpipe/sp_context.h" -#include "softpipe/sp_defines.h" - - -/** - * Convert GLenum stencil func tokens to softpipe tokens. - */ -static GLuint -gl_stencil_func_to_sp(GLenum func) -{ - /* Same values, just biased */ - assert(SP_STENCIL_FUNC_NEVER == GL_NEVER - GL_NEVER); - assert(SP_STENCIL_FUNC_LESS == GL_LESS - GL_NEVER); - assert(SP_STENCIL_FUNC_EQUAL == GL_EQUAL - GL_NEVER); - assert(SP_STENCIL_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); - assert(SP_STENCIL_FUNC_GREATER == GL_GREATER - GL_NEVER); - assert(SP_STENCIL_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); - assert(SP_STENCIL_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); - assert(SP_STENCIL_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); - assert(func >= GL_NEVER); - assert(func <= GL_ALWAYS); - return func - GL_NEVER; -} - - -/** - * Convert GLenum stencil op tokens to softpipe tokens. - */ -static GLuint -gl_stencil_op_to_sp(GLenum func) -{ - switch (func) { - case GL_KEEP: - return SP_STENCIL_OP_KEEP; - case GL_ZERO: - return SP_STENCIL_OP_ZERO; - case GL_REPLACE: - return SP_STENCIL_OP_REPLACE; - case GL_INCR: - return SP_STENCIL_OP_INCR; - case GL_DECR: - return SP_STENCIL_OP_DECR; - case GL_INCR_WRAP: - return SP_STENCIL_OP_INCR_WRAP; - case GL_DECR_WRAP: - return SP_STENCIL_OP_DECR_WRAP; - case GL_INVERT: - return SP_STENCIL_OP_INVERT; - default: - assert("invalid GL token in gl_stencil_op_to_sp()" == NULL); - return 0; - } -} - - -static void -update_stencil( struct st_context *st ) -{ - struct softpipe_stencil_state stencil; - - memset(&stencil, 0, sizeof(stencil)); - - if (st->ctx->Stencil.Enabled) { - stencil.front_enabled = 1; - stencil.front_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[0]); - stencil.front_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[0]); - stencil.front_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[0]); - stencil.front_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[0]); - stencil.ref_value[0] = st->ctx->Stencil.Ref[0] & 0xff; - stencil.value_mask[0] = st->ctx->Stencil.ValueMask[0] & 0xff; - stencil.write_mask[0] = st->ctx->Stencil.WriteMask[0] & 0xff; - if (st->ctx->Stencil.TestTwoSide) { - stencil.back_enabled = 1; - stencil.back_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[1]); - stencil.back_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[1]); - stencil.back_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[1]); - stencil.back_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[1]); - stencil.ref_value[1] = st->ctx->Stencil.Ref[1] & 0xff; - stencil.value_mask[1] = st->ctx->Stencil.ValueMask[1] & 0xff; - stencil.write_mask[1] = st->ctx->Stencil.WriteMask[1] & 0xff; - } - stencil.clear_value = st->ctx->Stencil.Clear & 0xff; - } - - if (memcmp(&stencil, &st->state.stencil, sizeof(stencil)) != 0) { - /* state has changed */ - st->state.stencil = stencil; /* struct copy */ - st->softpipe->set_stencil_state(st->softpipe, &stencil); /* set new state */ - } -} - - -const struct st_tracked_state st_update_stencil = { - .dirty = { - .mesa = (_NEW_STENCIL), - .st = 0, - }, - .update = update_stencil -}; - - - - - diff --git a/src/mesa/softpipe/state_tracker/st_atom_viewport.c b/src/mesa/softpipe/state_tracker/st_atom_viewport.c deleted file mode 100644 index af896e2e31a..00000000000 --- a/src/mesa/softpipe/state_tracker/st_atom_viewport.c +++ /dev/null @@ -1,117 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include "context.h" -#include "colormac.h" -#include "st_context.h" -#include "softpipe/sp_context.h" -#include "st_atom.h" - - - - - -/** - * Update the viewport transformation matrix. Depends on: - * - viewport pos/size - * - depthrange - * - window pos/size or FBO size - */ -static void update_viewport( struct st_context *st ) -{ - GLcontext *ctx = st->ctx; - const GLframebuffer *DrawBuffer = ctx->DrawBuffer; - GLfloat yScale = 1.0; - GLfloat yBias = 0.0; - - /* _NEW_BUFFERS - */ - if (DrawBuffer) { - -#if 0 - if (DrawBuffer->Name) { - /* User created FBO */ - struct st_renderbuffer *irb - = st_renderbuffer(DrawBuffer->_ColorDrawBuffers[0][0]); - if (irb && !irb->RenderToTexture) { - /* y=0=top */ - yScale = -1.0; - yBias = irb->Base.Height; - } - else { - /* y=0=bottom */ - yScale = 1.0; - yBias = 0.0; - } - } - else - { - /* window buffer, y=0=top */ - yScale = -1.0; - yBias = DrawBuffer->Height; - } -#endif - } - - { - /* _NEW_VIEWPORT - */ - GLfloat x = ctx->Viewport.X; - GLfloat y = ctx->Viewport.Y; - GLfloat z = ctx->Viewport.Near; - GLfloat half_width = ctx->Viewport.Width / 2.0; - GLfloat half_height = ctx->Viewport.Height / 2.0; - GLfloat half_depth = (ctx->Viewport.Far - ctx->Viewport.Near) / 2.0; - - struct softpipe_viewport vp; - - vp.scale[0] = half_width; - vp.scale[1] = half_height * yScale; - vp.scale[2] = half_depth; - vp.scale[3] = 1.0; - - vp.translate[0] = (half_width + x); - vp.translate[1] = (half_height + y) * yScale + yBias; - vp.translate[2] = (half_depth + z); - vp.translate[3] = 0.0; - - if (memcmp(&vp, &st->state.viewport, sizeof(vp)) != 0) { - st->state.viewport = vp; - st->softpipe->set_viewport(st->softpipe, &vp); - } - } -} - - -const struct st_tracked_state st_update_viewport = { - .dirty = { - .mesa = _NEW_BUFFERS | _NEW_VIEWPORT, - .st = 0, - }, - .update = update_viewport -}; diff --git a/src/mesa/softpipe/state_tracker/st_cb_program.c b/src/mesa/softpipe/state_tracker/st_cb_program.c deleted file mode 100644 index 67a589ca8d3..00000000000 --- a/src/mesa/softpipe/state_tracker/st_cb_program.c +++ /dev/null @@ -1,165 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - /* - * Authors: - * Keith Whitwell - */ - -#include "st_context.h" -#include "st_program.h" - -#include "glheader.h" -#include "macros.h" -#include "enums.h" -#include "prog_instruction.h" -#include "prog_parameter.h" -#include "program.h" -#include "programopt.h" -#include "tnl/tnl.h" - - -static void st_bind_program( GLcontext *ctx, - GLenum target, - struct gl_program *prog ) -{ - struct st_context *st = st_context(ctx); - - switch (target) { - case GL_VERTEX_PROGRAM_ARB: - break; - case GL_FRAGMENT_PROGRAM_ARB: - st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - break; - } -} - -static struct gl_program *st_new_program( GLcontext *ctx, - GLenum target, - GLuint id ) -{ - struct st_context *st = st_context(ctx); - - switch (target) { - case GL_VERTEX_PROGRAM_ARB: - return _mesa_init_vertex_program(ctx, - CALLOC_STRUCT(gl_vertex_program), - target, - id); - - case GL_FRAGMENT_PROGRAM_ARB: { - struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); - - prog->id = st->program_id++; - - return _mesa_init_fragment_program( ctx, - &prog->Base, - target, - id ); - } - - default: - return _mesa_new_program(ctx, target, id); - } -} - -static void st_delete_program( GLcontext *ctx, - struct gl_program *prog ) -{ - _mesa_delete_program( ctx, prog ); -} - - -static GLboolean st_is_program_native( GLcontext *ctx, - GLenum target, - struct gl_program *prog ) -{ - return GL_TRUE; -} - -static void st_program_string_notify( GLcontext *ctx, - GLenum target, - struct gl_program *prog ) -{ - if (target == GL_FRAGMENT_PROGRAM_ARB) { - struct st_context *st = st_context(ctx); - - if (prog == &st->ctx->FragmentProgram._Current->Base) - { - struct st_fragment_program *p = - (struct st_fragment_program *) prog; - - st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - - p->id = st->program_id++; -#if 0 - p->param_state = p->Base.Base.Parameters->StateFlags; - p->translated = 0; -#endif - - /* Gack! do this in the compiler: - */ - if (p->Base.FogOption) { - /* add extra instructions to do fog, then turn off FogOption field */ - _mesa_append_fog_code(ctx, &p->Base); - p->Base.FogOption = GL_NONE; - } - } - } - else if (target == GL_VERTEX_PROGRAM_ARB) { - - /* Also tell tnl about it: - */ - _tnl_program_string(ctx, target, prog); - } -} - - - -void st_init_cb_program( struct st_context *st ) -{ - struct dd_function_table *functions = &st->ctx->Driver; - - /* Need these flags: - */ - st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; - st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; - - - assert(functions->ProgramStringNotify == _tnl_program_string); - functions->BindProgram = st_bind_program; - functions->NewProgram = st_new_program; - functions->DeleteProgram = st_delete_program; - functions->IsProgramNative = st_is_program_native; - functions->ProgramStringNotify = st_program_string_notify; -} - - -void st_destroy_cb_program( struct st_context *st ) -{ -} - diff --git a/src/mesa/softpipe/state_tracker/st_context.c b/src/mesa/softpipe/state_tracker/st_context.c deleted file mode 100644 index 8a06dd88df7..00000000000 --- a/src/mesa/softpipe/state_tracker/st_context.c +++ /dev/null @@ -1,76 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "imports.h" -#include "st_public.h" -#include "st_context.h" -#include "st_atom.h" -#include "st_draw.h" -#include "st_program.h" -#include "softpipe/sp_context.h" - -void st_invalidate_state(GLcontext * ctx, GLuint new_state) -{ - struct st_context *st = st_context(ctx); - - st->dirty.mesa |= new_state; - st->dirty.st |= ST_NEW_MESA; -} - - -struct st_context *st_create_context( GLcontext *ctx, - struct softpipe_context *softpipe ) -{ - struct st_context *st = CALLOC_STRUCT( st_context ); - - ctx->st = st; - - st->ctx = ctx; - st->softpipe = softpipe; - - st->dirty.mesa = ~0; - st->dirty.st = ~0; - - st_init_atoms( st ); - st_init_draw( st ); - st_init_cb_program( st ); - - return st; -} - - -void st_destroy_context( struct st_context *st ) -{ - st_destroy_atoms( st ); - st_destroy_draw( st ); - st_destroy_cb_program( st ); - st->softpipe->destroy( st->softpipe ); - FREE( st ); -} - - - diff --git a/src/mesa/softpipe/state_tracker/st_context.h b/src/mesa/softpipe/state_tracker/st_context.h deleted file mode 100644 index 317d3773718..00000000000 --- a/src/mesa/softpipe/state_tracker/st_context.h +++ /dev/null @@ -1,111 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef ST_CONTEXT_H -#define ST_CONTEXT_H - -#include "mtypes.h" -#include "softpipe/sp_state.h" - - -struct st_context; -struct st_region; -struct st_texture_object; -struct st_texture_image; -struct st_fragment_program; - -#define ST_NEW_MESA 0x1 /* Mesa state has changed */ -#define ST_NEW_FRAGMENT_PROGRAM 0x2 - -struct st_state_flags { - GLuint mesa; - GLuint st; -}; - -struct st_tracked_state { - struct st_state_flags dirty; - void (*update)( struct st_context *st ); -}; - - - - -struct st_context -{ - GLcontext *ctx; - - struct softpipe_context *softpipe; - - /* Eventually will use a cache to feed the softpipe with - * create/bind/delete calls to constant state objects. Not yet - * though, we just shove random objects across the interface. - */ - struct { - struct softpipe_viewport viewport; - struct softpipe_setup_state setup; - struct softpipe_fs_state fs; - struct softpipe_blend_state blend; - struct softpipe_surface cbuf; - struct softpipe_clip_state clip; - struct softpipe_depth_state depth; - struct softpipe_scissor_rect scissor; - struct softpipe_poly_stipple poly_stipple; - struct softpipe_stencil_state stencil; - } state; - - struct { - struct st_tracked_state tracked_state; - } constants; - - struct { - struct gl_fragment_program *fragment_program; - } cb; - - /* State to be validated: - */ - struct st_tracked_state **atoms; - GLuint nr_atoms; - - struct st_state_flags dirty; - - /* Counter to track program string changes: - */ - GLuint program_id; - - GLfloat polygon_offset_scale; /* ?? */ -}; - - -/* Need this so that we can implement Mesa callbacks in this module. - */ -static INLINE struct st_context *st_context(GLcontext *ctx) -{ - return ctx->st; -} - - -#endif diff --git a/src/mesa/softpipe/state_tracker/st_draw.c b/src/mesa/softpipe/state_tracker/st_draw.c deleted file mode 100644 index 12646402eec..00000000000 --- a/src/mesa/softpipe/state_tracker/st_draw.c +++ /dev/null @@ -1,107 +0,0 @@ -/************************************************************************** - * - * 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 - */ - -#include "imports.h" - -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" - -#include "st_context.h" -#include "st_atom.h" -#include "st_draw.h" -#include "softpipe/sp_context.h" - -/* - * TNL stage which feedsinto the above. - * - * XXX: this needs to go into each driver using this code, because we - * cannot make the leap from ctx->draw_context in this file. The - * driver needs to customize tnl anyway, so this isn't a big deal. - */ -static GLboolean draw( GLcontext * ctx, struct tnl_pipeline_stage *stage ) -{ - struct st_context *st = st_context(ctx); - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - /* Validate driver and softpipe state: - */ - st_validate_state( st ); - - /* Call into the new draw code to handle the VB: - */ - st->softpipe->draw_vb( st->softpipe, VB ); - - /* Finished - */ - return GL_FALSE; -} - -const struct tnl_pipeline_stage st_draw = { - "check state and draw", - NULL, - NULL, - NULL, - NULL, - draw -}; - -static const struct tnl_pipeline_stage *intel_pipeline[] = { - &_tnl_vertex_transform_stage, - &_tnl_vertex_cull_stage, - &_tnl_normal_transform_stage, - &_tnl_lighting_stage, - &_tnl_fog_coordinate_stage, - &_tnl_texgen_stage, - &_tnl_texture_transform_stage, - &_tnl_point_attenuation_stage, - &_tnl_vertex_program_stage, - &st_draw, /* ADD: escape to softpipe */ - 0, -}; - -/* This is all a hack to keep using tnl until we have vertex programs - * up and running. - */ -void st_init_draw( struct st_context *st ) -{ - GLcontext *ctx = st->ctx; - - _tnl_destroy_pipeline( ctx ); - _tnl_install_pipeline( ctx, intel_pipeline ); -} - - -void st_destroy_draw( struct st_context *st ) -{ - /* Nothing to do. - */ -} diff --git a/src/mesa/softpipe/state_tracker/st_draw.h b/src/mesa/softpipe/state_tracker/st_draw.h deleted file mode 100644 index f51059706ad..00000000000 --- a/src/mesa/softpipe/state_tracker/st_draw.h +++ /dev/null @@ -1,40 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - /* - * Authors: - * Keith Whitwell - */ - - -#ifndef ST_DRAW_H -#define ST_DRAW_H - -void st_init_draw( struct st_context *st ); -void st_destroy_draw( struct st_context *st ); - -#endif diff --git a/src/mesa/softpipe/state_tracker/st_program.h b/src/mesa/softpipe/state_tracker/st_program.h deleted file mode 100644 index a47059d7a69..00000000000 --- a/src/mesa/softpipe/state_tracker/st_program.h +++ /dev/null @@ -1,68 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - /* - * Authors: - * Keith Whitwell - */ - - -#ifndef ST_PROGRAM_H -#define ST_PROGRAM_H - -struct st_fragment_program -{ - struct gl_fragment_program Base; - GLboolean error; /* If program is malformed for any reason. */ - - GLuint id; /* String id, for tracking - * ProgramStringNotify changes. - */ - -#if 0 - GLfloat (*cbuffer)[4]; - GLuint nr_constants; - - /* Translate all the parameters, etc, into a constant buffer which - * we update on state changes. - */ - struct - { - GLuint reg; /* Constant idx */ - const GLfloat *values; /* Pointer to tracked values */ - } *param; - GLuint nr_params; - - GLuint param_state; -#endif -}; - - -void st_init_cb_program( struct st_context *st ); -void st_destroy_cb_program( struct st_context *st ); - -#endif diff --git a/src/mesa/softpipe/state_tracker/st_public.h b/src/mesa/softpipe/state_tracker/st_public.h deleted file mode 100644 index 8241dbd52d1..00000000000 --- a/src/mesa/softpipe/state_tracker/st_public.h +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef ST_PUBLIC_H -#define ST_PUBLIC_H - -#include "mtypes.h" - -struct st_context; -struct softpipe_context; - -struct st_context *st_create_context( GLcontext *ctx, - struct softpipe_context *softpipe); - -void st_destroy_context( struct st_context *st ); - -void st_invalidate_state(GLcontext * ctx, GLuint new_state); - -#endif diff --git a/src/mesa/state_tracker/Makefile b/src/mesa/state_tracker/Makefile new file mode 100644 index 00000000000..0ab1dc6e6bd --- /dev/null +++ b/src/mesa/state_tracker/Makefile @@ -0,0 +1,2 @@ +default: + cd ../.. ; make \ No newline at end of file diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c new file mode 100644 index 00000000000..fdbfb9021da --- /dev/null +++ b/src/mesa/state_tracker/st_atom.c @@ -0,0 +1,171 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "glheader.h" +#include "context.h" + +#include "st_context.h" +#include "st_atom.h" + + + +/* This is used to initialize st->atoms[]. We could use this list + * directly except for a single atom, st_update_constants, which has a + * .dirty value which changes according to the parameters of the + * current fragment and vertex programs, and so cannot be a static + * value. + */ +static const struct st_tracked_state *atoms[] = +{ + &st_update_cbuf, + &st_update_clip, + &st_update_fs, + &st_update_setup, + &st_update_viewport, + &st_update_scissor, + &st_update_blend, + &st_update_stencil, + /* will be patched out at runtime */ +/* &st_update_constants */ +}; + + +void st_init_atoms( struct st_context *st ) +{ + GLuint i; + + st->atoms = _mesa_malloc(sizeof(atoms)); + st->nr_atoms = sizeof(atoms)/sizeof(*atoms); + memcpy(st->atoms, atoms, sizeof(atoms)); + + /* Patch in a pointer to the dynamic state atom: + */ + for (i = 0; i < st->nr_atoms; i++) + if (st->atoms[i] == &st_update_constants) + st->atoms[i] = &st->constants.tracked_state; + + memcpy(&st->constants.tracked_state, + &st_update_constants, + sizeof(st_update_constants)); +} + + +void st_destroy_atoms( struct st_context *st ) +{ + if (st->atoms) { + _mesa_free(st->atoms); + st->atoms = NULL; + } +} + + +/*********************************************************************** + */ + +static GLboolean check_state( const struct st_state_flags *a, + const struct st_state_flags *b ) +{ + return ((a->mesa & b->mesa) || + (a->st & b->st)); +} + +static void accumulate_state( struct st_state_flags *a, + const struct st_state_flags *b ) +{ + a->mesa |= b->mesa; + a->st |= b->st; +} + + +static void xor_states( struct st_state_flags *result, + const struct st_state_flags *a, + const struct st_state_flags *b ) +{ + result->mesa = a->mesa ^ b->mesa; + result->st = a->st ^ b->st; +} + + +/*********************************************************************** + * Update all derived state: + */ + +void st_validate_state( struct st_context *st ) +{ + struct st_state_flags *state = &st->dirty; + GLuint i; + + if (state->st == 0) + return; + + if (1) { + /* Debug version which enforces various sanity checks on the + * state flags which are generated and checked to help ensure + * state atoms are ordered correctly in the list. + */ + struct st_state_flags examined, prev; + _mesa_memset(&examined, 0, sizeof(examined)); + prev = *state; + + for (i = 0; i < st->nr_atoms; i++) { + const struct st_tracked_state *atom = st->atoms[i]; + struct st_state_flags generated; + + assert(atom->dirty.mesa || + atom->dirty.st); + assert(atom->update); + + if (check_state(state, &atom->dirty)) { + st->atoms[i]->update( st ); + } + + accumulate_state(&examined, &atom->dirty); + + /* generated = (prev ^ state) + * if (examined & generated) + * fail; + */ + xor_states(&generated, &prev, state); + assert(!check_state(&examined, &generated)); + prev = *state; + } + } + else { + const GLuint nr = st->nr_atoms; + + for (i = 0; i < nr; i++) { + if (check_state(state, &st->atoms[i]->dirty)) + st->atoms[i]->update( st ); + } + } + + memset(state, 0, sizeof(*state)); +} + + + diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h new file mode 100644 index 00000000000..1d8da463368 --- /dev/null +++ b/src/mesa/state_tracker/st_atom.h @@ -0,0 +1,59 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef ST_ATOM_H +#define ST_ATOM_H + +struct st_context; +struct st_tracked_state; + +void st_init_atoms( struct st_context *st ); +void st_destroy_atoms( struct st_context *st ); + + +void st_validate_state( struct st_context *st ); + + +const struct st_tracked_state st_update_cbuf; +const struct st_tracked_state st_update_clip; +const struct st_tracked_state st_update_depth; +const struct st_tracked_state st_update_fs; +const struct st_tracked_state st_update_setup; +const struct st_tracked_state st_update_viewport; +const struct st_tracked_state st_update_constants; +const struct st_tracked_state st_update_scissor; +const struct st_tracked_state st_update_blend; +const struct st_tracked_state st_update_stencil; + + +#endif diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c new file mode 100644 index 00000000000..eabb9172ba5 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -0,0 +1,202 @@ +/************************************************************************** + * + * 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 + * Brian Paul + */ + + +#include "st_context.h" +#include "st_atom.h" +#include "softpipe/sp_context.h" +#include "softpipe/sp_defines.h" + + +/** + * Convert GLenum blend tokens to softpipe tokens. + * Both blend factors and blend funcs are accepted. + */ +static GLuint +gl_blend_to_sp(GLenum blend) +{ + switch (blend) { + /* blend functions */ + case GL_FUNC_ADD: + return SP_BLEND_ADD; + case GL_FUNC_SUBTRACT: + return SP_BLEND_SUBTRACT; + case GL_FUNC_REVERSE_SUBTRACT: + return SP_BLEND_REVERSE_SUBTRACT; + case GL_MIN: + return SP_BLEND_MIN; + case GL_MAX: + return SP_BLEND_MAX; + + /* blend factors */ + case GL_ONE: + return SP_BLENDFACTOR_ONE; + case GL_SRC_COLOR: + return SP_BLENDFACTOR_SRC_COLOR; + case GL_SRC_ALPHA: + return SP_BLENDFACTOR_SRC_ALPHA; + case GL_DST_ALPHA: + return SP_BLENDFACTOR_DST_ALPHA; + case GL_DST_COLOR: + return SP_BLENDFACTOR_DST_COLOR; + case GL_SRC_ALPHA_SATURATE: + return SP_BLENDFACTOR_SRC_ALPHA_SATURATE; + case GL_CONSTANT_COLOR: + return SP_BLENDFACTOR_CONST_COLOR; + case GL_CONSTANT_ALPHA: + return SP_BLENDFACTOR_CONST_ALPHA; + /* + return SP_BLENDFACTOR_SRC1_COLOR; + return SP_BLENDFACTOR_SRC1_ALPHA; + */ + case GL_ZERO: + return SP_BLENDFACTOR_ZERO; + case GL_ONE_MINUS_SRC_COLOR: + return SP_BLENDFACTOR_INV_SRC_COLOR; + case GL_ONE_MINUS_SRC_ALPHA: + return SP_BLENDFACTOR_INV_SRC_ALPHA; + case GL_ONE_MINUS_DST_COLOR: + return SP_BLENDFACTOR_INV_DST_ALPHA; + case GL_ONE_MINUS_DST_ALPHA: + return SP_BLENDFACTOR_INV_DST_COLOR; + case GL_ONE_MINUS_CONSTANT_COLOR: + return SP_BLENDFACTOR_INV_CONST_COLOR; + case GL_ONE_MINUS_CONSTANT_ALPHA: + return SP_BLENDFACTOR_INV_CONST_ALPHA; + /* + return SP_BLENDFACTOR_INV_SRC1_COLOR; + return SP_BLENDFACTOR_INV_SRC1_ALPHA; + */ + default: + assert("invalid GL token in gl_blend_to_sp()" == NULL); + return 0; + } +} + + +/** + * Convert GLenum logicop tokens to softpipe tokens. + */ +static GLuint +gl_logicop_to_sp(GLenum logicop) +{ + switch (logicop) { + case GL_CLEAR: + return SP_LOGICOP_CLEAR; + case GL_NOR: + return SP_LOGICOP_NOR; + case GL_AND_INVERTED: + return SP_LOGICOP_AND_INVERTED; + case GL_COPY_INVERTED: + return SP_LOGICOP_COPY_INVERTED; + case GL_AND_REVERSE: + return SP_LOGICOP_AND_REVERSE; + case GL_INVERT: + return SP_LOGICOP_INVERT; + case GL_XOR: + return SP_LOGICOP_XOR; + case GL_NAND: + return SP_LOGICOP_NAND; + case GL_AND: + return SP_LOGICOP_AND; + case GL_EQUIV: + return SP_LOGICOP_EQUIV; + case GL_NOOP: + return SP_LOGICOP_NOOP; + case GL_OR_INVERTED: + return SP_LOGICOP_OR_INVERTED; + case GL_COPY: + return SP_LOGICOP_COPY; + case GL_OR_REVERSE: + return SP_LOGICOP_OR_REVERSE; + case GL_OR: + return SP_LOGICOP_OR; + case GL_SET: + return SP_LOGICOP_SET; + default: + assert("invalid GL token in gl_logicop_to_sp()" == NULL); + return 0; + } +} + + +static void +update_blend( struct st_context *st ) +{ + struct softpipe_blend_state blend; + + memset(&blend, 0, sizeof(blend)); + + if (st->ctx->Color.ColorLogicOpEnabled || + (st->ctx->Color.BlendEnabled && + st->ctx->Color.BlendEquationRGB == GL_LOGIC_OP)) { + /* logicop enabled */ + blend.logicop_enable = 1; + blend.logicop_func = gl_logicop_to_sp(st->ctx->Color.LogicOp); + } + else if (st->ctx->Color.BlendEnabled) { + /* blending enabled */ + blend.blend_enable = 1; + + blend.rgb_func = gl_blend_to_sp(st->ctx->Color.BlendEquationRGB); + blend.rgb_src_factor = gl_blend_to_sp(st->ctx->Color.BlendSrcRGB); + blend.rgb_dst_factor = gl_blend_to_sp(st->ctx->Color.BlendDstRGB); + + blend.alpha_func = gl_blend_to_sp(st->ctx->Color.BlendEquationA); + blend.alpha_src_factor = gl_blend_to_sp(st->ctx->Color.BlendSrcA); + blend.alpha_dst_factor = gl_blend_to_sp(st->ctx->Color.BlendDstA); + } + else { + /* no blending / logicop */ + } + + if (memcmp(&blend, &st->state.blend, sizeof(blend)) != 0) { + /* state has changed */ + st->state.blend = blend; /* struct copy */ + st->softpipe->set_blend_state(st->softpipe, &blend); /* set new state */ + } +} + + +const struct st_tracked_state st_update_blend = { + .dirty = { + .mesa = (_NEW_COLOR), /* XXX _NEW_BLEND someday? */ + .st = 0, + }, + .update = update_blend +}; + + + + + diff --git a/src/mesa/state_tracker/st_atom_cbuf.c b/src/mesa/state_tracker/st_atom_cbuf.c new file mode 100644 index 00000000000..cd707ec5ef5 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_cbuf.c @@ -0,0 +1,72 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + +extern GLboolean xmesa_get_cbuf_details( GLcontext *ctx, + void **ptr, + GLuint *cpp, + GLint *stride, + GLuint *format ); + + +/* This is a hack to work with the X11 driver as a test harness + */ +static void update_cbuf_state( struct st_context *st ) +{ + struct softpipe_surface cbuf; + GLboolean ok; + + ok = xmesa_get_cbuf_details( st->ctx, + (void **)&cbuf.ptr, + &cbuf.cpp, + &cbuf.stride, + &cbuf.format ); + + assert(ok); + + if (memcmp(&cbuf, &st->state.cbuf, sizeof(cbuf)) != 0) { + st->state.cbuf = cbuf; + st->softpipe->set_cbuf_state( st->softpipe, &cbuf ); + } +} + +const struct st_tracked_state st_update_cbuf = { + .dirty = { + .mesa = _NEW_BUFFERS, + .st = 0, + }, + .update = update_cbuf_state +}; + diff --git a/src/mesa/state_tracker/st_atom_clip.c b/src/mesa/state_tracker/st_atom_clip.c new file mode 100644 index 00000000000..710d6ffc84f --- /dev/null +++ b/src/mesa/state_tracker/st_atom_clip.c @@ -0,0 +1,75 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + + +/* Second state atom for user clip planes: + */ +static void update_clip( struct st_context *st ) +{ + struct softpipe_clip_state clip; + GLuint i; + + memset(&clip, 0, sizeof(clip)); + + for (i = 0; i < SP_MAX_CLIP_PLANES; i++) { + if (st->ctx->Transform.ClipPlanesEnabled & (1 << i)) { + memcpy(clip.ucp[clip.nr], + st->ctx->Transform._ClipUserPlane[i], + sizeof(clip.ucp[0])); + clip.nr++; + } + } + + if (memcmp(&clip, &st->state.clip, sizeof(clip)) != 0) { + st->state.clip = clip; + st->softpipe->set_clip_state(st->softpipe, &clip); + } +} + + +const struct st_tracked_state st_update_clip = { + .dirty = { + .mesa = (_NEW_TRANSFORM), + .st = 0, + }, + .update = update_clip +}; + + + + + diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c new file mode 100644 index 00000000000..5532abc8fd7 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -0,0 +1,88 @@ +/************************************************************************** + * + * 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 + * Brian Paul + */ + + +#include "st_context.h" +#include "st_atom.h" +#include "softpipe/sp_context.h" +#include "softpipe/sp_defines.h" + + +/** + * Convert GLenum depth func tokens to softpipe tokens. + */ +static GLuint +gl_depth_func_to_sp(GLenum func) +{ + /* Same values, just biased */ + assert(SP_DEPTH_FUNC_NEVER == GL_NEVER - GL_NEVER); + assert(SP_DEPTH_FUNC_LESS == GL_LESS - GL_NEVER); + assert(SP_DEPTH_FUNC_EQUAL == GL_EQUAL - GL_NEVER); + assert(SP_DEPTH_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); + assert(SP_DEPTH_FUNC_GREATER == GL_GREATER - GL_NEVER); + assert(SP_DEPTH_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); + assert(SP_DEPTH_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); + assert(SP_DEPTH_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); + assert(func >= GL_NEVER); + assert(func <= GL_ALWAYS); + return func - GL_NEVER; +} + + +static void +update_depth( struct st_context *st ) +{ + struct softpipe_depth_state depth; + + memset(&depth, 0, sizeof(depth)); + + depth.enabled = st->ctx->Depth.Test; + depth.writemask = st->ctx->Depth.Mask; + depth.func = gl_depth_func_to_sp(st->ctx->Depth.Func); + depth.clear = st->ctx->Depth.Clear; + + if (memcmp(&depth, &st->state.depth, sizeof(depth)) != 0) { + /* state has changed */ + st->state.depth = depth; /* struct copy */ + st->softpipe->set_depth_state(st->softpipe, &depth); /* set new state */ + } +} + + +const struct st_tracked_state st_update_depth = { + .dirty = { + .mesa = (_NEW_DEPTH), + .st = 0, + }, + .update = update_depth +}; diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c new file mode 100644 index 00000000000..ca109d2d343 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -0,0 +1,56 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + + +static void update_fs( struct st_context *st ) +{ + struct softpipe_fs_state fs; + + fs.fp = st->ctx->FragmentProgram._Current; + + if (memcmp(&fs, &st->state.fs, sizeof(fs)) != 0) { + st->state.fs = fs; + st->softpipe->set_fs_state(st->softpipe, &fs); + } +} + + +const struct st_tracked_state st_update_fs = { + .dirty = { + .mesa = 0, + .st = ST_NEW_FRAGMENT_PROGRAM, + }, + .update = update_fs +}; diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c new file mode 100644 index 00000000000..105c2a6dd92 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_scissor.c @@ -0,0 +1,88 @@ +/************************************************************************** + * + * 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 + */ + + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + + +/** + * Scissor depends on the scissor box, and the framebuffer dimensions. + */ +static void +update_scissor( struct st_context *st ) +{ + struct softpipe_scissor_rect scissor; + const struct gl_framebuffer *fb = st->ctx->DrawBuffer; + + scissor.minx = 0; + scissor.miny = 0; + scissor.maxx = fb->Width; + scissor.maxy = fb->Height; + + if (st->ctx->Scissor.Enabled) { + if (st->ctx->Scissor.X > scissor.minx) + scissor.minx = st->ctx->Scissor.X; + if (st->ctx->Scissor.Y > scissor.miny) + scissor.miny = st->ctx->Scissor.Y; + + if (st->ctx->Scissor.X + st->ctx->Scissor.Width < scissor.maxx) + scissor.maxx = st->ctx->Scissor.X + st->ctx->Scissor.Width; + if (st->ctx->Scissor.Y + st->ctx->Scissor.Height < scissor.maxy) + scissor.maxy = st->ctx->Scissor.Y + st->ctx->Scissor.Height; + + /* check for null space */ + if (scissor.minx >= scissor.maxx || scissor.miny >= scissor.maxy) + scissor.minx = scissor.miny = scissor.maxx = scissor.maxy = 0; + } + + if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) { + /* state has changed */ + st->state.scissor = scissor; /* struct copy */ + st->softpipe->set_scissor_rect(st->softpipe, &scissor); /* activate */ + } +} + + +const struct st_tracked_state st_update_scissor = { + .dirty = { + .mesa = (_NEW_SCISSOR | _NEW_BUFFERS), + .st = 0, + }, + .update = update_scissor +}; + + + + + diff --git a/src/mesa/state_tracker/st_atom_setup.c b/src/mesa/state_tracker/st_atom_setup.c new file mode 100644 index 00000000000..2a582ea36ca --- /dev/null +++ b/src/mesa/state_tracker/st_atom_setup.c @@ -0,0 +1,175 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + + +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + +static GLuint translate_fill( GLenum mode ) +{ + switch (mode) { + case GL_POINT: return FILL_POINT; + case GL_LINE: return FILL_LINE; + case GL_FILL: return FILL_TRI; + default: assert(0); return 0; + } +} + +static GLboolean get_offset_flag( GLuint fill_mode, + const struct gl_polygon_attrib *Polygon ) +{ + switch (fill_mode) { + case FILL_POINT: return Polygon->OffsetPoint; + case FILL_LINE: return Polygon->OffsetLine; + case FILL_TRI: return Polygon->OffsetFill; + default: assert(0); return 0; + } +} + + +static void update_setup_state( struct st_context *st ) +{ + GLcontext *ctx = st->ctx; + struct softpipe_setup_state setup; + + memset(&setup, 0, sizeof(setup)); + + /* _NEW_POLYGON, _NEW_BUFFERS + */ + { + setup.front_winding = WINDING_CW; + + if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0) + setup.front_winding ^= WINDING_BOTH; + + if (ctx->Polygon.FrontFace != GL_CCW) + setup.front_winding ^= WINDING_BOTH; + } + + /* _NEW_LIGHT + */ + if (ctx->Light.ShadeModel == GL_FLAT) + setup.flatshade = 1; + + /* _NEW_LIGHT + * + * Not sure about the light->enabled requirement - does this still + * apply?? + */ + if (ctx->Light.Enabled && + ctx->Light.Model.TwoSide) + setup.light_twoside = 1; + + + /* _NEW_POLYGON + */ + if (ctx->Polygon.CullFlag) { + if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) { + setup.cull_mode = WINDING_BOTH; + } + else if (ctx->Polygon.CullFaceMode == GL_FRONT) { + setup.cull_mode = setup.front_winding; + } + else { + setup.cull_mode = setup.front_winding ^ WINDING_BOTH; + } + } + + /* _NEW_POLYGON + */ + { + GLuint fill_front = translate_fill( ctx->Polygon.FrontMode ); + GLuint fill_back = translate_fill( ctx->Polygon.BackMode ); + + if (setup.front_winding == WINDING_CW) { + setup.fill_cw = fill_front; + setup.fill_ccw = fill_back; + } + else { + setup.fill_cw = fill_back; + setup.fill_ccw = fill_front; + } + + /* Simplify when culling is active: + */ + if (setup.cull_mode & WINDING_CW) { + setup.fill_cw = setup.fill_ccw; + } + + if (setup.cull_mode & WINDING_CCW) { + setup.fill_ccw = setup.fill_cw; + } + } + + /* Hardware does offset for filled prims, but need to do it in + * software for unfilled. + * + * _NEW_POLYGON + */ + if (setup.fill_cw != FILL_TRI) + setup.offset_cw = get_offset_flag( setup.fill_cw, + &ctx->Polygon ); + + if (setup.fill_ccw != FILL_TRI) + setup.offset_ccw = get_offset_flag( setup.fill_ccw, + &ctx->Polygon ); + + + /* _NEW_BUFFERS, _NEW_POLYGON + */ + if (setup.fill_cw != FILL_TRI || + setup.fill_ccw != FILL_TRI) + { + GLfloat mrd = (ctx->DrawBuffer ? + ctx->DrawBuffer->_MRD : + 1.0); + + setup.offset_units = ctx->Polygon.OffsetFactor * mrd; + setup.offset_scale = (ctx->Polygon.OffsetUnits * mrd * + st->polygon_offset_scale); + } + + + if (memcmp(&setup, &st->state.setup, sizeof(setup)) != 0) { + st->state.setup = setup; + st->softpipe->set_setup_state( st->softpipe, &setup ); + } +} + +const struct st_tracked_state st_update_setup = { + .dirty = { + .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_BUFFERS), + .st = 0, + }, + .update = update_setup_state +}; diff --git a/src/mesa/state_tracker/st_atom_stencil.c b/src/mesa/state_tracker/st_atom_stencil.c new file mode 100644 index 00000000000..32610c3d24d --- /dev/null +++ b/src/mesa/state_tracker/st_atom_stencil.c @@ -0,0 +1,140 @@ +/************************************************************************** + * + * 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 + * Brian Paul + */ + + +#include "st_context.h" +#include "st_atom.h" +#include "softpipe/sp_context.h" +#include "softpipe/sp_defines.h" + + +/** + * Convert GLenum stencil func tokens to softpipe tokens. + */ +static GLuint +gl_stencil_func_to_sp(GLenum func) +{ + /* Same values, just biased */ + assert(SP_STENCIL_FUNC_NEVER == GL_NEVER - GL_NEVER); + assert(SP_STENCIL_FUNC_LESS == GL_LESS - GL_NEVER); + assert(SP_STENCIL_FUNC_EQUAL == GL_EQUAL - GL_NEVER); + assert(SP_STENCIL_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); + assert(SP_STENCIL_FUNC_GREATER == GL_GREATER - GL_NEVER); + assert(SP_STENCIL_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); + assert(SP_STENCIL_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); + assert(SP_STENCIL_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); + assert(func >= GL_NEVER); + assert(func <= GL_ALWAYS); + return func - GL_NEVER; +} + + +/** + * Convert GLenum stencil op tokens to softpipe tokens. + */ +static GLuint +gl_stencil_op_to_sp(GLenum func) +{ + switch (func) { + case GL_KEEP: + return SP_STENCIL_OP_KEEP; + case GL_ZERO: + return SP_STENCIL_OP_ZERO; + case GL_REPLACE: + return SP_STENCIL_OP_REPLACE; + case GL_INCR: + return SP_STENCIL_OP_INCR; + case GL_DECR: + return SP_STENCIL_OP_DECR; + case GL_INCR_WRAP: + return SP_STENCIL_OP_INCR_WRAP; + case GL_DECR_WRAP: + return SP_STENCIL_OP_DECR_WRAP; + case GL_INVERT: + return SP_STENCIL_OP_INVERT; + default: + assert("invalid GL token in gl_stencil_op_to_sp()" == NULL); + return 0; + } +} + + +static void +update_stencil( struct st_context *st ) +{ + struct softpipe_stencil_state stencil; + + memset(&stencil, 0, sizeof(stencil)); + + if (st->ctx->Stencil.Enabled) { + stencil.front_enabled = 1; + stencil.front_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[0]); + stencil.front_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[0]); + stencil.front_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[0]); + stencil.front_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[0]); + stencil.ref_value[0] = st->ctx->Stencil.Ref[0] & 0xff; + stencil.value_mask[0] = st->ctx->Stencil.ValueMask[0] & 0xff; + stencil.write_mask[0] = st->ctx->Stencil.WriteMask[0] & 0xff; + if (st->ctx->Stencil.TestTwoSide) { + stencil.back_enabled = 1; + stencil.back_func = gl_stencil_func_to_sp(st->ctx->Stencil.Function[1]); + stencil.back_fail_op = gl_stencil_op_to_sp(st->ctx->Stencil.FailFunc[1]); + stencil.back_zfail_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZFailFunc[1]); + stencil.back_zpass_op = gl_stencil_op_to_sp(st->ctx->Stencil.ZPassFunc[1]); + stencil.ref_value[1] = st->ctx->Stencil.Ref[1] & 0xff; + stencil.value_mask[1] = st->ctx->Stencil.ValueMask[1] & 0xff; + stencil.write_mask[1] = st->ctx->Stencil.WriteMask[1] & 0xff; + } + stencil.clear_value = st->ctx->Stencil.Clear & 0xff; + } + + if (memcmp(&stencil, &st->state.stencil, sizeof(stencil)) != 0) { + /* state has changed */ + st->state.stencil = stencil; /* struct copy */ + st->softpipe->set_stencil_state(st->softpipe, &stencil); /* set new state */ + } +} + + +const struct st_tracked_state st_update_stencil = { + .dirty = { + .mesa = (_NEW_STENCIL), + .st = 0, + }, + .update = update_stencil +}; + + + + + diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c new file mode 100644 index 00000000000..af896e2e31a --- /dev/null +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -0,0 +1,117 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "context.h" +#include "colormac.h" +#include "st_context.h" +#include "softpipe/sp_context.h" +#include "st_atom.h" + + + + + +/** + * Update the viewport transformation matrix. Depends on: + * - viewport pos/size + * - depthrange + * - window pos/size or FBO size + */ +static void update_viewport( struct st_context *st ) +{ + GLcontext *ctx = st->ctx; + const GLframebuffer *DrawBuffer = ctx->DrawBuffer; + GLfloat yScale = 1.0; + GLfloat yBias = 0.0; + + /* _NEW_BUFFERS + */ + if (DrawBuffer) { + +#if 0 + if (DrawBuffer->Name) { + /* User created FBO */ + struct st_renderbuffer *irb + = st_renderbuffer(DrawBuffer->_ColorDrawBuffers[0][0]); + if (irb && !irb->RenderToTexture) { + /* y=0=top */ + yScale = -1.0; + yBias = irb->Base.Height; + } + else { + /* y=0=bottom */ + yScale = 1.0; + yBias = 0.0; + } + } + else + { + /* window buffer, y=0=top */ + yScale = -1.0; + yBias = DrawBuffer->Height; + } +#endif + } + + { + /* _NEW_VIEWPORT + */ + GLfloat x = ctx->Viewport.X; + GLfloat y = ctx->Viewport.Y; + GLfloat z = ctx->Viewport.Near; + GLfloat half_width = ctx->Viewport.Width / 2.0; + GLfloat half_height = ctx->Viewport.Height / 2.0; + GLfloat half_depth = (ctx->Viewport.Far - ctx->Viewport.Near) / 2.0; + + struct softpipe_viewport vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height * yScale; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0; + + vp.translate[0] = (half_width + x); + vp.translate[1] = (half_height + y) * yScale + yBias; + vp.translate[2] = (half_depth + z); + vp.translate[3] = 0.0; + + if (memcmp(&vp, &st->state.viewport, sizeof(vp)) != 0) { + st->state.viewport = vp; + st->softpipe->set_viewport(st->softpipe, &vp); + } + } +} + + +const struct st_tracked_state st_update_viewport = { + .dirty = { + .mesa = _NEW_BUFFERS | _NEW_VIEWPORT, + .st = 0, + }, + .update = update_viewport +}; diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c new file mode 100644 index 00000000000..67a589ca8d3 --- /dev/null +++ b/src/mesa/state_tracker/st_cb_program.c @@ -0,0 +1,165 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "st_context.h" +#include "st_program.h" + +#include "glheader.h" +#include "macros.h" +#include "enums.h" +#include "prog_instruction.h" +#include "prog_parameter.h" +#include "program.h" +#include "programopt.h" +#include "tnl/tnl.h" + + +static void st_bind_program( GLcontext *ctx, + GLenum target, + struct gl_program *prog ) +{ + struct st_context *st = st_context(ctx); + + switch (target) { + case GL_VERTEX_PROGRAM_ARB: + break; + case GL_FRAGMENT_PROGRAM_ARB: + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + break; + } +} + +static struct gl_program *st_new_program( GLcontext *ctx, + GLenum target, + GLuint id ) +{ + struct st_context *st = st_context(ctx); + + switch (target) { + case GL_VERTEX_PROGRAM_ARB: + return _mesa_init_vertex_program(ctx, + CALLOC_STRUCT(gl_vertex_program), + target, + id); + + case GL_FRAGMENT_PROGRAM_ARB: { + struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); + + prog->id = st->program_id++; + + return _mesa_init_fragment_program( ctx, + &prog->Base, + target, + id ); + } + + default: + return _mesa_new_program(ctx, target, id); + } +} + +static void st_delete_program( GLcontext *ctx, + struct gl_program *prog ) +{ + _mesa_delete_program( ctx, prog ); +} + + +static GLboolean st_is_program_native( GLcontext *ctx, + GLenum target, + struct gl_program *prog ) +{ + return GL_TRUE; +} + +static void st_program_string_notify( GLcontext *ctx, + GLenum target, + struct gl_program *prog ) +{ + if (target == GL_FRAGMENT_PROGRAM_ARB) { + struct st_context *st = st_context(ctx); + + if (prog == &st->ctx->FragmentProgram._Current->Base) + { + struct st_fragment_program *p = + (struct st_fragment_program *) prog; + + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + + p->id = st->program_id++; +#if 0 + p->param_state = p->Base.Base.Parameters->StateFlags; + p->translated = 0; +#endif + + /* Gack! do this in the compiler: + */ + if (p->Base.FogOption) { + /* add extra instructions to do fog, then turn off FogOption field */ + _mesa_append_fog_code(ctx, &p->Base); + p->Base.FogOption = GL_NONE; + } + } + } + else if (target == GL_VERTEX_PROGRAM_ARB) { + + /* Also tell tnl about it: + */ + _tnl_program_string(ctx, target, prog); + } +} + + + +void st_init_cb_program( struct st_context *st ) +{ + struct dd_function_table *functions = &st->ctx->Driver; + + /* Need these flags: + */ + st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; + st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; + + + assert(functions->ProgramStringNotify == _tnl_program_string); + functions->BindProgram = st_bind_program; + functions->NewProgram = st_new_program; + functions->DeleteProgram = st_delete_program; + functions->IsProgramNative = st_is_program_native; + functions->ProgramStringNotify = st_program_string_notify; +} + + +void st_destroy_cb_program( struct st_context *st ) +{ +} + diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c new file mode 100644 index 00000000000..8a06dd88df7 --- /dev/null +++ b/src/mesa/state_tracker/st_context.c @@ -0,0 +1,76 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "imports.h" +#include "st_public.h" +#include "st_context.h" +#include "st_atom.h" +#include "st_draw.h" +#include "st_program.h" +#include "softpipe/sp_context.h" + +void st_invalidate_state(GLcontext * ctx, GLuint new_state) +{ + struct st_context *st = st_context(ctx); + + st->dirty.mesa |= new_state; + st->dirty.st |= ST_NEW_MESA; +} + + +struct st_context *st_create_context( GLcontext *ctx, + struct softpipe_context *softpipe ) +{ + struct st_context *st = CALLOC_STRUCT( st_context ); + + ctx->st = st; + + st->ctx = ctx; + st->softpipe = softpipe; + + st->dirty.mesa = ~0; + st->dirty.st = ~0; + + st_init_atoms( st ); + st_init_draw( st ); + st_init_cb_program( st ); + + return st; +} + + +void st_destroy_context( struct st_context *st ) +{ + st_destroy_atoms( st ); + st_destroy_draw( st ); + st_destroy_cb_program( st ); + st->softpipe->destroy( st->softpipe ); + FREE( st ); +} + + + diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h new file mode 100644 index 00000000000..317d3773718 --- /dev/null +++ b/src/mesa/state_tracker/st_context.h @@ -0,0 +1,111 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef ST_CONTEXT_H +#define ST_CONTEXT_H + +#include "mtypes.h" +#include "softpipe/sp_state.h" + + +struct st_context; +struct st_region; +struct st_texture_object; +struct st_texture_image; +struct st_fragment_program; + +#define ST_NEW_MESA 0x1 /* Mesa state has changed */ +#define ST_NEW_FRAGMENT_PROGRAM 0x2 + +struct st_state_flags { + GLuint mesa; + GLuint st; +}; + +struct st_tracked_state { + struct st_state_flags dirty; + void (*update)( struct st_context *st ); +}; + + + + +struct st_context +{ + GLcontext *ctx; + + struct softpipe_context *softpipe; + + /* Eventually will use a cache to feed the softpipe with + * create/bind/delete calls to constant state objects. Not yet + * though, we just shove random objects across the interface. + */ + struct { + struct softpipe_viewport viewport; + struct softpipe_setup_state setup; + struct softpipe_fs_state fs; + struct softpipe_blend_state blend; + struct softpipe_surface cbuf; + struct softpipe_clip_state clip; + struct softpipe_depth_state depth; + struct softpipe_scissor_rect scissor; + struct softpipe_poly_stipple poly_stipple; + struct softpipe_stencil_state stencil; + } state; + + struct { + struct st_tracked_state tracked_state; + } constants; + + struct { + struct gl_fragment_program *fragment_program; + } cb; + + /* State to be validated: + */ + struct st_tracked_state **atoms; + GLuint nr_atoms; + + struct st_state_flags dirty; + + /* Counter to track program string changes: + */ + GLuint program_id; + + GLfloat polygon_offset_scale; /* ?? */ +}; + + +/* Need this so that we can implement Mesa callbacks in this module. + */ +static INLINE struct st_context *st_context(GLcontext *ctx) +{ + return ctx->st; +} + + +#endif diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c new file mode 100644 index 00000000000..12646402eec --- /dev/null +++ b/src/mesa/state_tracker/st_draw.c @@ -0,0 +1,107 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "imports.h" + +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +#include "st_context.h" +#include "st_atom.h" +#include "st_draw.h" +#include "softpipe/sp_context.h" + +/* + * TNL stage which feedsinto the above. + * + * XXX: this needs to go into each driver using this code, because we + * cannot make the leap from ctx->draw_context in this file. The + * driver needs to customize tnl anyway, so this isn't a big deal. + */ +static GLboolean draw( GLcontext * ctx, struct tnl_pipeline_stage *stage ) +{ + struct st_context *st = st_context(ctx); + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + + /* Validate driver and softpipe state: + */ + st_validate_state( st ); + + /* Call into the new draw code to handle the VB: + */ + st->softpipe->draw_vb( st->softpipe, VB ); + + /* Finished + */ + return GL_FALSE; +} + +const struct tnl_pipeline_stage st_draw = { + "check state and draw", + NULL, + NULL, + NULL, + NULL, + draw +}; + +static const struct tnl_pipeline_stage *intel_pipeline[] = { + &_tnl_vertex_transform_stage, + &_tnl_vertex_cull_stage, + &_tnl_normal_transform_stage, + &_tnl_lighting_stage, + &_tnl_fog_coordinate_stage, + &_tnl_texgen_stage, + &_tnl_texture_transform_stage, + &_tnl_point_attenuation_stage, + &_tnl_vertex_program_stage, + &st_draw, /* ADD: escape to softpipe */ + 0, +}; + +/* This is all a hack to keep using tnl until we have vertex programs + * up and running. + */ +void st_init_draw( struct st_context *st ) +{ + GLcontext *ctx = st->ctx; + + _tnl_destroy_pipeline( ctx ); + _tnl_install_pipeline( ctx, intel_pipeline ); +} + + +void st_destroy_draw( struct st_context *st ) +{ + /* Nothing to do. + */ +} diff --git a/src/mesa/state_tracker/st_draw.h b/src/mesa/state_tracker/st_draw.h new file mode 100644 index 00000000000..f51059706ad --- /dev/null +++ b/src/mesa/state_tracker/st_draw.h @@ -0,0 +1,40 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef ST_DRAW_H +#define ST_DRAW_H + +void st_init_draw( struct st_context *st ); +void st_destroy_draw( struct st_context *st ); + +#endif diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h new file mode 100644 index 00000000000..a47059d7a69 --- /dev/null +++ b/src/mesa/state_tracker/st_program.h @@ -0,0 +1,68 @@ +/************************************************************************** + * + * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef ST_PROGRAM_H +#define ST_PROGRAM_H + +struct st_fragment_program +{ + struct gl_fragment_program Base; + GLboolean error; /* If program is malformed for any reason. */ + + GLuint id; /* String id, for tracking + * ProgramStringNotify changes. + */ + +#if 0 + GLfloat (*cbuffer)[4]; + GLuint nr_constants; + + /* Translate all the parameters, etc, into a constant buffer which + * we update on state changes. + */ + struct + { + GLuint reg; /* Constant idx */ + const GLfloat *values; /* Pointer to tracked values */ + } *param; + GLuint nr_params; + + GLuint param_state; +#endif +}; + + +void st_init_cb_program( struct st_context *st ); +void st_destroy_cb_program( struct st_context *st ); + +#endif diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h new file mode 100644 index 00000000000..8241dbd52d1 --- /dev/null +++ b/src/mesa/state_tracker/st_public.h @@ -0,0 +1,43 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef ST_PUBLIC_H +#define ST_PUBLIC_H + +#include "mtypes.h" + +struct st_context; +struct softpipe_context; + +struct st_context *st_create_context( GLcontext *ctx, + struct softpipe_context *softpipe); + +void st_destroy_context( struct st_context *st ); + +void st_invalidate_state(GLcontext * ctx, GLuint new_state); + +#endif