2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Templates for the span/pixel-array write/read functions called via
28 * the gl_renderbuffer's GetRow, GetValues, PutRow, PutMonoRow, PutValues
29 * and PutMonoValues functions.
31 * Define the following macros before including this file:
32 * NAME(BASE) to generate the function name (i.e. add prefix or suffix)
33 * RB_TYPE the renderbuffer DataType
34 * CI_MODE if set, color index mode, else RGBA
35 * SPAN_VARS to declare any local variables
36 * INIT_PIXEL_PTR(P, X, Y) to initialize a pointer to a pixel
37 * INC_PIXEL_PTR(P) to increment a pixel pointer by one pixel
38 * STORE_PIXEL(DST, X, Y, VALUE) to store pixel values in buffer
39 * FETCH_PIXEL(DST, SRC) to fetch pixel values from buffer
41 * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
42 * for the pixels to be stored. This is useful when dithering and probably
46 #include "main/macros.h"
50 #define RB_COMPONENTS 1
51 #elif !defined(RB_COMPONENTS)
52 #define RB_COMPONENTS 4
57 NAME(get_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
58 GLuint count
, GLint x
, GLint y
, void *values
)
64 RB_TYPE
*dest
= (RB_TYPE
*) values
;
66 RB_TYPE (*dest
)[RB_COMPONENTS
] = (RB_TYPE (*)[RB_COMPONENTS
]) values
;
69 INIT_PIXEL_PTR(pixel
, x
, y
);
70 for (i
= 0; i
< count
; i
++) {
71 FETCH_PIXEL(dest
[i
], pixel
);
79 NAME(get_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
80 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
86 RB_TYPE
*dest
= (RB_TYPE
*) values
;
88 RB_TYPE (*dest
)[RB_COMPONENTS
] = (RB_TYPE (*)[RB_COMPONENTS
]) values
;
91 for (i
= 0; i
< count
; i
++) {
92 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
93 FETCH_PIXEL(dest
[i
], pixel
);
100 NAME(put_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
101 GLuint count
, GLint x
, GLint y
,
102 const void *values
, const GLubyte mask
[] )
107 const RB_TYPE (*src
)[RB_COMPONENTS
] = (const RB_TYPE (*)[RB_COMPONENTS
]) values
;
109 INIT_PIXEL_PTR(pixel
, x
, y
);
111 for (i
= 0; i
< count
; i
++) {
113 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
115 INC_PIXEL_PTR(pixel
);
119 for (i
= 0; i
< count
; i
++) {
120 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
121 INC_PIXEL_PTR(pixel
);
128 #if !defined(CI_MODE)
130 NAME(put_row_rgb
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
131 GLuint count
, GLint x
, GLint y
,
132 const void *values
, const GLubyte mask
[] )
137 const RB_TYPE (*src
)[3] = (const RB_TYPE (*)[3]) values
;
139 INIT_PIXEL_PTR(pixel
, x
, y
);
140 for (i
= 0; i
< count
; i
++) {
141 if (!mask
|| mask
[i
]) {
142 #ifdef STORE_PIXEL_RGB
143 STORE_PIXEL_RGB(pixel
, x
+ i
, y
, src
[i
]);
145 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
148 INC_PIXEL_PTR(pixel
);
156 NAME(put_mono_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
157 GLuint count
, GLint x
, GLint y
,
158 const void *value
, const GLubyte mask
[] )
163 const RB_TYPE
*src
= (const RB_TYPE
*) value
;
165 INIT_PIXEL_PTR(pixel
, x
, y
);
167 for (i
= 0; i
< count
; i
++) {
169 STORE_PIXEL(pixel
, x
+ i
, y
, src
);
171 INC_PIXEL_PTR(pixel
);
175 for (i
= 0; i
< count
; i
++) {
176 STORE_PIXEL(pixel
, x
+ i
, y
, src
);
177 INC_PIXEL_PTR(pixel
);
185 NAME(put_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
186 GLuint count
, const GLint x
[], const GLint y
[],
187 const void *values
, const GLubyte mask
[] )
192 const RB_TYPE (*src
)[RB_COMPONENTS
] = (const RB_TYPE (*)[RB_COMPONENTS
]) values
;
195 for (i
= 0; i
< count
; i
++) {
197 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
198 STORE_PIXEL(pixel
, x
[i
], y
[i
], src
[i
]);
206 NAME(put_mono_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
207 GLuint count
, const GLint x
[], const GLint y
[],
208 const void *value
, const GLubyte mask
[] )
213 const RB_TYPE
*src
= (const RB_TYPE
*) value
;
216 for (i
= 0; i
< count
; i
++) {
218 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
219 STORE_PIXEL(pixel
, x
[i
], y
[i
], src
);
231 #undef INIT_PIXEL_PTR
234 #undef STORE_PIXEL_RGB