Delete all Trailing spaces in code.
[reactos.git] / reactos / dll / 3rdparty / mesa32 / src / tnl / t_pipeline.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.1
5 *
6 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29 #include "glheader.h"
30 #include "context.h"
31 #include "imports.h"
32 #include "state.h"
33 #include "mtypes.h"
34
35 #include "math/m_translate.h"
36 #include "math/m_xform.h"
37
38 #include "t_context.h"
39 #include "t_pipeline.h"
40 #include "t_vp_build.h"
41 #include "t_vertex.h"
42
43 void _tnl_install_pipeline( GLcontext *ctx,
44 const struct tnl_pipeline_stage **stages )
45 {
46 TNLcontext *tnl = TNL_CONTEXT(ctx);
47 GLuint i;
48
49 tnl->pipeline.new_state = ~0;
50
51 /* Create a writeable copy of each stage.
52 */
53 for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) {
54 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
55 MEMCPY(s, stages[i], sizeof(*s));
56 if (s->create)
57 s->create(ctx, s);
58 }
59
60 tnl->pipeline.nr_stages = i;
61 }
62
63 void _tnl_destroy_pipeline( GLcontext *ctx )
64 {
65 TNLcontext *tnl = TNL_CONTEXT(ctx);
66 GLuint i;
67
68 for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) {
69 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
70 if (s->destroy)
71 s->destroy(s);
72 }
73
74 tnl->pipeline.nr_stages = 0;
75 }
76
77
78
79 static GLuint check_input_changes( GLcontext *ctx )
80 {
81 TNLcontext *tnl = TNL_CONTEXT(ctx);
82 GLuint i;
83
84 for (i = 0; i < _TNL_ATTRIB_EDGEFLAG; i++) {
85 if (tnl->vb.AttribPtr[i]->size != tnl->pipeline.last_attrib_size[i] ||
86 tnl->vb.AttribPtr[i]->stride != tnl->pipeline.last_attrib_stride[i]) {
87 tnl->pipeline.last_attrib_size[i] = tnl->vb.AttribPtr[i]->size;
88 tnl->pipeline.last_attrib_stride[i] = tnl->vb.AttribPtr[i]->stride;
89 tnl->pipeline.input_changes |= 1<<i;
90 }
91 }
92
93 return tnl->pipeline.input_changes;
94 }
95
96
97 static GLuint check_output_changes( GLcontext *ctx )
98 {
99 #if 0
100 TNLcontext *tnl = TNL_CONTEXT(ctx);
101
102 for (i = 0; i < VERT_RESULT_MAX; i++) {
103 if (tnl->vb.ResultPtr[i]->size != tnl->last_result_size[i] ||
104 tnl->vb.ResultPtr[i]->stride != tnl->last_result_stride[i]) {
105 tnl->last_result_size[i] = tnl->vb.ResultPtr[i]->size;
106 tnl->last_result_stride[i] = tnl->vb.ResultPtr[i]->stride;
107 tnl->pipeline.output_changes |= 1<<i;
108 }
109 }
110
111 if (tnl->pipeline.output_changes)
112 tnl->Driver.NotifyOutputChanges( ctx, tnl->pipeline.output_changes );
113
114 return tnl->pipeline.output_changes;
115 #else
116 return ~0;
117 #endif
118 }
119
120
121 void _tnl_run_pipeline( GLcontext *ctx )
122 {
123 TNLcontext *tnl = TNL_CONTEXT(ctx);
124 unsigned short __tmp;
125 GLuint i;
126
127 if (!tnl->vb.Count)
128 return;
129
130 /* Check for changed input sizes or change in stride to/from zero
131 * (ie const or non-const).
132 */
133 if (check_input_changes( ctx ) || tnl->pipeline.new_state) {
134 if (ctx->_MaintainTnlProgram)
135 _tnl_UpdateFixedFunctionProgram( ctx );
136
137 for (i = 0; i < tnl->pipeline.nr_stages ; i++) {
138 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
139 if (s->validate)
140 s->validate( ctx, s );
141 }
142
143 tnl->pipeline.new_state = 0;
144 tnl->pipeline.input_changes = 0;
145
146 /* Pipeline can only change its output in response to either a
147 * statechange or an input size/stride change. No other changes
148 * are allowed.
149 */
150 if (check_output_changes( ctx ))
151 _tnl_notify_pipeline_output_change( ctx );
152 }
153
154 START_FAST_MATH(__tmp);
155
156 for (i = 0; i < tnl->pipeline.nr_stages ; i++) {
157 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
158 if (!s->run( ctx, s ))
159 break;
160 }
161
162 END_FAST_MATH(__tmp);
163 }
164
165
166
167 /* The default pipeline. This is useful for software rasterizers, and
168 * simple hardware rasterizers. For customization, I don't recommend
169 * tampering with the internals of these stages in the way that
170 * drivers did in Mesa 3.4. These stages are basically black boxes,
171 * and should be left intact.
172 *
173 * To customize the pipeline, consider:
174 *
175 * - removing redundant stages (making sure that the software rasterizer
176 * can cope with this on fallback paths). An example is fog
177 * coordinate generation, which is not required in the FX driver.
178 *
179 * - replacing general-purpose machine-independent stages with
180 * general-purpose machine-specific stages. There is no example of
181 * this to date, though it must be borne in mind that all subsequent
182 * stages that reference the output of the new stage must cope with
183 * any machine-specific data introduced. This may not be easy
184 * unless there are no such stages (ie the new stage is the last in
185 * the pipe).
186 *
187 * - inserting optimized (but specialized) stages ahead of the
188 * general-purpose fallback implementation. For example, the old
189 * fastpath mechanism, which only works when the VB->Elts input is
190 * available, can be duplicated by placing the fastpath stage at the
191 * head of this pipeline. Such specialized stages are currently
192 * constrained to have no outputs (ie. they must either finish the *
193 * pipeline by returning GL_FALSE from run(), or do nothing).
194 *
195 * Some work can be done to lift some of the restrictions in the final
196 * case, if it becomes necessary to do so.
197 */
198 const struct tnl_pipeline_stage *_tnl_default_pipeline[] = {
199 &_tnl_vertex_transform_stage,
200 &_tnl_normal_transform_stage,
201 &_tnl_lighting_stage,
202 &_tnl_fog_coordinate_stage,
203 &_tnl_texgen_stage,
204 &_tnl_texture_transform_stage,
205 &_tnl_point_attenuation_stage,
206 #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
207 &_tnl_arb_vertex_program_stage,
208 &_tnl_vertex_program_stage,
209 #endif
210 &_tnl_render_stage,
211 NULL
212 };
213
214 const struct tnl_pipeline_stage *_tnl_vp_pipeline[] = {
215 &_tnl_arb_vertex_program_stage,
216 &_tnl_render_stage,
217 NULL
218 };