1cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/* 2cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Mesa 3-D graphics library 36e4f594a02fc384b17d5732be652d7d28618aec2Brian Paul * Version: 6.5 4cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 56e4f594a02fc384b17d5732be652d7d28618aec2Brian Paul * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. 6cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 7cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 8cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * copy of this software and associated documentation files (the "Software"), 9cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * to deal in the Software without restriction, including without limitation 10cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * and/or sell copies of the Software, and to permit persons to whom the 12cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Software is furnished to do so, subject to the following conditions: 13cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 14cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * The above copyright notice and this permission notice shall be included 15cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * in all copies or substantial portions of the Software. 16cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 17cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2358e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell * 2422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * Authors: 2505a4b37707d2c598ea68c05d07a3d65bcbf5a076Brian Paul * Keith Whitwell <keith@tungstengraphics.com> 26cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 27cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 28cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 29cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/* 30cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Render whole vertex buffers, including projection of vertices from 31cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * clip space and clipping of primitives. 32cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 33cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * This file makes calls to project vertices and to the point, line 34cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * and triangle rasterizers via the function pointers: 35cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 361182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell * context->Driver.Render.* 3758e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell * 38cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 39cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 40cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 41bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/glheader.h" 42bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/context.h" 43bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/enums.h" 44bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/macros.h" 45bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/imports.h" 46bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/mtypes.h" 47f4511c4835879090ce7e6afe3ac26b98fb91899aVinson Lee#include "math/m_xform.h" 48cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 49cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "t_pipeline.h" 50cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 51cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 52cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 53cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/**********************************************************************/ 54cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/* Clip single primitives */ 55cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/**********************************************************************/ 56cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 57cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 58cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define W(i) coord[i][3] 59cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define Z(i) coord[i][2] 60cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define Y(i) coord[i][1] 61cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define X(i) coord[i][0] 62cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define SIZE 4 63cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define TAG(x) x##_4 64cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "t_vb_cliptmp.h" 65cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 66cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 67cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 68cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/**********************************************************************/ 6958e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell/* Clip and render whole begin/end objects */ 70cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/**********************************************************************/ 71cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 7229b4076f9acff96a867760fc885f5eaeb7586977Brian Paul#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL) 7358e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] 7458e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val 75cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 76cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 7751faca127005c41277df76bc8eafc8fd64ca0673Brian Paul/* This does NOT include the CLIP_USER_BIT! */ 7851faca127005c41277df76bc8eafc8fd64ca0673Brian Paul#define CLIPMASK (CLIP_FRUSTUM_BITS | CLIP_CULL_BIT) 79352d4dbfb24c65f327759c00c7db7d30a9482e35Keith Whitwell 80352d4dbfb24c65f327759c00c7db7d30a9482e35Keith Whitwell 8158e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell/* Vertices, with the possibility of clipping. 82cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 83cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define RENDER_POINTS( start, count ) \ 841182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Points( ctx, start, count ) 85cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 8658e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define RENDER_LINE( v1, v2 ) \ 8758e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwelldo { \ 8858e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell GLubyte c1 = mask[v1], c2 = mask[v2]; \ 8958e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell GLubyte ormask = c1|c2; \ 9058e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell if (!ormask) \ 9158e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell LineFunc( ctx, v1, v2 ); \ 92352d4dbfb24c65f327759c00c7db7d30a9482e35Keith Whitwell else if (!(c1 & c2 & CLIPMASK)) \ 935c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell clip_line_4( ctx, v1, v2, ormask ); \ 9458e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell} while (0) 95cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 9658e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define RENDER_TRI( v1, v2, v3 ) \ 97cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwelldo { \ 9858e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell GLubyte c1 = mask[v1], c2 = mask[v2], c3 = mask[v3]; \ 9958e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell GLubyte ormask = c1|c2|c3; \ 10058e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell if (!ormask) \ 10158e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell TriangleFunc( ctx, v1, v2, v3 ); \ 102352d4dbfb24c65f327759c00c7db7d30a9482e35Keith Whitwell else if (!(c1 & c2 & c3 & CLIPMASK)) \ 1035c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell clip_tri_4( ctx, v1, v2, v3, ormask ); \ 104cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} while (0) 105cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 10658e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define RENDER_QUAD( v1, v2, v3, v4 ) \ 10758e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwelldo { \ 10858e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell GLubyte c1 = mask[v1], c2 = mask[v2]; \ 10958e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell GLubyte c3 = mask[v3], c4 = mask[v4]; \ 11058e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell GLubyte ormask = c1|c2|c3|c4; \ 11158e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell if (!ormask) \ 11258e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell QuadFunc( ctx, v1, v2, v3, v4 ); \ 113352d4dbfb24c65f327759c00c7db7d30a9482e35Keith Whitwell else if (!(c1 & c2 & c3 & c4 & CLIPMASK)) \ 1145c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ 11558e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell} while (0) 116cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 117cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 118709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell#define LOCAL_VARS \ 119709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); \ 120709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell struct vertex_buffer *VB = &tnl->vb; \ 121709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell const GLuint * const elt = VB->Elts; \ 122709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell const GLubyte *mask = VB->ClipMask; \ 123709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell const GLuint sz = VB->ClipPtr->size; \ 1243d38361b718d490e1e7fda64519952ec887cd149Keith Whitwell const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ 1253d38361b718d490e1e7fda64519952ec887cd149Keith Whitwell const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ 1263d38361b718d490e1e7fda64519952ec887cd149Keith Whitwell const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ 127709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell const GLboolean stipple = ctx->Line.StippleFlag; \ 128709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell (void) (LineFunc && TriangleFunc && QuadFunc); \ 129709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell (void) elt; (void) mask; (void) sz; (void) stipple; 13058e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell 13158e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define TAG(x) clip_##x##_verts 1321182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) 1330cb28418d06c30e431bdff515c1d36a812d5950dKeith Whitwell#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) 134cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define PRESERVE_VB_DEFS 135cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "t_vb_rendertmp.h" 136cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 137cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 13858e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell 13958e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell/* Elts, with the possibility of clipping. 140cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 141cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#undef ELT 142cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#undef TAG 143cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define ELT(x) elt[x] 14458e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define TAG(x) clip_##x##_elts 145cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "t_vb_rendertmp.h" 146cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 1475c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell/* TODO: do this for all primitives, verts and elts: 1485c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell */ 149f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void clip_elt_triangles( struct gl_context *ctx, 1505c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell GLuint start, 1515c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell GLuint count, 1525c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell GLuint flags ) 1535c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell{ 154709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 1553d38361b718d490e1e7fda64519952ec887cd149Keith Whitwell tnl_render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES]; 156709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell struct vertex_buffer *VB = &tnl->vb; 1575c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell const GLuint * const elt = VB->Elts; 1585c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell GLubyte *mask = VB->ClipMask; 159709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell GLuint last = count-2; 160709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell GLuint j; 1615c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell (void) flags; 16222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes 1631182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES ); 1645c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell 1655c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell for (j=start; j < last; j+=3 ) { 1665c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell GLubyte c1 = mask[elt[j]]; 1675c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell GLubyte c2 = mask[elt[j+1]]; 1685c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell GLubyte c3 = mask[elt[j+2]]; 1695c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell GLubyte ormask = c1|c2|c3; 1705c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell if (ormask) { 17122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes if (start < j) 1725c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell render_tris( ctx, start, j, 0 ); 173352d4dbfb24c65f327759c00c7db7d30a9482e35Keith Whitwell if (!(c1&c2&c3&CLIPMASK)) 1745c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); 1755c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell start = j+3; 1765c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell } 1775c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell } 1785c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell 17922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes if (start < j) 1805c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell render_tris( ctx, start, j, 0 ); 1815c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell} 182cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 18358e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell/**********************************************************************/ 18458e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell/* Render whole begin/end objects */ 18558e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell/**********************************************************************/ 186cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 18729b4076f9acff96a867760fc885f5eaeb7586977Brian Paul#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL) 18858e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define EDGEFLAG_GET(idx) VB->EdgeFlag[idx] 18958e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val 190cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 19158e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell 19258e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell/* Vertices, no clipping. 193cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 19458e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define RENDER_POINTS( start, count ) \ 1951182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Points( ctx, start, count ) 196cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 19758e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define RENDER_LINE( v1, v2 ) \ 19858e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell LineFunc( ctx, v1, v2 ) 199cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 2002448fc7deeaa870d879de17158f243f239c05b15Keith Whitwell#define RENDER_TRI( v1, v2, v3 ) \ 20158e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell TriangleFunc( ctx, v1, v2, v3 ) 202cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 2032448fc7deeaa870d879de17158f243f239c05b15Keith Whitwell#define RENDER_QUAD( v1, v2, v3, v4 ) \ 20458e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell QuadFunc( ctx, v1, v2, v3, v4 ) 205cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 20658e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define TAG(x) _tnl_##x##_verts 207cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 208709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell#define LOCAL_VARS \ 209709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); \ 210709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell struct vertex_buffer *VB = &tnl->vb; \ 211709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell const GLuint * const elt = VB->Elts; \ 2123d38361b718d490e1e7fda64519952ec887cd149Keith Whitwell const tnl_line_func LineFunc = tnl->Driver.Render.Line; \ 2133d38361b718d490e1e7fda64519952ec887cd149Keith Whitwell const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \ 2143d38361b718d490e1e7fda64519952ec887cd149Keith Whitwell const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \ 215aa46094ca671a9a110338c4649a9f28bad83f5b9Keith Whitwell const GLboolean stipple = ctx->Line.StippleFlag; \ 216709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell (void) (LineFunc && TriangleFunc && QuadFunc); \ 217aa46094ca671a9a110338c4649a9f28bad83f5b9Keith Whitwell (void) elt; (void) stipple 218709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell 2190cb28418d06c30e431bdff515c1d36a812d5950dKeith Whitwell#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx ) 2201182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x ) 22122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes#define RENDER_TAB_QUALIFIER 222cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define PRESERVE_VB_DEFS 223cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "t_vb_rendertmp.h" 224cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 225cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 22658e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell/* Elts, no clipping. 227cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 228cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#undef ELT 22958e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell#define TAG(x) _tnl_##x##_elts 230cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#define ELT(x) elt[x] 231cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "t_vb_rendertmp.h" 232cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 233cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 2341182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell/**********************************************************************/ 2351182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell/* Helper functions for drivers */ 2361182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell/**********************************************************************/ 2371182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell 238f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid _tnl_RenderClippedPolygon( struct gl_context *ctx, const GLuint *elts, GLuint n ) 2391182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell{ 2401182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 2411182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell struct vertex_buffer *VB = &tnl->vb; 2421182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell GLuint *tmp = VB->Elts; 2431182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell 2441182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell VB->Elts = (GLuint *)elts; 2451182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); 2461182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell VB->Elts = tmp; 2471182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell} 2481182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell 249f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid _tnl_RenderClippedLine( struct gl_context *ctx, GLuint ii, GLuint jj ) 2501182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell{ 2511182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 2521182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Line( ctx, ii, jj ); 2531182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell} 2541182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell 255cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 25658e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell 257cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/**********************************************************************/ 258cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/* Clip and render whole vertex buffers */ 259cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/**********************************************************************/ 260cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 261cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 262f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic GLboolean run_render( struct gl_context *ctx, 263ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell struct tnl_pipeline_stage *stage ) 264cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell{ 265cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 26622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes struct vertex_buffer *VB = &tnl->vb; 2673d38361b718d490e1e7fda64519952ec887cd149Keith Whitwell tnl_render_func *tab; 268cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell GLint pass = 0; 269cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 27058e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell /* Allow the drivers to lock before projected verts are built so 27158e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell * that window coordinates are guarenteed not to change before 27258e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell * rendering. 27358e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell */ 2741182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.Start); 275709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell 2761182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Start( ctx ); 277709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell 2781182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.BuildVertices); 2791182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.PrimitiveNotify); 2801182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.Points); 2811182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.Line); 2821182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.Triangle); 2831182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.Quad); 2841182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.ResetLineStipple); 2851182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.Interp); 2861182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.CopyPV); 2871182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.ClippedLine); 2881182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.ClippedPolygon); 2891182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell ASSERT(tnl->Driver.Render.Finish); 290709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell 2916f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 ); 2925c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell 29358e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell if (VB->ClipOrMask) { 29458e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; 2955c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; 296cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 29758e991705392a2e17a1c8b034f4083a0adaf1943Keith Whitwell else { 2981182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tab = (VB->Elts ? 2991182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.PrimTabElts : 3001182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.PrimTabVerts); 30122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes } 302cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 303cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell do 304cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell { 3058236a534b7c31b5d3b688323de05cfa5e446f70dBrian Paul GLuint i; 306ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell 307ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell for (i = 0 ; i < VB->PrimitiveCount ; i++) 308cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell { 309b1f176039ae3690b38e3ccacb079b3d7c3e50402Keith Whitwell GLuint prim = _tnl_translate_prim(&VB->Primitive[i]); 310ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell GLuint start = VB->Primitive[i].start; 311ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell GLuint length = VB->Primitive[i].count; 312ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell 3130ad64faec79770ad97044257ab1baf0675187aeaBrian Paul assert((prim & PRIM_MODE_MASK) <= GL_POLYGON); 314306d3fcdbad523428501833405e47e9897896defKeith Whitwell 315ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell if (MESA_VERBOSE & VERBOSE_PRIMS) 3164e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul _mesa_debug(NULL, "MESA prim %s %d..%d\n", 317ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK), 318ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell start, start+length); 319306d3fcdbad523428501833405e47e9897896defKeith Whitwell 320cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (length) 321ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell tab[prim & PRIM_MODE_MASK]( ctx, start, start + length, prim ); 322cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell } 3231182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell } while (tnl->Driver.Render.Multipass && 3241182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Multipass( ctx, ++pass )); 325cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 3261182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Finish( ctx ); 327ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell 328cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return GL_FALSE; /* finished the pipe */ 329cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell} 330cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 331cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 332cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/**********************************************************************/ 333cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/* Render pipeline stage */ 334cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/**********************************************************************/ 335cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 336cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 337cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 338cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 339cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 340ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwellconst struct tnl_pipeline_stage _tnl_render_stage = 34122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes{ 34286b842790b720cd6b1499ce8edca8a4e9c8dc029Brian Paul "render", /* name */ 34386b842790b720cd6b1499ce8edca8a4e9c8dc029Brian Paul NULL, /* private data */ 3446f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell NULL, /* creator */ 3456f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell NULL, /* destructor */ 3466f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell NULL, /* validate */ 347cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell run_render /* run */ 348cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell}; 349