Remove 'pv' parameter from Line/Tri/Point funcs. The provoking vertex
[mesa.git] / src / mesa / swrast_setup / ss_context.c
1 /* $Id: ss_context.c,v 1.6 2001/01/05 02:26:49 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 #include "tnl/t_context.h"
42
43 /* Stub for swsetup->Triangle to select a true triangle function
44 * after a state change.
45 */
46 static void
47 _swsetup_validate_quad( GLcontext *ctx, GLuint v0, GLuint v1,
48 GLuint v2, GLuint v3 )
49 {
50 _swsetup_choose_trifuncs( ctx );
51 SWSETUP_CONTEXT(ctx)->Quad( ctx, v0, v1, v2, v3 );
52 }
53
54 static void
55 _swsetup_validate_triangle( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2 )
56 {
57 _swsetup_choose_trifuncs( ctx );
58 SWSETUP_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2 );
59 }
60
61 static void
62 _swsetup_validate_line( GLcontext *ctx, GLuint v0, GLuint v1 )
63 {
64 _swsetup_choose_trifuncs( ctx );
65 SWSETUP_CONTEXT(ctx)->Line( ctx, v0, v1 );
66 }
67
68
69 static 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
78 static void
79 _swsetup_validate_buildprojverts( GLcontext *ctx,
80 GLuint start, GLuint end, GLuint new_inputs )
81 {
82 _swsetup_choose_rastersetup_func( ctx );
83 SWSETUP_CONTEXT(ctx)->BuildProjVerts( ctx, start, end, new_inputs );
84 }
85
86
87 #define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
88 _NEW_TEXTURE| \
89 _NEW_COLOR| \
90 _NEW_FOG| \
91 _NEW_POINT)
92
93 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
94
95
96 #if 0
97 /* TODO: sleep/wakeup mechanism
98 */
99 static void
100 _swsetup_sleep( GLcontext *ctx, GLuint new_state )
101 {
102 }
103 #endif
104
105 static void
106 _swsetup_invalidate_state( GLcontext *ctx, GLuint new_state )
107 {
108 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
109
110 swsetup->NewState |= new_state;
111
112 if (new_state & _SWSETUP_NEW_RENDERINDEX) {
113 swsetup->Triangle = _swsetup_validate_triangle;
114 swsetup->Line = _swsetup_validate_line;
115 swsetup->Points = _swsetup_validate_points;
116 swsetup->Quad = _swsetup_validate_quad;
117 }
118
119 if (new_state & _SWSETUP_NEW_VERTS) {
120 swsetup->BuildProjVerts = _swsetup_validate_buildprojverts;
121 }
122 }
123
124
125
126 /* Dispatch from these fixed entrypoints to the state-dependent
127 * functions:
128 */
129 void
130 _swsetup_Quad( GLcontext *ctx, GLuint v0, GLuint v1,
131 GLuint v2, GLuint v3 )
132 {
133 SWSETUP_CONTEXT(ctx)->Quad( ctx, v0, v1, v2, v3 );
134 }
135
136 void
137 _swsetup_Triangle( GLcontext *ctx, GLuint v0, GLuint v1,
138 GLuint v2 )
139 {
140 SWSETUP_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2 );
141 }
142
143 void
144 _swsetup_Line( GLcontext *ctx, GLuint v0, GLuint v1 )
145 {
146 SWSETUP_CONTEXT(ctx)->Line( ctx, v0, v1 );
147 }
148
149
150 void
151 _swsetup_Points( GLcontext *ctx, GLuint first, GLuint last )
152 {
153 SWSETUP_CONTEXT(ctx)->Points( ctx, first, last );
154 }
155
156 void
157 _swsetup_BuildProjectedVertices( GLcontext *ctx, GLuint start, GLuint end,
158 GLuint new_inputs )
159 {
160 SWSETUP_CONTEXT(ctx)->BuildProjVerts( ctx, start, end, new_inputs );
161 }
162
163 void
164 _swsetup_InvalidateState( GLcontext *ctx, GLuint new_state )
165 {
166 SWSETUP_CONTEXT(ctx)->InvalidateState( ctx, new_state );
167 }
168
169
170 GLboolean
171 _swsetup_CreateContext( GLcontext *ctx )
172 {
173 TNLcontext *tnl = TNL_CONTEXT(ctx);
174 SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext));
175
176 if (!swsetup)
177 return GL_FALSE;
178
179 swsetup->verts = ALIGN_MALLOC( sizeof(SWvertex) * tnl->vb.Size, 32);
180 if (!swsetup->verts) {
181 FREE(swsetup);
182 return GL_FALSE;
183 }
184
185 ctx->swsetup_context = swsetup;
186
187 swsetup->NewState = ~0;
188 swsetup->InvalidateState = _swsetup_invalidate_state;
189 swsetup->Quad = _swsetup_validate_quad;
190 swsetup->Triangle = _swsetup_validate_triangle;
191 swsetup->Line = _swsetup_validate_line;
192 swsetup->Points = _swsetup_validate_points;
193 swsetup->BuildProjVerts = _swsetup_validate_buildprojverts;
194
195 _swsetup_vb_init( ctx );
196 _swsetup_trifuncs_init( ctx );
197
198 return GL_TRUE;
199 }
200
201 void
202 _swsetup_DestroyContext( GLcontext *ctx )
203 {
204 if (SWSETUP_CONTEXT(ctx)) {
205 if (SWSETUP_CONTEXT(ctx)->verts)
206 ALIGN_FREE(SWSETUP_CONTEXT(ctx)->verts);
207
208 FREE(SWSETUP_CONTEXT(ctx));
209 ctx->swsetup_context = 0;
210 }
211 }
212
213