ss_context.c revision 9ac51f57efe07ed43a1e4224a7f5daddec401b36
1 2/* 3 * Mesa 3-D graphics library 4 * Version: 4.1 5 * 6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the "Software"), 10 * to deal in the Software without restriction, including without limitation 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 * and/or sell copies of the Software, and to permit persons to whom the 13 * Software is furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included 16 * in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * 25 * Authors: 26 * Keith Whitwell <keith@tungstengraphics.com> 27 */ 28 29#include "glheader.h" 30#include "imports.h" 31#include "ss_context.h" 32#include "ss_triangle.h" 33#include "ss_vb.h" 34#include "swrast_setup.h" 35#include "tnl/tnl.h" 36#include "tnl/t_context.h" 37#include "tnl/t_pipeline.h" 38 39 40#define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \ 41 _NEW_POLYGON| \ 42 _NEW_LIGHT| \ 43 _NEW_TEXTURE| \ 44 _NEW_COLOR| \ 45 _NEW_FOG| \ 46 _NEW_POINT) 47 48#define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT) 49 50 51GLboolean 52_swsetup_CreateContext( GLcontext *ctx ) 53{ 54 TNLcontext *tnl = TNL_CONTEXT(ctx); 55 SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext)); 56 57 if (!swsetup) 58 return GL_FALSE; 59 60 swsetup->verts = (SWvertex *) ALIGN_CALLOC( sizeof(SWvertex) * tnl->vb.Size, 61 32); 62 if (!swsetup->verts) { 63 FREE(swsetup); 64 return GL_FALSE; 65 } 66 67 ctx->swsetup_context = swsetup; 68 69 swsetup->NewState = ~0; 70 _swsetup_vb_init( ctx ); 71 _swsetup_trifuncs_init( ctx ); 72 73 return GL_TRUE; 74} 75 76void 77_swsetup_DestroyContext( GLcontext *ctx ) 78{ 79 SScontext *swsetup = SWSETUP_CONTEXT(ctx); 80 81 if (swsetup) { 82 if (swsetup->verts) 83 ALIGN_FREE(swsetup->verts); 84 85 if (swsetup->ChanSecondaryColor.Ptr) 86 ALIGN_FREE(swsetup->ChanSecondaryColor.Ptr); 87 88 if (swsetup->ChanColor.Ptr) 89 ALIGN_FREE(swsetup->ChanColor.Ptr); 90 91 FREE(swsetup); 92 ctx->swsetup_context = 0; 93 } 94} 95 96static void 97_swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode ) 98{ 99 SWSETUP_CONTEXT(ctx)->render_prim = mode; 100 _swrast_render_primitive( ctx, mode ); 101} 102 103/* 104 * We patch this function into tnl->Driver.Render.Start. 105 * It's called when we start rendering a vertex buffer. 106 */ 107static void 108_swsetup_RenderStart( GLcontext *ctx ) 109{ 110 SScontext *swsetup = SWSETUP_CONTEXT(ctx); 111 GLuint new_state = swsetup->NewState; 112 113 if (new_state & _SWSETUP_NEW_RENDERINDEX) { 114 _swsetup_choose_trifuncs( ctx ); 115 } 116 117 if (new_state & _SWSETUP_NEW_VERTS) { 118 _swsetup_choose_rastersetup_func( ctx ); 119 } 120 121 swsetup->NewState = 0; 122 123 _swrast_render_start( ctx ); 124} 125 126/* 127 * We patch this function into tnl->Driver.Render.Finish. 128 * It's called when we finish rendering a vertex buffer. 129 */ 130static void 131_swsetup_RenderFinish( GLcontext *ctx ) 132{ 133 _swrast_render_finish( ctx ); 134} 135 136void 137_swsetup_InvalidateState( GLcontext *ctx, GLuint new_state ) 138{ 139 SScontext *swsetup = SWSETUP_CONTEXT(ctx); 140 swsetup->NewState |= new_state; 141} 142 143 144void 145_swsetup_Wakeup( GLcontext *ctx ) 146{ 147 TNLcontext *tnl = TNL_CONTEXT(ctx); 148 tnl->Driver.Render.Start = _swsetup_RenderStart; 149 tnl->Driver.Render.Finish = _swsetup_RenderFinish; 150 tnl->Driver.Render.PrimitiveNotify = _swsetup_RenderPrimitive; 151 /* interp */ 152 /* copypv */ 153 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; /* new */ 154 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; /* new */ 155 /* points */ 156 /* line */ 157 /* triangle */ 158 /* quad */ 159 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts; 160 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts; 161 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple; 162 /* buildvertices */ 163 tnl->Driver.Render.Multipass = 0; 164 _tnl_need_projected_coords( ctx, GL_TRUE ); 165 _swsetup_InvalidateState( ctx, ~0 ); 166} 167