| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.3 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved. |
| 6 |
* |
| 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: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 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. |
| 23 |
*/ |
| 24 |
|
| 25 |
|
| 26 |
/* |
| 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. |
| 30 |
* |
| 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 |
| 39 |
* |
| 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 |
| 42 |
* ignored otherwise. |
| 43 |
*/ |
| 44 |
|
| 45 |
#include "macros.h" |
| 46 |
|
| 47 |
|
| 48 |
static void |
| 49 |
NAME(get_row)( GLcontext *ctx, struct gl_renderbuffer *rb, |
| 50 |
GLuint count, GLint x, GLint y, void *values ) |
| 51 |
{ |
| 52 |
#ifdef SPAN_VARS |
| 53 |
SPAN_VARS |
| 54 |
#endif |
| 55 |
#if FORMAT == GL_RGBA |
| 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; |
| 61 |
#else |
| 62 |
#error FORMAT must be set!!!! |
| 63 |
#endif |
| 64 |
GLuint i; |
| 65 |
INIT_PIXEL_PTR(pixel, x, y); |
| 66 |
for (i = 0; i < count; i++) { |
| 67 |
FETCH_PIXEL(dest[i], pixel); |
| 68 |
INC_PIXEL_PTR(pixel); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
static void |
| 73 |
NAME(get_values)( GLcontext *ctx, struct gl_renderbuffer *rb, |
| 74 |
GLuint count, const GLint x[], const GLint y[], void *values ) |
| 75 |
{ |
| 76 |
#ifdef SPAN_VARS |
| 77 |
SPAN_VARS |
| 78 |
#endif |
| 79 |
#if FORMAT == GL_RGBA |
| 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; |
| 85 |
#endif |
| 86 |
GLuint i; |
| 87 |
for (i = 0; i < count; i++) { |
| 88 |
INIT_PIXEL_PTR(pixel, x[i], y[i]); |
| 89 |
FETCH_PIXEL(dest[i], pixel); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
static void |
| 95 |
NAME(put_row)( GLcontext *ctx, struct gl_renderbuffer *rb, |
| 96 |
GLuint count, GLint x, GLint y, |
| 97 |
const void *values, const GLubyte mask[] ) |
| 98 |
{ |
| 99 |
#ifdef SPAN_VARS |
| 100 |
SPAN_VARS |
| 101 |
#endif |
| 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; |
| 108 |
#endif |
| 109 |
GLuint i; |
| 110 |
INIT_PIXEL_PTR(pixel, x, y); |
| 111 |
if (mask) { |
| 112 |
for (i = 0; i < count; i++) { |
| 113 |
if (mask[i]) { |
| 114 |
STORE_PIXEL(pixel, x + i, y, src[i]); |
| 115 |
} |
| 116 |
INC_PIXEL_PTR(pixel); |
| 117 |
} |
| 118 |
} |
| 119 |
else { |
| 120 |
for (i = 0; i < count; i++) { |
| 121 |
STORE_PIXEL(pixel, x + i, y, src[i]); |
| 122 |
INC_PIXEL_PTR(pixel); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
#if (FORMAT == GL_RGBA) || (FORMAT == GL_RGBA8) |
| 128 |
static void |
| 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[] ) |
| 132 |
{ |
| 133 |
#ifdef SPAN_VARS |
| 134 |
SPAN_VARS |
| 135 |
#endif |
| 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; |
| 140 |
#else |
| 141 |
#error bad format |
| 142 |
#endif |
| 143 |
GLuint i; |
| 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]); |
| 149 |
#else |
| 150 |
STORE_PIXEL(pixel, x + i, y, src[i]); |
| 151 |
#endif |
| 152 |
} |
| 153 |
INC_PIXEL_PTR(pixel); |
| 154 |
} |
| 155 |
} |
| 156 |
#endif |
| 157 |
|
| 158 |
static void |
| 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[] ) |
| 162 |
{ |
| 163 |
#ifdef SPAN_VARS |
| 164 |
SPAN_VARS |
| 165 |
#endif |
| 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; |
| 172 |
#endif |
| 173 |
GLuint i; |
| 174 |
INIT_PIXEL_PTR(pixel, x, y); |
| 175 |
if (mask) { |
| 176 |
for (i = 0; i < count; i++) { |
| 177 |
if (mask[i]) { |
| 178 |
STORE_PIXEL(pixel, x + i, y, src); |
| 179 |
} |
| 180 |
INC_PIXEL_PTR(pixel); |
| 181 |
} |
| 182 |
} |
| 183 |
else { |
| 184 |
for (i = 0; i < count; i++) { |
| 185 |
STORE_PIXEL(pixel, x + i, y, src); |
| 186 |
INC_PIXEL_PTR(pixel); |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
static void |
| 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[] ) |
| 196 |
{ |
| 197 |
#ifdef SPAN_VARS |
| 198 |
SPAN_VARS |
| 199 |
#endif |
| 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; |
| 206 |
#endif |
| 207 |
GLuint i; |
| 208 |
ASSERT(mask); |
| 209 |
for (i = 0; i < count; i++) { |
| 210 |
if (mask[i]) { |
| 211 |
INIT_PIXEL_PTR(pixel, x[i], y[i]); |
| 212 |
STORE_PIXEL(pixel, x[i], y[i], src[i]); |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
static void |
| 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[] ) |
| 222 |
{ |
| 223 |
#ifdef SPAN_VARS |
| 224 |
SPAN_VARS |
| 225 |
#endif |
| 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; |
| 232 |
#endif |
| 233 |
GLuint i; |
| 234 |
ASSERT(mask); |
| 235 |
for (i = 0; i < count; i++) { |
| 236 |
if (mask[i]) { |
| 237 |
INIT_PIXEL_PTR(pixel, x[i], y[i]); |
| 238 |
STORE_PIXEL(pixel, x[i], y[i], src); |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
#undef NAME |
| 245 |
#undef SPAN_VARS |
| 246 |
#undef INIT_PIXEL_PTR |
| 247 |
#undef INC_PIXEL_PTR |
| 248 |
#undef STORE_PIXEL |
| 249 |
#undef STORE_PIXEL_RGB |
| 250 |
#undef FETCH_PIXEL |
| 251 |
#undef FORMAT |