1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "main/glheader.h"
29 #include "main/macros.h"
30 #include "main/enums.h"
33 #include "pipe/draw/draw_context.h"
34 #include "sp_context.h"
38 #define EMIT_ATTR( VF_ATTR, FRAG_ATTR, INTERP ) \
40 slot_to_vf_attr[softpipe->nr_attrs] = VF_ATTR; \
41 softpipe->vf_attr_to_slot[VF_ATTR] = softpipe->nr_attrs; \
42 softpipe->fp_attr_to_slot[FRAG_ATTR] = softpipe->nr_attrs; \
43 softpipe->interp[softpipe->nr_attrs] = INTERP; \
44 softpipe->nr_attrs++; \
45 attr_mask |= (1 << (VF_ATTR)); \
49 static const GLuint frag_to_vf
[FRAG_ATTRIB_MAX
] =
66 /* Derived from: fs, setup states.
68 static void calculate_vertex_layout( struct softpipe_context
*softpipe
)
70 const GLuint inputsRead
= softpipe
->fs
.inputs_read
;
71 GLuint slot_to_vf_attr
[VF_ATTRIB_MAX
];
72 GLbitfield attr_mask
= 0x0;
75 softpipe
->nr_attrs
= 0;
76 memset(slot_to_vf_attr
, 0, sizeof(slot_to_vf_attr
));
78 memset(softpipe
->fp_attr_to_slot
, 0, sizeof(softpipe
->fp_attr_to_slot
));
79 memset(softpipe
->vf_attr_to_slot
, 0, sizeof(softpipe
->vf_attr_to_slot
));
81 /* TODO - Figure out if we need to do perspective divide, etc.
83 EMIT_ATTR(VF_ATTRIB_POS
, FRAG_ATTRIB_WPOS
, INTERP_LINEAR
);
85 /* Pull in the rest of the attributes. They are all in float4
86 * format. Future optimizations could be to keep some attributes
87 * as fixed point or ubyte format.
89 for (i
= 1; i
< FRAG_ATTRIB_TEX0
; i
++) {
90 if (inputsRead
& (i
<< i
)) {
91 if (softpipe
->setup
.flatshade
92 && (i
== FRAG_ATTRIB_COL0
|| i
== FRAG_ATTRIB_COL1
))
93 EMIT_ATTR(frag_to_vf
[i
], i
, INTERP_CONSTANT
);
95 EMIT_ATTR(frag_to_vf
[i
], i
, INTERP_LINEAR
);
99 for (i
= FRAG_ATTRIB_TEX0
; i
< FRAG_ATTRIB_MAX
; i
++) {
100 if (inputsRead
& (i
<< i
)) {
101 EMIT_ATTR(frag_to_vf
[i
], i
, INTERP_PERSPECTIVE
);
105 softpipe
->nr_frag_attrs
= softpipe
->nr_attrs
;
107 /* Additional attributes required for setup: Just twosided
108 * lighting. Edgeflag is dealt with specially by setting bits in
111 if (softpipe
->setup
.light_twoside
) {
112 if (inputsRead
& FRAG_BIT_COL0
) {
113 EMIT_ATTR(VF_ATTRIB_BFC0
, FRAG_ATTRIB_MAX
, 0); /* XXX: mark as discarded after setup */
116 if (inputsRead
& FRAG_BIT_COL1
) {
117 EMIT_ATTR(VF_ATTRIB_BFC1
, FRAG_ATTRIB_MAX
, 0); /* XXX: discard after setup */
121 /* If the attributes have changed, tell the draw module (which in turn
122 * tells the vf module) about the new vertex layout.
124 if (attr_mask
!= softpipe
->attr_mask
) {
125 softpipe
->attr_mask
= attr_mask
;
127 draw_set_vertex_attributes( softpipe
->draw
,
129 softpipe
->nr_attrs
);
134 /* Hopefully this will remain quite simple, otherwise need to pull in
135 * something like the state tracker mechanism.
137 void softpipe_update_derived( struct softpipe_context
*softpipe
)
139 if (softpipe
->dirty
& (SP_NEW_SETUP
| SP_NEW_FS
))
140 calculate_vertex_layout( softpipe
);
142 if (softpipe
->dirty
& (SP_NEW_BLEND
|
148 sp_build_quad_pipeline(softpipe
);