1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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 * 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
42 #include "pipe/p_compiler.h"
43 #include "pipe/p_state.h"
44 #include "util/u_debug.h"
45 #include "util/u_memory.h"
47 #define DRAW_ATTR_NONEXIST 255
50 * Vertex attribute emit modes
53 EMIT_OMIT
, /**< don't emit the attribute */
55 EMIT_1F_PSIZE
, /**< insert constant point size */
59 EMIT_4UB
, /**< is RGBA like the rest */
65 * Information about hardware/rasterization vertex layout.
70 uint hwfmt
[4]; /**< hardware format info for this format */
71 uint size
; /**< total vertex size in dwords */
73 /* Keep this small and at the end of the struct to allow quick
74 * memcmp() comparisons.
77 unsigned emit
:8; /**< EMIT_x */
78 unsigned src_index
:8; /**< map to post-xform attribs */
79 } attrib
[PIPE_MAX_SHADER_OUTPUTS
];
83 draw_vinfo_size( const struct vertex_info
*a
)
85 return offsetof(const struct vertex_info
, attrib
[a
->num_attribs
]);
89 draw_vinfo_compare( const struct vertex_info
*a
,
90 const struct vertex_info
*b
)
92 size_t sizea
= draw_vinfo_size( a
);
93 return memcmp( a
, b
, sizea
);
97 draw_vinfo_copy( struct vertex_info
*dst
,
98 const struct vertex_info
*src
)
100 size_t size
= draw_vinfo_size( src
);
101 memcpy( dst
, src
, size
);
107 * Add another attribute to the given vertex_info object.
108 * \param src_index indicates which post-transformed vertex attrib slot
109 * corresponds to this attribute.
110 * \return slot in which the attribute was added
113 draw_emit_vertex_attr(struct vertex_info
*vinfo
,
114 enum attrib_emit emit
,
117 const uint n
= vinfo
->num_attribs
;
119 /* If the src_index is negative, meaning it hasn't been found
120 * we'll assign it all zeros later - set to DRAW_ATTR_NONEXIST */
122 src_index
= DRAW_ATTR_NONEXIST
;
125 assert(n
< Elements(vinfo
->attrib
));
126 vinfo
->attrib
[n
].emit
= emit
;
127 vinfo
->attrib
[n
].src_index
= src_index
;
128 vinfo
->num_attribs
++;
133 extern void draw_compute_vertex_size(struct vertex_info
*vinfo
);
135 void draw_dump_emitted_vertex(const struct vertex_info
*vinfo
,
136 const uint8_t *data
);
139 static inline enum pipe_format
draw_translate_vinfo_format(enum attrib_emit emit
)
143 return PIPE_FORMAT_NONE
;
146 return PIPE_FORMAT_R32_FLOAT
;
148 return PIPE_FORMAT_R32G32_FLOAT
;
150 return PIPE_FORMAT_R32G32B32_FLOAT
;
152 return PIPE_FORMAT_R32G32B32A32_FLOAT
;
154 return PIPE_FORMAT_R8G8B8A8_UNORM
;
156 return PIPE_FORMAT_B8G8R8A8_UNORM
;
158 assert(!"unexpected format");
159 return PIPE_FORMAT_NONE
;
163 static inline unsigned draw_translate_vinfo_size(enum attrib_emit emit
)
170 return 1 * sizeof(float);
172 return 2 * sizeof(float);
174 return 3 * sizeof(float);
176 return 4 * sizeof(float);
178 return 4 * sizeof(unsigned char);
180 return 4 * sizeof(unsigned char);
182 assert(!"unexpected format");
187 #endif /* DRAW_VERTEX_H */