2 * Copyright 2008 Tungsten Graphics, inc.
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:
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
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.
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.
36 * Keith Whitwell <keithw@tungstengraphics.com>
43 #include "pipe/p_compiler.h"
44 #include "pipe/p_state.h"
46 #include "draw_vertex.h"
47 #include "draw_private.h" /* for vertex_header */
50 enum draw_vf_attr_format
{
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 */
67 DRAW_EMIT_PAD
, /**< leave a hole of 'offset' bytes */
71 struct draw_vf_attr_map
73 /** Input attribute number */
76 enum draw_vf_attr_format format
;
81 * Constant data for DRAW_EMIT_*_CONST
89 struct draw_vertex_fetch
;
95 draw_vf_set_vertex_attributes( struct draw_vertex_fetch
*vf
,
96 const struct draw_vf_attr_map
*map
,
98 unsigned vertex_stride
);
101 void draw_vf_set_vertex_info( struct draw_vertex_fetch
*vf
,
102 const struct vertex_info
*vinfo
,
107 draw_vf_set_sources( struct draw_vertex_fetch
*vf
,
108 GLvector4f
* const attrib
[],
113 draw_vf_emit_vertex( struct draw_vertex_fetch
*vf
,
114 struct vertex_header
*vertex
,
117 struct draw_vertex_fetch
*
118 draw_vf_create( void );
121 draw_vf_destroy( struct draw_vertex_fetch
*vf
);
125 /***********************************************************************
126 * Internal functions and structs:
131 typedef void (*draw_vf_extract_func
)( const struct draw_vf_attr
*a
,
135 typedef void (*draw_vf_insert_func
)( const struct draw_vf_attr
*a
,
139 typedef void (*draw_vf_emit_func
)( struct draw_vertex_fetch
*vf
,
146 * Describes how to convert/move a vertex attribute from a vertex
147 * array to a vertex structure.
151 struct draw_vertex_fetch
*vf
;
155 unsigned inputstride
;
156 unsigned vertoffset
; /**< position of the attrib in the vertex struct */
158 boolean isconst
; /**< read from const data below */
161 unsigned attrib
; /**< which vertex attrib (0=position, etc) */
162 unsigned vertattrsize
; /**< size of the attribute in bytes */
165 const draw_vf_insert_func
*insert
;
166 draw_vf_insert_func do_insert
;
167 draw_vf_extract_func extract
;
170 struct draw_vertex_fetch
172 struct draw_vf_attr attr
[PIPE_ATTRIB_MAX
];
174 unsigned vertex_stride
;
176 draw_vf_emit_func emit
;
178 /* Parameters and constants for codegen:
182 struct draw_vf_fastpath
*fastpath
;
184 void (*codegen_emit
)( struct draw_vertex_fetch
*vf
);
188 struct draw_vf_attr_type
{
195 /** XXX this could be moved into draw_vf.c */
196 struct draw_vf_fastpath
{
197 unsigned vertex_stride
;
199 boolean match_strides
;
201 struct draw_vf_attr_type
*attr
;
203 draw_vf_emit_func func
;
204 struct draw_vf_fastpath
*next
;
209 draw_vf_register_fastpath( struct draw_vertex_fetch
*vtx
,
210 boolean match_strides
);
213 draw_vf_generic_emit( struct draw_vertex_fetch
*vf
,
218 draw_vf_generate_hardwired_emit( struct draw_vertex_fetch
*vf
);
221 draw_vf_generate_sse_emit( struct draw_vertex_fetch
*vf
);
224 /** XXX this type and function could probably be moved into draw_vf.c */
225 struct draw_vf_format_info
{
227 draw_vf_insert_func insert
[4];
228 const unsigned attrsize
;
229 const boolean isconst
;
232 extern const struct draw_vf_format_info
233 draw_vf_format_info
[DRAW_EMIT_MAX
];