draw_pt_elts.c

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 
00028  /*
00029   * Authors:
00030   *   Keith Whitwell <keith@tungstengraphics.com>
00031   */
00032 
00033 #include "draw/draw_pt.h"
00034 #include "draw/draw_private.h"
00035 
00036 /* Neat get_elt func that also works for varrays drawing by encoding
00037  * the start value into a pointer.  
00038  */
00039 
00040 static unsigned elt_uint( const void *elts, unsigned idx )
00041 {
00042    return *(((const uint *)elts) + idx);
00043 }
00044 
00045 static unsigned elt_ushort( const void *elts, unsigned idx )
00046 {
00047    return *(((const ushort *)elts) + idx);
00048 }
00049 
00050 static unsigned elt_ubyte( const void *elts, unsigned idx )
00051 {
00052    return *(((const ubyte *)elts) + idx);
00053 }
00054 
00055 static unsigned elt_vert( const void *elts, unsigned idx )
00056 {
00057    return (const ubyte *)elts - (const ubyte *)NULL + idx;
00058 }
00059 
00060 pt_elt_func draw_pt_elt_func( struct draw_context *draw )
00061 {
00062    switch (draw->pt.user.eltSize) {
00063    case 0: return &elt_vert;
00064    case 1: return &elt_ubyte;
00065    case 2: return &elt_ushort; 
00066    case 4: return &elt_uint;
00067    default: return NULL;
00068    }
00069 }     
00070 
00071 const void *draw_pt_elt_ptr( struct draw_context *draw,
00072                              unsigned start )
00073 {
00074    const char *elts = draw->pt.user.elts;
00075 
00076    switch (draw->pt.user.eltSize) {
00077    case 0: 
00078       return (const void *)(((const ubyte *)NULL) + start);
00079    case 1: 
00080       return (const void *)(((const ubyte *)elts) + start);
00081    case 2: 
00082       return (const void *)(((const ushort *)elts) + start);
00083    case 4: 
00084       return (const void *)(((const uint *)elts) + start);
00085    default:
00086       return NULL;
00087    }
00088 }

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