Merge branch 'origin' into softpipe_0_1_branch
[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 "mtypes.h"
32 #include "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_POINTSIZE = 16,
52 VF_ATTRIB_BFC0 = 17,
53 VF_ATTRIB_BFC1 = 18,
54 VF_ATTRIB_CLIP_POS = 19,
55 VF_ATTRIB_VERTEX_HEADER = 20,
56 VF_ATTRIB_MAX = 21
57 };
58
59
60 enum vf_attr_format {
61 EMIT_1F,
62 EMIT_2F,
63 EMIT_3F,
64 EMIT_4F,
65 EMIT_2F_VIEWPORT, /* do viewport transform and emit */
66 EMIT_3F_VIEWPORT, /* do viewport transform and emit */
67 EMIT_4F_VIEWPORT, /* do viewport transform and emit */
68 EMIT_3F_XYW, /* for projective texture */
69 EMIT_1UB_1F, /* for fog coordinate */
70 EMIT_3UB_3F_RGB, /* for specular color */
71 EMIT_3UB_3F_BGR, /* for specular color */
72 EMIT_4UB_4F_RGBA, /* for color */
73 EMIT_4UB_4F_BGRA, /* for color */
74 EMIT_4UB_4F_ARGB, /* for color */
75 EMIT_4UB_4F_ABGR, /* for color */
76 EMIT_4CHAN_4F_RGBA, /* for swrast color */
77 EMIT_PAD, /* leave a hole of 'offset' bytes */
78 EMIT_MAX
79 };
80
81 struct vf_attr_map {
82 GLuint attrib;
83 enum vf_attr_format format;
84 GLuint offset;
85 };
86
87 struct vertex_fetch;
88
89 void vf_set_vp_matrix( struct vertex_fetch *vf,
90 const GLfloat *viewport );
91
92 void vf_set_vp_scale_translate( struct vertex_fetch *vf,
93 const GLfloat *scale,
94 const GLfloat *translate );
95
96 GLuint vf_set_vertex_attributes( struct vertex_fetch *vf,
97 const struct vf_attr_map *map,
98 GLuint nr,
99 GLuint vertex_stride );
100
101 void vf_set_sources( struct vertex_fetch *vf,
102 GLvector4f * const attrib[],
103 GLuint start );
104
105 void vf_emit_vertices( struct vertex_fetch *vf,
106 GLuint count,
107 void *dest );
108
109 void vf_get_attr( struct vertex_fetch *vf,
110 const void *vertex,
111 GLenum attr,
112 const GLfloat *dflt,
113 GLfloat *dest );
114
115 struct vertex_fetch *vf_create( GLboolean allow_viewport_emits );
116
117 void vf_destroy( struct vertex_fetch *vf );
118
119
120
121 /***********************************************************************
122 * Internal functions and structs:
123 */
124
125 struct vf_attr;
126
127 typedef void (*vf_extract_func)( const struct vf_attr *a,
128 GLfloat *out,
129 const GLubyte *v );
130
131 typedef void (*vf_insert_func)( const struct vf_attr *a,
132 GLubyte *v,
133 const GLfloat *in );
134
135 typedef void (*vf_emit_func)( struct vertex_fetch *vf,
136 GLuint count,
137 GLubyte *dest );
138
139
140
141 /* Describes how to convert/move a vertex attribute from a vertex
142 * array to a vertex structure.
143 */
144 struct vf_attr
145 {
146 struct vertex_fetch *vf;
147
148 GLuint format;
149 GLuint inputsize;
150 GLuint inputstride;
151 GLuint vertoffset; /* position of the attrib in the vertex struct */
152
153 GLuint attrib; /* which vertex attrib (0=position, etc) */
154 GLuint vertattrsize; /* size of the attribute in bytes */
155
156 GLubyte *inputptr;
157 const vf_insert_func *insert;
158 vf_insert_func do_insert;
159 vf_extract_func extract;
160 };
161
162 struct vertex_fetch
163 {
164 struct vf_attr attr[VF_ATTRIB_MAX];
165 GLuint attr_count;
166 GLuint vertex_stride;
167
168 struct vf_attr *lookup[VF_ATTRIB_MAX];
169
170 vf_emit_func emit;
171
172 /* Parameters and constants for codegen:
173 */
174 GLboolean allow_viewport_emits;
175 GLfloat vp[8];
176 GLfloat chan_scale[4];
177 GLfloat identity[4];
178
179 struct vf_fastpath *fastpath;
180
181 void (*codegen_emit)( struct vertex_fetch *vf );
182 };
183
184
185 struct vf_attr_type {
186 GLuint format;
187 GLuint size;
188 GLuint stride;
189 GLuint offset;
190 };
191
192 struct vf_fastpath {
193 GLuint vertex_stride;
194 GLuint attr_count;
195 GLboolean match_strides;
196
197 struct vf_attr_type *attr;
198
199 vf_emit_func func;
200 struct vf_fastpath *next;
201 };
202
203
204 void vf_register_fastpath( struct vertex_fetch *vtx,
205 GLboolean match_strides );
206
207 void vf_generic_emit( struct vertex_fetch *vf,
208 GLuint count,
209 GLubyte *v );
210
211 void vf_generate_hardwired_emit( struct vertex_fetch *vf );
212
213 void vf_generate_sse_emit( struct vertex_fetch *vf );
214
215
216 struct vf_format_info {
217 const char *name;
218 vf_extract_func extract;
219 vf_insert_func insert[4];
220 const GLuint attrsize;
221 };
222
223 const struct vf_format_info vf_format_info[EMIT_MAX];
224
225
226 #endif