Fix VERT_SET_RGBA, VERT_SET_SPEC macros to account for change to floating
[mesa.git] / src / mesa / tnl / t_context.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.1
5 *
6 * Copyright (C) 1999-2003 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
30 #include "api_arrayelt.h"
31 #include "glheader.h"
32 #include "imports.h"
33 #include "macros.h"
34 #include "mtypes.h"
35 #include "dlist.h"
36 #include "light.h"
37 #include "vtxfmt.h"
38
39 #include "t_context.h"
40 #include "t_array_api.h"
41 #include "t_vtx_api.h"
42 #include "t_save_api.h"
43 #include "t_pipeline.h"
44 #include "tnl.h"
45
46
47
48 void
49 _tnl_MakeCurrent( GLcontext *ctx,
50 GLframebuffer *drawBuffer,
51 GLframebuffer *readBuffer )
52 {
53 }
54
55
56 static void
57 install_driver_callbacks( GLcontext *ctx )
58 {
59 ctx->Driver.NewList = _tnl_NewList;
60 ctx->Driver.EndList = _tnl_EndList;
61 ctx->Driver.FlushVertices = _tnl_FlushVertices;
62 ctx->Driver.SaveFlushVertices = _tnl_SaveFlushVertices;
63 ctx->Driver.MakeCurrent = _tnl_MakeCurrent;
64 ctx->Driver.BeginCallList = _tnl_BeginCallList;
65 ctx->Driver.EndCallList = _tnl_EndCallList;
66 }
67
68
69
70 GLboolean
71 _tnl_CreateContext( GLcontext *ctx )
72 {
73 TNLcontext *tnl;
74
75 /* Create the TNLcontext structure
76 */
77 ctx->swtnl_context = tnl = (TNLcontext *) CALLOC( sizeof(TNLcontext) );
78
79 if (!tnl) {
80 return GL_FALSE;
81 }
82
83 /* Initialize the VB.
84 */
85 tnl->vb.Size = ctx->Const.MaxArrayLockSize + MAX_CLIPPED_VERTICES;
86
87
88 /* Initialize tnl state and tnl->vtxfmt.
89 */
90 _tnl_save_init( ctx );
91 _tnl_array_init( ctx );
92 _tnl_vtx_init( ctx );
93 _tnl_install_pipeline( ctx, _tnl_default_pipeline );
94
95 /* Initialize the arrayelt helper
96 */
97 if (!_ae_create_context( ctx ))
98 return GL_FALSE;
99
100
101 tnl->NeedNdcCoords = GL_TRUE;
102 tnl->LoopbackDListCassettes = GL_FALSE;
103 tnl->CalcDListNormalLengths = GL_TRUE;
104
105 /* Hook our functions into exec and compile dispatch tables.
106 */
107 _mesa_install_exec_vtxfmt( ctx, &tnl->exec_vtxfmt );
108
109
110 /* Set a few default values in the driver struct.
111 */
112 install_driver_callbacks(ctx);
113 ctx->Driver.NeedFlush = 0;
114 ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
115 ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
116
117 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
118 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
119 tnl->Driver.NotifyMaterialChange = _mesa_validate_all_lighting_tables;
120
121 return GL_TRUE;
122 }
123
124
125 void
126 _tnl_DestroyContext( GLcontext *ctx )
127 {
128 TNLcontext *tnl = TNL_CONTEXT(ctx);
129
130 _tnl_array_destroy( ctx );
131 _tnl_vtx_destroy( ctx );
132 _tnl_save_destroy( ctx );
133 _tnl_destroy_pipeline( ctx );
134
135 FREE(tnl);
136 ctx->swtnl_context = 0;
137 }
138
139
140 void
141 _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
142 {
143 TNLcontext *tnl = TNL_CONTEXT(ctx);
144
145 if (new_state & _NEW_ARRAY) {
146 tnl->pipeline.run_input_changes |= ctx->Array.NewState; /* overkill */
147 }
148
149 tnl->pipeline.run_state_changes |= new_state;
150 tnl->pipeline.build_state_changes |= (new_state &
151 tnl->pipeline.build_state_trigger);
152
153 tnl->vtx.eval.new_state |= new_state;
154 }
155
156
157 void
158 _tnl_wakeup_exec( GLcontext *ctx )
159 {
160 TNLcontext *tnl = TNL_CONTEXT(ctx);
161
162 install_driver_callbacks(ctx);
163 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;
164
165 /* Hook our functions into exec and compile dispatch tables.
166 */
167 _mesa_install_exec_vtxfmt( ctx, &tnl->exec_vtxfmt );
168
169 /* Call all appropriate driver callbacks to revive state.
170 */
171 _tnl_MakeCurrent( ctx, ctx->DrawBuffer, ctx->ReadBuffer );
172
173 /* Assume we haven't been getting state updates either:
174 */
175 _tnl_InvalidateState( ctx, ~0 );
176 tnl->pipeline.run_input_changes = ~0;
177
178 if (ctx->Light.ColorMaterialEnabled) {
179 _mesa_update_color_material( ctx,
180 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
181 }
182 }
183
184
185 void
186 _tnl_wakeup_save_exec( GLcontext *ctx )
187 {
188 TNLcontext *tnl = TNL_CONTEXT(ctx);
189
190 _tnl_wakeup_exec( ctx );
191 _mesa_install_save_vtxfmt( ctx, &tnl->save_vtxfmt );
192 }
193
194
195 /**
196 * Drivers call this function to tell the TCL module whether or not
197 * it wants Normalized Device Coords (NDC) computed. I.e. whether
198 * we should "Divide-by-W". Software renders will want that.
199 */
200 void
201 _tnl_need_projected_coords( GLcontext *ctx, GLboolean mode )
202 {
203 TNLcontext *tnl = TNL_CONTEXT(ctx);
204 if (tnl->NeedNdcCoords != mode) {
205 tnl->NeedNdcCoords = mode;
206 _tnl_InvalidateState( ctx, _NEW_PROJECTION );
207 }
208 }
209
210 void
211 _tnl_need_dlist_loopback( GLcontext *ctx, GLboolean mode )
212 {
213 TNLcontext *tnl = TNL_CONTEXT(ctx);
214 tnl->LoopbackDListCassettes = mode;
215 }
216
217 void
218 _tnl_need_dlist_norm_lengths( GLcontext *ctx, GLboolean mode )
219 {
220 TNLcontext *tnl = TNL_CONTEXT(ctx);
221 tnl->CalcDListNormalLengths = mode;
222 }
223
224 void
225 _tnl_isolate_materials( GLcontext *ctx, GLboolean mode )
226 {
227 TNLcontext *tnl = TNL_CONTEXT(ctx);
228 tnl->IsolateMaterials = mode;
229 }