3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
26 * Keith Whitwell <keith@tungstengraphics.com>
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"
49 struct immediate
*_tnl_CurrentInput
= NULL
;
54 _tnl_MakeCurrent( GLcontext
*ctx
,
55 GLframebuffer
*drawBuffer
,
56 GLframebuffer
*readBuffer
)
59 SET_IMMEDIATE( ctx
, TNL_CURRENT_IM(ctx
) );
65 install_driver_callbacks( GLcontext
*ctx
)
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
;
78 _tnl_CreateContext( GLcontext
*ctx
)
82 /* Create the TNLcontext structure
84 ctx
->swtnl_context
= tnl
= (TNLcontext
*) CALLOC( sizeof(TNLcontext
) );
92 tnl
->vb
.Size
= MAX2( IMM_SIZE
,
93 ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
);
96 /* Initialize tnl state and tnl->vtxfmt.
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
);
105 tnl
->NeedNdcCoords
= GL_TRUE
;
106 tnl
->LoopbackDListCassettes
= GL_FALSE
;
107 tnl
->CalcDListNormalLengths
= GL_TRUE
;
109 /* Hook our functions into exec and compile dispatch tables.
111 _mesa_install_exec_vtxfmt( ctx
, &tnl
->vtxfmt
);
113 tnl
->save_vtxfmt
= tnl
->vtxfmt
;
114 tnl
->save_vtxfmt
.CallList
= _mesa_save_CallList
;
115 tnl
->save_vtxfmt
.EvalMesh1
= _mesa_save_EvalMesh1
;
116 tnl
->save_vtxfmt
.EvalMesh2
= _mesa_save_EvalMesh2
;
117 tnl
->save_vtxfmt
.Begin
= _tnl_save_Begin
;
119 _mesa_install_save_vtxfmt( ctx
, &tnl
->save_vtxfmt
);
122 /* Set a few default values in the driver struct.
124 install_driver_callbacks(ctx
);
125 ctx
->Driver
.NeedFlush
= FLUSH_UPDATE_CURRENT
;
126 ctx
->Driver
.CurrentExecPrimitive
= PRIM_OUTSIDE_BEGIN_END
;
127 ctx
->Driver
.CurrentSavePrimitive
= PRIM_UNKNOWN
;
129 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
130 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
131 tnl
->Driver
.NotifyMaterialChange
= _mesa_validate_all_lighting_tables
;
140 _tnl_DestroyContext( GLcontext
*ctx
)
142 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
144 _tnl_array_destroy( ctx
);
145 _tnl_imm_destroy( ctx
);
146 _tnl_destroy_pipeline( ctx
);
147 _tnl_free_immediate( ctx
, tnl
->freed_immediate
);
150 ctx
->swtnl_context
= 0;
155 _tnl_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
157 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
159 if (new_state
& _NEW_ARRAY
) {
160 struct immediate
*IM
= TNL_CURRENT_IM(ctx
);
161 IM
->ArrayEltFlags
= ~ctx
->Array
._Enabled
;
162 IM
->ArrayEltFlush
= (ctx
->Array
.LockCount
163 ? FLUSH_ELT_LAZY
: FLUSH_ELT_EAGER
);
164 IM
->ArrayEltIncr
= (ctx
->Array
.Vertex
.Enabled
||
165 (ctx
->VertexProgram
.Enabled
&&
166 ctx
->Array
.VertexAttrib
[0].Enabled
)) ? 1 : 0;
167 tnl
->pipeline
.run_input_changes
|= ctx
->Array
.NewState
; /* overkill */
170 tnl
->pipeline
.run_state_changes
|= new_state
;
171 tnl
->pipeline
.build_state_changes
|= (new_state
&
172 tnl
->pipeline
.build_state_trigger
);
174 tnl
->eval
.EvalNewState
|= new_state
;
179 _tnl_wakeup_exec( GLcontext
*ctx
)
181 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
183 install_driver_callbacks(ctx
);
184 ctx
->Driver
.NeedFlush
|= FLUSH_UPDATE_CURRENT
;
186 /* Hook our functions into exec and compile dispatch tables.
188 _mesa_install_exec_vtxfmt( ctx
, &tnl
->vtxfmt
);
190 /* Call all appropriate driver callbacks to revive state.
192 _tnl_MakeCurrent( ctx
, ctx
->DrawBuffer
, ctx
->ReadBuffer
);
194 /* Assume we haven't been getting state updates either:
196 _tnl_InvalidateState( ctx
, ~0 );
197 tnl
->pipeline
.run_input_changes
= ~0;
199 if (ctx
->Light
.ColorMaterialEnabled
) {
200 _mesa_update_color_material( ctx
, ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
207 _tnl_wakeup_save_exec( GLcontext
*ctx
)
209 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
211 _tnl_wakeup_exec( ctx
);
212 _mesa_install_save_vtxfmt( ctx
, &tnl
->save_vtxfmt
);
217 * Drivers call this function to tell the TCL module whether or not
218 * it wants Normalized Device Coords (NDC) computed. I.e. whether
219 * we should "Divide-by-W". Software renders will want that.
222 _tnl_need_projected_coords( GLcontext
*ctx
, GLboolean mode
)
224 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
225 if (tnl
->NeedNdcCoords
!= mode
) {
226 tnl
->NeedNdcCoords
= mode
;
227 _tnl_InvalidateState( ctx
, _NEW_PROJECTION
);
232 _tnl_need_dlist_loopback( GLcontext
*ctx
, GLboolean mode
)
234 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
235 tnl
->LoopbackDListCassettes
= mode
;
239 _tnl_need_dlist_norm_lengths( GLcontext
*ctx
, GLboolean mode
)
241 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
242 tnl
->CalcDListNormalLengths
= mode
;
246 _tnl_isolate_materials( GLcontext
*ctx
, GLboolean mode
)
248 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
249 tnl
->IsolateMaterials
= mode
;