1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "draw/draw_pt.h"
34 #include "draw/draw_private.h"
36 /* Neat get_elt func that also works for varrays drawing by encoding
37 * the start value into a pointer.
40 static unsigned elt_uint( const void *elts
, unsigned idx
)
42 return *(((const uint
*)elts
) + idx
);
45 static unsigned elt_ushort( const void *elts
, unsigned idx
)
47 return *(((const ushort
*)elts
) + idx
);
50 static unsigned elt_ubyte( const void *elts
, unsigned idx
)
52 return *(((const ubyte
*)elts
) + idx
);
55 static unsigned elt_vert( const void *elts
, unsigned idx
)
57 /* unsigned index is packed in the pointer */
58 return (unsigned)(uintptr_t)elts
+ idx
;
61 pt_elt_func
draw_pt_elt_func( struct draw_context
*draw
)
63 switch (draw
->pt
.user
.eltSize
) {
64 case 0: return &elt_vert
;
65 case 1: return &elt_ubyte
;
66 case 2: return &elt_ushort
;
67 case 4: return &elt_uint
;
72 const void *draw_pt_elt_ptr( struct draw_context
*draw
,
75 const char *elts
= draw
->pt
.user
.elts
;
77 switch (draw
->pt
.user
.eltSize
) {
79 return (const void *)(((const ubyte
*)NULL
) + start
);
81 return (const void *)(((const ubyte
*)elts
) + start
);
83 return (const void *)(((const ushort
*)elts
) + start
);
85 return (const void *)(((const uint
*)elts
) + start
);