93886b71101daf986342a6284a09bf03a879da3b
[mesa.git] / src / mesa / tnl / t_context.c
1 /* $Id: t_context.c,v 1.9 2001/01/08 21:56:00 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 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 ctx->Driver.RenderTabElts = _tnl_render_tab_elts;
75 ctx->Driver.RenderTabVerts = _tnl_render_tab_verts;
76 }
77
78
79
80 GLboolean
81 _tnl_CreateContext( GLcontext *ctx )
82 {
83 TNLcontext *tnl;
84
85 /* Create the TNLcontext structure
86 */
87 ctx->swtnl_context = tnl = CALLOC( sizeof(TNLcontext) );
88
89 if (!tnl) {
90 return GL_FALSE;
91 }
92
93 /* Initialize the VB.
94 */
95 tnl->vb.Size = MAX2( IMM_SIZE,
96 ctx->Const.MaxArrayLockSize + MAX_CLIPPED_VERTICES);
97
98
99 /* Initialize tnl state and tnl->vtxfmt.
100 */
101 _tnl_dlist_init( ctx );
102 _tnl_array_init( ctx );
103 _tnl_imm_init( ctx );
104 _tnl_eval_init( ctx );
105 _tnl_install_pipeline( ctx, _tnl_default_pipeline );
106
107
108 /* Hook our functions into exec and compile dispatch tables.
109 */
110 _mesa_install_exec_vtxfmt( ctx, &tnl->vtxfmt );
111 _mesa_install_save_vtxfmt( ctx, &tnl->vtxfmt );
112 ctx->Save->EvalMesh1 = _mesa_save_EvalMesh1; /* fixme */
113 ctx->Save->EvalMesh2 = _mesa_save_EvalMesh2;
114 ctx->Save->Begin = _tnl_save_Begin;
115
116 /* Set a few default values in the driver struct.
117 */
118 install_driver_callbacks(ctx);
119 ctx->Driver.NeedFlush = FLUSH_UPDATE_CURRENT;
120 ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
121 ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
122 return GL_TRUE;
123 }
124
125
126 void
127 _tnl_DestroyContext( GLcontext *ctx )
128 {
129 TNLcontext *tnl = TNL_CONTEXT(ctx);
130
131 /* _tnl_dlist_destroy( ctx ); */
132 _tnl_array_destroy( ctx );
133 _tnl_imm_destroy( ctx );
134 /* _tnl_eval_destroy( ctx ); */
135 _tnl_destroy_pipeline( ctx );
136
137 FREE(tnl);
138 ctx->swtnl_context = 0;
139 }
140
141
142 void
143 _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
144 {
145 TNLcontext *tnl = TNL_CONTEXT(ctx);
146
147 if (new_state & _NEW_ARRAY) {
148 struct immediate *IM = TNL_CURRENT_IM(ctx);
149 IM->ArrayEltFlags = ~ctx->Array._Enabled;
150 IM->ArrayEltFlush = !ctx->Array.LockCount;
151 IM->ArrayEltIncr = ctx->Array.Vertex.Enabled ? 1 : 0;
152 tnl->pipeline.run_input_changes |= ctx->Array.NewState; /* overkill */
153 }
154
155 tnl->pipeline.run_state_changes |= new_state;
156 tnl->pipeline.build_state_changes |= (new_state &
157 tnl->pipeline.build_state_trigger);
158
159 tnl->eval.EvalNewState |= new_state;
160 }
161
162
163 void
164 _tnl_wakeup_exec( GLcontext *ctx )
165 {
166 TNLcontext *tnl = TNL_CONTEXT(ctx);
167
168 install_driver_callbacks(ctx);
169 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;
170
171 /* Hook our functions into exec and compile dispatch tables.
172 */
173 _mesa_install_exec_vtxfmt( ctx, &tnl->vtxfmt );
174
175 /* Call all appropriate driver callbacks to revive state.
176 */
177 _tnl_MakeCurrent( ctx, ctx->DrawBuffer, ctx->ReadBuffer );
178
179 /* Assume we haven't been getting state updates either:
180 */
181 _tnl_InvalidateState( ctx, ~0 );
182 tnl->pipeline.run_input_changes = ~0;
183 }
184
185
186 void
187 _tnl_wakeup_save_exec( GLcontext *ctx )
188 {
189 TNLcontext *tnl = TNL_CONTEXT(ctx);
190
191 _tnl_wakeup_exec( ctx );
192 _mesa_install_save_vtxfmt( ctx, &tnl->vtxfmt );
193 ctx->Save->EvalMesh1 = _mesa_save_EvalMesh1; /* fixme */
194 ctx->Save->EvalMesh2 = _mesa_save_EvalMesh2;
195 ctx->Save->Begin = _tnl_save_Begin;
196 }
197