fixed a bunch of g++ warnings/errors. Compiling with g++ can help find lots of poten...
[mesa.git] / src / mesa / swrast_setup / ss_context.c
1 /* $Id: ss_context.c,v 1.12 2001/03/07 05:06:13 brianp 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 #include "glheader.h"
31 #include "mem.h"
32 #include "ss_context.h"
33 #include "ss_triangle.h"
34 #include "ss_vb.h"
35 #include "ss_interp.h"
36 #include "swrast_setup.h"
37 #include "tnl/t_context.h"
38
39
40 #define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
41 _NEW_LIGHT| \
42 _NEW_TEXTURE| \
43 _NEW_COLOR| \
44 _NEW_FOG| \
45 _NEW_POINT)
46
47 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
48
49
50 /* Dispatch from these fixed entrypoints to the state-dependent
51 * functions.
52 *
53 * The design of swsetup suggests that we could really program
54 * ctx->Driver.TriangleFunc directly from _swsetup_RenderStart, and
55 * avoid this second level of indirection. However, this is more
56 * convient for fallback cases in hardware rasterization drivers.
57 */
58 void
59 _swsetup_Quad( GLcontext *ctx, GLuint v0, GLuint v1,
60 GLuint v2, GLuint v3 )
61 {
62 SWSETUP_CONTEXT(ctx)->Quad( ctx, v0, v1, v2, v3 );
63 }
64
65 void
66 _swsetup_Triangle( GLcontext *ctx, GLuint v0, GLuint v1,
67 GLuint v2 )
68 {
69 SWSETUP_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2 );
70 }
71
72 void
73 _swsetup_Line( GLcontext *ctx, GLuint v0, GLuint v1 )
74 {
75 SWSETUP_CONTEXT(ctx)->Line( ctx, v0, v1 );
76 }
77
78 void
79 _swsetup_Points( GLcontext *ctx, GLuint first, GLuint last )
80 {
81 SWSETUP_CONTEXT(ctx)->Points( ctx, first, last );
82 }
83
84 void
85 _swsetup_BuildProjectedVertices( GLcontext *ctx, GLuint start, GLuint end,
86 GLuint new_inputs )
87 {
88 SWSETUP_CONTEXT(ctx)->BuildProjVerts( ctx, start, end, new_inputs );
89 }
90
91
92 GLboolean
93 _swsetup_CreateContext( GLcontext *ctx )
94 {
95 TNLcontext *tnl = TNL_CONTEXT(ctx);
96 SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext));
97
98 if (!swsetup)
99 return GL_FALSE;
100
101 swsetup->verts = (SWvertex *) ALIGN_MALLOC( sizeof(SWvertex) * tnl->vb.Size, 32);
102 if (!swsetup->verts) {
103 FREE(swsetup);
104 return GL_FALSE;
105 }
106
107 ctx->swsetup_context = swsetup;
108
109 swsetup->NewState = ~0;
110 _swsetup_vb_init( ctx );
111 _swsetup_interp_init( ctx );
112 _swsetup_trifuncs_init( ctx );
113
114 return GL_TRUE;
115 }
116
117 void
118 _swsetup_DestroyContext( GLcontext *ctx )
119 {
120 if (SWSETUP_CONTEXT(ctx)) {
121 if (SWSETUP_CONTEXT(ctx)->verts)
122 ALIGN_FREE(SWSETUP_CONTEXT(ctx)->verts);
123
124 FREE(SWSETUP_CONTEXT(ctx));
125 ctx->swsetup_context = 0;
126 }
127 }
128
129 void
130 _swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode )
131 {
132 SWSETUP_CONTEXT(ctx)->render_prim = mode;
133 }
134
135 void
136 _swsetup_RenderStart( GLcontext *ctx )
137 {
138 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
139 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
140 GLuint new_state = swsetup->NewState;
141
142 if (new_state & _SWSETUP_NEW_RENDERINDEX) {
143 _swsetup_choose_trifuncs( ctx );
144 }
145
146 if (new_state & _SWSETUP_NEW_VERTS) {
147 _swsetup_choose_rastersetup_func( ctx );
148 }
149
150 swsetup->NewState = 0;
151
152 if (VB->ClipMask && VB->importable_data)
153 VB->import_data( ctx,
154 VB->importable_data,
155 VEC_NOT_WRITEABLE|VEC_BAD_STRIDE);
156 }
157
158 void
159 _swsetup_RenderFinish( GLcontext *ctx )
160 {
161 _swrast_flush( ctx );
162 }
163
164 void
165 _swsetup_InvalidateState( GLcontext *ctx, GLuint new_state )
166 {
167 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
168 swsetup->NewState |= new_state;
169
170 if (new_state & _SWSETUP_NEW_INTERP) {
171 swsetup->RenderInterp = _swsetup_validate_interp;
172 swsetup->RenderCopyPV = _swsetup_validate_copypv;
173 }
174 }
175
176 void
177 _swsetup_RenderInterp( GLcontext *ctx, GLfloat t,
178 GLuint dst, GLuint out, GLuint in,
179 GLboolean force_boundary )
180 {
181 SWSETUP_CONTEXT(ctx)->RenderInterp( ctx, t, dst, out, in, force_boundary );
182 }
183
184 void
185 _swsetup_RenderCopyPV( GLcontext *ctx, GLuint dst, GLuint src )
186 {
187 SWSETUP_CONTEXT(ctx)->RenderCopyPV( ctx, dst, src );
188 }
189