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>
30 #include "api_arrayelt.h"
39 #include "t_context.h"
40 #include "t_array_api.h"
41 #include "t_vtx_api.h"
42 #include "t_save_api.h"
43 #include "t_pipeline.h"
49 _tnl_MakeCurrent( GLcontext
*ctx
,
50 GLframebuffer
*drawBuffer
,
51 GLframebuffer
*readBuffer
)
57 install_driver_callbacks( GLcontext
*ctx
)
59 ctx
->Driver
.NewList
= _tnl_NewList
;
60 ctx
->Driver
.EndList
= _tnl_EndList
;
61 ctx
->Driver
.FlushVertices
= _tnl_FlushVertices
;
62 ctx
->Driver
.SaveFlushVertices
= _tnl_SaveFlushVertices
;
63 ctx
->Driver
.MakeCurrent
= _tnl_MakeCurrent
;
64 ctx
->Driver
.BeginCallList
= _tnl_BeginCallList
;
65 ctx
->Driver
.EndCallList
= _tnl_EndCallList
;
71 _tnl_CreateContext( GLcontext
*ctx
)
75 /* Create the TNLcontext structure
77 ctx
->swtnl_context
= tnl
= (TNLcontext
*) CALLOC( sizeof(TNLcontext
) );
85 tnl
->vb
.Size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
88 /* Initialize tnl state and tnl->vtxfmt.
90 _tnl_save_init( ctx
);
91 _tnl_array_init( ctx
);
93 _tnl_install_pipeline( ctx
, _tnl_default_pipeline
);
95 /* Initialize the arrayelt helper
97 if (!_ae_create_context( ctx
))
101 tnl
->NeedNdcCoords
= GL_TRUE
;
102 tnl
->LoopbackDListCassettes
= GL_FALSE
;
103 tnl
->CalcDListNormalLengths
= GL_TRUE
;
105 /* Hook our functions into exec and compile dispatch tables.
107 _mesa_install_exec_vtxfmt( ctx
, &tnl
->exec_vtxfmt
);
110 /* Set a few default values in the driver struct.
112 install_driver_callbacks(ctx
);
113 ctx
->Driver
.NeedFlush
= 0;
114 ctx
->Driver
.CurrentExecPrimitive
= PRIM_OUTSIDE_BEGIN_END
;
115 ctx
->Driver
.CurrentSavePrimitive
= PRIM_UNKNOWN
;
117 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
118 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
119 tnl
->Driver
.NotifyMaterialChange
= _mesa_validate_all_lighting_tables
;
126 _tnl_DestroyContext( GLcontext
*ctx
)
128 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
130 _tnl_array_destroy( ctx
);
131 _tnl_vtx_destroy( ctx
);
132 _tnl_save_destroy( ctx
);
133 _tnl_destroy_pipeline( ctx
);
136 ctx
->swtnl_context
= 0;
141 _tnl_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
143 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
145 if (new_state
& _NEW_ARRAY
) {
146 tnl
->pipeline
.run_input_changes
|= ctx
->Array
.NewState
; /* overkill */
149 tnl
->pipeline
.run_state_changes
|= new_state
;
150 tnl
->pipeline
.build_state_changes
|= (new_state
&
151 tnl
->pipeline
.build_state_trigger
);
153 tnl
->vtx
.eval
.new_state
|= new_state
;
158 _tnl_wakeup_exec( GLcontext
*ctx
)
160 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
162 install_driver_callbacks(ctx
);
163 ctx
->Driver
.NeedFlush
|= FLUSH_UPDATE_CURRENT
;
165 /* Hook our functions into exec and compile dispatch tables.
167 _mesa_install_exec_vtxfmt( ctx
, &tnl
->exec_vtxfmt
);
169 /* Call all appropriate driver callbacks to revive state.
171 _tnl_MakeCurrent( ctx
, ctx
->DrawBuffer
, ctx
->ReadBuffer
);
173 /* Assume we haven't been getting state updates either:
175 _tnl_InvalidateState( ctx
, ~0 );
176 tnl
->pipeline
.run_input_changes
= ~0;
178 if (ctx
->Light
.ColorMaterialEnabled
) {
179 _mesa_update_color_material( ctx
,
180 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
186 _tnl_wakeup_save_exec( GLcontext
*ctx
)
188 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
190 _tnl_wakeup_exec( ctx
);
191 _mesa_install_save_vtxfmt( ctx
, &tnl
->save_vtxfmt
);
196 * Drivers call this function to tell the TCL module whether or not
197 * it wants Normalized Device Coords (NDC) computed. I.e. whether
198 * we should "Divide-by-W". Software renders will want that.
201 _tnl_need_projected_coords( GLcontext
*ctx
, GLboolean mode
)
203 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
204 if (tnl
->NeedNdcCoords
!= mode
) {
205 tnl
->NeedNdcCoords
= mode
;
206 _tnl_InvalidateState( ctx
, _NEW_PROJECTION
);
211 _tnl_need_dlist_loopback( GLcontext
*ctx
, GLboolean mode
)
213 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
214 tnl
->LoopbackDListCassettes
= mode
;
218 _tnl_need_dlist_norm_lengths( GLcontext
*ctx
, GLboolean mode
)
220 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
221 tnl
->CalcDListNormalLengths
= mode
;
225 _tnl_isolate_materials( GLcontext
*ctx
, GLboolean mode
)
227 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
228 tnl
->IsolateMaterials
= mode
;