Rename some of the tnl->Driver.* functions to tnl->Driver.Render.*, to make it
[mesa.git] / src / mesa / tnl / t_context.c
1 /* $Id: t_context.c,v 1.21 2001/07/12 22:09:21 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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 "macros.h"
33 #include "mtypes.h"
34 #include "mem.h"
35 #include "dlist.h"
36 #include "vtxfmt.h"
37
38 #include "t_context.h"
39 #include "t_array_api.h"
40 #include "t_eval_api.h"
41 #include "t_imm_alloc.h"
42 #include "t_imm_api.h"
43 #include "t_imm_exec.h"
44 #include "t_imm_dlist.h"
45 #include "t_pipeline.h"
46 #include "tnl.h"
47
48 #ifndef THREADS
49 struct immediate *_tnl_CurrentInput = NULL;
50 #endif
51
52
53 void
54 _tnl_MakeCurrent( GLcontext *ctx,
55 GLframebuffer *drawBuffer,
56 GLframebuffer *readBuffer )
57 {
58 #ifndef THREADS
59 SET_IMMEDIATE( ctx, TNL_CURRENT_IM(ctx) );
60 #endif
61 }
62
63
64 static void
65 install_driver_callbacks( GLcontext *ctx )
66 {
67 ctx->Driver.NewList = _tnl_NewList;
68 ctx->Driver.EndList = _tnl_EndList;
69 ctx->Driver.FlushVertices = _tnl_flush_vertices;
70 ctx->Driver.MakeCurrent = _tnl_MakeCurrent;
71 ctx->Driver.BeginCallList = _tnl_BeginCallList;
72 ctx->Driver.EndCallList = _tnl_EndCallList;
73 }
74
75
76
77 GLboolean
78 _tnl_CreateContext( GLcontext *ctx )
79 {
80 TNLcontext *tnl;
81
82 /* Create the TNLcontext structure
83 */
84 ctx->swtnl_context = tnl = (TNLcontext *) CALLOC( sizeof(TNLcontext) );
85
86 if (!tnl) {
87 return GL_FALSE;
88 }
89
90 /* Initialize the VB.
91 */
92 tnl->vb.Size = MAX2( IMM_SIZE,
93 ctx->Const.MaxArrayLockSize + MAX_CLIPPED_VERTICES);
94
95
96 /* Initialize tnl state and tnl->vtxfmt.
97 */
98 _tnl_dlist_init( ctx );
99 _tnl_array_init( ctx );
100 _tnl_imm_init( ctx );
101 _tnl_eval_init( ctx );
102 _tnl_install_pipeline( ctx, _tnl_default_pipeline );
103
104
105 tnl->NeedProjCoords = GL_TRUE;
106 tnl->LoopbackDListCassettes = GL_FALSE;
107 tnl->CalcDListNormalLengths = GL_TRUE;
108
109 /* Hook our functions into exec and compile dispatch tables.
110 */
111 _mesa_install_exec_vtxfmt( ctx, &tnl->vtxfmt );
112 _mesa_install_save_vtxfmt( ctx, &tnl->vtxfmt );
113 ctx->Save->CallList = _mesa_save_CallList;
114 ctx->Save->CallLists = _mesa_save_CallLists;
115 ctx->Save->EvalMesh1 = _mesa_save_EvalMesh1;
116 ctx->Save->EvalMesh2 = _mesa_save_EvalMesh2;
117 ctx->Save->Begin = _tnl_save_Begin;
118
119 /* Set a few default values in the driver struct.
120 */
121 install_driver_callbacks(ctx);
122 ctx->Driver.NeedFlush = FLUSH_UPDATE_CURRENT;
123 ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
124 ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
125
126 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
127 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
128
129
130 return GL_TRUE;
131 }
132
133
134 void
135 _tnl_DestroyContext( GLcontext *ctx )
136 {
137 TNLcontext *tnl = TNL_CONTEXT(ctx);
138
139 _tnl_array_destroy( ctx );
140 _tnl_imm_destroy( ctx );
141 _tnl_destroy_pipeline( ctx );
142
143 FREE(tnl);
144 ctx->swtnl_context = 0;
145 }
146
147
148 void
149 _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
150 {
151 TNLcontext *tnl = TNL_CONTEXT(ctx);
152
153 if (new_state & _NEW_ARRAY) {
154 struct immediate *IM = TNL_CURRENT_IM(ctx);
155 IM->ArrayEltFlags = ~ctx->Array._Enabled;
156 IM->ArrayEltFlush = (ctx->Array.LockCount
157 ? FLUSH_ELT_LAZY : FLUSH_ELT_EAGER);
158 IM->ArrayEltIncr = ctx->Array.Vertex.Enabled ? 1 : 0;
159 tnl->pipeline.run_input_changes |= ctx->Array.NewState; /* overkill */
160 }
161
162 tnl->pipeline.run_state_changes |= new_state;
163 tnl->pipeline.build_state_changes |= (new_state &
164 tnl->pipeline.build_state_trigger);
165
166 tnl->eval.EvalNewState |= new_state;
167 }
168
169
170 void
171 _tnl_wakeup_exec( GLcontext *ctx )
172 {
173 TNLcontext *tnl = TNL_CONTEXT(ctx);
174
175 install_driver_callbacks(ctx);
176 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;
177
178 /* Hook our functions into exec and compile dispatch tables.
179 */
180 _mesa_install_exec_vtxfmt( ctx, &tnl->vtxfmt );
181
182 /* Call all appropriate driver callbacks to revive state.
183 */
184 _tnl_MakeCurrent( ctx, ctx->DrawBuffer, ctx->ReadBuffer );
185
186 /* Assume we haven't been getting state updates either:
187 */
188 _tnl_InvalidateState( ctx, ~0 );
189 tnl->pipeline.run_input_changes = ~0;
190 }
191
192
193 void
194 _tnl_wakeup_save_exec( GLcontext *ctx )
195 {
196 TNLcontext *tnl = TNL_CONTEXT(ctx);
197
198 _tnl_wakeup_exec( ctx );
199 _mesa_install_save_vtxfmt( ctx, &tnl->vtxfmt );
200 ctx->Save->CallList = _mesa_save_CallList; /* fixme */
201 ctx->Save->CallLists = _mesa_save_CallLists;
202 ctx->Save->EvalMesh1 = _mesa_save_EvalMesh1; /* fixme */
203 ctx->Save->EvalMesh2 = _mesa_save_EvalMesh2;
204 ctx->Save->Begin = _tnl_save_Begin;
205 }
206
207
208 void
209 _tnl_need_projected_coords( GLcontext *ctx, GLboolean mode )
210 {
211 TNLcontext *tnl = TNL_CONTEXT(ctx);
212 if (tnl->NeedProjCoords != mode) {
213 tnl->NeedProjCoords = mode;
214 _tnl_InvalidateState( ctx, _NEW_PROJECTION );
215 }
216 }
217
218 void
219 _tnl_need_dlist_loopback( GLcontext *ctx, GLboolean mode )
220 {
221 TNLcontext *tnl = TNL_CONTEXT(ctx);
222 if (tnl->LoopbackDListCassettes != mode) {
223 tnl->LoopbackDListCassettes = mode;
224 }
225 }
226
227 void
228 _tnl_need_dlist_norm_lengths( GLcontext *ctx, GLboolean mode )
229 {
230 TNLcontext *tnl = TNL_CONTEXT(ctx);
231 if (tnl->CalcDListNormalLengths != mode) {
232 tnl->CalcDListNormalLengths = mode;
233 }
234 }