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>
31 _tnl_CreateContext( struct gl_context
*ctx
)
35 /* Create the TNLcontext structure
37 ctx
->swtnl_context
= tnl
= (TNLcontext
*) CALLOC( sizeof(TNLcontext
) );
45 tnl
->vb
.Size
= ctx
->Const
.MaxArrayLockSize
+ MAX_CLIPPED_VERTICES
;
48 /* Initialize tnl state.
50 _tnl_install_pipeline( ctx
, _tnl_default_pipeline
);
52 tnl
->NeedNdcCoords
= GL_TRUE
;
53 tnl
->AllowVertexFog
= GL_TRUE
;
54 tnl
->AllowPixelFog
= GL_TRUE
;
56 /* Set a few default values in the driver struct.
58 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
59 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
60 tnl
->Driver
.NotifyMaterialChange
= _mesa_validate_all_lighting_tables
;
64 /* plug in the VBO drawing function */
65 vbo_set_draw_func(ctx
, _tnl_vbo_draw_prims
);
67 _math_init_transformation();
68 _math_init_translate();
75 _tnl_DestroyContext( struct gl_context
*ctx
)
77 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
79 _tnl_destroy_pipeline( ctx
);
82 ctx
->swtnl_context
= NULL
;
87 _tnl_InvalidateState( struct gl_context
*ctx
, GLuint new_state
)
89 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
91 if (new_state
& _NEW_HINT
) {
92 ASSERT(tnl
->AllowVertexFog
|| tnl
->AllowPixelFog
);
93 tnl
->_DoVertexFog
= ((tnl
->AllowVertexFog
&& (ctx
->Hint
.Fog
!= GL_NICEST
))
94 || !tnl
->AllowPixelFog
);
97 tnl
->pipeline
.new_state
|= new_state
;
99 /* Calculate tnl->render_inputs. This bitmask indicates which vertex
100 * attributes need to be emitted to the rasterizer.
102 tnl
->render_inputs_bitset
= BITFIELD64_BIT(_TNL_ATTRIB_POS
);
104 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_COLOR
);
106 if (ctx
->Texture
._EnabledCoord
) {
107 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_TEX
);
110 if (ctx
->Fog
.Enabled
) {
111 /* Either fixed-function fog or a fragment program needs fog coord.
113 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_FOG
);
116 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
117 ctx
->Polygon
.BackMode
!= GL_FILL
)
118 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_EDGEFLAG
);
120 if (ctx
->RenderMode
== GL_FEEDBACK
)
121 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_TEX
);
123 if (ctx
->Point
._Attenuated
)
124 tnl
->render_inputs_bitset
|= BITFIELD64_BIT(_TNL_ATTRIB_POINTSIZE
);
129 _tnl_wakeup( struct gl_context
*ctx
)
131 /* Assume we haven't been getting state updates either:
133 _tnl_InvalidateState( ctx
, ~0 );
136 if (ctx
->Light
.ColorMaterialEnabled
) {
137 _mesa_update_color_material( ctx
,
138 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
147 * Drivers call this function to tell the TCL module whether or not
148 * it wants Normalized Device Coords (NDC) computed. I.e. whether
149 * we should "Divide-by-W". Software renders will want that.
152 _tnl_need_projected_coords( struct gl_context
*ctx
, GLboolean mode
)
154 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
155 tnl
->NeedNdcCoords
= mode
;
159 _tnl_allow_vertex_fog( struct gl_context
*ctx
, GLboolean value
)
161 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
162 tnl
->AllowVertexFog
= value
;
163 tnl
->_DoVertexFog
= ((tnl
->AllowVertexFog
&& (ctx
->Hint
.Fog
!= GL_NICEST
))
164 || !tnl
->AllowPixelFog
);
169 _tnl_allow_pixel_fog( struct gl_context
*ctx
, GLboolean value
)
171 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
172 tnl
->AllowPixelFog
= value
;
173 tnl
->_DoVertexFog
= ((tnl
->AllowVertexFog
&& (ctx
->Hint
.Fog
!= GL_NICEST
))
174 || !tnl
->AllowPixelFog
);