ss_context.c revision 7c20642b1091df1aab7d9076a3fe2fb11c6f011c
1/* $Id: ss_context.c,v 1.1 2000/11/05 18:20:18 keithw Exp $ */ 2 3/* 4 * Mesa 3-D graphics library 5 * Version: 3.5 6 * 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the "Software"), 11 * to deal in the Software without restriction, including without limitation 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 * and/or sell copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 * Authors: 27 * Keith Whitwell <keithw@valinux.com> 28 */ 29 30 31#include "glheader.h" 32#include "mem.h" 33 34 35#include "ss_context.h" 36#include "ss_triangle.h" 37#include "ss_vb.h" 38 39#include "swrast_setup.h" 40 41 42/* Stub for swsetup->Triangle to select a true triangle function 43 * after a state change. 44 */ 45static void 46_swsetup_validate_quad( GLcontext *ctx, GLuint v0, GLuint v1, 47 GLuint v2, GLuint v3, GLuint pv ) 48{ 49 _swsetup_choose_trifuncs( ctx ); 50 SWSETUP_CONTEXT(ctx)->Quad( ctx, v0, v1, v2, v3, pv ); 51} 52 53static void 54_swsetup_validate_triangle( GLcontext *ctx, GLuint v0, GLuint v1, 55 GLuint v2, GLuint pv ) 56{ 57 _swsetup_choose_trifuncs( ctx ); 58 SWSETUP_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2, pv ); 59} 60 61static void 62_swsetup_validate_line( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv ) 63{ 64 _swsetup_choose_trifuncs( ctx ); 65 SWSETUP_CONTEXT(ctx)->Line( ctx, v0, v1, pv ); 66} 67 68 69static void 70_swsetup_validate_points( GLcontext *ctx, GLuint first, GLuint last ) 71{ 72 _swsetup_choose_trifuncs( ctx ); 73 SWSETUP_CONTEXT(ctx)->Points( ctx, first, last ); 74} 75 76 77 78static void 79_swsetup_validate_rastersetup( struct vertex_buffer *VB, 80 GLuint start, GLuint end ) 81{ 82 GLcontext *ctx = VB->ctx; 83 _swsetup_choose_rastersetup_func( ctx ); 84 SWSETUP_CONTEXT(ctx)->RasterSetup( VB, start, end ); 85} 86 87 88#define _SWSETUP_NEW_RASTERSETUP (_NEW_RENDERMODE| \ 89 _NEW_TEXTURE| \ 90 _NEW_COLOR| \ 91 _NEW_FOG| \ 92 _NEW_POINT) 93 94#define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT) 95 96 97#if 0 98/* TODO: sleep/wakeup mechanism 99 */ 100static void 101_swsetup_sleep( GLcontext *ctx, GLuint new_state ) 102{ 103} 104#endif 105 106static void 107_swsetup_invalidate_state( GLcontext *ctx, GLuint new_state ) 108{ 109 SScontext *swsetup = SWSETUP_CONTEXT(ctx); 110 111 swsetup->NewState |= new_state; 112 113 114 if (new_state & _SWSETUP_NEW_RENDERINDEX) { 115 swsetup->Triangle = _swsetup_validate_triangle; 116 swsetup->Line = _swsetup_validate_line; 117 swsetup->Points = _swsetup_validate_points; 118 swsetup->Quad = _swsetup_validate_quad; 119 } 120 121 if (new_state & _SWSETUP_NEW_RASTERSETUP) { 122 swsetup->RasterSetup = _swsetup_validate_rastersetup; 123 } 124} 125 126 127 128/* Dispatch from these fixed entrypoints to the state-dependent 129 * functions: 130 */ 131void 132_swsetup_Quad( GLcontext *ctx, GLuint v0, GLuint v1, 133 GLuint v2, GLuint v3, GLuint pv ) 134{ 135 SWSETUP_CONTEXT(ctx)->Quad( ctx, v0, v1, v2, v3, pv ); 136} 137 138void 139_swsetup_Triangle( GLcontext *ctx, GLuint v0, GLuint v1, 140 GLuint v2, GLuint pv ) 141{ 142 SWSETUP_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2, pv ); 143} 144 145void 146_swsetup_Line( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv ) 147{ 148 SWSETUP_CONTEXT(ctx)->Line( ctx, v0, v1, pv ); 149} 150 151 152void 153_swsetup_Points( GLcontext *ctx, GLuint first, GLuint last ) 154{ 155 SWSETUP_CONTEXT(ctx)->Points( ctx, first, last ); 156} 157 158void 159_swsetup_RasterSetup( struct vertex_buffer *VB, GLuint start, GLuint end ) 160{ 161 SWSETUP_CONTEXT(VB->ctx)->RasterSetup( VB, start, end ); 162} 163 164void 165_swsetup_InvalidateState( GLcontext *ctx, GLuint new_state ) 166{ 167 SWSETUP_CONTEXT(ctx)->InvalidateState( ctx, new_state ); 168} 169 170 171GLboolean 172_swsetup_CreateContext( GLcontext *ctx ) 173{ 174 SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext)); 175 176 if (!swsetup) 177 return GL_FALSE; 178 179 ctx->swsetup_context = swsetup; 180 181 swsetup->NewState = ~0; 182 swsetup->InvalidateState = _swsetup_invalidate_state; 183 swsetup->Quad = _swsetup_validate_quad; 184 swsetup->Triangle = _swsetup_validate_triangle; 185 swsetup->Line = _swsetup_validate_line; 186 swsetup->Points = _swsetup_validate_points; 187 swsetup->RasterSetup = _swsetup_validate_rastersetup; 188 189 _swsetup_vb_init( ctx ); 190 _swsetup_trifuncs_init( ctx ); 191 192 return GL_TRUE; 193} 194 195void 196_swsetup_DestroyContext( GLcontext *ctx ) 197{ 198 if (SWSETUP_CONTEXT(ctx)) { 199 FREE(SWSETUP_CONTEXT(ctx)); 200 ctx->swsetup_context = 0; 201 } 202} 203 204GLboolean 205_swsetup_RegisterVB( struct vertex_buffer *VB ) 206{ 207 SSvertexbuffer *ssvb = (SSvertexbuffer *)CALLOC(sizeof(SSvertexbuffer) ); 208 209 ssvb->verts = ALIGN_MALLOC( sizeof(SWvertex) * VB->Size, 32); 210 if (!ssvb->verts) { 211 FREE(ssvb); 212 return GL_FALSE; 213 } 214 215 VB->swsetup_vb = ssvb; 216 return GL_TRUE; 217} 218 219 220void 221_swsetup_UnregisterVB( struct vertex_buffer *VB ) 222{ 223 SSvertexbuffer *ssvb = SWSETUP_VB(VB); 224 225 if (ssvb) { 226 if (ssvb->verts) ALIGN_FREE(ssvb->verts); 227 FREE(ssvb); 228 VB->swsetup_vb = 0; 229 } 230} 231