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 * Modified version of swrast/s_spantemp.h for front-buffer rendering. The
28 * no-mask paths use a scratch row to avoid repeated calls to the loader.
30 * For the mask paths we always use an array of 4 elements of RB_TYPE. This is
31 * to satisfy the xorg loader requirement of an image pitch of 32 bits and
32 * should be ok for other loaders also.
36 #ifndef _SWRAST_SPANTEMP_ONCE
37 #define _SWRAST_SPANTEMP_ONCE
40 PUT_PIXEL( GLcontext
*glCtx
, GLint x
, GLint y
, GLubyte
*p
)
42 __DRIcontext
*ctx
= swrast_context(glCtx
)->cPriv
;
43 __DRIdrawable
*draw
= swrast_drawable(glCtx
->DrawBuffer
)->dPriv
;
45 __DRIscreen
*screen
= ctx
->driScreenPriv
;
47 screen
->swrast_loader
->putImage(draw
, __DRI_SWRAST_IMAGE_OP_DRAW
,
48 x
, y
, 1, 1, (char *)p
,
54 GET_PIXEL( GLcontext
*glCtx
, GLint x
, GLint y
, GLubyte
*p
)
56 __DRIcontext
*ctx
= swrast_context(glCtx
)->cPriv
;
57 __DRIdrawable
*read
= swrast_drawable(glCtx
->ReadBuffer
)->dPriv
;
59 __DRIscreen
*screen
= ctx
->driScreenPriv
;
61 screen
->swrast_loader
->getImage(read
, x
, y
, 1, 1, (char *)p
,
66 PUT_ROW( GLcontext
*glCtx
, GLint x
, GLint y
, GLuint n
, char *row
)
68 __DRIcontext
*ctx
= swrast_context(glCtx
)->cPriv
;
69 __DRIdrawable
*draw
= swrast_drawable(glCtx
->DrawBuffer
)->dPriv
;
71 __DRIscreen
*screen
= ctx
->driScreenPriv
;
73 screen
->swrast_loader
->putImage(draw
, __DRI_SWRAST_IMAGE_OP_DRAW
,
79 GET_ROW( GLcontext
*glCtx
, GLint x
, GLint y
, GLuint n
, char *row
)
81 __DRIcontext
*ctx
= swrast_context(glCtx
)->cPriv
;
82 __DRIdrawable
*read
= swrast_drawable(glCtx
->ReadBuffer
)->dPriv
;
84 __DRIscreen
*screen
= ctx
->driScreenPriv
;
86 screen
->swrast_loader
->getImage(read
, x
, y
, n
, 1, row
,
90 #endif /* _SWRAST_SPANTEMP_ONCE */
94 * Templates for the span/pixel-array write/read functions called via
95 * the gl_renderbuffer's GetRow, GetValues, PutRow, PutMonoRow, PutValues
96 * and PutMonoValues functions.
98 * Define the following macros before including this file:
99 * NAME(BASE) to generate the function name (i.e. add prefix or suffix)
100 * RB_TYPE the renderbuffer DataType
101 * SPAN_VARS to declare any local variables
102 * INIT_PIXEL_PTR(P, X, Y) to initialize a pointer to a pixel
103 * INC_PIXEL_PTR(P) to increment a pixel pointer by one pixel
104 * STORE_PIXEL(DST, X, Y, VALUE) to store pixel values in buffer
105 * FETCH_PIXEL(DST, SRC) to fetch pixel values from buffer
107 * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
108 * for the pixels to be stored. This is useful when dithering and probably
112 #include "main/macros.h"
115 #if !defined(RB_COMPONENTS)
116 #define RB_COMPONENTS 4
121 NAME(get_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
122 GLuint count
, GLint x
, GLint y
, void *values
)
127 RB_TYPE (*dest
)[RB_COMPONENTS
] = (RB_TYPE (*)[RB_COMPONENTS
]) values
;
129 char *row
= swrast_drawable(ctx
->ReadBuffer
)->row
;
130 INIT_PIXEL_PTR(pixel
, x
, y
);
131 GET_ROW( ctx
, x
, YFLIP(xrb
, y
), count
, row
);
132 for (i
= 0; i
< count
; i
++) {
133 FETCH_PIXEL(dest
[i
], pixel
);
134 INC_PIXEL_PTR(pixel
);
141 NAME(get_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
142 GLuint count
, const GLint x
[], const GLint y
[], void *values
)
147 RB_TYPE (*dest
)[RB_COMPONENTS
] = (RB_TYPE (*)[RB_COMPONENTS
]) values
;
149 for (i
= 0; i
< count
; i
++) {
151 GET_PIXEL(ctx
, x
[i
], YFLIP(xrb
, y
[i
]), pixel
);
152 FETCH_PIXEL(dest
[i
], pixel
);
159 NAME(put_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
160 GLuint count
, GLint x
, GLint y
,
161 const void *values
, const GLubyte mask
[] )
166 const RB_TYPE (*src
)[RB_COMPONENTS
] = (const RB_TYPE (*)[RB_COMPONENTS
]) values
;
169 for (i
= 0; i
< count
; i
++) {
172 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
173 PUT_PIXEL(ctx
, x
+ i
, YFLIP(xrb
, y
), pixel
);
178 char *row
= swrast_drawable(ctx
->DrawBuffer
)->row
;
179 INIT_PIXEL_PTR(pixel
, x
, y
);
180 for (i
= 0; i
< count
; i
++) {
181 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
182 INC_PIXEL_PTR(pixel
);
184 PUT_ROW( ctx
, x
, YFLIP(xrb
, y
), count
, row
);
191 NAME(put_row_rgb
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
192 GLuint count
, GLint x
, GLint y
,
193 const void *values
, const GLubyte mask
[] )
198 const RB_TYPE (*src
)[3] = (const RB_TYPE (*)[3]) values
;
201 for (i
= 0; i
< count
; i
++) {
204 #ifdef STORE_PIXEL_RGB
205 STORE_PIXEL_RGB(pixel
, x
+ i
, y
, src
[i
]);
207 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
209 PUT_PIXEL(ctx
, x
+ i
, YFLIP(xrb
, y
), pixel
);
214 char *row
= swrast_drawable(ctx
->DrawBuffer
)->row
;
215 INIT_PIXEL_PTR(pixel
, x
, y
);
216 for (i
= 0; i
< count
; i
++) {
217 #ifdef STORE_PIXEL_RGB
218 STORE_PIXEL_RGB(pixel
, x
+ i
, y
, src
[i
]);
220 STORE_PIXEL(pixel
, x
+ i
, y
, src
[i
]);
222 INC_PIXEL_PTR(pixel
);
224 PUT_ROW( ctx
, x
, YFLIP(xrb
, y
), count
, row
);
231 NAME(put_mono_row
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
232 GLuint count
, GLint x
, GLint y
,
233 const void *value
, const GLubyte mask
[] )
238 const RB_TYPE
*src
= (const RB_TYPE
*) value
;
241 for (i
= 0; i
< count
; i
++) {
244 STORE_PIXEL(pixel
, x
+ i
, y
, src
);
245 PUT_PIXEL(ctx
, x
+ i
, YFLIP(xrb
, y
), pixel
);
250 char *row
= swrast_drawable(ctx
->DrawBuffer
)->row
;
251 INIT_PIXEL_PTR(pixel
, x
, y
);
252 for (i
= 0; i
< count
; i
++) {
253 STORE_PIXEL(pixel
, x
+ i
, y
, src
);
254 INC_PIXEL_PTR(pixel
);
256 PUT_ROW( ctx
, x
, YFLIP(xrb
, y
), count
, row
);
263 NAME(put_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
264 GLuint count
, const GLint x
[], const GLint y
[],
265 const void *values
, const GLubyte mask
[] )
270 const RB_TYPE (*src
)[RB_COMPONENTS
] = (const RB_TYPE (*)[RB_COMPONENTS
]) values
;
273 for (i
= 0; i
< count
; i
++) {
276 STORE_PIXEL(pixel
, x
[i
], y
[i
], src
[i
]);
277 PUT_PIXEL(ctx
, x
[i
], YFLIP(xrb
, y
[i
]), pixel
);
285 NAME(put_mono_values
)( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
286 GLuint count
, const GLint x
[], const GLint y
[],
287 const void *value
, const GLubyte mask
[] )
292 const RB_TYPE
*src
= (const RB_TYPE
*) value
;
295 for (i
= 0; i
< count
; i
++) {
298 STORE_PIXEL(pixel
, x
[i
], y
[i
], src
);
299 PUT_PIXEL(ctx
, x
[i
], YFLIP(xrb
, y
[i
]), pixel
);
310 #undef INIT_PIXEL_PTR
313 #undef STORE_PIXEL_RGB