Fixed a few typos in the german translation.
[mesa.git] / src / mesa / swrast_setup / ss_context.c
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 "colormac.h"
32 #include "ss_context.h"
33 #include "ss_triangle.h"
34 #include "swrast_setup.h"
35 #include "tnl/tnl.h"
36 #include "tnl/t_context.h"
37 #include "tnl/t_pipeline.h"
38 #include "tnl/t_vertex.h"
39
40 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
41
42
43 GLboolean
44 _swsetup_CreateContext( GLcontext *ctx )
45 {
46 SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext));
47
48 if (!swsetup)
49 return GL_FALSE;
50
51 ctx->swsetup_context = swsetup;
52
53 swsetup->NewState = ~0;
54 _swsetup_trifuncs_init( ctx );
55
56 _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12,
57 sizeof(SWvertex) );
58
59
60 return GL_TRUE;
61 }
62
63 void
64 _swsetup_DestroyContext( GLcontext *ctx )
65 {
66 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
67
68 if (swsetup) {
69 FREE(swsetup);
70 ctx->swsetup_context = 0;
71 }
72
73 _tnl_free_vertices( ctx );
74 }
75
76 static void
77 _swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode )
78 {
79 SWSETUP_CONTEXT(ctx)->render_prim = mode;
80 _swrast_render_primitive( ctx, mode );
81 }
82
83 #define SWZ ((SWvertex *)0)
84 #define SWOffset(MEMBER) (((char *)&(SWZ->MEMBER)) - ((char *)SWZ))
85
86 #define EMIT_ATTR( ATTR, STYLE, MEMBER ) \
87 do { \
88 map[e].attrib = (ATTR); \
89 map[e].format = (STYLE); \
90 map[e].offset = SWOffset(MEMBER); \
91 e++; \
92 } while (0)
93
94
95 /*
96 * We patch this function into tnl->Driver.Render.Start.
97 * It's called when we start rendering a vertex buffer.
98 */
99 static void
100 _swsetup_RenderStart( GLcontext *ctx )
101 {
102 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
103 TNLcontext *tnl = TNL_CONTEXT(ctx);
104 struct vertex_buffer *VB = &tnl->vb;
105 GLuint new_state = swsetup->NewState;
106
107 if (new_state & _SWSETUP_NEW_RENDERINDEX) {
108 _swsetup_choose_trifuncs( ctx );
109 }
110
111 swsetup->NewState = 0;
112
113 _swrast_render_start( ctx );
114
115 /* Important:
116 */
117 VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;
118
119
120 if (tnl->render_inputs != swsetup->last_index) {
121 GLuint index = tnl->render_inputs;
122 struct tnl_attr_map map[_TNL_ATTRIB_MAX];
123 int i, e = 0;
124
125 EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, win );
126
127 if (index & _TNL_BIT_COLOR0)
128 EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color );
129
130 if (index & _TNL_BIT_COLOR1)
131 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_4CHAN_4F_RGBA, specular);
132
133 if (index & _TNL_BIT_FOG)
134 EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1F, fog);
135
136 if (index & _TNL_BITS_TEX_ANY) {
137 for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
138 if (index & _TNL_BIT_TEX(i)) {
139 EMIT_ATTR( _TNL_ATTRIB_TEX0+i, EMIT_4F, texcoord[i] );
140 }
141 }
142 }
143
144 if (index & _TNL_BIT_INDEX)
145 EMIT_ATTR( _TNL_ATTRIB_INDEX, EMIT_1F, index );
146
147 if (index & _TNL_BIT_POINTSIZE)
148 EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize );
149
150 _tnl_install_attrs( ctx, map, e,
151 ctx->Viewport._WindowMap.m,
152 sizeof(SWvertex) );
153
154 swsetup->last_index = index;
155 }
156
157 }
158
159 /*
160 * We patch this function into tnl->Driver.Render.Finish.
161 * It's called when we finish rendering a vertex buffer.
162 */
163 static void
164 _swsetup_RenderFinish( GLcontext *ctx )
165 {
166 _swrast_render_finish( ctx );
167 }
168
169 void
170 _swsetup_InvalidateState( GLcontext *ctx, GLuint new_state )
171 {
172 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
173 swsetup->NewState |= new_state;
174 _tnl_invalidate_vertex_state( ctx, new_state );
175 }
176
177
178 void
179 _swsetup_Wakeup( GLcontext *ctx )
180 {
181 TNLcontext *tnl = TNL_CONTEXT(ctx);
182 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
183
184 tnl->Driver.Render.Start = _swsetup_RenderStart;
185 tnl->Driver.Render.Finish = _swsetup_RenderFinish;
186 tnl->Driver.Render.PrimitiveNotify = _swsetup_RenderPrimitive;
187 tnl->Driver.Render.Interp = _tnl_interp;
188 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
189 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; /* new */
190 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; /* new */
191 /* points */
192 /* line */
193 /* triangle */
194 /* quad */
195 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
196 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
197 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
198 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
199 tnl->Driver.Render.Multipass = 0;
200
201 _tnl_invalidate_vertices( ctx, ~0 );
202 _tnl_need_projected_coords( ctx, GL_TRUE );
203 _swsetup_InvalidateState( ctx, ~0 );
204
205 swsetup->verts = (SWvertex *)tnl->clipspace.vertex_buf;
206 swsetup->last_index = 0;
207 }
208
209
210
211
212
213 /* Populate a swrast SWvertex from an attrib-style vertex.
214 */
215 void
216 _swsetup_Translate( GLcontext *ctx, const void *vertex, SWvertex *dest )
217 {
218 const GLfloat *m = ctx->Viewport._WindowMap.m;
219 GLfloat tmp[4];
220 GLint i;
221
222 _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POS, tmp );
223
224 dest->win[0] = m[0] * tmp[0] + m[12];
225 dest->win[1] = m[5] * tmp[1] + m[13];
226 dest->win[2] = m[10] * tmp[2] + m[15];
227 dest->win[3] = tmp[3];
228
229
230 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
231 _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_TEX0+i, dest->texcoord[i] );
232
233 _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR0, tmp );
234 UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest->color, tmp );
235
236 _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_COLOR1, tmp );
237 UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest->specular, tmp );
238
239 _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_FOG, tmp );
240 dest->fog = tmp[0];
241
242 _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_INDEX, tmp );
243 dest->index = (GLuint) tmp[0];
244
245 _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POINTSIZE, tmp );
246 dest->pointSize = tmp[0];
247 }
248