Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / auxiliary / draw / draw_vertex.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * 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
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.
25 *
26 **************************************************************************/
27
28 /**
29 * Post-transform vertex format info. The vertex_info struct is used by
30 * the draw_vbuf code to emit hardware-specific vertex layouts into hw
31 * vertex buffers.
32 *
33 * Author:
34 * Brian Paul
35 */
36
37
38 #ifndef DRAW_VERTEX_H
39 #define DRAW_VERTEX_H
40
41
42 #include "pipe/p_state.h"
43
44
45 /**
46 * Vertex attribute emit modes
47 */
48 enum attrib_emit {
49 EMIT_OMIT, /**< don't emit the attribute */
50 EMIT_1F,
51 EMIT_1F_PSIZE, /**< insert constant point size */
52 EMIT_2F,
53 EMIT_3F,
54 EMIT_4F,
55 EMIT_4UB /**< XXX may need variations for RGBA vs BGRA, etc */
56 };
57
58
59 /**
60 * Attribute interpolation mode
61 */
62 enum interp_mode {
63 INTERP_NONE, /**< never interpolate vertex header info */
64 INTERP_POS, /**< special case for frag position */
65 INTERP_CONSTANT,
66 INTERP_LINEAR,
67 INTERP_PERSPECTIVE
68 };
69
70
71 /**
72 * Information about hardware/rasterization vertex layout.
73 */
74 struct vertex_info
75 {
76 uint num_attribs;
77 uint hwfmt[4]; /**< hardware format info for this format */
78 uint size; /**< total vertex size in dwords */
79
80 /* Keep this small and at the end of the struct to allow quick
81 * memcmp() comparisons.
82 */
83 struct {
84 unsigned interp_mode:4; /**< INTERP_x */
85 unsigned emit:4; /**< EMIT_x */
86 unsigned src_index:8; /**< map to post-xform attribs */
87 } attrib[PIPE_MAX_SHADER_INPUTS];
88 };
89
90 static INLINE size_t
91 draw_vinfo_size( const struct vertex_info *a )
92 {
93 return offsetof(const struct vertex_info, attrib[a->num_attribs]);
94 }
95
96 static INLINE int
97 draw_vinfo_compare( const struct vertex_info *a,
98 const struct vertex_info *b )
99 {
100 size_t sizea = draw_vinfo_size( a );
101 return memcmp( a, b, sizea );
102 }
103
104 static INLINE void
105 draw_vinfo_copy( struct vertex_info *dst,
106 const struct vertex_info *src )
107 {
108 size_t size = draw_vinfo_size( src );
109 memcpy( dst, src, size );
110 }
111
112
113
114 /**
115 * Add another attribute to the given vertex_info object.
116 * \param src_index indicates which post-transformed vertex attrib slot
117 * corresponds to this attribute.
118 * \return slot in which the attribute was added
119 */
120 static INLINE uint
121 draw_emit_vertex_attr(struct vertex_info *vinfo,
122 enum attrib_emit emit,
123 enum interp_mode interp, /* only used by softpipe??? */
124 uint src_index)
125 {
126 const uint n = vinfo->num_attribs;
127 assert(n < PIPE_MAX_SHADER_INPUTS);
128 vinfo->attrib[n].emit = emit;
129 vinfo->attrib[n].interp_mode = interp;
130 vinfo->attrib[n].src_index = src_index;
131 vinfo->num_attribs++;
132 return n;
133 }
134
135
136 extern void draw_compute_vertex_size(struct vertex_info *vinfo);
137
138 void draw_dump_emitted_vertex(const struct vertex_info *vinfo,
139 const uint8_t *data);
140
141
142 static INLINE unsigned draw_translate_vinfo_format(unsigned format )
143 {
144 switch (format) {
145 case EMIT_1F:
146 case EMIT_1F_PSIZE:
147 return PIPE_FORMAT_R32_FLOAT;
148 case EMIT_2F:
149 return PIPE_FORMAT_R32G32_FLOAT;
150 case EMIT_3F:
151 return PIPE_FORMAT_R32G32B32_FLOAT;
152 case EMIT_4F:
153 return PIPE_FORMAT_R32G32B32A32_FLOAT;
154 case EMIT_4UB:
155 return PIPE_FORMAT_R8G8B8A8_UNORM;
156 default:
157 return PIPE_FORMAT_NONE;
158 }
159 }
160
161
162 #endif /* DRAW_VERTEX_H */