call _ae_destroy_context() and _ae_invalidate_state() from the proper places
[mesa.git] / src / mesa / tnl / t_context.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 5.1
4 *
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28
29 #include "api_arrayelt.h"
30 #include "glheader.h"
31 #include "imports.h"
32 #include "macros.h"
33 #include "mtypes.h"
34 #include "dlist.h"
35 #include "light.h"
36 #include "vtxfmt.h"
37
38 #include "t_context.h"
39 #include "t_array_api.h"
40 #include "t_vtx_api.h"
41 #include "t_save_api.h"
42 #include "t_pipeline.h"
43 #include "tnl.h"
44
45
46
47 void
48 _tnl_MakeCurrent( GLcontext *ctx,
49 GLframebuffer *drawBuffer,
50 GLframebuffer *readBuffer )
51 {
52 }
53
54
55 static void
56 install_driver_callbacks( GLcontext *ctx )
57 {
58 ctx->Driver.NewList = _tnl_NewList;
59 ctx->Driver.EndList = _tnl_EndList;
60 ctx->Driver.FlushVertices = _tnl_FlushVertices;
61 ctx->Driver.SaveFlushVertices = _tnl_SaveFlushVertices;
62 ctx->Driver.MakeCurrent = _tnl_MakeCurrent;
63 ctx->Driver.BeginCallList = _tnl_BeginCallList;
64 ctx->Driver.EndCallList = _tnl_EndCallList;
65 }
66
67
68
69 GLboolean
70 _tnl_CreateContext( GLcontext *ctx )
71 {
72 TNLcontext *tnl;
73
74 /* Create the TNLcontext structure
75 */
76 ctx->swtnl_context = tnl = (TNLcontext *) CALLOC( sizeof(TNLcontext) );
77
78 if (!tnl) {
79 return GL_FALSE;
80 }
81
82 /* Initialize the VB.
83 */
84 tnl->vb.Size = ctx->Const.MaxArrayLockSize + MAX_CLIPPED_VERTICES;
85
86
87 /* Initialize tnl state and tnl->vtxfmt.
88 */
89 _tnl_save_init( ctx );
90 _tnl_array_init( ctx );
91 _tnl_vtx_init( ctx );
92 _tnl_install_pipeline( ctx, _tnl_default_pipeline );
93
94 /* Initialize the arrayelt helper
95 */
96 if (!_ae_create_context( ctx ))
97 return GL_FALSE;
98
99
100 tnl->NeedNdcCoords = GL_TRUE;
101 tnl->LoopbackDListCassettes = GL_FALSE;
102 tnl->CalcDListNormalLengths = GL_TRUE;
103
104 /* Hook our functions into exec and compile dispatch tables.
105 */
106 _mesa_install_exec_vtxfmt( ctx, &tnl->exec_vtxfmt );
107
108
109 /* Set a few default values in the driver struct.
110 */
111 install_driver_callbacks(ctx);
112 ctx->Driver.NeedFlush = 0;
113 ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
114 ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
115
116 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
117 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
118 tnl->Driver.NotifyMaterialChange = _mesa_validate_all_lighting_tables;
119
120 return GL_TRUE;
121 }
122
123
124 void
125 _tnl_DestroyContext( GLcontext *ctx )
126 {
127 TNLcontext *tnl = TNL_CONTEXT(ctx);
128
129 _tnl_array_destroy( ctx );
130 _tnl_vtx_destroy( ctx );
131 _tnl_save_destroy( ctx );
132 _tnl_destroy_pipeline( ctx );
133 _ae_destroy_context( 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 _ae_invalidate_state(ctx, new_state);
150
151 tnl->pipeline.run_state_changes |= new_state;
152 tnl->pipeline.build_state_changes |= (new_state &
153 tnl->pipeline.build_state_trigger);
154
155 tnl->vtx.eval.new_state |= new_state;
156 }
157
158
159 void
160 _tnl_wakeup_exec( GLcontext *ctx )
161 {
162 TNLcontext *tnl = TNL_CONTEXT(ctx);
163
164 install_driver_callbacks(ctx);
165 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;
166
167 /* Hook our functions into exec and compile dispatch tables.
168 */
169 _mesa_install_exec_vtxfmt( ctx, &tnl->exec_vtxfmt );
170
171 /* Call all appropriate driver callbacks to revive state.
172 */
173 _tnl_MakeCurrent( ctx, ctx->DrawBuffer, ctx->ReadBuffer );
174
175 /* Assume we haven't been getting state updates either:
176 */
177 _tnl_InvalidateState( ctx, ~0 );
178 tnl->pipeline.run_input_changes = ~0;
179
180 if (ctx->Light.ColorMaterialEnabled) {
181 _mesa_update_color_material( ctx,
182 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
183 }
184 }
185
186
187 void
188 _tnl_wakeup_save_exec( GLcontext *ctx )
189 {
190 TNLcontext *tnl = TNL_CONTEXT(ctx);
191
192 _tnl_wakeup_exec( ctx );
193 _mesa_install_save_vtxfmt( ctx, &tnl->save_vtxfmt );
194 }
195
196
197 /**
198 * Drivers call this function to tell the TCL module whether or not
199 * it wants Normalized Device Coords (NDC) computed. I.e. whether
200 * we should "Divide-by-W". Software renders will want that.
201 */
202 void
203 _tnl_need_projected_coords( GLcontext *ctx, GLboolean mode )
204 {
205 TNLcontext *tnl = TNL_CONTEXT(ctx);
206 if (tnl->NeedNdcCoords != mode) {
207 tnl->NeedNdcCoords = mode;
208 _tnl_InvalidateState( ctx, _NEW_PROJECTION );
209 }
210 }
211
212 void
213 _tnl_need_dlist_loopback( GLcontext *ctx, GLboolean mode )
214 {
215 TNLcontext *tnl = TNL_CONTEXT(ctx);
216 tnl->LoopbackDListCassettes = mode;
217 }
218
219 void
220 _tnl_need_dlist_norm_lengths( GLcontext *ctx, GLboolean mode )
221 {
222 TNLcontext *tnl = TNL_CONTEXT(ctx);
223 tnl->CalcDListNormalLengths = mode;
224 }
225
226 void
227 _tnl_isolate_materials( GLcontext *ctx, GLboolean mode )
228 {
229 TNLcontext *tnl = TNL_CONTEXT(ctx);
230 tnl->IsolateMaterials = mode;
231 }