Sync with trunk r63637.
[reactos.git] / dll / opengl / mesa / tnl / t_context.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.2
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28 #include <precomp.h>
29
30 GLboolean
31 _tnl_CreateContext( struct gl_context *ctx )
32 {
33 TNLcontext *tnl;
34
35 /* Create the TNLcontext structure
36 */
37 ctx->swtnl_context = tnl = (TNLcontext *) CALLOC( sizeof(TNLcontext) );
38
39 if (!tnl) {
40 return GL_FALSE;
41 }
42
43 /* Initialize the VB.
44 */
45 tnl->vb.Size = ctx->Const.MaxArrayLockSize + MAX_CLIPPED_VERTICES;
46
47
48 /* Initialize tnl state.
49 */
50 _tnl_install_pipeline( ctx, _tnl_default_pipeline );
51
52 tnl->NeedNdcCoords = GL_TRUE;
53 tnl->AllowVertexFog = GL_TRUE;
54 tnl->AllowPixelFog = GL_TRUE;
55
56 /* Set a few default values in the driver struct.
57 */
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;
61
62 tnl->nr_blocks = 0;
63
64 /* plug in the VBO drawing function */
65 vbo_set_draw_func(ctx, _tnl_vbo_draw_prims);
66
67 _math_init_transformation();
68 _math_init_translate();
69
70 return GL_TRUE;
71 }
72
73
74 void
75 _tnl_DestroyContext( struct gl_context *ctx )
76 {
77 TNLcontext *tnl = TNL_CONTEXT(ctx);
78
79 _tnl_destroy_pipeline( ctx );
80
81 FREE(tnl);
82 ctx->swtnl_context = NULL;
83 }
84
85
86 void
87 _tnl_InvalidateState( struct gl_context *ctx, GLuint new_state )
88 {
89 TNLcontext *tnl = TNL_CONTEXT(ctx);
90
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);
95 }
96
97 tnl->pipeline.new_state |= new_state;
98
99 /* Calculate tnl->render_inputs. This bitmask indicates which vertex
100 * attributes need to be emitted to the rasterizer.
101 */
102 tnl->render_inputs_bitset = BITFIELD64_BIT(_TNL_ATTRIB_POS);
103
104 tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_COLOR);
105
106 if (ctx->Texture._EnabledCoord) {
107 tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_TEX);
108 }
109
110 if (ctx->Fog.Enabled) {
111 /* Either fixed-function fog or a fragment program needs fog coord.
112 */
113 tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_FOG);
114 }
115
116 if (ctx->Polygon.FrontMode != GL_FILL ||
117 ctx->Polygon.BackMode != GL_FILL)
118 tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_EDGEFLAG);
119
120 if (ctx->RenderMode == GL_FEEDBACK)
121 tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_TEX);
122
123 if (ctx->Point._Attenuated)
124 tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_POINTSIZE);
125 }
126
127
128 void
129 _tnl_wakeup( struct gl_context *ctx )
130 {
131 /* Assume we haven't been getting state updates either:
132 */
133 _tnl_InvalidateState( ctx, ~0 );
134
135 #if 0
136 if (ctx->Light.ColorMaterialEnabled) {
137 _mesa_update_color_material( ctx,
138 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
139 }
140 #endif
141 }
142
143
144
145
146 /**
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.
150 */
151 void
152 _tnl_need_projected_coords( struct gl_context *ctx, GLboolean mode )
153 {
154 TNLcontext *tnl = TNL_CONTEXT(ctx);
155 tnl->NeedNdcCoords = mode;
156 }
157
158 void
159 _tnl_allow_vertex_fog( struct gl_context *ctx, GLboolean value )
160 {
161 TNLcontext *tnl = TNL_CONTEXT(ctx);
162 tnl->AllowVertexFog = value;
163 tnl->_DoVertexFog = ((tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
164 || !tnl->AllowPixelFog);
165
166 }
167
168 void
169 _tnl_allow_pixel_fog( struct gl_context *ctx, GLboolean value )
170 {
171 TNLcontext *tnl = TNL_CONTEXT(ctx);
172 tnl->AllowPixelFog = value;
173 tnl->_DoVertexFog = ((tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
174 || !tnl->AllowPixelFog);
175 }
176