draw->vcache.vertex[i] = (struct vertex_header *)(tmp + i * MAX_VERTEX_SIZE);
}
+ draw->attrib_front0 = -1;
+ draw->attrib_back0 = -1;
+ draw->attrib_front1 = -1;
+ draw->attrib_back1 = -1;
+
return draw;
}
{
draw->vertex_shader = *shader;
}
+
+
+/**
+ * This function is used to tell the draw module about attributes
+ * (like colors) that need to be selected based on front/back face
+ * orientation.
+ *
+ * The logic is:
+ * if (polygon is back-facing) {
+ * vertex->attrib[front0] = vertex->attrib[back0];
+ * vertex->attrib[front1] = vertex->attrib[back1];
+ * }
+ *
+ * \param front0 first attrib to replace if the polygon is back-facing
+ * \param back0 first attrib to copy if the polygon is back-facing
+ * \param front1 second attrib to replace if the polygon is back-facing
+ * \param back1 second attrib to copy if the polygon is back-facing
+ *
+ * Pass -1 to disable two-sided attributes.
+ */
+void
+draw_set_twoside_attributes(struct draw_context *draw,
+ uint front0, uint back0,
+ uint front1, uint back1)
+{
+ /* XXX we could alternately pass an array of front/back attribs if there's
+ * ever need for more than two. One could imagine a shader extension
+ * that allows arbitrary attributes to be selected based on polygon
+ * orientation...
+ */
+ draw->attrib_front0 = front0;
+ draw->attrib_back0 = back0;
+ draw->attrib_front1 = front1;
+ draw->attrib_back1 = back1;
+}
+
const uint *attrs, const uint *interp_mode,
unsigned nr_attrs );
+void draw_set_twoside_attributes(struct draw_context *draw,
+ uint front0, uint back0,
+ uint front1, uint back1);
+
unsigned draw_prim_info( unsigned prim, unsigned *first, unsigned *incr );
unsigned draw_trim( unsigned count, unsigned first, unsigned incr );
/** Describes the layout of post-transformation vertices */
struct vertex_info vertex_info;
+ /** Two-sided attributes: */
+ uint attrib_front0, attrib_back0;
+ uint attrib_front1, attrib_back1;
unsigned nr_vertices;
}
-static INLINE void copy_color( unsigned attr_dst,
+static INLINE void copy_attrib( unsigned attr_dst,
unsigned attr_src,
struct vertex_header *v )
{
- if (attr_dst && attr_src) {
- memcpy( v->data[attr_dst],
- v->data[attr_src],
- sizeof(v->data[0]) );
- }
+ COPY_4FV(v->data[attr_dst], v->data[attr_src]);
}
unsigned idx )
{
struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx );
+ const struct draw_context *draw = twoside->stage.draw;
- copy_color( twoside->lookup[TGSI_ATTRIB_COLOR0],
- twoside->lookup[TGSI_ATTRIB_BFC0],
- tmp );
-
- copy_color( twoside->lookup[TGSI_ATTRIB_COLOR1],
- twoside->lookup[TGSI_ATTRIB_BFC1],
- tmp );
+ if (draw->attrib_front0) {
+ assert(draw->attrib_back0);
+ copy_attrib(draw->attrib_front0, draw->attrib_back0, tmp);
+ }
+ if (draw->attrib_front1) {
+ assert(draw->attrib_back1);
+ copy_attrib(draw->attrib_front1, draw->attrib_back1, tmp);
+ }
return tmp;
}
tmp.det = header->det;
tmp.edgeflags = header->edgeflags;
- /* copy back colors to front color slots */
+ /* copy back attribs to front attribs */
tmp.v[0] = copy_bfc(twoside, header->v[0], 0);
tmp.v[1] = copy_bfc(twoside, header->v[1], 1);
tmp.v[2] = copy_bfc(twoside, header->v[2], 2);
#include "i915_fpc.h"
-static INLINE void
-emit_vertex_attr(struct vertex_info *vinfo, uint vfAttr, uint format, uint interp)
+static INLINE uint
+emit_vertex_attr(struct vertex_info *vinfo, uint vfAttr, uint format,
+ uint interp)
{
const uint n = vinfo->num_attribs;
vinfo->attr_mask |= (1 << vfAttr);
vinfo->format[n] = format;
vinfo->interp_mode[n] = interp;
vinfo->num_attribs++;
+ return n;
}
const uint colorInterp
= i915->setup.flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
struct vertex_info *vinfo = &i915->current.vertex_info;
+ uint front0 = 0, back0 = 0, front1 = 0, back1 = 0;
boolean needW = 0;
memset(vinfo, 0, sizeof(*vinfo));
/* color0 */
if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) {
- emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0, FORMAT_4UB, colorInterp);
+ front0 = emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0,
+ FORMAT_4UB, colorInterp);
vinfo->hwfmt[0] |= S4_VFMT_COLOR;
}
/* color 1 */
if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) {
assert(0); /* untested */
- emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1, FORMAT_4UB, colorInterp);
+ front1 = emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1,
+ FORMAT_4UB, colorInterp);
vinfo->hwfmt[0] |= S4_VFMT_SPEC_FOG;
}
*/
if (i915->setup.light_twoside) {
if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) {
- emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0, FORMAT_OMIT, colorInterp);
+ back0 = emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0,
+ FORMAT_OMIT, colorInterp);
}
if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) {
- emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1, FORMAT_OMIT, colorInterp);
+ back1 = emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1,
+ FORMAT_OMIT, colorInterp);
}
}
vinfo->interp_mode,
vinfo->num_attribs);
+ draw_set_twoside_attributes(i915->draw,
+ front0, back0, front1, back1);
+
/* Need to set this flag so that the LIS2/4 registers get set.
* It also means the i915_update_immediate() function must be called
* after this one, in i915_update_derived().
-static void
+/**
+ * Add another attribute to the given vertex_info object.
+ * \return slot in which the attribute was added
+ */
+static uint
emit_vertex_attr(struct vertex_info *vinfo, uint vfAttr, uint format,
uint interp)
{
const uint n = vinfo->num_attribs;
vinfo->attr_mask |= (1 << vfAttr);
vinfo->slot_to_attrib[n] = vfAttr;
- vinfo->interp_mode[n] = interp;
vinfo->format[n] = format;
+ vinfo->interp_mode[n] = interp;
vinfo->num_attribs++;
+ return n;
}
const uint colorInterp
= softpipe->setup.flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
struct vertex_info *vinfo = &softpipe->vertex_info;
+ uint front0 = 0, back0 = 0, front1 = 0, back1 = 0;
uint i;
memset(vinfo, 0, sizeof(*vinfo));
/* color0 */
if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) {
- emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0, FORMAT_4F, colorInterp);
+ front0 = emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0,
+ FORMAT_4F, colorInterp);
}
/* color1 */
if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) {
- emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1, FORMAT_4F, colorInterp);
+ front1 = emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1,
+ FORMAT_4F, colorInterp);
}
/* fog */
*/
if (softpipe->setup.light_twoside) {
if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) {
- emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0, FORMAT_OMIT, INTERP_LINEAR);
+ back0 = emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0,
+ FORMAT_OMIT, colorInterp);
}
if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) {
- emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1, FORMAT_OMIT, INTERP_LINEAR);
+ back1 = emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1,
+ FORMAT_OMIT, colorInterp);
}
}
vinfo->slot_to_attrib,
vinfo->interp_mode,
vinfo->num_attribs);
+
+ draw_set_twoside_attributes(softpipe->draw,
+ front0, back0, front1, back1);
}
}