Merge commit 'origin/gallium-master-merge'
[mesa.git] / src / mesa / vf / vf.h
1 /*
2 * Copyright 2003 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 * Authors:
25 * Keith Whitwell <keithw@tungstengraphics.com>
26 */
27
28 #ifndef VF_VERTEX_H
29 #define VF_VERTEX_H
30
31 #include "main/mtypes.h"
32 #include "math/m_vector.h"
33
34 enum {
35 VF_ATTRIB_POS = 0,
36 VF_ATTRIB_WEIGHT = 1,
37 VF_ATTRIB_NORMAL = 2,
38 VF_ATTRIB_COLOR0 = 3,
39 VF_ATTRIB_COLOR1 = 4,
40 VF_ATTRIB_FOG = 5,
41 VF_ATTRIB_COLOR_INDEX = 6,
42 VF_ATTRIB_EDGEFLAG = 7,
43 VF_ATTRIB_TEX0 = 8,
44 VF_ATTRIB_TEX1 = 9,
45 VF_ATTRIB_TEX2 = 10,
46 VF_ATTRIB_TEX3 = 11,
47 VF_ATTRIB_TEX4 = 12,
48 VF_ATTRIB_TEX5 = 13,
49 VF_ATTRIB_TEX6 = 14,
50 VF_ATTRIB_TEX7 = 15,
51 VF_ATTRIB_VAR0 = 16,
52 VF_ATTRIB_VAR1 = 17,
53 VF_ATTRIB_VAR2 = 18,
54 VF_ATTRIB_VAR3 = 19,
55 VF_ATTRIB_VAR4 = 20,
56 VF_ATTRIB_VAR5 = 21,
57 VF_ATTRIB_VAR6 = 22,
58 VF_ATTRIB_VAR7 = 23,
59 VF_ATTRIB_POINTSIZE = 24,
60 VF_ATTRIB_BFC0 = 25,
61 VF_ATTRIB_BFC1 = 26,
62 VF_ATTRIB_CLIP_POS = 27,
63 VF_ATTRIB_VERTEX_HEADER = 28,
64 VF_ATTRIB_MAX = 29
65 };
66
67
68 enum vf_attr_format {
69 EMIT_1F,
70 EMIT_2F,
71 EMIT_3F,
72 EMIT_4F,
73 EMIT_2F_VIEWPORT, /* do viewport transform and emit */
74 EMIT_3F_VIEWPORT, /* do viewport transform and emit */
75 EMIT_4F_VIEWPORT, /* do viewport transform and emit */
76 EMIT_3F_XYW, /* for projective texture */
77 EMIT_1UB_1F, /* for fog coordinate */
78 EMIT_3UB_3F_RGB, /* for specular color */
79 EMIT_3UB_3F_BGR, /* for specular color */
80 EMIT_4UB_4F_RGBA, /* for color */
81 EMIT_4UB_4F_BGRA, /* for color */
82 EMIT_4UB_4F_ARGB, /* for color */
83 EMIT_4UB_4F_ABGR, /* for color */
84 EMIT_4CHAN_4F_RGBA, /* for swrast color */
85 EMIT_PAD, /* leave a hole of 'offset' bytes */
86 EMIT_MAX
87 };
88
89 struct vf_attr_map {
90 GLuint attrib;
91 enum vf_attr_format format;
92 GLuint offset;
93 };
94
95 struct vertex_fetch;
96
97 void vf_set_vp_matrix( struct vertex_fetch *vf,
98 const GLfloat *viewport );
99
100 void vf_set_vp_scale_translate( struct vertex_fetch *vf,
101 const GLfloat *scale,
102 const GLfloat *translate );
103
104 GLuint vf_set_vertex_attributes( struct vertex_fetch *vf,
105 const struct vf_attr_map *map,
106 GLuint nr,
107 GLuint vertex_stride );
108
109 void vf_set_sources( struct vertex_fetch *vf,
110 GLvector4f * const attrib[],
111 GLuint start );
112
113 void vf_emit_vertices( struct vertex_fetch *vf,
114 GLuint count,
115 void *dest );
116
117 void vf_get_attr( struct vertex_fetch *vf,
118 const void *vertex,
119 GLenum attr,
120 const GLfloat *dflt,
121 GLfloat *dest );
122
123 struct vertex_fetch *vf_create( GLboolean allow_viewport_emits );
124
125 void vf_destroy( struct vertex_fetch *vf );
126
127
128
129 /***********************************************************************
130 * Internal functions and structs:
131 */
132
133 struct vf_attr;
134
135 typedef void (*vf_extract_func)( const struct vf_attr *a,
136 GLfloat *out,
137 const GLubyte *v );
138
139 typedef void (*vf_insert_func)( const struct vf_attr *a,
140 GLubyte *v,
141 const GLfloat *in );
142
143 typedef void (*vf_emit_func)( struct vertex_fetch *vf,
144 GLuint count,
145 GLubyte *dest );
146
147
148
149 /* Describes how to convert/move a vertex attribute from a vertex
150 * array to a vertex structure.
151 */
152 struct vf_attr
153 {
154 struct vertex_fetch *vf;
155
156 GLuint format;
157 GLuint inputsize;
158 GLuint inputstride;
159 GLuint vertoffset; /* position of the attrib in the vertex struct */
160
161 GLuint attrib; /* which vertex attrib (0=position, etc) */
162 GLuint vertattrsize; /* size of the attribute in bytes */
163
164 GLubyte *inputptr;
165 const vf_insert_func *insert;
166 vf_insert_func do_insert;
167 vf_extract_func extract;
168 };
169
170 struct vertex_fetch
171 {
172 struct vf_attr attr[VF_ATTRIB_MAX];
173 GLuint attr_count;
174 GLuint vertex_stride;
175
176 struct vf_attr *lookup[VF_ATTRIB_MAX];
177
178 vf_emit_func emit;
179
180 /* Parameters and constants for codegen:
181 */
182 GLboolean allow_viewport_emits;
183 GLfloat vp[8];
184 GLfloat chan_scale[4];
185 GLfloat identity[4];
186
187 struct vf_fastpath *fastpath;
188
189 void (*codegen_emit)( struct vertex_fetch *vf );
190 };
191
192
193 struct vf_attr_type {
194 GLuint format;
195 GLuint size;
196 GLuint stride;
197 GLuint offset;
198 };
199
200 struct vf_fastpath {
201 GLuint vertex_stride;
202 GLuint attr_count;
203 GLboolean match_strides;
204
205 struct vf_attr_type *attr;
206
207 vf_emit_func func;
208 struct vf_fastpath *next;
209 };
210
211
212 void vf_register_fastpath( struct vertex_fetch *vtx,
213 GLboolean match_strides );
214
215 void vf_generic_emit( struct vertex_fetch *vf,
216 GLuint count,
217 GLubyte *v );
218
219 void vf_generate_hardwired_emit( struct vertex_fetch *vf );
220
221 void vf_generate_sse_emit( struct vertex_fetch *vf );
222
223
224 struct vf_format_info {
225 const char *name;
226 vf_extract_func extract;
227 vf_insert_func insert[4];
228 const GLuint attrsize;
229 };
230
231 const struct vf_format_info vf_format_info[EMIT_MAX];
232
233
234 #endif