Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3770 | Serge | 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_compiler.h" |
||
43 | #include "pipe/p_state.h" |
||
44 | #include "util/u_debug.h" |
||
45 | #include "util/u_memory.h" |
||
46 | |||
47 | |||
48 | /** |
||
49 | * Vertex attribute emit modes |
||
50 | */ |
||
51 | enum attrib_emit { |
||
52 | EMIT_OMIT, /**< don't emit the attribute */ |
||
53 | EMIT_1F, |
||
54 | EMIT_1F_PSIZE, /**< insert constant point size */ |
||
55 | EMIT_2F, |
||
56 | EMIT_3F, |
||
57 | EMIT_4F, |
||
58 | EMIT_4UB, /**< is RGBA like the rest */ |
||
59 | EMIT_4UB_BGRA |
||
60 | }; |
||
61 | |||
62 | |||
63 | /** |
||
64 | * Attribute interpolation mode |
||
65 | */ |
||
66 | enum interp_mode { |
||
67 | INTERP_NONE, /**< never interpolate vertex header info */ |
||
68 | INTERP_POS, /**< special case for frag position */ |
||
69 | INTERP_CONSTANT, |
||
70 | INTERP_LINEAR, |
||
71 | INTERP_PERSPECTIVE |
||
72 | }; |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Information about hardware/rasterization vertex layout. |
||
77 | */ |
||
78 | struct vertex_info |
||
79 | { |
||
80 | uint num_attribs; |
||
81 | uint hwfmt[4]; /**< hardware format info for this format */ |
||
82 | uint size; /**< total vertex size in dwords */ |
||
83 | |||
84 | /* Keep this small and at the end of the struct to allow quick |
||
85 | * memcmp() comparisons. |
||
86 | */ |
||
87 | struct { |
||
88 | unsigned interp_mode:4; /**< INTERP_x */ |
||
89 | unsigned emit:4; /**< EMIT_x */ |
||
90 | unsigned src_index:8; /**< map to post-xform attribs */ |
||
91 | } attrib[PIPE_MAX_SHADER_OUTPUTS]; |
||
92 | }; |
||
93 | |||
94 | static INLINE size_t |
||
95 | draw_vinfo_size( const struct vertex_info *a ) |
||
96 | { |
||
97 | return offsetof(const struct vertex_info, attrib[a->num_attribs]); |
||
98 | } |
||
99 | |||
100 | static INLINE int |
||
101 | draw_vinfo_compare( const struct vertex_info *a, |
||
102 | const struct vertex_info *b ) |
||
103 | { |
||
104 | size_t sizea = draw_vinfo_size( a ); |
||
105 | return memcmp( a, b, sizea ); |
||
106 | } |
||
107 | |||
108 | static INLINE void |
||
109 | draw_vinfo_copy( struct vertex_info *dst, |
||
110 | const struct vertex_info *src ) |
||
111 | { |
||
112 | size_t size = draw_vinfo_size( src ); |
||
113 | memcpy( dst, src, size ); |
||
114 | } |
||
115 | |||
116 | |||
117 | |||
118 | /** |
||
119 | * Add another attribute to the given vertex_info object. |
||
120 | * \param src_index indicates which post-transformed vertex attrib slot |
||
121 | * corresponds to this attribute. |
||
122 | * \return slot in which the attribute was added |
||
123 | */ |
||
124 | static INLINE uint |
||
125 | draw_emit_vertex_attr(struct vertex_info *vinfo, |
||
126 | enum attrib_emit emit, |
||
127 | enum interp_mode interp, /* only used by softpipe??? */ |
||
128 | int src_index) |
||
129 | { |
||
130 | const uint n = vinfo->num_attribs; |
||
131 | |||
132 | /* If the src_index is negative, meaning it hasn't been found |
||
133 | * lets just redirect it to the first output slot */ |
||
134 | if (src_index < 0) { |
||
135 | src_index = 0; |
||
136 | } |
||
137 | |||
138 | assert(n < Elements(vinfo->attrib)); |
||
139 | vinfo->attrib[n].emit = emit; |
||
140 | vinfo->attrib[n].interp_mode = interp; |
||
141 | vinfo->attrib[n].src_index = src_index; |
||
142 | vinfo->num_attribs++; |
||
143 | return n; |
||
144 | } |
||
145 | |||
146 | |||
147 | extern void draw_compute_vertex_size(struct vertex_info *vinfo); |
||
148 | |||
149 | void draw_dump_emitted_vertex(const struct vertex_info *vinfo, |
||
150 | const uint8_t *data); |
||
151 | |||
152 | |||
153 | static INLINE enum pipe_format draw_translate_vinfo_format(enum attrib_emit emit) |
||
154 | { |
||
155 | switch (emit) { |
||
156 | case EMIT_OMIT: |
||
157 | return PIPE_FORMAT_NONE; |
||
158 | case EMIT_1F: |
||
159 | case EMIT_1F_PSIZE: |
||
160 | return PIPE_FORMAT_R32_FLOAT; |
||
161 | case EMIT_2F: |
||
162 | return PIPE_FORMAT_R32G32_FLOAT; |
||
163 | case EMIT_3F: |
||
164 | return PIPE_FORMAT_R32G32B32_FLOAT; |
||
165 | case EMIT_4F: |
||
166 | return PIPE_FORMAT_R32G32B32A32_FLOAT; |
||
167 | case EMIT_4UB: |
||
168 | return PIPE_FORMAT_R8G8B8A8_UNORM; |
||
169 | case EMIT_4UB_BGRA: |
||
170 | return PIPE_FORMAT_B8G8R8A8_UNORM; |
||
171 | default: |
||
172 | assert(!"unexpected format"); |
||
173 | return PIPE_FORMAT_NONE; |
||
174 | } |
||
175 | } |
||
176 | |||
177 | static INLINE unsigned draw_translate_vinfo_size(enum attrib_emit emit) |
||
178 | { |
||
179 | switch (emit) { |
||
180 | case EMIT_OMIT: |
||
181 | return 0; |
||
182 | case EMIT_1F: |
||
183 | case EMIT_1F_PSIZE: |
||
184 | return 1 * sizeof(float); |
||
185 | case EMIT_2F: |
||
186 | return 2 * sizeof(float); |
||
187 | case EMIT_3F: |
||
188 | return 3 * sizeof(float); |
||
189 | case EMIT_4F: |
||
190 | return 4 * sizeof(float); |
||
191 | case EMIT_4UB: |
||
192 | return 4 * sizeof(unsigned char); |
||
193 | case EMIT_4UB_BGRA: |
||
194 | return 4 * sizeof(unsigned char); |
||
195 | default: |
||
196 | assert(!"unexpected format"); |
||
197 | return 0; |
||
198 | } |
||
199 | } |
||
200 | |||
201 | #endif /* DRAW_VERTEX_H */>>>>>>>>>>>> |