Code reorganization: placeholder for state-trackers.
[mesa.git] / src / gallium / aux / draw / draw_vf.h
1 /*
2 * Copyright 2008 Tungsten Graphics, inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * Vertex fetch/store/convert code. This functionality is used in two places:
28 * 1. Vertex fetch/convert - to grab vertex data from incoming vertex
29 * arrays and convert to format needed by vertex shaders.
30 * 2. Vertex store/emit - to convert simple float[][4] vertex attributes
31 * (which is the organization used throughout the draw/prim pipeline) to
32 * hardware-specific formats and emit into hardware vertex buffers.
33 *
34 *
35 * Authors:
36 * Keith Whitwell <keithw@tungstengraphics.com>
37 */
38
39 #ifndef DRAW_VF_H
40 #define DRAW_VF_H
41
42
43 #include "pipe/p_compiler.h"
44 #include "pipe/p_state.h"
45
46 #include "draw_vertex.h"
47 #include "draw_private.h" /* for vertex_header */
48
49
50 enum draw_vf_attr_format {
51 DRAW_EMIT_1F,
52 DRAW_EMIT_2F,
53 DRAW_EMIT_3F,
54 DRAW_EMIT_4F,
55 DRAW_EMIT_3F_XYW, /**< for projective texture */
56 DRAW_EMIT_1UB_1F, /**< for fog coordinate */
57 DRAW_EMIT_3UB_3F_RGB, /**< for specular color */
58 DRAW_EMIT_3UB_3F_BGR, /**< for specular color */
59 DRAW_EMIT_4UB_4F_RGBA, /**< for color */
60 DRAW_EMIT_4UB_4F_BGRA, /**< for color */
61 DRAW_EMIT_4UB_4F_ARGB, /**< for color */
62 DRAW_EMIT_4UB_4F_ABGR, /**< for color */
63 DRAW_EMIT_1F_CONST,
64 DRAW_EMIT_2F_CONST,
65 DRAW_EMIT_3F_CONST,
66 DRAW_EMIT_4F_CONST,
67 DRAW_EMIT_PAD, /**< leave a hole of 'offset' bytes */
68 DRAW_EMIT_MAX
69 };
70
71 struct draw_vf_attr_map
72 {
73 /** Input attribute number */
74 unsigned attrib;
75
76 enum draw_vf_attr_format format;
77
78 unsigned offset;
79
80 /**
81 * Constant data for DRAW_EMIT_*_CONST
82 */
83 union {
84 uint8_t ub[4];
85 float f[4];
86 } data;
87 };
88
89 struct draw_vertex_fetch;
90
91
92
93 #if 0
94 unsigned
95 draw_vf_set_vertex_attributes( struct draw_vertex_fetch *vf,
96 const struct draw_vf_attr_map *map,
97 unsigned nr,
98 unsigned vertex_stride );
99 #endif
100
101 void draw_vf_set_vertex_info( struct draw_vertex_fetch *vf,
102 const struct vertex_info *vinfo,
103 float point_size );
104
105 #if 0
106 void
107 draw_vf_set_sources( struct draw_vertex_fetch *vf,
108 GLvector4f * const attrib[],
109 unsigned start );
110 #endif
111
112 void
113 draw_vf_emit_vertex( struct draw_vertex_fetch *vf,
114 struct vertex_header *vertex,
115 void *dest );
116
117 struct draw_vertex_fetch *
118 draw_vf_create( void );
119
120 void
121 draw_vf_destroy( struct draw_vertex_fetch *vf );
122
123
124
125 /***********************************************************************
126 * Internal functions and structs:
127 */
128
129 struct draw_vf_attr;
130
131 typedef void (*draw_vf_extract_func)( const struct draw_vf_attr *a,
132 float *out,
133 const uint8_t *v );
134
135 typedef void (*draw_vf_insert_func)( const struct draw_vf_attr *a,
136 uint8_t *v,
137 const float *in );
138
139 typedef void (*draw_vf_emit_func)( struct draw_vertex_fetch *vf,
140 unsigned count,
141 uint8_t *dest );
142
143
144
145 /**
146 * Describes how to convert/move a vertex attribute from a vertex
147 * array to a vertex structure.
148 */
149 struct draw_vf_attr
150 {
151 struct draw_vertex_fetch *vf;
152
153 unsigned format;
154 unsigned inputsize;
155 unsigned inputstride;
156 unsigned vertoffset; /**< position of the attrib in the vertex struct */
157
158 boolean isconst; /**< read from const data below */
159 uint8_t data[16];
160
161 unsigned attrib; /**< which vertex attrib (0=position, etc) */
162 unsigned vertattrsize; /**< size of the attribute in bytes */
163
164 uint8_t *inputptr;
165 const draw_vf_insert_func *insert;
166 draw_vf_insert_func do_insert;
167 draw_vf_extract_func extract;
168 };
169
170 struct draw_vertex_fetch
171 {
172 struct draw_vf_attr attr[PIPE_ATTRIB_MAX];
173 unsigned attr_count;
174 unsigned vertex_stride;
175
176 draw_vf_emit_func emit;
177
178 /* Parameters and constants for codegen:
179 */
180 float identity[4];
181
182 struct draw_vf_fastpath *fastpath;
183
184 void (*codegen_emit)( struct draw_vertex_fetch *vf );
185 };
186
187
188 struct draw_vf_attr_type {
189 unsigned format;
190 unsigned size;
191 unsigned stride;
192 unsigned offset;
193 };
194
195 /** XXX this could be moved into draw_vf.c */
196 struct draw_vf_fastpath {
197 unsigned vertex_stride;
198 unsigned attr_count;
199 boolean match_strides;
200
201 struct draw_vf_attr_type *attr;
202
203 draw_vf_emit_func func;
204 struct draw_vf_fastpath *next;
205 };
206
207
208 void
209 draw_vf_register_fastpath( struct draw_vertex_fetch *vtx,
210 boolean match_strides );
211
212 void
213 draw_vf_generic_emit( struct draw_vertex_fetch *vf,
214 unsigned count,
215 uint8_t *v );
216
217 void
218 draw_vf_generate_hardwired_emit( struct draw_vertex_fetch *vf );
219
220 void
221 draw_vf_generate_sse_emit( struct draw_vertex_fetch *vf );
222
223
224 /** XXX this type and function could probably be moved into draw_vf.c */
225 struct draw_vf_format_info {
226 const char *name;
227 draw_vf_insert_func insert[4];
228 const unsigned attrsize;
229 const boolean isconst;
230 };
231
232 extern const struct draw_vf_format_info
233 draw_vf_format_info[DRAW_EMIT_MAX];
234
235
236 #endif