X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmesa%2Ftnl%2Ft_vb_render.c;h=aff5b9a6832e651f3b6b5e3ac907070d4af57dca;hb=dca350201e00c7cf1cfb009158f4abf27fbc96d2;hp=ec3cb02bb66869dce05d1b7a8a45546f5f7d1831;hpb=24ae7c4c1f18c3086a779a2ee8f480ee5f4e7612;p=mesa.git diff --git a/src/mesa/tnl/t_vb_render.c b/src/mesa/tnl/t_vb_render.c index ec3cb02bb66..aff5b9a6832 100644 --- a/src/mesa/tnl/t_vb_render.c +++ b/src/mesa/tnl/t_vb_render.c @@ -1,10 +1,7 @@ -/* $Id: t_vb_render.c,v 1.21 2001/06/15 15:22:08 brianp Exp $ */ - /* * Mesa 3-D graphics library - * Version: 3.5 * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * 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"), @@ -19,12 +16,13 @@ * 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. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. * * Authors: - * Keith Whitwell + * Keith Whitwell */ @@ -35,28 +33,17 @@ * This file makes calls to project vertices and to the point, line * and triangle rasterizers via the function pointers: * - * context->Driver.BuildProjectedVertices() - * - * context->Driver.PointsFunc() - * context->Driver.LineFunc() - * context->Driver.TriangleFunc() - * context->Driver.QuadFunc() + * context->Driver.Render.* * - * context->Driver.RenderTabVerts[] - * context->Driver.RenderTabElts[] - * - * None of these may be null. */ -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "mem.h" -#include "mtypes.h" -#include "mmath.h" - -#include "math/m_matrix.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/enums.h" +#include "main/macros.h" +#include "main/imports.h" +#include "main/mtypes.h" #include "math/m_xform.h" #include "t_pipeline.h" @@ -68,18 +55,6 @@ /**********************************************************************/ -#if defined(USE_IEEE) -#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31)) -#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31)) -#else -#define NEGATIVE(x) (x < 0) -#define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0) -/* Could just use (x*y<0) except for the flatshading requirements. - * Maybe there's a better way? - */ -#endif - - #define W(i) coord[i][3] #define Z(i) coord[i][2] #define Y(i) coord[i][1] @@ -94,15 +69,19 @@ /* Clip and render whole begin/end objects */ /**********************************************************************/ -#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) +#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL) #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val +/* This does NOT include the CLIP_USER_BIT! */ +#define CLIPMASK (CLIP_FRUSTUM_BITS | CLIP_CULL_BIT) + + /* Vertices, with the possibility of clipping. */ #define RENDER_POINTS( start, count ) \ - tnl->Driver.PointsFunc( ctx, start, count ) + tnl->Driver.Render.Points( ctx, start, count ) #define RENDER_LINE( v1, v2 ) \ do { \ @@ -110,7 +89,7 @@ do { \ GLubyte ormask = c1|c2; \ if (!ormask) \ LineFunc( ctx, v1, v2 ); \ - else if (!(c1 & c2 & 0x3f)) \ + else if (!(c1 & c2 & CLIPMASK)) \ clip_line_4( ctx, v1, v2, ormask ); \ } while (0) @@ -120,7 +99,7 @@ do { \ GLubyte ormask = c1|c2|c3; \ if (!ormask) \ TriangleFunc( ctx, v1, v2, v3 ); \ - else if (!(c1 & c2 & c3 & 0x3f)) \ + else if (!(c1 & c2 & c3 & CLIPMASK)) \ clip_tri_4( ctx, v1, v2, v3, ormask ); \ } while (0) @@ -131,7 +110,7 @@ do { \ GLubyte ormask = c1|c2|c3|c4; \ if (!ormask) \ QuadFunc( ctx, v1, v2, v3, v4 ); \ - else if (!(c1 & c2 & c3 & c4 & 0x3f)) \ + else if (!(c1 & c2 & c3 & c4 & CLIPMASK)) \ clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ } while (0) @@ -142,17 +121,16 @@ do { \ const GLuint * const elt = VB->Elts; \ const GLubyte *mask = VB->ClipMask; \ const GLuint sz = VB->ClipPtr->size; \ - const line_func LineFunc = tnl->Driver.LineFunc; \ - const triangle_func TriangleFunc = tnl->Driver.TriangleFunc; \ - const quad_func QuadFunc = tnl->Driver.QuadFunc; \ + const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ + const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ + const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ const GLboolean stipple = ctx->Line.StippleFlag; \ (void) (LineFunc && TriangleFunc && QuadFunc); \ (void) elt; (void) mask; (void) sz; (void) stipple; #define TAG(x) clip_##x##_verts -#define INIT(x) tnl->Driver.RenderPrimitive( ctx, x ) -#define RESET_STIPPLE if (stipple) tnl->Driver.ResetLineStipple( ctx ) -#define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE +#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) +#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) #define PRESERVE_VB_DEFS #include "t_vb_rendertmp.h" @@ -168,13 +146,13 @@ do { \ /* TODO: do this for all primitives, verts and elts: */ -static void clip_elt_triangles( GLcontext *ctx, +static void clip_elt_triangles( struct gl_context *ctx, GLuint start, GLuint count, GLuint flags ) { TNLcontext *tnl = TNL_CONTEXT(ctx); - render_func render_tris = tnl->Driver.RenderTabElts[GL_TRIANGLES]; + tnl_render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES]; struct vertex_buffer *VB = &tnl->vb; const GLuint * const elt = VB->Elts; GLubyte *mask = VB->ClipMask; @@ -182,7 +160,7 @@ static void clip_elt_triangles( GLcontext *ctx, GLuint j; (void) flags; - tnl->Driver.RenderPrimitive( ctx, GL_TRIANGLES ); + tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES ); for (j=start; j < last; j+=3 ) { GLubyte c1 = mask[elt[j]]; @@ -192,7 +170,7 @@ static void clip_elt_triangles( GLcontext *ctx, if (ormask) { if (start < j) render_tris( ctx, start, j, 0 ); - if (!(c1&c2&c3&0x3f)) + if (!(c1&c2&c3&CLIPMASK)) clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); start = j+3; } @@ -206,7 +184,7 @@ static void clip_elt_triangles( GLcontext *ctx, /* Render whole begin/end objects */ /**********************************************************************/ -#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED) +#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL) #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val @@ -214,7 +192,7 @@ static void clip_elt_triangles( GLcontext *ctx, /* Vertices, no clipping. */ #define RENDER_POINTS( start, count ) \ - tnl->Driver.PointsFunc( ctx, start, count ) + tnl->Driver.Render.Points( ctx, start, count ) #define RENDER_LINE( v1, v2 ) \ LineFunc( ctx, v1, v2 ) @@ -231,15 +209,15 @@ static void clip_elt_triangles( GLcontext *ctx, TNLcontext *tnl = TNL_CONTEXT(ctx); \ struct vertex_buffer *VB = &tnl->vb; \ const GLuint * const elt = VB->Elts; \ - const line_func LineFunc = tnl->Driver.LineFunc; \ - const triangle_func TriangleFunc = tnl->Driver.TriangleFunc; \ - const quad_func QuadFunc = tnl->Driver.QuadFunc; \ + const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ + const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ + const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ + const GLboolean stipple = ctx->Line.StippleFlag; \ (void) (LineFunc && TriangleFunc && QuadFunc); \ - (void) elt; + (void) elt; (void) stipple -#define RESET_STIPPLE tnl->Driver.ResetLineStipple( ctx ) -#define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE -#define INIT(x) tnl->Driver.RenderPrimitive( ctx, x ) +#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) +#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) #define RENDER_TAB_QUALIFIER #define PRESERVE_VB_DEFS #include "t_vb_rendertmp.h" @@ -253,6 +231,27 @@ static void clip_elt_triangles( GLcontext *ctx, #include "t_vb_rendertmp.h" +/**********************************************************************/ +/* Helper functions for drivers */ +/**********************************************************************/ + +void _tnl_RenderClippedPolygon( struct gl_context *ctx, const GLuint *elts, GLuint n ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; + GLuint *tmp = VB->Elts; + + VB->Elts = (GLuint *)elts; + tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); + VB->Elts = tmp; +} + +void _tnl_RenderClippedLine( struct gl_context *ctx, GLuint ii, GLuint jj ) +{ + TNLcontext *tnl = TNL_CONTEXT(ctx); + tnl->Driver.Render.Line( ctx, ii, jj ); +} + /**********************************************************************/ @@ -260,66 +259,72 @@ static void clip_elt_triangles( GLcontext *ctx, /**********************************************************************/ -static GLboolean run_render( GLcontext *ctx, - struct gl_pipeline_stage *stage ) +static GLboolean run_render( struct gl_context *ctx, + struct tnl_pipeline_stage *stage ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; - GLuint new_inputs = stage->changed_inputs; - render_func *tab; + tnl_render_func *tab; GLint pass = 0; - /* Allow the drivers to lock before projected verts are built so * that window coordinates are guarenteed not to change before * rendering. */ - ASSERT(tnl->Driver.RenderStart); + ASSERT(tnl->Driver.Render.Start); - tnl->Driver.RenderStart( ctx ); + tnl->Driver.Render.Start( ctx ); - ASSERT(tnl->Driver.BuildProjectedVertices); - ASSERT(tnl->Driver.RenderPrimitive); - ASSERT(tnl->Driver.PointsFunc); - ASSERT(tnl->Driver.LineFunc); - ASSERT(tnl->Driver.TriangleFunc); - ASSERT(tnl->Driver.QuadFunc); - ASSERT(tnl->Driver.ResetLineStipple); - ASSERT(tnl->Driver.RenderInterp); - ASSERT(tnl->Driver.RenderCopyPV); - ASSERT(tnl->Driver.RenderClippedLine); - ASSERT(tnl->Driver.RenderClippedPolygon); - ASSERT(tnl->Driver.RenderFinish); + ASSERT(tnl->Driver.Render.BuildVertices); + ASSERT(tnl->Driver.Render.PrimitiveNotify); + ASSERT(tnl->Driver.Render.Points); + ASSERT(tnl->Driver.Render.Line); + ASSERT(tnl->Driver.Render.Triangle); + ASSERT(tnl->Driver.Render.Quad); + ASSERT(tnl->Driver.Render.ResetLineStipple); + ASSERT(tnl->Driver.Render.Interp); + ASSERT(tnl->Driver.Render.CopyPV); + ASSERT(tnl->Driver.Render.ClippedLine); + ASSERT(tnl->Driver.Render.ClippedPolygon); + ASSERT(tnl->Driver.Render.Finish); - tnl->Driver.BuildProjectedVertices( ctx, 0, VB->Count, new_inputs ); + tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 ); if (VB->ClipOrMask) { tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; } else { - tab = VB->Elts ? tnl->Driver.RenderTabElts : tnl->Driver.RenderTabVerts; + tab = (VB->Elts ? + tnl->Driver.Render.PrimTabElts : + tnl->Driver.Render.PrimTabVerts); } do { - GLuint i, length, flags = 0; - for (i = 0 ; !(flags & PRIM_LAST) ; i += length) + GLuint i; + + for (i = 0 ; i < VB->PrimitiveCount ; i++) { - flags = VB->Primitive[i]; - length= VB->PrimitiveLength[i]; - ASSERT(length || (flags & PRIM_LAST)); - ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1); + GLuint prim = _tnl_translate_prim(&VB->Primitive[i]); + GLuint start = VB->Primitive[i].start; + GLuint length = VB->Primitive[i].count; + + assert((prim & PRIM_MODE_MASK) <= GL_POLYGON); + + if (MESA_VERBOSE & VERBOSE_PRIMS) + _mesa_debug(NULL, "MESA prim %s %d..%d\n", + _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK), + start, start+length); + if (length) - tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags ); + tab[prim & PRIM_MODE_MASK]( ctx, start, start + length, prim ); } - } while (tnl->Driver.MultipassFunc && - tnl->Driver.MultipassFunc( ctx, ++pass )); + } while (tnl->Driver.Render.Multipass && + tnl->Driver.Render.Multipass( ctx, ++pass )); + tnl->Driver.Render.Finish( ctx ); - tnl->Driver.RenderFinish( ctx ); -/* _swrast_flush(ctx); */ -/* usleep(1000000); */ return GL_FALSE; /* finished the pipe */ } @@ -330,73 +335,14 @@ static GLboolean run_render( GLcontext *ctx, -/* Quite a bit of work involved in finding out the inputs for the - * render stage. - */ -static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage ) -{ - GLuint inputs = VERT_CLIP; - GLuint i; - - if (ctx->Visual.rgbMode) { - inputs |= VERT_RGBA; - - if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) - inputs |= VERT_SPEC_RGB; - - if (ctx->Texture._ReallyEnabled) { - for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) { - if (ctx->Texture.Unit[i]._ReallyEnabled) - inputs |= VERT_TEX(i); - } - } - } - else { - inputs |= VERT_INDEX; - } - - if (ctx->Point._Attenuated) - inputs |= VERT_POINT_SIZE; - - /* How do drivers turn this off? - */ - if (ctx->Fog.Enabled) - inputs |= VERT_FOG_COORD; - - if (ctx->_TriangleCaps & DD_TRI_UNFILLED) - inputs |= VERT_EDGE; - - if (ctx->RenderMode==GL_FEEDBACK) - inputs |= VERT_TEX_ANY; - - stage->inputs = inputs; -} - - - - -static void dtr( struct gl_pipeline_stage *stage ) -{ -} -const struct gl_pipeline_stage _tnl_render_stage = +const struct tnl_pipeline_stage _tnl_render_stage = { - "render", - (_NEW_BUFFERS | - _DD_NEW_SEPARATE_SPECULAR | - _DD_NEW_FLATSHADE | - _NEW_TEXTURE| - _NEW_LIGHT| - _NEW_POINT| - _NEW_FOG| - _DD_NEW_TRI_UNFILLED | - _NEW_RENDERMODE), /* re-check (new inputs, interp function) */ - 0, /* re-run (always runs) */ - GL_TRUE, /* active */ - 0, 0, /* inputs (set in check_render), outputs */ - 0, 0, /* changed_inputs, private */ - dtr, /* destructor */ - check_render, /* check */ + "render", /* name */ + NULL, /* private data */ + NULL, /* creator */ + NULL, /* destructor */ + NULL, /* validate */ run_render /* run */ };