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 * 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
45 #include "main/macros.h"
48 #if !defined(RB_COMPONENTS)
49 #define RB_COMPONENTS 4
54 NAME(get_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
55 GLuint count, GLint x, GLint y, void *values )
60 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
62 INIT_PIXEL_PTR(pixel, x, y);
63 for (i = 0; i < count; i++) {
64 FETCH_PIXEL(dest[i], pixel);
72 NAME(get_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
73 GLuint count, const GLint x[], const GLint y[], void *values )
78 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
80 for (i = 0; i < count; i++) {
81 INIT_PIXEL_PTR(pixel, x[i], y[i]);
82 FETCH_PIXEL(dest[i], pixel);
89 NAME(put_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
90 GLuint count, GLint x, GLint y,
91 const void *values, const GLubyte mask[] )
96 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
98 INIT_PIXEL_PTR(pixel, x, y);
100 for (i = 0; i < count; i++) {
102 STORE_PIXEL(pixel, x + i, y, src[i]);
104 INC_PIXEL_PTR(pixel);
108 for (i = 0; i < count; i++) {
109 STORE_PIXEL(pixel, x + i, y, src[i]);
110 INC_PIXEL_PTR(pixel);
118 NAME(put_row_rgb)( struct gl_context *ctx, struct gl_renderbuffer *rb,
119 GLuint count, GLint x, GLint y,
120 const void *values, const GLubyte mask[] )
125 const RB_TYPE (*src)[3] = (const RB_TYPE (*)[3]) values;
127 INIT_PIXEL_PTR(pixel, x, y);
128 for (i = 0; i < count; i++) {
129 if (!mask || mask[i]) {
130 #ifdef STORE_PIXEL_RGB
131 STORE_PIXEL_RGB(pixel, x + i, y, src[i]);
133 STORE_PIXEL(pixel, x + i, y, src[i]);
136 INC_PIXEL_PTR(pixel);
143 NAME(put_mono_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
144 GLuint count, GLint x, GLint y,
145 const void *value, const GLubyte mask[] )
150 const RB_TYPE *src = (const RB_TYPE *) value;
152 INIT_PIXEL_PTR(pixel, x, y);
154 for (i = 0; i < count; i++) {
156 STORE_PIXEL(pixel, x + i, y, src);
158 INC_PIXEL_PTR(pixel);
162 for (i = 0; i < count; i++) {
163 STORE_PIXEL(pixel, x + i, y, src);
164 INC_PIXEL_PTR(pixel);
172 NAME(put_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
173 GLuint count, const GLint x[], const GLint y[],
174 const void *values, const GLubyte mask[] )
179 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
182 for (i = 0; i < count; i++) {
184 INIT_PIXEL_PTR(pixel, x[i], y[i]);
185 STORE_PIXEL(pixel, x[i], y[i], src[i]);
193 NAME(put_mono_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
194 GLuint count, const GLint x[], const GLint y[],
195 const void *value, const GLubyte mask[] )
200 const RB_TYPE *src = (const RB_TYPE *) value;
203 for (i = 0; i < count; i++) {
205 INIT_PIXEL_PTR(pixel, x[i], y[i]);
206 STORE_PIXEL(pixel, x[i], y[i], src);
217 #undef INIT_PIXEL_PTR
220 #undef STORE_PIXEL_RGB