r300c/r300g: add 3155 rv380 pci id
[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 /* unsigned index is packed in the pointer */
58 return (unsigned)(uintptr_t)elts + idx;
59 }
60
61 pt_elt_func draw_pt_elt_func( struct draw_context *draw )
62 {
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;
68 default: return NULL;
69 }
70 }
71
72 const void *draw_pt_elt_ptr( struct draw_context *draw,
73 unsigned start )
74 {
75 const char *elts = draw->pt.user.elts;
76
77 switch (draw->pt.user.eltSize) {
78 case 0:
79 return (const void *)(((const ubyte *)NULL) + start);
80 case 1:
81 return (const void *)(((const ubyte *)elts) + start);
82 case 2:
83 return (const void *)(((const ushort *)elts) + start);
84 case 4:
85 return (const void *)(((const uint *)elts) + start);
86 default:
87 return NULL;
88 }
89 }