draw_vertex.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00038 #ifndef DRAW_VERTEX_H
00039 #define DRAW_VERTEX_H
00040 
00041 
00042 #include "pipe/p_state.h"
00043 
00044 
00048 enum attrib_emit {
00049    EMIT_OMIT,      
00050    EMIT_1F,
00051    EMIT_1F_PSIZE,  
00052    EMIT_2F,
00053    EMIT_3F,
00054    EMIT_4F,
00055    EMIT_4UB  
00056 };
00057 
00058 
00062 enum interp_mode {
00063    INTERP_NONE,      
00064    INTERP_POS,       
00065    INTERP_CONSTANT,
00066    INTERP_LINEAR,
00067    INTERP_PERSPECTIVE
00068 };
00069 
00070 
00074 struct vertex_info
00075 {
00076    uint num_attribs;
00077    uint hwfmt[4];      
00078    uint size;          
00080    /* Keep this small and at the end of the struct to allow quick
00081     * memcmp() comparisons.
00082     */
00083    struct {
00084       ubyte interp_mode:4;      
00085       ubyte emit:4;             
00086       ubyte src_index;          
00087    } attrib[PIPE_MAX_SHADER_INPUTS];
00088 };
00089 
00090 static INLINE int
00091 draw_vinfo_size( const struct vertex_info *a )
00092 {
00093    return ((const char *)&a->attrib[a->num_attribs] -
00094            (const char *)a);
00095 }
00096 
00097 static INLINE int
00098 draw_vinfo_compare( const struct vertex_info *a,
00099                     const struct vertex_info *b )
00100 {
00101    unsigned sizea = draw_vinfo_size( a );
00102    return memcmp( a, b, sizea );
00103 }
00104 
00105 static INLINE void
00106 draw_vinfo_copy( struct vertex_info *dst,
00107                  const struct vertex_info *src )
00108 {
00109    unsigned size = draw_vinfo_size( src );
00110    memcpy( dst, src, size );
00111 }
00112 
00113 
00114 
00121 static INLINE uint
00122 draw_emit_vertex_attr(struct vertex_info *vinfo,
00123                       enum attrib_emit emit, 
00124                       enum interp_mode interp, /* only used by softpipe??? */
00125                       uint src_index)
00126 {
00127    const uint n = vinfo->num_attribs;
00128    assert(n < PIPE_MAX_SHADER_INPUTS);
00129    vinfo->attrib[n].emit = emit;
00130    vinfo->attrib[n].interp_mode = interp;
00131    vinfo->attrib[n].src_index = src_index;
00132    vinfo->num_attribs++;
00133    return n;
00134 }
00135 
00136 
00137 extern void draw_compute_vertex_size(struct vertex_info *vinfo);
00138 
00139 void draw_dump_emitted_vertex(const struct vertex_info *vinfo, 
00140                               const uint8_t *data);
00141 
00142 
00143 static INLINE unsigned draw_translate_vinfo_format(unsigned format )
00144 {
00145    switch (format) {
00146    case EMIT_1F:
00147    case EMIT_1F_PSIZE:
00148       return PIPE_FORMAT_R32_FLOAT;
00149    case EMIT_2F:
00150       return PIPE_FORMAT_R32G32_FLOAT;
00151    case EMIT_3F:
00152       return PIPE_FORMAT_R32G32B32_FLOAT;
00153    case EMIT_4F:
00154       return PIPE_FORMAT_R32G32B32A32_FLOAT;
00155    case EMIT_4UB:
00156       return PIPE_FORMAT_R8G8B8A8_UNORM;
00157    default:
00158       return PIPE_FORMAT_NONE;
00159    }
00160 }
00161 
00162 
00163 #endif /* DRAW_VERTEX_H */

Generated on Tue Sep 29 06:25:14 2009 for Gallium3D by  doxygen 1.5.4