Merge branch 'gallium-i915-current' into gallium-0.1
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_elts.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33 #include "draw/draw_pt.h"
34 #include "draw/draw_private.h"
35
36 /* Neat get_elt func that also works for varrays drawing by encoding
37 * the start value into a pointer.
38 */
39
40 static unsigned elt_uint( const void *elts, unsigned idx )
41 {
42 return *(((const uint *)elts) + idx);
43 }
44
45 static unsigned elt_ushort( const void *elts, unsigned idx )
46 {
47 return *(((const ushort *)elts) + idx);
48 }
49
50 static unsigned elt_ubyte( const void *elts, unsigned idx )
51 {
52 return *(((const ubyte *)elts) + idx);
53 }
54
55 static unsigned elt_vert( const void *elts, unsigned idx )
56 {
57 return (const ubyte *)elts - (const ubyte *)NULL + idx;
58 }
59
60 pt_elt_func draw_pt_elt_func( struct draw_context *draw )
61 {
62 switch (draw->pt.user.eltSize) {
63 case 0: return elt_vert;
64 case 1: return elt_ubyte;
65 case 2: return elt_ushort;
66 case 4: return elt_uint;
67 default: return NULL;
68 }
69 }
70
71 const void *draw_pt_elt_ptr( struct draw_context *draw,
72 unsigned start )
73 {
74 const char *elts = draw->pt.user.elts;
75
76 switch (draw->pt.user.eltSize) {
77 case 0:
78 return (const void *)(((const ubyte *)NULL) + start);
79 case 1:
80 return (const void *)(((const ubyte *)elts) + start);
81 case 2:
82 return (const void *)(((const ushort *)elts) + start);
83 case 4:
84 return (const void *)(((const uint *)elts) + start);
85 default:
86 return NULL;
87 }
88 }