2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 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>
33 #include "nvfragprog.h"
35 #include "swrast/swrast.h"
36 #include "tnl/t_context.h"
37 #include "math/m_vector.h"
38 #include "math/m_translate.h"
40 #include "ss_context.h"
45 static void do_import( struct vertex_buffer
*VB
,
46 struct gl_client_array
*to
,
47 struct gl_client_array
*from
)
49 GLuint count
= VB
->Count
;
52 to
->Ptr
= (GLubyte
*) ALIGN_MALLOC( VB
->Size
* 4 * sizeof(GLchan
), 32 );
56 /* No need to transform the same value 3000 times.
63 to
->StrideB
= 4 * sizeof(GLchan
);
65 _math_trans_4chan( (GLchan (*)[4]) to
->Ptr
,
74 static void import_float_colors( GLcontext
*ctx
)
76 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
77 struct gl_client_array
*to
= &SWSETUP_CONTEXT(ctx
)->ChanColor
;
78 do_import( VB
, to
, VB
->ColorPtr
[0] );
82 static void import_float_spec_colors( GLcontext
*ctx
)
84 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
85 struct gl_client_array
*to
= &SWSETUP_CONTEXT(ctx
)->ChanSecondaryColor
;
86 do_import( VB
, to
, VB
->SecondaryColorPtr
[0] );
87 VB
->SecondaryColorPtr
[0] = to
;
91 /* Provides a RasterSetup function which prebuilds vertices for the
92 * software rasterizer. This is required for the triangle functions
93 * in this module, but not the rest of the swrast module.
104 #define MAX_SETUPFUNC 0x80
106 static setup_func setup_tab
[MAX_SETUPFUNC
];
107 static interp_func interp_tab
[MAX_SETUPFUNC
];
108 static copy_pv_func copy_pv_tab
[MAX_SETUPFUNC
];
112 #define TAG(x) x##_none
113 #include "ss_vbtmp.h"
116 #define TAG(x) x##_color
117 #include "ss_vbtmp.h"
119 #define IND (COLOR|SPEC)
120 #define TAG(x) x##_color_spec
121 #include "ss_vbtmp.h"
123 #define IND (COLOR|FOG)
124 #define TAG(x) x##_color_fog
125 #include "ss_vbtmp.h"
127 #define IND (COLOR|SPEC|FOG)
128 #define TAG(x) x##_color_spec_fog
129 #include "ss_vbtmp.h"
131 #define IND (COLOR|TEX0)
132 #define TAG(x) x##_color_tex0
133 #include "ss_vbtmp.h"
135 #define IND (COLOR|TEX0|SPEC)
136 #define TAG(x) x##_color_tex0_spec
137 #include "ss_vbtmp.h"
139 #define IND (COLOR|TEX0|FOG)
140 #define TAG(x) x##_color_tex0_fog
141 #include "ss_vbtmp.h"
143 #define IND (COLOR|TEX0|SPEC|FOG)
144 #define TAG(x) x##_color_tex0_spec_fog
145 #include "ss_vbtmp.h"
147 #define IND (COLOR|MULTITEX)
148 #define TAG(x) x##_color_multitex
149 #include "ss_vbtmp.h"
151 #define IND (COLOR|MULTITEX|SPEC)
152 #define TAG(x) x##_color_multitex_spec
153 #include "ss_vbtmp.h"
155 #define IND (COLOR|MULTITEX|FOG)
156 #define TAG(x) x##_color_multitex_fog
157 #include "ss_vbtmp.h"
159 #define IND (COLOR|MULTITEX|SPEC|FOG)
160 #define TAG(x) x##_color_multitex_spec_fog
161 #include "ss_vbtmp.h"
163 #define IND (COLOR|POINT)
164 #define TAG(x) x##_color_point
165 #include "ss_vbtmp.h"
167 #define IND (COLOR|SPEC|POINT)
168 #define TAG(x) x##_color_spec_point
169 #include "ss_vbtmp.h"
171 #define IND (COLOR|FOG|POINT)
172 #define TAG(x) x##_color_fog_point
173 #include "ss_vbtmp.h"
175 #define IND (COLOR|SPEC|FOG|POINT)
176 #define TAG(x) x##_color_spec_fog_point
177 #include "ss_vbtmp.h"
179 #define IND (COLOR|TEX0|POINT)
180 #define TAG(x) x##_color_tex0_point
181 #include "ss_vbtmp.h"
183 #define IND (COLOR|TEX0|SPEC|POINT)
184 #define TAG(x) x##_color_tex0_spec_point
185 #include "ss_vbtmp.h"
187 #define IND (COLOR|TEX0|FOG|POINT)
188 #define TAG(x) x##_color_tex0_fog_point
189 #include "ss_vbtmp.h"
191 #define IND (COLOR|TEX0|SPEC|FOG|POINT)
192 #define TAG(x) x##_color_tex0_spec_fog_point
193 #include "ss_vbtmp.h"
195 #define IND (COLOR|MULTITEX|POINT)
196 #define TAG(x) x##_color_multitex_point
197 #include "ss_vbtmp.h"
199 #define IND (COLOR|MULTITEX|SPEC|POINT)
200 #define TAG(x) x##_color_multitex_spec_point
201 #include "ss_vbtmp.h"
203 #define IND (COLOR|MULTITEX|FOG|POINT)
204 #define TAG(x) x##_color_multitex_fog_point
205 #include "ss_vbtmp.h"
207 #define IND (COLOR|MULTITEX|SPEC|FOG|POINT)
208 #define TAG(x) x##_color_multitex_spec_fog_point
209 #include "ss_vbtmp.h"
212 #define TAG(x) x##_index
213 #include "ss_vbtmp.h"
215 #define IND (INDEX|FOG)
216 #define TAG(x) x##_index_fog
217 #include "ss_vbtmp.h"
219 #define IND (INDEX|POINT)
220 #define TAG(x) x##_index_point
221 #include "ss_vbtmp.h"
223 #define IND (INDEX|FOG|POINT)
224 #define TAG(x) x##_index_fog_point
225 #include "ss_vbtmp.h"
228 /***********************************************************************
229 * Additional setup and interp for back color and edgeflag.
230 ***********************************************************************/
232 #define GET_COLOR(ptr, idx) (((GLfloat (*)[4])((ptr)->data))[idx])
234 static void interp_extras( GLcontext
*ctx
,
236 GLuint dst
, GLuint out
, GLuint in
,
237 GLboolean force_boundary
)
239 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
241 if (VB
->ColorPtr
[1]) {
243 GET_COLOR(VB
->ColorPtr
[1], dst
),
244 GET_COLOR(VB
->ColorPtr
[1], out
),
245 GET_COLOR(VB
->ColorPtr
[1], in
) );
247 if (VB
->SecondaryColorPtr
[1]) {
249 GET_COLOR(VB
->SecondaryColorPtr
[1], dst
),
250 GET_COLOR(VB
->SecondaryColorPtr
[1], out
),
251 GET_COLOR(VB
->SecondaryColorPtr
[1], in
) );
254 else if (VB
->IndexPtr
[1]) {
255 VB
->IndexPtr
[1]->data
[dst
][0] = LINTERP( t
,
256 VB
->IndexPtr
[1]->data
[out
][0],
257 VB
->IndexPtr
[1]->data
[in
][0] );
261 VB
->EdgeFlag
[dst
] = VB
->EdgeFlag
[out
] || force_boundary
;
264 interp_tab
[SWSETUP_CONTEXT(ctx
)->SetupIndex
](ctx
, t
, dst
, out
, in
,
268 static void copy_pv_extras( GLcontext
*ctx
, GLuint dst
, GLuint src
)
270 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
272 if (VB
->ColorPtr
[1]) {
273 COPY_4FV( GET_COLOR(VB
->ColorPtr
[1], dst
),
274 GET_COLOR(VB
->ColorPtr
[1], src
) );
276 if (VB
->SecondaryColorPtr
[1]) {
277 COPY_3V( GET_COLOR(VB
->SecondaryColorPtr
[1], dst
),
278 GET_COLOR(VB
->SecondaryColorPtr
[1], src
) );
281 else if (VB
->IndexPtr
[1]) {
282 VB
->IndexPtr
[1]->data
[dst
][0] = VB
->IndexPtr
[1]->data
[src
][0];
285 copy_pv_tab
[SWSETUP_CONTEXT(ctx
)->SetupIndex
](ctx
, dst
, src
);
291 /***********************************************************************
293 ***********************************************************************/
296 emit_invalid( GLcontext
*ctx
, GLuint start
, GLuint end
, GLuint newinputs
)
298 _mesa_debug(ctx
, "swrast_setup: invalid setup function\n");
299 (void) (ctx
&& start
&& end
&& newinputs
);
304 interp_invalid( GLcontext
*ctx
, GLfloat t
,
305 GLuint edst
, GLuint eout
, GLuint ein
,
306 GLboolean force_boundary
)
308 _mesa_debug(ctx
, "swrast_setup: invalid interp function\n");
309 (void) (ctx
&& t
&& edst
&& eout
&& ein
&& force_boundary
);
314 copy_pv_invalid( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
316 _mesa_debug(ctx
, "swrast_setup: invalid copy_pv function\n");
317 (void) (ctx
&& edst
&& esrc
);
321 static void init_standard( void )
325 for (i
= 0 ; i
< Elements(setup_tab
) ; i
++) {
326 setup_tab
[i
] = emit_invalid
;
327 interp_tab
[i
] = interp_invalid
;
328 copy_pv_tab
[i
] = copy_pv_invalid
;
335 init_color_spec_fog();
337 init_color_tex0_spec();
338 init_color_tex0_fog();
339 init_color_tex0_spec_fog();
340 init_color_multitex();
341 init_color_multitex_spec();
342 init_color_multitex_fog();
343 init_color_multitex_spec_fog();
345 init_color_spec_point();
346 init_color_fog_point();
347 init_color_spec_fog_point();
348 init_color_tex0_point();
349 init_color_tex0_spec_point();
350 init_color_tex0_fog_point();
351 init_color_tex0_spec_fog_point();
352 init_color_multitex_point();
353 init_color_multitex_spec_point();
354 init_color_multitex_fog_point();
355 init_color_multitex_spec_fog_point();
359 init_index_fog_point();
366 printSetupFlags(const GLcontext
*ctx
, char *msg
, GLuint flags
)
368 _mesa_debug(ctx
, "%s(%x): %s%s%s%s%s%s%s\n",
371 (flags
& COLOR
) ? "color, " : "",
372 (flags
& INDEX
) ? "index, " : "",
373 (flags
& TEX0
) ? "tex0, " : "",
374 (flags
& MULTITEX
) ? "multitex, " : "",
375 (flags
& SPEC
) ? "spec, " : "",
376 (flags
& FOG
) ? "fog, " : "",
377 (flags
& POINT
) ? "point, " : "");
382 _swsetup_choose_rastersetup_func(GLcontext
*ctx
)
384 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
385 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
388 if (ctx
->RenderMode
== GL_RENDER
) {
389 if (ctx
->Visual
.rgbMode
) {
392 if (ctx
->Texture
._EnabledCoordUnits
> 1)
393 funcindex
|= MULTITEX
; /* a unit above unit[0] is enabled */
394 else if (ctx
->Texture
._EnabledCoordUnits
== 1)
395 funcindex
|= TEX0
; /* only unit 0 is enabled */
397 if (NEED_SECONDARY_COLOR(ctx
))
404 if (ctx
->Point
._Attenuated
||
405 (ctx
->VertexProgram
.Enabled
&& ctx
->VertexProgram
.PointSizeEnabled
))
408 if (ctx
->Fog
.Enabled
)
411 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
412 if (ctx
->Visual
.rgbMode
)
413 funcindex
= (COLOR
| TEX0
); /* is feedback color subject to fogging? */
420 swsetup
->SetupIndex
= funcindex
;
421 tnl
->Driver
.Render
.BuildVertices
= setup_tab
[funcindex
];
423 if (NEED_TWO_SIDED_LIGHTING(ctx
) ||
424 ctx
->Polygon
.FrontMode
!= GL_FILL
||
425 ctx
->Polygon
.BackMode
!= GL_FILL
) {
426 tnl
->Driver
.Render
.Interp
= interp_extras
;
427 tnl
->Driver
.Render
.CopyPV
= copy_pv_extras
;
430 tnl
->Driver
.Render
.Interp
= interp_tab
[funcindex
];
431 tnl
->Driver
.Render
.CopyPV
= copy_pv_tab
[funcindex
];
434 ASSERT(tnl
->Driver
.Render
.BuildVertices
);
435 ASSERT(tnl
->Driver
.Render
.BuildVertices
!= emit_invalid
);
440 _swsetup_vb_init( GLcontext
*ctx
)
445 printSetupFlags(ctx);