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 _tnl_MakeCurrent( GLcontext
*ctx
,
52 GLframebuffer
*drawBuffer
,
53 GLframebuffer
*readBuffer
)
55 (void) ctx
; (void) drawBuffer
; (void) readBuffer
;
60 install_driver_callbacks( GLcontext
*ctx
)
62 ctx
->Driver
.NewList
= _tnl_NewList
;
63 ctx
->Driver
.EndList
= _tnl_EndList
;
64 ctx
->Driver
.FlushVertices
= _tnl_FlushVertices
;
65 ctx
->Driver
.SaveFlushVertices
= _tnl_SaveFlushVertices
;
66 ctx
->Driver
.MakeCurrent
= _tnl_MakeCurrent
;
67 ctx
->Driver
.BeginCallList
= _tnl_BeginCallList
;
68 ctx
->Driver
.EndCallList
= _tnl_EndCallList
;
74 _tnl_CreateContext( GLcontext
*ctx
)
78 /* Create the TNLcontext structure
80 ctx
->swtnl_context
= tnl
= (TNLcontext
*) CALLOC( sizeof(TNLcontext
) );
86 if (getenv("MESA_CODEGEN"))
87 tnl
->AllowCodegen
= GL_TRUE
;
91 tnl
->vb
.Size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
94 /* Initialize tnl state and tnl->vtxfmt.
96 _tnl_save_init( ctx
);
97 _tnl_array_init( ctx
);
100 if (ctx
->_MaintainTnlProgram
)
101 _tnl_install_pipeline( ctx
, _tnl_vp_pipeline
);
103 _tnl_install_pipeline( ctx
, _tnl_default_pipeline
);
105 /* Initialize the arrayelt helper
107 if (!_ae_create_context( ctx
))
111 tnl
->NeedNdcCoords
= GL_TRUE
;
112 tnl
->LoopbackDListCassettes
= GL_FALSE
;
113 tnl
->CalcDListNormalLengths
= GL_TRUE
;
114 tnl
->AllowVertexFog
= GL_TRUE
;
115 tnl
->AllowPixelFog
= GL_TRUE
;
117 /* Hook our functions into exec and compile dispatch tables.
119 _mesa_install_exec_vtxfmt( ctx
, &tnl
->exec_vtxfmt
);
122 /* Set a few default values in the driver struct.
124 install_driver_callbacks(ctx
);
125 ctx
->Driver
.NeedFlush
= 0;
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
;
138 _tnl_DestroyContext( GLcontext
*ctx
)
140 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
142 _tnl_array_destroy( ctx
);
143 _tnl_vtx_destroy( ctx
);
144 _tnl_save_destroy( ctx
);
145 _tnl_destroy_pipeline( ctx
);
146 _ae_destroy_context( ctx
);
148 _tnl_ProgramCacheDestroy( ctx
);
151 ctx
->swtnl_context
= NULL
;
156 _tnl_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
158 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
160 if (new_state
& (_NEW_HINT
)) {
161 ASSERT(tnl
->AllowVertexFog
|| tnl
->AllowPixelFog
);
162 tnl
->_DoVertexFog
= (tnl
->AllowVertexFog
&& (ctx
->Hint
.Fog
!= GL_NICEST
))
163 || !tnl
->AllowPixelFog
;
166 _ae_invalidate_state(ctx
, new_state
);
168 tnl
->pipeline
.new_state
|= new_state
;
169 tnl
->vtx
.eval
.new_state
|= new_state
;
171 /* Calculate tnl->render_inputs:
173 if (ctx
->Visual
.rgbMode
) {
174 tnl
->render_inputs
= (_TNL_BIT_POS
|
176 (ctx
->Texture
._EnabledCoordUnits
<< _TNL_ATTRIB_TEX0
));
178 if (NEED_SECONDARY_COLOR(ctx
))
179 tnl
->render_inputs
|= _TNL_BIT_COLOR1
;
182 tnl
->render_inputs
|= (_TNL_BIT_POS
|_TNL_BIT_INDEX
);
185 if (ctx
->Fog
.Enabled
||
186 (ctx
->FragmentProgram
._Active
&&
187 ctx
->FragmentProgram
._Current
->FogOption
!= GL_NONE
))
188 tnl
->render_inputs
|= _TNL_BIT_FOG
;
190 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
191 ctx
->Polygon
.BackMode
!= GL_FILL
)
192 tnl
->render_inputs
|= _TNL_BIT_EDGEFLAG
;
194 if (ctx
->RenderMode
== GL_FEEDBACK
)
195 tnl
->render_inputs
|= _TNL_BIT_TEX0
;
197 if (ctx
->Point
._Attenuated
||
198 (ctx
->VertexProgram
._Enabled
&& ctx
->VertexProgram
.PointSizeEnabled
))
199 tnl
->render_inputs
|= _TNL_BIT_POINTSIZE
;
204 _tnl_wakeup_exec( GLcontext
*ctx
)
206 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
208 install_driver_callbacks(ctx
);
209 ctx
->Driver
.NeedFlush
|= FLUSH_UPDATE_CURRENT
;
211 /* Hook our functions into exec and compile dispatch tables.
213 _mesa_install_exec_vtxfmt( ctx
, &tnl
->exec_vtxfmt
);
215 /* Call all appropriate driver callbacks to revive state.
217 _tnl_MakeCurrent( ctx
, ctx
->DrawBuffer
, ctx
->ReadBuffer
);
219 /* Assume we haven't been getting state updates either:
221 _tnl_InvalidateState( ctx
, ~0 );
223 if (ctx
->Light
.ColorMaterialEnabled
) {
224 _mesa_update_color_material( ctx
,
225 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
231 _tnl_wakeup_save_exec( GLcontext
*ctx
)
233 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
235 _tnl_wakeup_exec( ctx
);
236 _mesa_install_save_vtxfmt( ctx
, &tnl
->save_vtxfmt
);
241 * Drivers call this function to tell the TCL module whether or not
242 * it wants Normalized Device Coords (NDC) computed. I.e. whether
243 * we should "Divide-by-W". Software renders will want that.
246 _tnl_need_projected_coords( GLcontext
*ctx
, GLboolean mode
)
248 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
249 if (tnl
->NeedNdcCoords
!= mode
) {
250 tnl
->NeedNdcCoords
= mode
;
251 _tnl_InvalidateState( ctx
, _NEW_PROJECTION
);
256 _tnl_need_dlist_loopback( GLcontext
*ctx
, GLboolean mode
)
258 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
259 tnl
->LoopbackDListCassettes
= mode
;
263 _tnl_need_dlist_norm_lengths( GLcontext
*ctx
, GLboolean mode
)
265 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
266 tnl
->CalcDListNormalLengths
= mode
;
270 _tnl_isolate_materials( GLcontext
*ctx
, GLboolean mode
)
272 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
273 tnl
->IsolateMaterials
= mode
;
277 _tnl_allow_vertex_fog( GLcontext
*ctx
, GLboolean value
)
279 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
280 tnl
->AllowVertexFog
= value
;
284 _tnl_allow_pixel_fog( GLcontext
*ctx
, GLboolean value
)
286 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
287 tnl
->AllowPixelFog
= value
;