2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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 "main/glheader.h"
30 #include "main/imports.h"
31 #include "main/context.h"
32 #include "main/macros.h"
33 #include "main/mtypes.h"
34 #include "main/light.h"
35 #include "math/m_translate.h"
36 #include "math/m_xform.h"
37 #include "main/state.h"
40 #include "t_context.h"
41 #include "t_pipeline.h"
46 _tnl_CreateContext( struct gl_context
*ctx
)
50 /* Create the TNLcontext structure
52 ctx
->swtnl_context
= tnl
= (TNLcontext
*) CALLOC( sizeof(TNLcontext
) );
60 tnl
->vb
.Size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
63 /* Initialize tnl state.
65 if (ctx
->VertexProgram
._MaintainTnlProgram
) {
66 _tnl_install_pipeline( ctx
, _tnl_vp_pipeline
);
68 _tnl_install_pipeline( ctx
, _tnl_default_pipeline
);
71 tnl
->NeedNdcCoords
= GL_TRUE
;
72 tnl
->AllowVertexFog
= GL_TRUE
;
73 tnl
->AllowPixelFog
= GL_TRUE
;
75 /* Set a few default values in the driver struct.
77 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
78 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
79 tnl
->Driver
.NotifyMaterialChange
= _mesa_validate_all_lighting_tables
;
83 /* plug in the VBO drawing function */
84 vbo_set_draw_func(ctx
, _tnl_vbo_draw_prims
);
86 _math_init_transformation();
87 _math_init_translate();
94 _tnl_DestroyContext( struct gl_context
*ctx
)
96 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
98 _tnl_destroy_pipeline( ctx
);
101 ctx
->swtnl_context
= NULL
;
106 _tnl_InvalidateState( struct gl_context
*ctx
, GLuint new_state
)
108 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
109 const struct gl_vertex_program
*vp
= ctx
->VertexProgram
._Current
;
110 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
._Current
;
113 if (new_state
& (_NEW_HINT
| _NEW_PROGRAM
)) {
114 ASSERT(tnl
->AllowVertexFog
|| tnl
->AllowPixelFog
);
115 tnl
->_DoVertexFog
= ((tnl
->AllowVertexFog
&& (ctx
->Hint
.Fog
!= GL_NICEST
))
116 || !tnl
->AllowPixelFog
) && !fp
;
119 tnl
->pipeline
.new_state
|= new_state
;
121 /* Calculate tnl->render_inputs. This bitmask indicates which vertex
122 * attributes need to be emitted to the rasterizer.
124 tnl
->render_inputs_bitset
= BITFIELD64_BIT(_TNL_ATTRIB_POS
);
126 if (!fp
|| (fp
->Base
.InputsRead
& FRAG_BIT_COL0
)) {
127 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_COLOR0
);
130 if (_mesa_need_secondary_color(ctx
))
131 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_COLOR1
);
133 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++) {
134 if (ctx
->Texture
._EnabledCoordUnits
& (1 << i
) ||
135 (fp
&& fp
->Base
.InputsRead
& FRAG_BIT_TEX(i
))) {
136 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_TEX(i
));
141 || (fp
!= NULL
&& (fp
->Base
.InputsRead
& FRAG_BIT_FOGC
) != 0)) {
142 /* Either fixed-function fog or a fragment program needs fog coord.
144 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_FOG
);
147 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
148 ctx
->Polygon
.BackMode
!= GL_FILL
)
149 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_EDGEFLAG
);
151 if (ctx
->RenderMode
== GL_FEEDBACK
)
152 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_TEX0
);
154 if (ctx
->Point
._Attenuated
|| ctx
->VertexProgram
.PointSizeEnabled
)
155 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_POINTSIZE
);
157 /* check for varying vars which are written by the vertex program */
160 for (i
= 0; i
< MAX_VARYING
; i
++) {
161 if (vp
->Base
.OutputsWritten
& BITFIELD64_BIT(VERT_RESULT_VAR0
+ i
)) {
162 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_GENERIC(i
));
170 _tnl_wakeup( struct gl_context
*ctx
)
172 /* Assume we haven't been getting state updates either:
174 _tnl_InvalidateState( ctx
, ~0 );
177 if (ctx
->Light
.ColorMaterialEnabled
) {
178 _mesa_update_color_material( ctx
,
179 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
188 * Drivers call this function to tell the TCL module whether or not
189 * it wants Normalized Device Coords (NDC) computed. I.e. whether
190 * we should "Divide-by-W". Software renders will want that.
193 _tnl_need_projected_coords( struct gl_context
*ctx
, GLboolean mode
)
195 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
196 tnl
->NeedNdcCoords
= mode
;
200 _tnl_allow_vertex_fog( struct gl_context
*ctx
, GLboolean value
)
202 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
203 tnl
->AllowVertexFog
= value
;
204 tnl
->_DoVertexFog
= ((tnl
->AllowVertexFog
&& (ctx
->Hint
.Fog
!= GL_NICEST
))
205 || !tnl
->AllowPixelFog
) && !ctx
->FragmentProgram
._Current
;
210 _tnl_allow_pixel_fog( struct gl_context
*ctx
, GLboolean value
)
212 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
213 tnl
->AllowPixelFog
= value
;
214 tnl
->_DoVertexFog
= ((tnl
->AllowVertexFog
&& (ctx
->Hint
.Fog
!= GL_NICEST
))
215 || !tnl
->AllowPixelFog
) && !ctx
->FragmentProgram
._Current
;