From: Keith Whitwell Date: Mon, 5 Jan 2004 15:24:53 +0000 (+0000) Subject: Beef up t_vertex.c: X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=588225770c60834dfd2a95850435cc549167dc05;p=mesa.git Beef up t_vertex.c: - cope with input vectors with size less than that of the emitted attribute. - cope with vertices with 'holes' inside and between vertices. Fix calculation of tnl->render_inputs to work with fp programs. Mirror VB->PointSizePtr in VB->AttribPtr so that it can work with t_vertex.c. Transition swrast_setup/ to use t_vertex.c to build swrast vertices. --- diff --git a/src/mesa/sources b/src/mesa/sources index f7bbf48d8a8..2cfe9034ec3 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -110,8 +110,7 @@ SWRAST_SOURCES = \ SWRAST_SETUP_SOURCES = \ swrast_setup/ss_context.c \ - swrast_setup/ss_triangle.c \ - swrast_setup/ss_vb.c + swrast_setup/ss_triangle.c TNL_SOURCES = \ tnl/t_array_api.c \ diff --git a/src/mesa/swrast_setup/ss_context.c b/src/mesa/swrast_setup/ss_context.c index 55fe141c258..df99fdb20b7 100644 --- a/src/mesa/swrast_setup/ss_context.c +++ b/src/mesa/swrast_setup/ss_context.c @@ -31,47 +31,32 @@ #include "colormac.h" #include "ss_context.h" #include "ss_triangle.h" -#include "ss_vb.h" #include "swrast_setup.h" #include "tnl/tnl.h" #include "tnl/t_context.h" #include "tnl/t_pipeline.h" #include "tnl/t_vertex.h" - -#define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \ - _NEW_POLYGON| \ - _NEW_LIGHT| \ - _NEW_TEXTURE| \ - _NEW_COLOR| \ - _NEW_FOG| \ - _NEW_POINT) - #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT) GLboolean _swsetup_CreateContext( GLcontext *ctx ) { - TNLcontext *tnl = TNL_CONTEXT(ctx); SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext)); if (!swsetup) return GL_FALSE; - swsetup->verts = (SWvertex *) ALIGN_CALLOC( sizeof(SWvertex) * tnl->vb.Size, - 32); - if (!swsetup->verts) { - FREE(swsetup); - return GL_FALSE; - } - ctx->swsetup_context = swsetup; swsetup->NewState = ~0; - _swsetup_vb_init( ctx ); _swsetup_trifuncs_init( ctx ); + _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, + sizeof(SWvertex) ); + + return GL_TRUE; } @@ -81,18 +66,11 @@ _swsetup_DestroyContext( GLcontext *ctx ) SScontext *swsetup = SWSETUP_CONTEXT(ctx); if (swsetup) { - if (swsetup->verts) - ALIGN_FREE(swsetup->verts); - - if (swsetup->ChanSecondaryColor.Ptr) - ALIGN_FREE((void *) swsetup->ChanSecondaryColor.Ptr); - - if (swsetup->ChanColor.Ptr) - ALIGN_FREE((void *) swsetup->ChanColor.Ptr); - FREE(swsetup); ctx->swsetup_context = 0; } + + _tnl_free_vertices( ctx ); } static void @@ -102,6 +80,18 @@ _swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode ) _swrast_render_primitive( ctx, mode ); } +#define SWZ ((SWvertex *)0) +#define SWOffset(MEMBER) (((char *)&(SWZ->MEMBER)) - ((char *)SWZ)) + +#define EMIT_ATTR( ATTR, STYLE, MEMBER ) \ +do { \ + map[e].attrib = (ATTR); \ + map[e].format = (STYLE); \ + map[e].offset = SWOffset(MEMBER); \ + e++; \ +} while (0) + + /* * We patch this function into tnl->Driver.Render.Start. * It's called when we start rendering a vertex buffer. @@ -110,19 +100,60 @@ static void _swsetup_RenderStart( GLcontext *ctx ) { SScontext *swsetup = SWSETUP_CONTEXT(ctx); + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; GLuint new_state = swsetup->NewState; if (new_state & _SWSETUP_NEW_RENDERINDEX) { _swsetup_choose_trifuncs( ctx ); } - if (new_state & _SWSETUP_NEW_VERTS) { - _swsetup_choose_rastersetup_func( ctx ); - } - swsetup->NewState = 0; _swrast_render_start( ctx ); + + /* Important: + */ + VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; + + + if (tnl->render_inputs != swsetup->last_index) { + GLuint index = tnl->render_inputs; + struct tnl_attr_map map[_TNL_ATTRIB_MAX]; + int i, e = 0; + + EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, win ); + + if (index & _TNL_BIT_COLOR0) + EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color ); + + if (index & _TNL_BIT_COLOR1) + EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4CHAN_4F_RGBA, specular); + + if (index & _TNL_BIT_FOG) + EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1F, fog); + + if (index & _TNL_BITS_TEX_ANY) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { + if (index & _TNL_BIT_TEX(i)) { + EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_4F, texcoord[i] ); + } + } + } + + if (index & _TNL_BIT_INDEX) + EMIT_ATTR( _TNL_ATTRIB_INDEX, EMIT_1F, index ); + + if (index & _TNL_BIT_POINTSIZE) + EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize ); + + _tnl_install_attrs( ctx, map, e, + ctx->Viewport._WindowMap.m, + sizeof(SWvertex) ); + + swsetup->last_index = index; + } + } /* @@ -140,6 +171,7 @@ _swsetup_InvalidateState( GLcontext *ctx, GLuint new_state ) { SScontext *swsetup = SWSETUP_CONTEXT(ctx); swsetup->NewState |= new_state; + _tnl_invalidate_vertex_state( ctx, new_state ); } @@ -147,11 +179,13 @@ void _swsetup_Wakeup( GLcontext *ctx ) { TNLcontext *tnl = TNL_CONTEXT(ctx); + SScontext *swsetup = SWSETUP_CONTEXT(ctx); + tnl->Driver.Render.Start = _swsetup_RenderStart; tnl->Driver.Render.Finish = _swsetup_RenderFinish; tnl->Driver.Render.PrimitiveNotify = _swsetup_RenderPrimitive; - /* interp */ - /* copypv */ + tnl->Driver.Render.Interp = _tnl_interp; + tnl->Driver.Render.CopyPV = _tnl_copy_pv; tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; /* new */ tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; /* new */ /* points */ @@ -161,10 +195,15 @@ _swsetup_Wakeup( GLcontext *ctx ) tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts; tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts; tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple; - /* buildvertices */ + tnl->Driver.Render.BuildVertices = _tnl_build_vertices; tnl->Driver.Render.Multipass = 0; + + _tnl_invalidate_vertices( ctx, ~0 ); _tnl_need_projected_coords( ctx, GL_TRUE ); _swsetup_InvalidateState( ctx, ~0 ); + + swsetup->verts = (SWvertex *)tnl->clipspace.vertex_buf; + swsetup->last_index = 0; } @@ -196,11 +235,7 @@ _swsetup_Translate( GLcontext *ctx, const void *vertex, SWvertex *dest ) _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_INDEX, tmp ); dest->index = (GLuint) tmp[0]; -/* - Need to check how pointsize is related to vertex program attributes: - _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POINTSIZE, tmp ); dest->pointSize = tmp[0]; -*/ } diff --git a/src/mesa/swrast_setup/ss_context.h b/src/mesa/swrast_setup/ss_context.h index 84813e98eb0..2c6e4faf3da 100644 --- a/src/mesa/swrast_setup/ss_context.h +++ b/src/mesa/swrast_setup/ss_context.h @@ -35,14 +35,9 @@ typedef struct { GLuint NewState; - SWvertex *verts; GLenum render_prim; - GLuint SetupIndex; - - /* Temporaries for translating away float colors: - */ - struct gl_client_array ChanColor; - struct gl_client_array ChanSecondaryColor; + GLuint last_index; + SWvertex *verts; } SScontext; #define SWSETUP_CONTEXT(ctx) ((SScontext *)ctx->swsetup_context) diff --git a/src/mesa/swrast_setup/ss_vb.c b/src/mesa/swrast_setup/ss_vb.c deleted file mode 100644 index dfa0ea03a2a..00000000000 --- a/src/mesa/swrast_setup/ss_vb.c +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 5.1 - * - * Copyright (C) 1999-2003 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. - * - * Authors: - * Keith Whitwell - */ - -#include "glheader.h" -#include "colormac.h" -#include "context.h" -#include "macros.h" -#include "imports.h" -#include "nvfragprog.h" - -#include "swrast/swrast.h" -#include "tnl/t_context.h" -#include "math/m_vector.h" -#include "math/m_translate.h" - -#include "ss_context.h" -#include "ss_vb.h" - - -#if 0 -static void do_import( struct vertex_buffer *VB, - struct gl_client_array *to, - struct gl_client_array *from ) -{ - GLuint count = VB->Count; - - if (!to->Ptr) { - to->Ptr = (GLubyte *) ALIGN_MALLOC( VB->Size * 4 * sizeof(GLchan), 32 ); - to->Type = CHAN_TYPE; - } - - /* No need to transform the same value 3000 times. - */ - if (!from->StrideB) { - to->StrideB = 0; - count = 1; - } - else - to->StrideB = 4 * sizeof(GLchan); - - _math_trans_4chan( (GLchan (*)[4]) to->Ptr, - from->Ptr, - from->StrideB, - from->Type, - from->Size, - 0, - count); -} - -static void import_float_colors( GLcontext *ctx ) -{ - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - struct gl_client_array *to = &SWSETUP_CONTEXT(ctx)->ChanColor; - do_import( VB, to, VB->ColorPtr[0] ); - VB->ColorPtr[0] = to; -} - -static void import_float_spec_colors( GLcontext *ctx ) -{ - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - struct gl_client_array *to = &SWSETUP_CONTEXT(ctx)->ChanSecondaryColor; - do_import( VB, to, VB->SecondaryColorPtr[0] ); - VB->SecondaryColorPtr[0] = to; -} -#endif - -/* Provides a RasterSetup function which prebuilds vertices for the - * software rasterizer. This is required for the triangle functions - * in this module, but not the rest of the swrast module. - */ - - -#define COLOR 0x1 -#define INDEX 0x2 -#define TEX0 0x4 -#define MULTITEX 0x8 -#define SPEC 0x10 -#define FOG 0x20 -#define POINT 0x40 -#define MAX_SETUPFUNC 0x80 - -static setup_func setup_tab[MAX_SETUPFUNC]; -static interp_func interp_tab[MAX_SETUPFUNC]; -static copy_pv_func copy_pv_tab[MAX_SETUPFUNC]; - - -#define IND (0) -#define TAG(x) x##_none -#include "ss_vbtmp.h" - -#define IND (COLOR) -#define TAG(x) x##_color -#include "ss_vbtmp.h" - -#define IND (COLOR|SPEC) -#define TAG(x) x##_color_spec -#include "ss_vbtmp.h" - -#define IND (COLOR|FOG) -#define TAG(x) x##_color_fog -#include "ss_vbtmp.h" - -#define IND (COLOR|SPEC|FOG) -#define TAG(x) x##_color_spec_fog -#include "ss_vbtmp.h" - -#define IND (COLOR|TEX0) -#define TAG(x) x##_color_tex0 -#include "ss_vbtmp.h" - -#define IND (COLOR|TEX0|SPEC) -#define TAG(x) x##_color_tex0_spec -#include "ss_vbtmp.h" - -#define IND (COLOR|TEX0|FOG) -#define TAG(x) x##_color_tex0_fog -#include "ss_vbtmp.h" - -#define IND (COLOR|TEX0|SPEC|FOG) -#define TAG(x) x##_color_tex0_spec_fog -#include "ss_vbtmp.h" - -#define IND (COLOR|MULTITEX) -#define TAG(x) x##_color_multitex -#include "ss_vbtmp.h" - -#define IND (COLOR|MULTITEX|SPEC) -#define TAG(x) x##_color_multitex_spec -#include "ss_vbtmp.h" - -#define IND (COLOR|MULTITEX|FOG) -#define TAG(x) x##_color_multitex_fog -#include "ss_vbtmp.h" - -#define IND (COLOR|MULTITEX|SPEC|FOG) -#define TAG(x) x##_color_multitex_spec_fog -#include "ss_vbtmp.h" - -#define IND (COLOR|POINT) -#define TAG(x) x##_color_point -#include "ss_vbtmp.h" - -#define IND (COLOR|SPEC|POINT) -#define TAG(x) x##_color_spec_point -#include "ss_vbtmp.h" - -#define IND (COLOR|FOG|POINT) -#define TAG(x) x##_color_fog_point -#include "ss_vbtmp.h" - -#define IND (COLOR|SPEC|FOG|POINT) -#define TAG(x) x##_color_spec_fog_point -#include "ss_vbtmp.h" - -#define IND (COLOR|TEX0|POINT) -#define TAG(x) x##_color_tex0_point -#include "ss_vbtmp.h" - -#define IND (COLOR|TEX0|SPEC|POINT) -#define TAG(x) x##_color_tex0_spec_point -#include "ss_vbtmp.h" - -#define IND (COLOR|TEX0|FOG|POINT) -#define TAG(x) x##_color_tex0_fog_point -#include "ss_vbtmp.h" - -#define IND (COLOR|TEX0|SPEC|FOG|POINT) -#define TAG(x) x##_color_tex0_spec_fog_point -#include "ss_vbtmp.h" - -#define IND (COLOR|MULTITEX|POINT) -#define TAG(x) x##_color_multitex_point -#include "ss_vbtmp.h" - -#define IND (COLOR|MULTITEX|SPEC|POINT) -#define TAG(x) x##_color_multitex_spec_point -#include "ss_vbtmp.h" - -#define IND (COLOR|MULTITEX|FOG|POINT) -#define TAG(x) x##_color_multitex_fog_point -#include "ss_vbtmp.h" - -#define IND (COLOR|MULTITEX|SPEC|FOG|POINT) -#define TAG(x) x##_color_multitex_spec_fog_point -#include "ss_vbtmp.h" - -#define IND (INDEX) -#define TAG(x) x##_index -#include "ss_vbtmp.h" - -#define IND (INDEX|FOG) -#define TAG(x) x##_index_fog -#include "ss_vbtmp.h" - -#define IND (INDEX|POINT) -#define TAG(x) x##_index_point -#include "ss_vbtmp.h" - -#define IND (INDEX|FOG|POINT) -#define TAG(x) x##_index_fog_point -#include "ss_vbtmp.h" - - -/*********************************************************************** - * Additional setup and interp for back color and edgeflag. - ***********************************************************************/ - -#define GET_COLOR(ptr, idx) (((GLfloat (*)[4])((ptr)->data))[idx]) - -static void interp_extras( GLcontext *ctx, - GLfloat t, - GLuint dst, GLuint out, GLuint in, - GLboolean force_boundary ) -{ - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - if (VB->ColorPtr[1]) { - INTERP_4F( t, - GET_COLOR(VB->ColorPtr[1], dst), - GET_COLOR(VB->ColorPtr[1], out), - GET_COLOR(VB->ColorPtr[1], in) ); - - if (VB->SecondaryColorPtr[1]) { - INTERP_3F( t, - GET_COLOR(VB->SecondaryColorPtr[1], dst), - GET_COLOR(VB->SecondaryColorPtr[1], out), - GET_COLOR(VB->SecondaryColorPtr[1], in) ); - } - } - else if (VB->IndexPtr[1]) { - VB->IndexPtr[1]->data[dst][0] = LINTERP( t, - VB->IndexPtr[1]->data[out][0], - VB->IndexPtr[1]->data[in][0] ); - } - - if (VB->EdgeFlag) { - VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary; - } - - interp_tab[SWSETUP_CONTEXT(ctx)->SetupIndex](ctx, t, dst, out, in, - force_boundary); -} - -static void copy_pv_extras( GLcontext *ctx, GLuint dst, GLuint src ) -{ - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - if (VB->ColorPtr[1]) { - COPY_4FV( GET_COLOR(VB->ColorPtr[1], dst), - GET_COLOR(VB->ColorPtr[1], src) ); - - if (VB->SecondaryColorPtr[1]) { - COPY_3V( GET_COLOR(VB->SecondaryColorPtr[1], dst), - GET_COLOR(VB->SecondaryColorPtr[1], src) ); - } - } - else if (VB->IndexPtr[1]) { - VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0]; - } - - copy_pv_tab[SWSETUP_CONTEXT(ctx)->SetupIndex](ctx, dst, src); -} - - - - -/*********************************************************************** - * Initialization - ***********************************************************************/ - -static void -emit_invalid( GLcontext *ctx, GLuint start, GLuint end, GLuint newinputs ) -{ - _mesa_debug(ctx, "swrast_setup: invalid setup function\n"); - (void) (ctx && start && end && newinputs); -} - - -static void -interp_invalid( GLcontext *ctx, GLfloat t, - GLuint edst, GLuint eout, GLuint ein, - GLboolean force_boundary ) -{ - _mesa_debug(ctx, "swrast_setup: invalid interp function\n"); - (void) (ctx && t && edst && eout && ein && force_boundary); -} - - -static void -copy_pv_invalid( GLcontext *ctx, GLuint edst, GLuint esrc ) -{ - _mesa_debug(ctx, "swrast_setup: invalid copy_pv function\n"); - (void) (ctx && edst && esrc ); -} - - -static void init_standard( void ) -{ - GLuint i; - - for (i = 0 ; i < Elements(setup_tab) ; i++) { - setup_tab[i] = emit_invalid; - interp_tab[i] = interp_invalid; - copy_pv_tab[i] = copy_pv_invalid; - } - - init_none(); - init_color(); - init_color_spec(); - init_color_fog(); - init_color_spec_fog(); - init_color_tex0(); - init_color_tex0_spec(); - init_color_tex0_fog(); - init_color_tex0_spec_fog(); - init_color_multitex(); - init_color_multitex_spec(); - init_color_multitex_fog(); - init_color_multitex_spec_fog(); - init_color_point(); - init_color_spec_point(); - init_color_fog_point(); - init_color_spec_fog_point(); - init_color_tex0_point(); - init_color_tex0_spec_point(); - init_color_tex0_fog_point(); - init_color_tex0_spec_fog_point(); - init_color_multitex_point(); - init_color_multitex_spec_point(); - init_color_multitex_fog_point(); - init_color_multitex_spec_fog_point(); - init_index(); - init_index_fog(); - init_index_point(); - init_index_fog_point(); -} - - -/* debug only */ -#if 0 -static void -printSetupFlags(const GLcontext *ctx, char *msg, GLuint flags ) -{ - _mesa_debug(ctx, "%s(%x): %s%s%s%s%s%s%s\n", - msg, - (int) flags, - (flags & COLOR) ? "color, " : "", - (flags & INDEX) ? "index, " : "", - (flags & TEX0) ? "tex0, " : "", - (flags & MULTITEX) ? "multitex, " : "", - (flags & SPEC) ? "spec, " : "", - (flags & FOG) ? "fog, " : "", - (flags & POINT) ? "point, " : ""); -} -#endif - -void -_swsetup_choose_rastersetup_func(GLcontext *ctx) -{ - SScontext *swsetup = SWSETUP_CONTEXT(ctx); - TNLcontext *tnl = TNL_CONTEXT(ctx); - int funcindex = 0; - - if (ctx->RenderMode == GL_RENDER) { - if (ctx->Visual.rgbMode) { - funcindex = COLOR; - - if (ctx->Texture._EnabledCoordUnits > 1) - funcindex |= MULTITEX; /* a unit above unit[0] is enabled */ - else if (ctx->Texture._EnabledCoordUnits == 1) - funcindex |= TEX0; /* only unit 0 is enabled */ - - if (NEED_SECONDARY_COLOR(ctx)) - funcindex |= SPEC; - } - else { - funcindex = INDEX; - } - - if (ctx->Point._Attenuated || - (ctx->VertexProgram.Enabled && ctx->VertexProgram.PointSizeEnabled)) - funcindex |= POINT; - - if (ctx->Fog.Enabled) - funcindex |= FOG; - } - else if (ctx->RenderMode == GL_FEEDBACK) { - if (ctx->Visual.rgbMode) - funcindex = (COLOR | TEX0); /* is feedback color subject to fogging? */ - else - funcindex = INDEX; - } - else - funcindex = 0; - - swsetup->SetupIndex = funcindex; - tnl->Driver.Render.BuildVertices = setup_tab[funcindex]; - - if (NEED_TWO_SIDED_LIGHTING(ctx) || - ctx->Polygon.FrontMode != GL_FILL || - ctx->Polygon.BackMode != GL_FILL) { - tnl->Driver.Render.Interp = interp_extras; - tnl->Driver.Render.CopyPV = copy_pv_extras; - } - else { - tnl->Driver.Render.Interp = interp_tab[funcindex]; - tnl->Driver.Render.CopyPV = copy_pv_tab[funcindex]; - } - - ASSERT(tnl->Driver.Render.BuildVertices); - ASSERT(tnl->Driver.Render.BuildVertices != emit_invalid); -} - - -void -_swsetup_vb_init( GLcontext *ctx ) -{ - (void) ctx; - init_standard(); - /* - printSetupFlags(ctx); - */ -} - diff --git a/src/mesa/swrast_setup/ss_vbtmp.h b/src/mesa/swrast_setup/ss_vbtmp.h deleted file mode 100644 index d72a6693d65..00000000000 --- a/src/mesa/swrast_setup/ss_vbtmp.h +++ /dev/null @@ -1,247 +0,0 @@ - -/* - * Mesa 3-D graphics library - * Version: 5.1 - * - * Copyright (C) 1999-2003 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. - * - * Authors: - * Keith Whitwell - */ - - -static void TAG(emit)(GLcontext *ctx, GLuint start, GLuint end, - GLuint newinputs ) -{ - TNLcontext *tnl = TNL_CONTEXT(ctx); - struct vertex_buffer *VB = &tnl->vb; - SWvertex *v; - const GLfloat *ndc; /* NDC (i.e. projected clip coordinates) */ - const GLfloat *tc[MAX_TEXTURE_COORD_UNITS]; - const GLfloat *color; - const GLfloat *spec; - const GLfloat *index; - const GLfloat *fog; - const GLfloat *pointSize; - GLuint tsz[MAX_TEXTURE_COORD_UNITS]; - GLuint tstride[MAX_TEXTURE_COORD_UNITS]; - GLuint ndc_stride, color_stride, spec_stride, index_stride; - GLuint fog_stride, pointSize_stride; - GLuint i; - GLfloat *m = ctx->Viewport._WindowMap.m; - const GLfloat sx = m[0]; - const GLfloat sy = m[5]; - const GLfloat sz = m[10]; - const GLfloat tx = m[12]; - const GLfloat ty = m[13]; - const GLfloat tz = m[14]; - GLuint maxtex = 0; - - if (IND & TEX0) { - tc[0] = (GLfloat *)VB->TexCoordPtr[0]->data; - tsz[0] = VB->TexCoordPtr[0]->size; - tstride[0] = VB->TexCoordPtr[0]->stride; - } - - if (IND & MULTITEX) { - for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) { - if (VB->TexCoordPtr[i]) { - maxtex = i+1; - tc[i] = (GLfloat *)VB->TexCoordPtr[i]->data; - tsz[i] = VB->TexCoordPtr[i]->size; - tstride[i] = VB->TexCoordPtr[i]->stride; - } - else tc[i] = 0; - } - } - - ndc = VB->NdcPtr->data[0]; - ndc_stride = VB->NdcPtr->stride; - - if (IND & FOG) { - fog = (GLfloat *) VB->FogCoordPtr->data; - fog_stride = VB->FogCoordPtr->stride; - } - if (IND & COLOR) { - color = (GLfloat *) VB->ColorPtr[0]->data; - color_stride = VB->ColorPtr[0]->stride; - } - if (IND & SPEC) { - spec = (GLfloat *) VB->SecondaryColorPtr[0]->data; - spec_stride = VB->SecondaryColorPtr[0]->stride; - } - if (IND & INDEX) { - index = (GLfloat *) VB->IndexPtr[0]->data; - index_stride = VB->IndexPtr[0]->stride; - } - if (IND & POINT) { - pointSize = (GLfloat *) VB->PointSizePtr->data; - pointSize_stride = VB->PointSizePtr->stride; - } - - v = &(SWSETUP_CONTEXT(ctx)->verts[start]); - - for (i=start; i < end; i++, v++) { - if (VB->ClipMask[i] == 0) { - v->win[0] = sx * ndc[0] + tx; - v->win[1] = sy * ndc[1] + ty; - v->win[2] = sz * ndc[2] + tz; - v->win[3] = ndc[3]; - } - STRIDE_F(ndc, ndc_stride); - - if (IND & TEX0) { - COPY_CLEAN_4V( v->texcoord[0], tsz[0], tc[0] ); - STRIDE_F(tc[0], tstride[0]); - } - - if (IND & MULTITEX) { - GLuint u; - for (u = 0 ; u < maxtex ; u++) - if (tc[u]) { - COPY_CLEAN_4V( v->texcoord[u], tsz[u], tc[u] ); - STRIDE_F(tc[u], tstride[u]); - } - } - - if (IND & COLOR) { - UNCLAMPED_FLOAT_TO_RGBA_CHAN(v->color, color); - STRIDE_F(color, color_stride); - } - - if (IND & SPEC) { - UNCLAMPED_FLOAT_TO_RGBA_CHAN(v->specular, spec); - STRIDE_F(spec, spec_stride); - } - - if (IND & FOG) { - v->fog = fog[0]; - STRIDE_F(fog, fog_stride); - } - - if (IND & INDEX) { - v->index = (GLuint) index[0]; - STRIDE_F(index, index_stride); - } - - if (IND & POINT) { - v->pointSize = pointSize[0]; - STRIDE_F(pointSize, pointSize_stride); - } - } -} - - - -static void TAG(interp)( GLcontext *ctx, - GLfloat t, - GLuint edst, GLuint eout, GLuint ein, - GLboolean force_boundary ) -{ - SScontext *swsetup = SWSETUP_CONTEXT(ctx); - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - GLfloat *m = ctx->Viewport._WindowMap.m; - GLfloat *clip = VB->ClipPtr->data[edst]; - - SWvertex *dst = &swsetup->verts[edst]; - SWvertex *in = &swsetup->verts[ein]; - SWvertex *out = &swsetup->verts[eout]; - - /* Avoid division by zero by rearranging order of clip planes? - */ - if (clip[3] != 0.0) { - GLfloat oow = 1.0F / clip[3]; - dst->win[0] = m[0] * clip[0] * oow + m[12]; - dst->win[1] = m[5] * clip[1] * oow + m[13]; - dst->win[2] = m[10] * clip[2] * oow + m[14]; - dst->win[3] = oow; - } - - if (IND & TEX0) { - INTERP_4F( t, dst->texcoord[0], out->texcoord[0], in->texcoord[0] ); - } - - if (IND & MULTITEX) { - GLuint u; - GLuint maxtex = ctx->Const.MaxTextureUnits; - for (u = 0 ; u < maxtex ; u++) - if (VB->TexCoordPtr[u]) { - INTERP_4F( t, dst->texcoord[u], out->texcoord[u], in->texcoord[u] ); - } - } - - if (IND & COLOR) { - INTERP_CHAN( t, dst->color[0], out->color[0], in->color[0] ); - INTERP_CHAN( t, dst->color[1], out->color[1], in->color[1] ); - INTERP_CHAN( t, dst->color[2], out->color[2], in->color[2] ); - INTERP_CHAN( t, dst->color[3], out->color[3], in->color[3] ); - } - - if (IND & SPEC) { - INTERP_CHAN( t, dst->specular[0], out->specular[0], in->specular[0] ); - INTERP_CHAN( t, dst->specular[1], out->specular[1], in->specular[1] ); - INTERP_CHAN( t, dst->specular[2], out->specular[2], in->specular[2] ); - } - - if (IND & FOG) { - INTERP_F( t, dst->fog, out->fog, in->fog ); - } - - if (IND & INDEX) { - INTERP_UI( t, dst->index, out->index, in->index ); - } - - /* XXX Point size interpolation??? */ - if (IND & POINT) { - INTERP_F( t, dst->pointSize, out->pointSize, in->pointSize ); - } -} - - -static void TAG(copy_pv)( GLcontext *ctx, GLuint edst, GLuint esrc ) -{ - SScontext *swsetup = SWSETUP_CONTEXT(ctx); - SWvertex *dst = &swsetup->verts[edst]; - SWvertex *src = &swsetup->verts[esrc]; - - if (IND & COLOR) { - COPY_CHAN4( dst->color, src->color ); - } - - if (IND & SPEC) { - COPY_3V( dst->specular, src->specular ); - } - - if (IND & INDEX) { - dst->index = src->index; - } -} - - -static void TAG(init)( void ) -{ - setup_tab[IND] = TAG(emit); - interp_tab[IND] = TAG(interp); - copy_pv_tab[IND] = TAG(copy_pv); -} - -#undef TAG -#undef IND -#undef SETUP_FLAGS diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c index 8b83372fa73..ec5f88cd96c 100644 --- a/src/mesa/tnl/t_context.c +++ b/src/mesa/tnl/t_context.c @@ -161,7 +161,7 @@ _tnl_InvalidateState( GLcontext *ctx, GLuint new_state ) if (ctx->Visual.rgbMode) { tnl->render_inputs = (_TNL_BIT_POS| _TNL_BIT_COLOR0| - (ctx->Texture._EnabledUnits << _TNL_ATTRIB_TEX0)); + (ctx->Texture._EnabledCoordUnits << _TNL_ATTRIB_TEX0)); if (NEED_SECONDARY_COLOR(ctx)) tnl->render_inputs |= _TNL_BIT_COLOR1; @@ -179,6 +179,10 @@ _tnl_InvalidateState( GLcontext *ctx, GLuint new_state ) if (ctx->RenderMode == GL_FEEDBACK) tnl->render_inputs |= _TNL_BIT_TEX0; + + if (ctx->Point._Attenuated || + (ctx->VertexProgram.Enabled && ctx->VertexProgram.PointSizeEnabled)) + tnl->render_inputs |= _TNL_BIT_POINTSIZE; } diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h index ab146b29305..a9d36d24882 100644 --- a/src/mesa/tnl/t_context.h +++ b/src/mesa/tnl/t_context.h @@ -88,6 +88,13 @@ * in mtypes.h. However, the tnl module has additional attributes * for materials, color indexes, edge flags, etc. */ +/* Note: These are currently being used to define both inputs and + * outputs from the tnl pipeline. A better solution (which would also + * releive the congestion to slightly prolong the life of the bitmask + * below) is to have the fixed function pipeline populate a set of + * arrays named after those produced by the vertex program stage, and + * have the rest the mesa backend work on those. + */ enum { _TNL_ATTRIB_POS = 0, _TNL_ATTRIB_WEIGHT = 1, @@ -119,7 +126,8 @@ enum { _TNL_ATTRIB_MAT_BACK_INDEXES = 27, _TNL_ATTRIB_INDEX = 28, _TNL_ATTRIB_EDGEFLAG = 29, - _TNL_ATTRIB_MAX = 30 + _TNL_ATTRIB_POINTSIZE = 30, + _TNL_ATTRIB_MAX = 31 } ; /* Will probably have to revise this scheme fairly shortly, eg. by @@ -156,6 +164,7 @@ enum { #define _TNL_BIT_MAT_BACK_INDEXES (1<<27) #define _TNL_BIT_INDEX (1<<28) #define _TNL_BIT_EDGEFLAG (1<<29) +#define _TNL_BIT_POINTSIZE (1<<30) #define _TNL_BIT_TEX(u) (1 << (_TNL_ATTRIB_TEX0 + (u))) @@ -495,20 +504,24 @@ struct tnl_pipeline { GLuint nr_stages; }; +struct tnl_clipspace_attr; + +typedef void (*extract_func)( const struct tnl_clipspace_attr *a, GLfloat *out, + const GLubyte *v ); + +typedef void (*insert_func)( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ); + struct tnl_clipspace_attr { int attrib; int vertoffset; int vertattrsize; - GLfloat *inputptr; + GLubyte *inputptr; int inputstride; - - void (*insert)( const struct tnl_clipspace_attr *a, - char *v, const GLfloat *input ); - - void (*extract)( const struct tnl_clipspace_attr *a, - GLfloat *output, const char *v ); - + insert_func *insert; + insert_func emit; + extract_func extract; const GLfloat *vp; }; diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c index 7bdf54bf43b..3ca25395da4 100644 --- a/src/mesa/tnl/t_vb_light.c +++ b/src/mesa/tnl/t_vb_light.c @@ -291,6 +291,11 @@ static GLboolean run_init_lighting( GLcontext *ctx, _mesa_vector4f_alloc( &store->LitIndex[0], 0, size, 32 ); _mesa_vector4f_alloc( &store->LitIndex[1], 0, size, 32 ); + store->LitColor[0].size = 4; + store->LitColor[1].size = 4; + store->LitSecondary[0].size = 3; + store->LitSecondary[1].size = 3; + store->LitIndex[0].size = 1; store->LitIndex[0].stride = sizeof(GLfloat); store->LitIndex[1].size = 1; diff --git a/src/mesa/tnl/t_vb_points.c b/src/mesa/tnl/t_vb_points.c index 7a071ed3739..9ef98fab22f 100644 --- a/src/mesa/tnl/t_vb_points.c +++ b/src/mesa/tnl/t_vb_points.c @@ -65,6 +65,7 @@ static GLboolean run_point_stage( GLcontext *ctx, } VB->PointSizePtr = &store->PointSize; + VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->PointSize; return GL_TRUE; } diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c index ba8a98f6127..62141ad1247 100644 --- a/src/mesa/tnl/t_vb_program.c +++ b/src/mesa/tnl/t_vb_program.c @@ -174,6 +174,7 @@ static GLboolean run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage ) VB->AttribPtr[VERT_ATTRIB_COLOR0] = VB->ColorPtr[0]; VB->AttribPtr[VERT_ATTRIB_COLOR1] = VB->SecondaryColorPtr[0]; VB->AttribPtr[VERT_ATTRIB_FOG] = VB->FogCoordPtr; + VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->attribs[VERT_RESULT_PSIZ]; for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { VB->AttribPtr[VERT_ATTRIB_TEX0+i] = VB->TexCoordPtr[i] = diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c index 6ac9f8a90c5..b10b3c4ce8c 100644 --- a/src/mesa/tnl/t_vertex.c +++ b/src/mesa/tnl/t_vertex.c @@ -44,7 +44,7 @@ #define GET_VERTEX_STATE(ctx) &(TNL_CONTEXT(ctx)->clipspace) -static void insert_4f_viewport( const struct tnl_clipspace_attr *a, char *v, +static void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)v; @@ -56,7 +56,7 @@ static void insert_4f_viewport( const struct tnl_clipspace_attr *a, char *v, out[3] = in[3]; } -static void insert_3f_viewport( const struct tnl_clipspace_attr *a, char *v, +static void insert_4f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)v; @@ -65,9 +65,10 @@ static void insert_3f_viewport( const struct tnl_clipspace_attr *a, char *v, out[0] = vp[0] * in[0] + vp[12]; out[1] = vp[5] * in[1] + vp[13]; out[2] = vp[10] * in[2] + vp[14]; + out[3] = 1; } -static void insert_2f_viewport( const struct tnl_clipspace_attr *a, char *v, +static void insert_4f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)v; @@ -75,10 +76,77 @@ static void insert_2f_viewport( const struct tnl_clipspace_attr *a, char *v, out[0] = vp[0] * in[0] + vp[12]; out[1] = vp[5] * in[1] + vp[13]; + out[2] = vp[14]; + out[3] = 1; } +static void insert_4f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)v; + const GLfloat * const vp = a->vp; + + out[0] = vp[0] * in[0] + vp[12]; + out[1] = vp[13]; + out[2] = vp[14]; + out[3] = 1; +} -static void insert_4f( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ) +static void insert_3f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)v; + const GLfloat * const vp = a->vp; + + out[0] = vp[0] * in[0] + vp[12]; + out[1] = vp[5] * in[1] + vp[13]; + out[2] = vp[10] * in[2] + vp[14]; +} + +static void insert_3f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)v; + const GLfloat * const vp = a->vp; + + out[0] = vp[0] * in[0] + vp[12]; + out[1] = vp[5] * in[1] + vp[13]; + out[2] = vp[10] * in[2] + vp[14]; +} + +static void insert_3f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)v; + const GLfloat * const vp = a->vp; + + out[0] = vp[0] * in[0] + vp[12]; + out[1] = vp[13]; + out[2] = vp[14]; +} + +static void insert_2f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)v; + const GLfloat * const vp = a->vp; + + out[0] = vp[0] * in[0] + vp[12]; + out[1] = vp[5] * in[1] + vp[13]; +} + +static void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)v; + const GLfloat * const vp = a->vp; + + out[0] = vp[0] * in[0] + vp[12]; + out[1] = vp[13]; +} + + +static void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)(v); @@ -88,73 +156,102 @@ static void insert_4f( const struct tnl_clipspace_attr *a, char *v, const GLfloa out[3] = in[3]; } -static void insert_3f_xyw( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ) +static void insert_4f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)(v); out[0] = in[0]; out[1] = in[1]; - out[2] = in[3]; + out[2] = in[2]; + out[3] = 1; } - -static void insert_3f( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ) +static void insert_4f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)(v); out[0] = in[0]; out[1] = in[1]; - out[2] = in[2]; + out[2] = 0; + out[3] = 1; } - -static void insert_2f( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ) +static void insert_4f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)(v); out[0] = in[0]; - out[1] = in[1]; + out[1] = 0; + out[2] = 0; + out[3] = 1; } -static void insert_1f( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ) +static void insert_3f_xyw_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)(v); out[0] = in[0]; + out[1] = in[1]; + out[2] = in[3]; +} + +static void insert_3f_xyw_err( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) +{ + abort(); } -static void insert_3f_pad( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ) +static void insert_3f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)(v); out[0] = in[0]; out[1] = in[1]; out[2] = in[2]; - out[3] = 1; } - -static void insert_2f_pad( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ) +static void insert_3f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)(v); out[0] = in[0]; out[1] = in[1]; out[2] = 0; - out[3] = 1; } -static void insert_1f_pad( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ) +static void insert_3f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLfloat *out = (GLfloat *)(v); out[0] = in[0]; out[1] = 0; out[2] = 0; - out[3] = 1; } -static void insert_4chan_4f_rgba( const struct tnl_clipspace_attr *a, char *v, + +static void insert_2f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)(v); + + out[0] = in[0]; + out[1] = in[1]; +} + +static void insert_2f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)(v); + + out[0] = in[0]; + out[1] = 0; +} + +static void insert_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) +{ + GLfloat *out = (GLfloat *)(v); + + out[0] = in[0]; +} + +static void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { GLchan *c = (GLchan *)v; @@ -164,7 +261,37 @@ static void insert_4chan_4f_rgba( const struct tnl_clipspace_attr *a, char *v, UNCLAMPED_FLOAT_TO_CHAN(c[3], in[3]); } -static void insert_4ub_4f_rgba( const struct tnl_clipspace_attr *a, char *v, +static void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLchan *c = (GLchan *)v; + UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]); + UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]); + UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]); + c[3] = CHAN_MAX; +} + +static void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLchan *c = (GLchan *)v; + UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]); + UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]); + c[2] = 0; + c[3] = CHAN_MAX; +} + +static void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + GLchan *c = (GLchan *)v; + UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]); + c[1] = 0; + c[2] = 0; + c[3] = CHAN_MAX; +} + +static void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); @@ -173,7 +300,34 @@ static void insert_4ub_4f_rgba( const struct tnl_clipspace_attr *a, char *v, UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]); } -static void insert_4ub_4f_bgra( const struct tnl_clipspace_attr *a, char *v, +static void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); + UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); + UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]); + v[3] = 0xff; +} + +static void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); + UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); + v[2] = 0; + v[3] = 0xff; +} + +static void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); + v[1] = 0; + v[2] = 0; + v[3] = 0xff; +} + +static void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); @@ -182,7 +336,34 @@ static void insert_4ub_4f_bgra( const struct tnl_clipspace_attr *a, char *v, UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]); } -static void insert_3ub_3f_rgb( const struct tnl_clipspace_attr *a, char *v, +static void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); + UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); + UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]); + v[3] = 0xff; +} + +static void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); + UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); + v[0] = 0; + v[3] = 0xff; +} + +static void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); + v[1] = 0; + v[0] = 0; + v[3] = 0xff; +} + +static void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); @@ -190,15 +371,48 @@ static void insert_3ub_3f_rgb( const struct tnl_clipspace_attr *a, char *v, UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]); } -static void insert_3ub_3f_bgr( const struct tnl_clipspace_attr *a, char *v, +static void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); + UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); + v[2] = 0; +} + +static void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); + v[1] = 0; + v[2] = 0; +} + +static void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) { UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]); } -static void insert_1ub_1f( const struct tnl_clipspace_attr *a, char *v, +static void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); + UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]); + v[0] = 0; +} + +static void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v, + const GLfloat *in ) +{ + UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]); + v[1] = 0; + v[0]= 0; +} + + +static void insert_1ub_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in ) { UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]); @@ -213,7 +427,7 @@ static void insert_1ub_1f( const struct tnl_clipspace_attr *a, char *v, */ static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ) + const GLubyte *v ) { const GLfloat *in = (const GLfloat *)v; const GLfloat * const vp = a->vp; @@ -225,7 +439,7 @@ static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *ou } static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ) + const GLubyte *v ) { const GLfloat *in = (const GLfloat *)v; const GLfloat * const vp = a->vp; @@ -238,7 +452,7 @@ static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *ou static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ) + const GLubyte *v ) { const GLfloat *in = (const GLfloat *)v; const GLfloat * const vp = a->vp; @@ -250,7 +464,7 @@ static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *ou } -static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const char *v ) +static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) { const GLfloat *in = (const GLfloat *)v; @@ -260,7 +474,7 @@ static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const out[3] = in[3]; } -static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const char *v ) +static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) { const GLfloat *in = (const GLfloat *)v; @@ -271,7 +485,7 @@ static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, co } -static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const char *v ) +static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) { const GLfloat *in = (const GLfloat *)v; @@ -282,7 +496,7 @@ static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const } -static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const char *v ) +static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) { const GLfloat *in = (const GLfloat *)v; @@ -292,7 +506,7 @@ static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const out[3] = 1; } -static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const char *v ) +static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) { const GLfloat *in = (const GLfloat *)v; @@ -303,7 +517,7 @@ static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const } static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ) + const GLubyte *v ) { GLchan *c = (GLchan *)v; @@ -314,7 +528,7 @@ static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat * } static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ) + const GLubyte *v ) { out[0] = UBYTE_TO_FLOAT(v[0]); out[1] = UBYTE_TO_FLOAT(v[1]); @@ -323,7 +537,7 @@ static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *ou } static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ) + const GLubyte *v ) { out[2] = UBYTE_TO_FLOAT(v[0]); out[1] = UBYTE_TO_FLOAT(v[1]); @@ -332,7 +546,7 @@ static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *ou } static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ) + const GLubyte *v ) { out[0] = UBYTE_TO_FLOAT(v[0]); out[1] = UBYTE_TO_FLOAT(v[1]); @@ -341,7 +555,7 @@ static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out } static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ) + const GLubyte *v ) { out[2] = UBYTE_TO_FLOAT(v[0]); out[1] = UBYTE_TO_FLOAT(v[1]); @@ -349,7 +563,7 @@ static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out out[3] = 1; } -static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const char *v ) +static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v ) { out[0] = UBYTE_TO_FLOAT(v[0]); out[1] = 0; @@ -358,86 +572,91 @@ static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, co } -typedef void (*extract_func)( const struct tnl_clipspace_attr *a, GLfloat *out, - const char *v ); - -typedef void (*insert_func)( const struct tnl_clipspace_attr *a, char *v, const GLfloat *in ); - - struct { + const char *name; extract_func extract; - insert_func insert; + insert_func insert[4]; GLuint attrsize; } format_info[EMIT_MAX] = { - { extract_1f, - insert_1f, + { "1f", + extract_1f, + { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 }, sizeof(GLfloat) }, - { extract_2f, - insert_2f, + { "2f", + extract_2f, + { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 }, 2 * sizeof(GLfloat) }, - { extract_3f, - insert_3f, + { "3f", + extract_3f, + { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 }, 3 * sizeof(GLfloat) }, - { extract_4f, - insert_4f, + { "4f", + extract_4f, + { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 }, 4 * sizeof(GLfloat) }, - { extract_2f_viewport, - insert_2f_viewport, + { "2f_viewport", + extract_2f_viewport, + { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2, + insert_2f_viewport_2 }, 2 * sizeof(GLfloat) }, - { extract_3f_viewport, - insert_3f_viewport, + { "3f_viewport", + extract_3f_viewport, + { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3, + insert_3f_viewport_3 }, 3 * sizeof(GLfloat) }, - { extract_4f_viewport, - insert_4f_viewport, + { "4f_viewport", + extract_4f_viewport, + { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3, + insert_4f_viewport_4 }, 4 * sizeof(GLfloat) }, - { extract_3f_xyw, - insert_3f_xyw, + { "3f_xyw", + extract_3f_xyw, + { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err, + insert_3f_xyw_4 }, 3 * sizeof(GLfloat) }, - { extract_1ub_1f, - insert_1ub_1f, + { "1ub_1f", + extract_1ub_1f, + { insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1 }, sizeof(GLubyte) }, - { extract_3ub_3f_rgb, - insert_3ub_3f_rgb, + { "3ub_3f_rgb", + extract_3ub_3f_rgb, + { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3, + insert_3ub_3f_rgb_3 }, 3 * sizeof(GLubyte) }, - { extract_3ub_3f_bgr, - insert_3ub_3f_bgr, + { "3ub_3f_bgr", + extract_3ub_3f_bgr, + { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3, + insert_3ub_3f_bgr_3 }, 3 * sizeof(GLubyte) }, - { extract_4ub_4f_rgba, - insert_4ub_4f_rgba, + { "4ub_4f_rgba", + extract_4ub_4f_rgba, + { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3, + insert_4ub_4f_rgba_4 }, 4 * sizeof(GLubyte) }, - { extract_4ub_4f_bgra, - insert_4ub_4f_bgra, + { "4ub_4f_bgra", + extract_4ub_4f_bgra, + { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3, + insert_4ub_4f_bgra_4 }, 4 * sizeof(GLubyte) }, - { extract_4chan_4f_rgba, - insert_4chan_4f_rgba, - 4 * sizeof(GLchan) }, - - { extract_1f, - insert_1f_pad, - 4 * sizeof(GLfloat) }, - - { extract_2f, - insert_2f_pad, - 4 * sizeof(GLfloat) }, - - { extract_3f, - insert_3f_pad, - 4 * sizeof(GLfloat) }, - + { "4chan_4f_rgba", + extract_4chan_4f_rgba, + { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3, + insert_4chan_4f_rgba_4 }, + 4 * sizeof(GLchan) } }; @@ -454,7 +673,7 @@ static void generic_emit( GLcontext *ctx, struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); struct tnl_clipspace_attr *a = vtx->attr; - char *v = (char *)dest; + GLubyte *v = (GLubyte *)dest; int i, j; GLuint count = vtx->attr_count; GLuint stride; @@ -462,7 +681,8 @@ static void generic_emit( GLcontext *ctx, for (j = 0; j < count; j++) { GLvector4f *vptr = VB->AttribPtr[a[j].attrib]; a[j].inputstride = vptr->stride; - a[j].inputptr = (GLfloat *)STRIDE_4F(vptr->data, start * vptr->stride); + a[j].inputptr = (GLubyte *)STRIDE_4F(vptr->data, start * vptr->stride); + a[j].emit = a[j].insert[vptr->size - 1]; } end -= start; @@ -470,9 +690,9 @@ static void generic_emit( GLcontext *ctx, for (i = 0 ; i < end ; i++, v += stride) { for (j = 0; j < count; j++) { - GLfloat *in = a[j].inputptr; - (char *)a[j].inputptr += a[j].inputstride; - a[j].insert( &a[j], v + a[j].vertoffset, in ); + GLfloat *in = (GLfloat *)a[j].inputptr; + a[j].inputptr += a[j].inputstride; + a[j].emit( &a[j], v + a[j].vertoffset, in ); } } } @@ -486,9 +706,9 @@ static void generic_interp( GLcontext *ctx, TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); - char *vin = vtx->vertex_buf + ein * vtx->vertex_size; - char *vout = vtx->vertex_buf + eout * vtx->vertex_size; - char *vdst = vtx->vertex_buf + edst * vtx->vertex_size; + GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size; + GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size; + GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size; const struct tnl_clipspace_attr *a = vtx->attr; int attr_count = vtx->attr_count; int j; @@ -503,10 +723,10 @@ static void generic_interp( GLcontext *ctx, pos[2] = dstclip[2] * w; pos[3] = w; - a[0].insert( &a[0], vdst, pos ); + a[0].insert[4-1]( &a[0], vdst, pos ); } else { - a[0].insert( &a[0], vdst, VB->ClipPtr->data[edst] ); + a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] ); } @@ -521,7 +741,7 @@ static void generic_interp( GLcontext *ctx, INTERP_F( t, fdst[1], fout[1], fin[1] ); INTERP_F( t, fdst[0], fout[0], fin[0] ); - a[j].insert( &a[j], vdst + a[j].vertoffset, fdst ); + a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst ); } } @@ -532,8 +752,8 @@ static void generic_interp( GLcontext *ctx, static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc ) { struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); - char *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size; - char *vdst = vtx->vertex_buf + edst * vtx->vertex_size; + GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size; + GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size; const struct tnl_clipspace_attr *a = vtx->attr; int attr_count = vtx->attr_count; int j; @@ -575,6 +795,11 @@ static void generic_interp_extras( GLcontext *ctx, VB->SecondaryColorPtr[1]->data[in] ); } } + else if (VB->IndexPtr[1]) { + VB->IndexPtr[1]->data[dst][0] = LINTERP( t, + VB->IndexPtr[1]->data[out][0], + VB->IndexPtr[1]->data[in][0] ); + } if (VB->EdgeFlag) { VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary; @@ -597,6 +822,9 @@ static void generic_copy_pv_extras( GLcontext *ctx, VB->SecondaryColorPtr[1]->data[src] ); } } + else if (VB->IndexPtr[1]) { + VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0]; + } _tnl_copy_pv(ctx, dst, src); } @@ -722,7 +950,8 @@ void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state ) GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map, - GLuint nr, const GLfloat *vp ) + GLuint nr, const GLfloat *vp, + GLuint unpacked_size ) { struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); int offset = 0; @@ -740,19 +969,30 @@ GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map, for (i = 0; i < nr; i++) { GLuint format = map[i].format; vtx->attr[i].attrib = map[i].attrib; -/* vtx->attr[i].format = map[i].format; */ vtx->attr[i].vp = vp; vtx->attr[i].insert = format_info[format].insert; vtx->attr[i].extract = format_info[format].extract; vtx->attr[i].vertattrsize = format_info[format].attrsize; - vtx->attr[i].vertoffset = offset; - offset += format_info[format].attrsize; + if (!unpacked_size) { + vtx->attr[i].vertoffset = offset; + offset += format_info[format].attrsize; + } + else { + vtx->attr[i].vertoffset = map[i].offset; + assert(map[i].offset + format_info[format].attrsize < unpacked_size); + } + + fprintf(stderr, "%d: offset %d, format: %s\n", + i, vtx->attr[i].vertoffset, format_info[format].name); } - assert(offset <= vtx->max_vertex_size); - - vtx->vertex_size = offset; + if (unpacked_size) + vtx->vertex_size = unpacked_size; + else + vtx->vertex_size = offset; + assert(vtx->vertex_size <= vtx->max_vertex_size); + return vtx->vertex_size; } @@ -790,7 +1030,7 @@ void *_tnl_emit_vertices_to_buffer( GLcontext *ctx, { struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); vtx->emit( ctx, start, count, dest ); - return (void *)((char *)dest + vtx->vertex_size * (count - start)); + return (void *)((GLubyte *)dest + vtx->vertex_size * (count - start)); } @@ -800,11 +1040,14 @@ void _tnl_init_vertices( GLcontext *ctx, { struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); - _tnl_install_attrs( ctx, 0, 0, 0 ); + _tnl_install_attrs( ctx, 0, 0, 0, 0 ); vtx->need_extras = GL_TRUE; - vtx->max_vertex_size = max_vertex_size; - vtx->vertex_buf = (char *)ALIGN_MALLOC(vb_size * 4 * 18, max_vertex_size); + if (max_vertex_size > vtx->max_vertex_size) { + _tnl_free_vertices( ctx ); + vtx->max_vertex_size = max_vertex_size; + vtx->vertex_buf = (GLubyte *)ALIGN_MALLOC(vb_size * max_vertex_size, 32 ); + } } diff --git a/src/mesa/tnl/t_vertex.h b/src/mesa/tnl/t_vertex.h index 050f525e295..10d67631c57 100644 --- a/src/mesa/tnl/t_vertex.h +++ b/src/mesa/tnl/t_vertex.h @@ -51,15 +51,13 @@ enum tnl_attr_format { EMIT_4UB_4F_BGRA, /* for color */ EMIT_4UB_4F_RGBA, /* for color */ EMIT_4CHAN_4F_RGBA, /* for swrast color */ - EMIT_1F_PAD_4F, /* for swrast texcoords */ - EMIT_2F_PAD_4F, /* for swrast texcoords */ - EMIT_3F_PAD_4F, /* for swrast texcoords */ EMIT_MAX }; struct tnl_attr_map { GLuint attrib; /* _TNL_ATTRIB_ enum */ enum tnl_attr_format format; + GLuint offset; }; @@ -90,7 +88,9 @@ extern void *_tnl_get_vertex( GLcontext *ctx, GLuint nr ); */ extern GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map, - GLuint nr, const GLfloat *vp ); + GLuint nr, const GLfloat *vp, + GLuint unpacked_size ); +