17c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell/* 27c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * Mesa 3-D graphics library 3a7008322146f589ed5cb7a563365ff5e31844c62Brian * Version: 7.1 422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 5335769a875d653f6076e653d3f63c6a4ba64dba2Brian * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 77c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 87c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * copy of this software and associated documentation files (the "Software"), 97c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * to deal in the Software without restriction, including without limitation 107c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense, 117c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the 127c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * Software is furnished to do so, subject to the following conditions: 1322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 147c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * The above copyright notice and this permission notice shall be included 157c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * in all copies or substantial portions of the Software. 1622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 177c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 187c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 197c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 207c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 217c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 227c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 237c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * 247c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell * Authors: 2505a4b37707d2c598ea68c05d07a3d65bcbf5a076Brian Paul * Keith Whitwell <keith@tungstengraphics.com> 267c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell */ 277c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 28bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/glheader.h" 29bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/imports.h" 30bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "main/colormac.h" 311182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell#include "tnl/tnl.h" 3223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "tnl/t_context.h" 331182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell#include "tnl/t_pipeline.h" 34790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell#include "tnl/t_vertex.h" 35bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "swrast_setup.h" 36bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "ss_context.h" 37bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul#include "ss_triangle.h" 38bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul 397c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 40609f35274c9dcf8607673ec1970efff583c97ed7Brian Paul/* Need to check lighting state and vertex program state to know 41609f35274c9dcf8607673ec1970efff583c97ed7Brian Paul * if two-sided lighting is in effect. 42609f35274c9dcf8607673ec1970efff583c97ed7Brian Paul */ 43609f35274c9dcf8607673ec1970efff583c97ed7Brian Paul#define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT|_NEW_PROGRAM) 447c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 457c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 46d6aff512feb102eacb41b36e9f9e750d94c299afBrian#define VARYING_EMIT_STYLE EMIT_4F 47d6aff512feb102eacb41b36e9f9e750d94c299afBrian 48d6aff512feb102eacb41b36e9f9e750d94c299afBrian 497c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith WhitwellGLboolean 50f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swsetup_CreateContext( struct gl_context *ctx ) 517c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell{ 527c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext)); 5322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes 5422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes if (!swsetup) 557c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell return GL_FALSE; 567c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 577c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell ctx->swsetup_context = swsetup; 587c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 597c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell swsetup->NewState = ~0; 607c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell _swsetup_trifuncs_init( ctx ); 61cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 62588225770c60834dfd2a95850435cc549167dc05Keith Whitwell _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, 63588225770c60834dfd2a95850435cc549167dc05Keith Whitwell sizeof(SWvertex) ); 64588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 65588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 667c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell return GL_TRUE; 677c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell} 687c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 697c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwellvoid 70f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swsetup_DestroyContext( struct gl_context *ctx ) 717c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell{ 7253560311294814ae0daa8457307a2b25077bf4e9Keith Whitwell SScontext *swsetup = SWSETUP_CONTEXT(ctx); 7353560311294814ae0daa8457307a2b25077bf4e9Keith Whitwell 7453560311294814ae0daa8457307a2b25077bf4e9Keith Whitwell if (swsetup) { 7553560311294814ae0daa8457307a2b25077bf4e9Keith Whitwell FREE(swsetup); 767c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell ctx->swsetup_context = 0; 777c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell } 78588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 79588225770c60834dfd2a95850435cc549167dc05Keith Whitwell _tnl_free_vertices( ctx ); 807c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell} 817c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 821182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwellstatic void 83f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swsetup_RenderPrimitive( struct gl_context *ctx, GLenum mode ) 84d43a5943d8952367d9292653800b47a85f905343Keith Whitwell{ 85d43a5943d8952367d9292653800b47a85f905343Keith Whitwell SWSETUP_CONTEXT(ctx)->render_prim = mode; 86f782b8189e718974a40d72ac4f6b8d213ca99e1eBrian Paul _swrast_render_primitive( ctx, mode ); 87d43a5943d8952367d9292653800b47a85f905343Keith Whitwell} 88d43a5943d8952367d9292653800b47a85f905343Keith Whitwell 89335769a875d653f6076e653d3f63c6a4ba64dba2Brian 90335769a875d653f6076e653d3f63c6a4ba64dba2Brian/** 91335769a875d653f6076e653d3f63c6a4ba64dba2Brian * Helper macros for setup_vertex_format() 92335769a875d653f6076e653d3f63c6a4ba64dba2Brian */ 93588225770c60834dfd2a95850435cc549167dc05Keith Whitwell#define SWZ ((SWvertex *)0) 94588225770c60834dfd2a95850435cc549167dc05Keith Whitwell#define SWOffset(MEMBER) (((char *)&(SWZ->MEMBER)) - ((char *)SWZ)) 95588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 96588225770c60834dfd2a95850435cc549167dc05Keith Whitwell#define EMIT_ATTR( ATTR, STYLE, MEMBER ) \ 97588225770c60834dfd2a95850435cc549167dc05Keith Whitwelldo { \ 98588225770c60834dfd2a95850435cc549167dc05Keith Whitwell map[e].attrib = (ATTR); \ 99588225770c60834dfd2a95850435cc549167dc05Keith Whitwell map[e].format = (STYLE); \ 100588225770c60834dfd2a95850435cc549167dc05Keith Whitwell map[e].offset = SWOffset(MEMBER); \ 101588225770c60834dfd2a95850435cc549167dc05Keith Whitwell e++; \ 102588225770c60834dfd2a95850435cc549167dc05Keith Whitwell} while (0) 103588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 104335769a875d653f6076e653d3f63c6a4ba64dba2Brian 105335769a875d653f6076e653d3f63c6a4ba64dba2Brian/** 106335769a875d653f6076e653d3f63c6a4ba64dba2Brian * Tell the tnl module how to build SWvertex objects for swrast. 107335769a875d653f6076e653d3f63c6a4ba64dba2Brian * We'll build the map[] array with that info and pass it to 108335769a875d653f6076e653d3f63c6a4ba64dba2Brian * _tnl_install_attrs(). 109f782b8189e718974a40d72ac4f6b8d213ca99e1eBrian Paul */ 1101182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwellstatic void 111f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergsetup_vertex_format(struct gl_context *ctx) 11222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes{ 113588225770c60834dfd2a95850435cc549167dc05Keith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 114335769a875d653f6076e653d3f63c6a4ba64dba2Brian SScontext *swsetup = SWSETUP_CONTEXT(ctx); 1155462d447aa5bce9e558594eabeddd624cd39b1deBrian Paul GLboolean intColors = !ctx->FragmentProgram._Current 1165462d447aa5bce9e558594eabeddd624cd39b1deBrian Paul && !ctx->ATIFragmentShader._Enabled 1175462d447aa5bce9e558594eabeddd624cd39b1deBrian Paul && ctx->RenderMode == GL_RENDER 118e3d8d25ebf4e052432f13513d03a420bc22d399dBrian Paul && CHAN_TYPE != GL_FLOAT; 119588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 1205462d447aa5bce9e558594eabeddd624cd39b1deBrian Paul if (intColors != swsetup->intColors || 121ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich tnl->render_inputs_bitset != swsetup->last_index_bitset) { 122ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich GLbitfield64 index_bitset = tnl->render_inputs_bitset; 123588225770c60834dfd2a95850435cc549167dc05Keith Whitwell struct tnl_attr_map map[_TNL_ATTRIB_MAX]; 124b30898f4ab533085d97a33638ad0a1cf9ddb1d67Karl Schultz unsigned int i, e = 0; 125588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 1265462d447aa5bce9e558594eabeddd624cd39b1deBrian Paul swsetup->intColors = intColors; 1275462d447aa5bce9e558594eabeddd624cd39b1deBrian Paul 1289e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, attrib[FRAG_ATTRIB_WPOS] ); 1299e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian 130ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_COLOR0)) { 131a7008322146f589ed5cb7a563365ff5e31844c62Brian if (swsetup->intColors) 1329e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color ); 133a7008322146f589ed5cb7a563365ff5e31844c62Brian else 134a7008322146f589ed5cb7a563365ff5e31844c62Brian EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4F, attrib[FRAG_ATTRIB_COL0]); 1359e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian } 136bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol 137ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_COLOR1)) { 1389e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4F, attrib[FRAG_ATTRIB_COL1]); 1399e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian } 140bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol 141ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_FOG)) { 142bcc3baadbafc3f3deb79e3a753d9ee3867917073Brian const GLint emit = ctx->FragmentProgram._Current ? EMIT_4F : EMIT_1F; 143bcc3baadbafc3f3deb79e3a753d9ee3867917073Brian EMIT_ATTR( _TNL_ATTRIB_FOG, emit, attrib[FRAG_ATTRIB_FOGC]); 144bcc3baadbafc3f3deb79e3a753d9ee3867917073Brian } 145bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol 146ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich if (index_bitset & BITFIELD64_RANGE(_TNL_ATTRIB_TEX0, _TNL_NUM_TEX)) 147335769a875d653f6076e653d3f63c6a4ba64dba2Brian { 148bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { 149ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_TEX(i))) { 150335769a875d653f6076e653d3f63c6a4ba64dba2Brian EMIT_ATTR( _TNL_ATTRIB_TEX(i), EMIT_4F, 151335769a875d653f6076e653d3f63c6a4ba64dba2Brian attrib[FRAG_ATTRIB_TEX0 + i] ); 152bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol } 153bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol } 154588225770c60834dfd2a95850435cc549167dc05Keith Whitwell } 155bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol 156d6aff512feb102eacb41b36e9f9e750d94c299afBrian /* shader varying vars */ 157ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich if (index_bitset & BITFIELD64_RANGE(_TNL_ATTRIB_GENERIC0, _TNL_NUM_GENERIC)) { 158d6aff512feb102eacb41b36e9f9e750d94c299afBrian for (i = 0; i < ctx->Const.MaxVarying; i++) { 159ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_GENERIC(i))) { 160d6aff512feb102eacb41b36e9f9e750d94c299afBrian EMIT_ATTR( _TNL_ATTRIB_GENERIC(i), VARYING_EMIT_STYLE, 161dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian attrib[FRAG_ATTRIB_VAR0 + i] ); 162d6aff512feb102eacb41b36e9f9e750d94c299afBrian } 163d6aff512feb102eacb41b36e9f9e750d94c299afBrian } 164bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol } 165bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol 166ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich if (index_bitset & BITFIELD64_BIT(_TNL_ATTRIB_POINTSIZE)) 167bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize ); 168bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol 169588225770c60834dfd2a95850435cc549167dc05Keith Whitwell _tnl_install_attrs( ctx, map, e, 170bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol ctx->Viewport._WindowMap.m, 171bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol sizeof(SWvertex) ); 172588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 173ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich swsetup->last_index_bitset = index_bitset; 174bb38cadb1c5f2dc13096a091bdaf61dc3e3cfa4dMichal Krol } 175d43a5943d8952367d9292653800b47a85f905343Keith Whitwell} 176d43a5943d8952367d9292653800b47a85f905343Keith Whitwell 177335769a875d653f6076e653d3f63c6a4ba64dba2Brian 178335769a875d653f6076e653d3f63c6a4ba64dba2Brian/** 179335769a875d653f6076e653d3f63c6a4ba64dba2Brian * Prepare to render a vertex buffer. 180335769a875d653f6076e653d3f63c6a4ba64dba2Brian * Called via tnl->Driver.Render.Start. 181335769a875d653f6076e653d3f63c6a4ba64dba2Brian */ 182335769a875d653f6076e653d3f63c6a4ba64dba2Brianstatic void 183f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swsetup_RenderStart( struct gl_context *ctx ) 184335769a875d653f6076e653d3f63c6a4ba64dba2Brian{ 185335769a875d653f6076e653d3f63c6a4ba64dba2Brian SScontext *swsetup = SWSETUP_CONTEXT(ctx); 186335769a875d653f6076e653d3f63c6a4ba64dba2Brian TNLcontext *tnl = TNL_CONTEXT(ctx); 187335769a875d653f6076e653d3f63c6a4ba64dba2Brian struct vertex_buffer *VB = &tnl->vb; 188335769a875d653f6076e653d3f63c6a4ba64dba2Brian 189335769a875d653f6076e653d3f63c6a4ba64dba2Brian if (swsetup->NewState & _SWSETUP_NEW_RENDERINDEX) { 190335769a875d653f6076e653d3f63c6a4ba64dba2Brian _swsetup_choose_trifuncs(ctx); 191335769a875d653f6076e653d3f63c6a4ba64dba2Brian } 192335769a875d653f6076e653d3f63c6a4ba64dba2Brian 1939e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian if (swsetup->NewState & _NEW_PROGRAM) { 194ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich swsetup->last_index_bitset = 0; 1959e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian } 1969e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian 197335769a875d653f6076e653d3f63c6a4ba64dba2Brian swsetup->NewState = 0; 198335769a875d653f6076e653d3f63c6a4ba64dba2Brian 199fcd7c37fd3d0f61cf6ac81170bc0b3fca64ad9bbBrian /* This will change if drawing unfilled tris */ 200fcd7c37fd3d0f61cf6ac81170bc0b3fca64ad9bbBrian _swrast_SetFacing(ctx, 0); 201fcd7c37fd3d0f61cf6ac81170bc0b3fca64ad9bbBrian 202335769a875d653f6076e653d3f63c6a4ba64dba2Brian _swrast_render_start(ctx); 203335769a875d653f6076e653d3f63c6a4ba64dba2Brian 204335769a875d653f6076e653d3f63c6a4ba64dba2Brian /* Important */ 205335769a875d653f6076e653d3f63c6a4ba64dba2Brian VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; 206335769a875d653f6076e653d3f63c6a4ba64dba2Brian 207335769a875d653f6076e653d3f63c6a4ba64dba2Brian setup_vertex_format(ctx); 208335769a875d653f6076e653d3f63c6a4ba64dba2Brian} 209335769a875d653f6076e653d3f63c6a4ba64dba2Brian 210335769a875d653f6076e653d3f63c6a4ba64dba2Brian 211f782b8189e718974a40d72ac4f6b8d213ca99e1eBrian Paul/* 212f782b8189e718974a40d72ac4f6b8d213ca99e1eBrian Paul * We patch this function into tnl->Driver.Render.Finish. 213f782b8189e718974a40d72ac4f6b8d213ca99e1eBrian Paul * It's called when we finish rendering a vertex buffer. 214f782b8189e718974a40d72ac4f6b8d213ca99e1eBrian Paul */ 2151182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwellstatic void 216f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swsetup_RenderFinish( struct gl_context *ctx ) 217d43a5943d8952367d9292653800b47a85f905343Keith Whitwell{ 218a9be374f82ace523c126c661399030c869201dabBrian Paul _swrast_render_finish( ctx ); 219d43a5943d8952367d9292653800b47a85f905343Keith Whitwell} 2207c20642b1091df1aab7d9076a3fe2fb11c6f011cKeith Whitwell 221b980b2eeb62dc48101a7481d02d196c80b9da397Keith Whitwellvoid 222f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swsetup_InvalidateState( struct gl_context *ctx, GLuint new_state ) 223b980b2eeb62dc48101a7481d02d196c80b9da397Keith Whitwell{ 22422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes SScontext *swsetup = SWSETUP_CONTEXT(ctx); 2255c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell swsetup->NewState |= new_state; 226588225770c60834dfd2a95850435cc549167dc05Keith Whitwell _tnl_invalidate_vertex_state( ctx, new_state ); 2275c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell} 2285c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell 2295c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell 23022144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesvoid 231f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swsetup_Wakeup( struct gl_context *ctx ) 2325c1e7fa6ee72f4403d9ec9d12830dd689b966e71Keith Whitwell{ 2331182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 234588225770c60834dfd2a95850435cc549167dc05Keith Whitwell SScontext *swsetup = SWSETUP_CONTEXT(ctx); 235588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 2361182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Start = _swsetup_RenderStart; 2371182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Finish = _swsetup_RenderFinish; 2381182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.PrimitiveNotify = _swsetup_RenderPrimitive; 239588225770c60834dfd2a95850435cc549167dc05Keith Whitwell tnl->Driver.Render.Interp = _tnl_interp; 240588225770c60834dfd2a95850435cc549167dc05Keith Whitwell tnl->Driver.Render.CopyPV = _tnl_copy_pv; 2411182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; /* new */ 2421182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; /* new */ 2431182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell /* points */ 2441182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell /* line */ 2451182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell /* triangle */ 2461182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell /* quad */ 2471182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts; 2481182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts; 2491182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple; 250588225770c60834dfd2a95850435cc549167dc05Keith Whitwell tnl->Driver.Render.BuildVertices = _tnl_build_vertices; 2511182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell tnl->Driver.Render.Multipass = 0; 252588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 253588225770c60834dfd2a95850435cc549167dc05Keith Whitwell _tnl_invalidate_vertices( ctx, ~0 ); 2541182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell _tnl_need_projected_coords( ctx, GL_TRUE ); 2551182ffeec39bf419928ba862c225e80a439fee7aKeith Whitwell _swsetup_InvalidateState( ctx, ~0 ); 256588225770c60834dfd2a95850435cc549167dc05Keith Whitwell 257588225770c60834dfd2a95850435cc549167dc05Keith Whitwell swsetup->verts = (SWvertex *)tnl->clipspace.vertex_buf; 258ccbf192f597186f6a4a04ed14391dba82ffee18bMathias Fröhlich swsetup->last_index_bitset = 0; 259b980b2eeb62dc48101a7481d02d196c80b9da397Keith Whitwell} 260790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell 261790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell 262a76c216b3709c2f6b29f3265d58f3c1d6f0a1559Brian Paul/** 263a76c216b3709c2f6b29f3265d58f3c1d6f0a1559Brian Paul * Populate a swrast SWvertex from an attrib-style vertex. 264790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell */ 265790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwellvoid 266f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_swsetup_Translate( struct gl_context *ctx, const void *vertex, SWvertex *dest ) 267790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell{ 26838bf45d4bbc576a695a2f7bb7d9ae3caf28a6838Keith Whitwell const GLfloat *m = ctx->Viewport._WindowMap.m; 269790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell GLfloat tmp[4]; 2701852f4fa338765bf62b21ea7644e43cc19a1d77fKarl Schultz GLuint i; 271790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell 27238bf45d4bbc576a695a2f7bb7d9ae3caf28a6838Keith Whitwell _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POS, tmp ); 27338bf45d4bbc576a695a2f7bb7d9ae3caf28a6838Keith Whitwell 2749e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian dest->attrib[FRAG_ATTRIB_WPOS][0] = m[0] * tmp[0] + m[12]; 2759e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian dest->attrib[FRAG_ATTRIB_WPOS][1] = m[5] * tmp[1] + m[13]; 2769e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian dest->attrib[FRAG_ATTRIB_WPOS][2] = m[10] * tmp[2] + m[14]; 2779e8a961dd7d7b717a9fb4ecdea1c1b60ea355efeBrian dest->attrib[FRAG_ATTRIB_WPOS][3] = tmp[3]; 27838bf45d4bbc576a695a2f7bb7d9ae3caf28a6838Keith Whitwell 2795c1b53d58de68582c378e28fbb2fe4c0277139a9Brian /** XXX try to limit these loops someday */ 280a76c216b3709c2f6b29f3265d58f3c1d6f0a1559Brian Paul for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) 281a164d3aee063580503e5e9a77980059d52c486d7Brian _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_TEX0 + i, 282dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian dest->attrib[FRAG_ATTRIB_TEX0 + i] ); 283dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian 284dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian for (i = 0 ; i < ctx->Const.MaxVarying ; i++) 285a164d3aee063580503e5e9a77980059d52c486d7Brian _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_GENERIC0 + i, 286dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian dest->attrib[FRAG_ATTRIB_VAR0 + i] ); 287dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian 288e650c07f47ac6f49a4dfcb58290fd049092fb768Ian Romanick _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR0, 289e650c07f47ac6f49a4dfcb58290fd049092fb768Ian Romanick dest->attrib[FRAG_ATTRIB_COL0] ); 290e650c07f47ac6f49a4dfcb58290fd049092fb768Ian Romanick UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest->color, tmp ); 291790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell 292e650c07f47ac6f49a4dfcb58290fd049092fb768Ian Romanick _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR1, 293e650c07f47ac6f49a4dfcb58290fd049092fb768Ian Romanick dest->attrib[FRAG_ATTRIB_COL1]); 294790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell 295790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_FOG, tmp ); 296c27adc52ce48d371b94170581be173b77c16e6e6Brian dest->attrib[FRAG_ATTRIB_FOGC][0] = tmp[0]; 297790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell 2985c1b53d58de68582c378e28fbb2fe4c0277139a9Brian /* XXX See _tnl_get_attr about pointsize ... */ 299790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POINTSIZE, tmp ); 300790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell dest->pointSize = tmp[0]; 301790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell} 302790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell 303