2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
29 #include "api_arrayelt.h"
38 #include "t_context.h"
39 #include "t_array_api.h"
40 #include "t_vtx_api.h"
41 #include "t_save_api.h"
42 #include "t_pipeline.h"
48 _tnl_MakeCurrent( GLcontext
*ctx
,
49 GLframebuffer
*drawBuffer
,
50 GLframebuffer
*readBuffer
)
56 install_driver_callbacks( GLcontext
*ctx
)
58 ctx
->Driver
.NewList
= _tnl_NewList
;
59 ctx
->Driver
.EndList
= _tnl_EndList
;
60 ctx
->Driver
.FlushVertices
= _tnl_FlushVertices
;
61 ctx
->Driver
.SaveFlushVertices
= _tnl_SaveFlushVertices
;
62 ctx
->Driver
.MakeCurrent
= _tnl_MakeCurrent
;
63 ctx
->Driver
.BeginCallList
= _tnl_BeginCallList
;
64 ctx
->Driver
.EndCallList
= _tnl_EndCallList
;
70 _tnl_CreateContext( GLcontext
*ctx
)
74 /* Create the TNLcontext structure
76 ctx
->swtnl_context
= tnl
= (TNLcontext
*) CALLOC( sizeof(TNLcontext
) );
84 tnl
->vb
.Size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
87 /* Initialize tnl state and tnl->vtxfmt.
89 _tnl_save_init( ctx
);
90 _tnl_array_init( ctx
);
92 _tnl_install_pipeline( ctx
, _tnl_default_pipeline
);
94 /* Initialize the arrayelt helper
96 if (!_ae_create_context( ctx
))
100 tnl
->NeedNdcCoords
= GL_TRUE
;
101 tnl
->LoopbackDListCassettes
= GL_FALSE
;
102 tnl
->CalcDListNormalLengths
= GL_TRUE
;
104 /* Hook our functions into exec and compile dispatch tables.
106 _mesa_install_exec_vtxfmt( ctx
, &tnl
->exec_vtxfmt
);
109 /* Set a few default values in the driver struct.
111 install_driver_callbacks(ctx
);
112 ctx
->Driver
.NeedFlush
= 0;
113 ctx
->Driver
.CurrentExecPrimitive
= PRIM_OUTSIDE_BEGIN_END
;
114 ctx
->Driver
.CurrentSavePrimitive
= PRIM_UNKNOWN
;
116 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
117 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
118 tnl
->Driver
.NotifyMaterialChange
= _mesa_validate_all_lighting_tables
;
125 _tnl_DestroyContext( GLcontext
*ctx
)
127 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
129 _tnl_array_destroy( ctx
);
130 _tnl_vtx_destroy( ctx
);
131 _tnl_save_destroy( ctx
);
132 _tnl_destroy_pipeline( ctx
);
133 _ae_destroy_context( 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 _ae_invalidate_state(ctx
, new_state
);
151 tnl
->pipeline
.run_state_changes
|= new_state
;
152 tnl
->pipeline
.build_state_changes
|= (new_state
&
153 tnl
->pipeline
.build_state_trigger
);
155 tnl
->vtx
.eval
.new_state
|= new_state
;
160 _tnl_wakeup_exec( GLcontext
*ctx
)
162 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
164 install_driver_callbacks(ctx
);
165 ctx
->Driver
.NeedFlush
|= FLUSH_UPDATE_CURRENT
;
167 /* Hook our functions into exec and compile dispatch tables.
169 _mesa_install_exec_vtxfmt( ctx
, &tnl
->exec_vtxfmt
);
171 /* Call all appropriate driver callbacks to revive state.
173 _tnl_MakeCurrent( ctx
, ctx
->DrawBuffer
, ctx
->ReadBuffer
);
175 /* Assume we haven't been getting state updates either:
177 _tnl_InvalidateState( ctx
, ~0 );
178 tnl
->pipeline
.run_input_changes
= ~0;
180 if (ctx
->Light
.ColorMaterialEnabled
) {
181 _mesa_update_color_material( ctx
,
182 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
188 _tnl_wakeup_save_exec( GLcontext
*ctx
)
190 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
192 _tnl_wakeup_exec( ctx
);
193 _mesa_install_save_vtxfmt( ctx
, &tnl
->save_vtxfmt
);
198 * Drivers call this function to tell the TCL module whether or not
199 * it wants Normalized Device Coords (NDC) computed. I.e. whether
200 * we should "Divide-by-W". Software renders will want that.
203 _tnl_need_projected_coords( GLcontext
*ctx
, GLboolean mode
)
205 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
206 if (tnl
->NeedNdcCoords
!= mode
) {
207 tnl
->NeedNdcCoords
= mode
;
208 _tnl_InvalidateState( ctx
, _NEW_PROJECTION
);
213 _tnl_need_dlist_loopback( GLcontext
*ctx
, GLboolean mode
)
215 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
216 tnl
->LoopbackDListCassettes
= mode
;
220 _tnl_need_dlist_norm_lengths( GLcontext
*ctx
, GLboolean mode
)
222 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
223 tnl
->CalcDListNormalLengths
= mode
;
227 _tnl_isolate_materials( GLcontext
*ctx
, GLboolean mode
)
229 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
230 tnl
->IsolateMaterials
= mode
;