Subversion Repositories shark

Rev

Rev 56 | Details | Compare with Previous | Last modification | View Log | RSS feed

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