2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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 "nvfragprog.h"
41 #include "t_array_api.h"
42 #include "t_context.h"
43 #include "t_pipeline.h"
44 #include "t_save_api.h"
45 #include "t_vp_build.h"
46 #include "t_vtx_api.h"
51 install_driver_callbacks( GLcontext
*ctx
)
53 ctx
->Driver
.NewList
= _tnl_NewList
;
54 ctx
->Driver
.EndList
= _tnl_EndList
;
55 ctx
->Driver
.FlushVertices
= _tnl_FlushVertices
;
56 ctx
->Driver
.SaveFlushVertices
= _tnl_SaveFlushVertices
;
57 ctx
->Driver
.BeginCallList
= _tnl_BeginCallList
;
58 ctx
->Driver
.EndCallList
= _tnl_EndCallList
;
64 _tnl_CreateContext( GLcontext
*ctx
)
68 /* Create the TNLcontext structure
70 ctx
->swtnl_context
= tnl
= (TNLcontext
*) CALLOC( sizeof(TNLcontext
) );
76 if (_mesa_getenv("MESA_CODEGEN"))
77 tnl
->AllowCodegen
= GL_TRUE
;
81 tnl
->vb
.Size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
84 /* Initialize tnl state and tnl->vtxfmt.
86 _tnl_save_init( ctx
);
87 _tnl_array_init( ctx
);
90 if (ctx
->_MaintainTnlProgram
)
91 _tnl_install_pipeline( ctx
, _tnl_vp_pipeline
);
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
;
104 tnl
->AllowVertexFog
= GL_TRUE
;
105 tnl
->AllowPixelFog
= GL_TRUE
;
107 /* Hook our functions into exec and compile dispatch tables.
109 _mesa_install_exec_vtxfmt( ctx
, &tnl
->exec_vtxfmt
);
112 /* Set a few default values in the driver struct.
114 install_driver_callbacks(ctx
);
115 ctx
->Driver
.NeedFlush
= 0;
116 ctx
->Driver
.CurrentExecPrimitive
= PRIM_OUTSIDE_BEGIN_END
;
117 ctx
->Driver
.CurrentSavePrimitive
= PRIM_UNKNOWN
;
119 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
120 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
121 tnl
->Driver
.NotifyMaterialChange
= _mesa_validate_all_lighting_tables
;
128 _tnl_DestroyContext( GLcontext
*ctx
)
130 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
132 _tnl_array_destroy( ctx
);
133 _tnl_vtx_destroy( ctx
);
134 _tnl_save_destroy( ctx
);
135 _tnl_destroy_pipeline( ctx
);
136 _ae_destroy_context( ctx
);
138 _tnl_ProgramCacheDestroy( ctx
);
141 ctx
->swtnl_context
= NULL
;
146 _tnl_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
148 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
150 if (new_state
& (_NEW_HINT
)) {
151 ASSERT(tnl
->AllowVertexFog
|| tnl
->AllowPixelFog
);
152 tnl
->_DoVertexFog
= (tnl
->AllowVertexFog
&& (ctx
->Hint
.Fog
!= GL_NICEST
))
153 || !tnl
->AllowPixelFog
;
156 _ae_invalidate_state(ctx
, new_state
);
158 tnl
->pipeline
.new_state
|= new_state
;
159 tnl
->vtx
.eval
.new_state
|= new_state
;
161 /* Calculate tnl->render_inputs:
163 if (ctx
->Visual
.rgbMode
) {
164 tnl
->render_inputs
= (_TNL_BIT_POS
|
166 (ctx
->Texture
._EnabledCoordUnits
<< _TNL_ATTRIB_TEX0
));
168 if (NEED_SECONDARY_COLOR(ctx
))
169 tnl
->render_inputs
|= _TNL_BIT_COLOR1
;
172 tnl
->render_inputs
|= (_TNL_BIT_POS
|_TNL_BIT_INDEX
);
175 if (ctx
->Fog
.Enabled
||
176 (ctx
->FragmentProgram
._Active
&&
177 ctx
->FragmentProgram
._Current
->FogOption
!= GL_NONE
))
178 tnl
->render_inputs
|= _TNL_BIT_FOG
;
180 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
181 ctx
->Polygon
.BackMode
!= GL_FILL
)
182 tnl
->render_inputs
|= _TNL_BIT_EDGEFLAG
;
184 if (ctx
->RenderMode
== GL_FEEDBACK
)
185 tnl
->render_inputs
|= _TNL_BIT_TEX0
;
187 if (ctx
->Point
._Attenuated
||
188 (ctx
->VertexProgram
._Enabled
&& ctx
->VertexProgram
.PointSizeEnabled
))
189 tnl
->render_inputs
|= _TNL_BIT_POINTSIZE
;
194 _tnl_wakeup_exec( GLcontext
*ctx
)
196 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
198 install_driver_callbacks(ctx
);
199 ctx
->Driver
.NeedFlush
|= FLUSH_UPDATE_CURRENT
;
201 /* Hook our functions into exec and compile dispatch tables.
203 _mesa_install_exec_vtxfmt( ctx
, &tnl
->exec_vtxfmt
);
205 /* Assume we haven't been getting state updates either:
207 _tnl_InvalidateState( ctx
, ~0 );
209 if (ctx
->Light
.ColorMaterialEnabled
) {
210 _mesa_update_color_material( ctx
,
211 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
217 _tnl_wakeup_save_exec( GLcontext
*ctx
)
219 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
221 _tnl_wakeup_exec( ctx
);
222 _mesa_install_save_vtxfmt( ctx
, &tnl
->save_vtxfmt
);
227 * Drivers call this function to tell the TCL module whether or not
228 * it wants Normalized Device Coords (NDC) computed. I.e. whether
229 * we should "Divide-by-W". Software renders will want that.
232 _tnl_need_projected_coords( GLcontext
*ctx
, GLboolean mode
)
234 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
235 if (tnl
->NeedNdcCoords
!= mode
) {
236 tnl
->NeedNdcCoords
= mode
;
237 _tnl_InvalidateState( ctx
, _NEW_PROJECTION
);
242 _tnl_need_dlist_loopback( GLcontext
*ctx
, GLboolean mode
)
244 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
245 tnl
->LoopbackDListCassettes
= mode
;
249 _tnl_need_dlist_norm_lengths( GLcontext
*ctx
, GLboolean mode
)
251 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
252 tnl
->CalcDListNormalLengths
= mode
;
256 _tnl_isolate_materials( GLcontext
*ctx
, GLboolean mode
)
258 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
259 tnl
->IsolateMaterials
= mode
;
263 _tnl_allow_vertex_fog( GLcontext
*ctx
, GLboolean value
)
265 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
266 tnl
->AllowVertexFog
= value
;
270 _tnl_allow_pixel_fog( GLcontext
*ctx
, GLboolean value
)
272 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
273 tnl
->AllowPixelFog
= value
;