6191fcedbf9626fe653afdb882bee73811a15e71
1 /**************************************************************************
3 * Copyright 2007 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 **************************************************************************/
29 * Functions for specifying the post-transformation vertex layout.
37 #include "pipe/draw/draw_private.h"
38 #include "pipe/draw/draw_vertex.h"
42 emit_vertex_attr(struct vertex_info
*vinfo
,
43 enum attrib_format format
, enum interp_mode interp
)
45 const uint n
= vinfo
->num_attribs
;
46 vinfo
->interp_mode
[n
] = interp
;
47 vinfo
->format
[n
] = format
;
53 * Compute the size of a vertex, in dwords/floats, to update the
57 draw_compute_vertex_size(struct vertex_info
*vinfo
)
62 for (i
= 0; i
< vinfo
->num_attribs
; i
++) {
63 switch (vinfo
->format
[i
]) {
87 assert(vinfo
->size
* 4 <= MAX_VERTEX_SIZE
);
92 * Tell the drawing module about the contents of post-transformation vertices.
93 * Note that the vertex attribute format info isn't used by 'draw'; all
94 * attributes are handled as float[4]. But when the driver emits vertices
95 * it'll use that info.
96 * We _do_ care about the number of attributes and their interpolation modes.
99 draw_set_vertex_info( struct draw_context
*draw
,
100 const struct vertex_info
*info
)
102 assert(info
->interp_mode
[0] == INTERP_LINEAR
); /* should be vert pos */
103 assert(info
->num_attribs
<= PIPE_MAX_SHADER_OUTPUTS
);
105 memcpy(&draw
->vertex_info
, info
, sizeof(*info
));
107 /* Need to know vertex size (in words) for vertex copying elsewhere.
108 * Four words per attribute, plus vertex header (uint) and clip
109 * position (float[4]).
111 draw
->vertex_info
.size
= draw
->vertex_info
.num_attribs
* 4 + 5;
116 * This function is used to tell the draw module about attributes
117 * (like colors) that need to be selected based on front/back face
121 * if (polygon is back-facing) {
122 * vertex->attrib[front0] = vertex->attrib[back0];
123 * vertex->attrib[front1] = vertex->attrib[back1];
126 * \param front0 first attrib to replace if the polygon is back-facing
127 * \param back0 first attrib to copy if the polygon is back-facing
128 * \param front1 second attrib to replace if the polygon is back-facing
129 * \param back1 second attrib to copy if the polygon is back-facing
131 * Pass -1 to disable two-sided attributes.
134 draw_set_twoside_attributes(struct draw_context
*draw
,
135 uint front0
, uint back0
,
136 uint front1
, uint back1
)
138 /* XXX we could alternately pass an array of front/back attribs if there's
139 * ever need for more than two. One could imagine a shader extension
140 * that allows arbitrary attributes to be selected based on polygon
143 draw
->attrib_front0
= front0
;
144 draw
->attrib_back0
= back0
;
145 draw
->attrib_front1
= front1
;
146 draw
->attrib_back1
= back1
;