2 * Copyright (C) 2009-2010 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "main/bufferobj.h"
28 #include "nouveau_driver.h"
29 #include "nouveau_array.h"
30 #include "nouveau_bufferobj.h"
33 get_array_extract(struct nouveau_array *a, extract_u_t *extract_u,
34 extract_f_t *extract_f)
36 #define EXTRACT(in_t, out_t, k) \
38 auto out_t f(struct nouveau_array *, int, int); \
39 out_t f(struct nouveau_array *a, int i, int j) { \
40 in_t x = ((in_t *)(a->buf + i * a->stride))[j]; \
42 return (out_t)x / (k); \
49 *extract_u = EXTRACT(char, unsigned, 1);
50 *extract_f = EXTRACT(char, float, SCHAR_MAX);
52 case GL_UNSIGNED_BYTE:
53 *extract_u = EXTRACT(unsigned char, unsigned, 1);
54 *extract_f = EXTRACT(unsigned char, float, UCHAR_MAX);
57 *extract_u = EXTRACT(short, unsigned, 1);
58 *extract_f = EXTRACT(short, float, SHRT_MAX);
60 case GL_UNSIGNED_SHORT:
61 *extract_u = EXTRACT(unsigned short, unsigned, 1);
62 *extract_f = EXTRACT(unsigned short, float, USHRT_MAX);
65 *extract_u = EXTRACT(int, unsigned, 1);
66 *extract_f = EXTRACT(int, float, INT_MAX);
69 *extract_u = EXTRACT(unsigned int, unsigned, 1);
70 *extract_f = EXTRACT(unsigned int, float, UINT_MAX);
73 *extract_u = EXTRACT(float, unsigned, 1.0 / UINT_MAX);
74 *extract_f = EXTRACT(float, float, 1);
82 nouveau_init_array(struct nouveau_array *a, int attr, int stride,
83 int fields, int type, struct gl_buffer_object *obj,
84 const void *ptr, GLboolean map)
93 if (nouveau_bufferobj_hw(obj)) {
94 struct nouveau_bufferobj *nbo =
95 to_nouveau_bufferobj(obj);
97 nouveau_bo_ref(nbo->bo, &a->bo);
98 a->offset = (intptr_t)ptr;
101 nouveau_bo_map(a->bo, NOUVEAU_BO_RD);
102 a->buf = a->bo->map + a->offset;
106 nouveau_bo_ref(NULL, &a->bo);
110 a->buf = ADD_POINTERS(
111 nouveau_bufferobj_sys(obj), ptr);
116 get_array_extract(a, &a->extract_u, &a->extract_f);
120 nouveau_deinit_array(struct nouveau_array *a)
124 nouveau_bo_unmap(a->bo);
132 nouveau_cleanup_array(struct nouveau_array *a)
134 nouveau_deinit_array(a);
135 nouveau_bo_ref(NULL, &a->bo);