2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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(PREFIX) to generate the function name
33 * FORMAT must be either GL_RGBA, GL_RGBA8 or GL_COLOR_INDEX8_EXT
34 * SPAN_VARS to declare any local variables
35 * INIT_PIXEL_PTR(P, X, Y) to initialize a pointer to a pixel
36 * INC_PIXEL_PTR(P) to increment a pixel pointer by one pixel
37 * STORE_PIXEL(DST, X, Y, VALUE) to store pixel values in buffer
38 * FETCH_PIXEL(DST, SRC) to fetch pixel values from buffer
40 * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
41 * for the pixels to be stored. This is useful when dithering and probably
49 NAME(get_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
50 GLuint count
, GLint x
, GLint y
, void *values
)
56 GLchan (*dest
)[4] = (GLchan (*)[4]) values
;
57 #elif FORMAT == GL_RGBA8
58 GLubyte (*dest
)[4] = (GLubyte (*)[4]) values
;
59 #elif FORMAT == GL_COLOR_INDEX8_EXT
60 GLubyte
*dest
= (GLubyte
*) values
;
62 #error FORMAT must be set!!!!
65 INIT_PIXEL_PTR(pixel
, x
, y
);
66 for (i
= 0; i
< count
; i
++) {
67 FETCH_PIXEL(dest
[i
], pixel
);
73 NAME(get_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
74 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
80 GLchan (*dest
)[4] = (GLchan (*)[4]) values
;
81 #elif FORMAT == GL_RGBA8
82 GLubyte (*dest
)[4] = (GLubyte (*)[4]) values
;
83 #elif FORMAT == GL_COLOR_INDEX8_EXT
84 GLubyte
*dest
= (GLubyte
*) values
;
87 for (i
= 0; i
< count
; i
++) {
88 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
89 FETCH_PIXEL(dest
[i
], pixel
);
95 NAME(put_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
96 GLuint count
, GLint x
, GLint y
,
97 const void *values
, const GLubyte mask
[] )
102 #if FORMAT == GL_RGBA
103 const GLchan (*src
)[4] = (const GLchan (*)[4]) values
;
104 #elif FORMAT == GL_RGBA8
105 const GLubyte (*src
)[4] = (const GLubyte (*)[4]) values
;
106 #elif FORMAT == GL_COLOR_INDEX8_EXT
107 const GLubyte (*src
)[1] = (const GLubyte (*)[1]) values
;
110 INIT_PIXEL_PTR(pixel
, x
, y
);
112 for (i
= 0; i
< count
; i
++) {
114 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
116 INC_PIXEL_PTR(pixel
);
120 for (i
= 0; i
< count
; i
++) {
121 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
122 INC_PIXEL_PTR(pixel
);
127 #if (FORMAT == GL_RGBA) || (FORMAT == GL_RGBA8)
129 NAME(put_row_rgb
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
130 GLuint count
, GLint x
, GLint y
,
131 const void *values
, const GLubyte mask
[] )
136 #if FORMAT == GL_RGBA
137 const GLchan (*src
)[3] = (const GLchan (*)[3]) values
;
138 #elif FORMAT == GL_RGBA8
139 const GLubyte (*src
)[3] = (const GLubyte (*)[3]) values
;
144 INIT_PIXEL_PTR(pixel
, x
, y
);
145 for (i
= 0; i
< count
; i
++) {
146 if (!mask
|| mask
[i
]) {
147 #ifdef STORE_PIXEL_RGB
148 STORE_PIXEL_RGB(pixel
, x
+ i
, y
, src
[i
]);
150 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
153 INC_PIXEL_PTR(pixel
);
159 NAME(put_mono_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
160 GLuint count
, GLint x
, GLint y
,
161 const void *value
, const GLubyte mask
[] )
166 #if FORMAT == GL_RGBA
167 const GLchan
*src
= (const GLchan
*) value
;
168 #elif FORMAT == GL_RGBA8
169 const GLubyte
*src
= (const GLubyte
*) value
;
170 #elif FORMAT == GL_COLOR_INDEX8_EXT
171 const GLubyte
*src
= (const GLubyte
*) value
;
174 INIT_PIXEL_PTR(pixel
, x
, y
);
176 for (i
= 0; i
< count
; i
++) {
178 STORE_PIXEL(pixel
, x
+ i
, y
, src
);
180 INC_PIXEL_PTR(pixel
);
184 for (i
= 0; i
< count
; i
++) {
185 STORE_PIXEL(pixel
, x
+ i
, y
, src
);
186 INC_PIXEL_PTR(pixel
);
193 NAME(put_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
194 GLuint count
, const GLint x
[], const GLint y
[],
195 const void *values
, const GLubyte mask
[] )
200 #if FORMAT == GL_RGBA
201 const GLchan (*src
)[4] = (const GLchan (*)[4]) values
;
202 #elif FORMAT == GL_RGBA8
203 const GLubyte (*src
)[4] = (const GLubyte (*)[4]) values
;
204 #elif FORMAT == GL_COLOR_INDEX8_EXT
205 const GLubyte (*src
)[1] = (const GLubyte (*)[1]) values
;
209 for (i
= 0; i
< count
; i
++) {
211 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
212 STORE_PIXEL(pixel
, x
[i
], y
[i
], src
[i
]);
219 NAME(put_mono_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
220 GLuint count
, const GLint x
[], const GLint y
[],
221 const void *value
, const GLubyte mask
[] )
226 #if FORMAT == GL_RGBA
227 const GLchan
*src
= (const GLchan
*) value
;
228 #elif FORMAT == GL_RGBA8
229 const GLubyte
*src
= (const GLubyte
*) value
;
230 #elif FORMAT == GL_COLOR_INDEX8_EXT
231 const GLubyte
*src
= (const GLubyte
*) value
;
235 for (i
= 0; i
< count
; i
++) {
237 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
238 STORE_PIXEL(pixel
, x
[i
], y
[i
], src
);
246 #undef INIT_PIXEL_PTR
249 #undef STORE_PIXEL_RGB