[3598] | 1 | /* $Id: drawpix.c,v 1.3 2000-05-23 20:40:31 jeroen Exp $ */
|
---|
[2938] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Mesa 3-D graphics library
|
---|
[3598] | 5 | * Version: 3.3
|
---|
[2938] | 6 | *
|
---|
| 7 | * Copyright (C) 1999 Brian Paul All Rights Reserved.
|
---|
| 8 | *
|
---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
| 10 | * copy of this software and associated documentation files (the "Software"),
|
---|
| 11 | * to deal in the Software without restriction, including without limitation
|
---|
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
| 13 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
| 14 | * Software is furnished to do so, subject to the following conditions:
|
---|
| 15 | *
|
---|
| 16 | * The above copyright notice and this permission notice shall be included
|
---|
| 17 | * in all copies or substantial portions of the Software.
|
---|
| 18 | *
|
---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
---|
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
---|
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
---|
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | #ifdef PC_HEADER
|
---|
| 29 | #include "all.h"
|
---|
| 30 | #else
|
---|
[3598] | 31 | #include "glheader.h"
|
---|
[2962] | 32 | #include "types.h"
|
---|
[2938] | 33 | #include "context.h"
|
---|
| 34 | #include "drawpix.h"
|
---|
[3598] | 35 | #include "mem.h"
|
---|
[2938] | 36 | #include "feedback.h"
|
---|
| 37 | #include "image.h"
|
---|
| 38 | #include "macros.h"
|
---|
| 39 | #include "mmath.h"
|
---|
| 40 | #include "pixel.h"
|
---|
| 41 | #include "span.h"
|
---|
| 42 | #include "stencil.h"
|
---|
| 43 | #include "zoom.h"
|
---|
[3598] | 44 | #include "state.h"
|
---|
[2938] | 45 | #endif
|
---|
| 46 |
|
---|
| 47 |
|
---|
[3598] | 48 | /*
|
---|
| 49 | * Given the dest position, size and skipPixels and skipRows values
|
---|
| 50 | * for a glDrawPixels command, perform clipping of the image bounds
|
---|
| 51 | * so the result lies withing the context's buffer bounds.
|
---|
| 52 | * Return: GL_TRUE if image is ready for drawing
|
---|
| 53 | * GL_FALSE if image was completely clipped away (draw nothing)
|
---|
| 54 | */
|
---|
| 55 | GLboolean
|
---|
| 56 | _mesa_clip_pixelrect(const GLcontext *ctx,
|
---|
| 57 | GLint *destX, GLint *destY,
|
---|
| 58 | GLsizei *width, GLsizei *height,
|
---|
| 59 | GLint *skipPixels, GLint *skipRows)
|
---|
| 60 | {
|
---|
| 61 | const GLframebuffer *buffer = ctx->DrawBuffer;
|
---|
[2938] | 62 |
|
---|
[3598] | 63 | /* left clipping */
|
---|
| 64 | if (*destX < buffer->Xmin) {
|
---|
| 65 | *skipPixels += (buffer->Xmin - *destX);
|
---|
| 66 | *width -= (buffer->Xmin - *destX);
|
---|
| 67 | *destX = buffer->Xmin;
|
---|
| 68 | }
|
---|
| 69 | /* right clipping */
|
---|
| 70 | if (*destX + *width > buffer->Xmax)
|
---|
| 71 | *width -= (*destX + *width - buffer->Xmax - 1);
|
---|
[2938] | 72 |
|
---|
[3598] | 73 | if (*width <= 0)
|
---|
| 74 | return GL_FALSE;
|
---|
[2938] | 75 |
|
---|
[3598] | 76 | /* bottom clipping */
|
---|
| 77 | if (*destY < buffer->Ymin) {
|
---|
| 78 | *skipRows += (buffer->Ymin - *destY);
|
---|
| 79 | *height -= (buffer->Ymin - *destY);
|
---|
| 80 | *destY = buffer->Ymin;
|
---|
| 81 | }
|
---|
| 82 | /* top clipping */
|
---|
| 83 | if (*destY + *height > buffer->Ymax)
|
---|
| 84 | *height -= (*destY + *height - buffer->Ymax - 1);
|
---|
| 85 |
|
---|
| 86 | if (*height <= 0)
|
---|
| 87 | return GL_TRUE;
|
---|
| 88 |
|
---|
| 89 | return GL_TRUE;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 |
|
---|
[2938] | 94 | /*
|
---|
[3598] | 95 | * Try to do a fast and simple RGB(a) glDrawPixels.
|
---|
[2938] | 96 | * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
|
---|
| 97 | */
|
---|
[3598] | 98 | static GLboolean
|
---|
| 99 | simple_DrawPixels( GLcontext *ctx, GLint x, GLint y,
|
---|
| 100 | GLsizei width, GLsizei height, GLenum format, GLenum type,
|
---|
| 101 | const GLvoid *pixels )
|
---|
[2938] | 102 | {
|
---|
[3598] | 103 | const struct gl_pixelstore_attrib *unpack = &ctx->Unpack;
|
---|
[2938] | 104 | GLubyte rgb[MAX_WIDTH][3];
|
---|
| 105 | GLubyte rgba[MAX_WIDTH][4];
|
---|
| 106 |
|
---|
| 107 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glDrawPixels",
|
---|
[3598] | 108 | GL_FALSE);
|
---|
[2938] | 109 |
|
---|
| 110 |
|
---|
| 111 | if (!ctx->Current.RasterPosValid) {
|
---|
| 112 | /* no-op */
|
---|
| 113 | return GL_TRUE;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | if (ctx->NewState) {
|
---|
| 117 | gl_update_state(ctx);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | if ((ctx->RasterMask&(~(SCISSOR_BIT|WINCLIP_BIT)))==0
|
---|
| 121 | && ctx->Pixel.RedBias==0.0 && ctx->Pixel.RedScale==1.0
|
---|
| 122 | && ctx->Pixel.GreenBias==0.0 && ctx->Pixel.GreenScale==1.0
|
---|
| 123 | && ctx->Pixel.BlueBias==0.0 && ctx->Pixel.BlueScale==1.0
|
---|
| 124 | && ctx->Pixel.AlphaBias==0.0 && ctx->Pixel.AlphaScale==1.0
|
---|
| 125 | && ctx->Pixel.IndexShift==0 && ctx->Pixel.IndexOffset==0
|
---|
| 126 | && ctx->Pixel.MapColorFlag==0
|
---|
| 127 | && unpack->Alignment==1
|
---|
| 128 | && !unpack->SwapBytes
|
---|
| 129 | && !unpack->LsbFirst) {
|
---|
| 130 |
|
---|
[3598] | 131 | GLint destX = x;
|
---|
| 132 | GLint destY = y;
|
---|
[2938] | 133 | GLint drawWidth = width; /* actual width drawn */
|
---|
| 134 | GLint drawHeight = height; /* actual height drawn */
|
---|
| 135 | GLint skipPixels = unpack->SkipPixels;
|
---|
| 136 | GLint skipRows = unpack->SkipRows;
|
---|
| 137 | GLint rowLength;
|
---|
| 138 | GLdepth zSpan[MAX_WIDTH]; /* only used when zooming */
|
---|
| 139 | GLint zoomY0;
|
---|
| 140 |
|
---|
| 141 | if (unpack->RowLength > 0)
|
---|
| 142 | rowLength = unpack->RowLength;
|
---|
| 143 | else
|
---|
| 144 | rowLength = width;
|
---|
| 145 |
|
---|
| 146 | /* If we're not using pixel zoom then do all clipping calculations
|
---|
| 147 | * now. Otherwise, we'll let the gl_write_zoomed_*_span() functions
|
---|
| 148 | * handle the clipping.
|
---|
| 149 | */
|
---|
| 150 | if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) {
|
---|
| 151 | /* horizontal clipping */
|
---|
[3598] | 152 | if (destX < ctx->DrawBuffer->Xmin) {
|
---|
| 153 | skipPixels += (ctx->DrawBuffer->Xmin - destX);
|
---|
| 154 | drawWidth -= (ctx->DrawBuffer->Xmin - destX);
|
---|
| 155 | destX = ctx->DrawBuffer->Xmin;
|
---|
[2938] | 156 | }
|
---|
[3598] | 157 | if (destX + drawWidth > ctx->DrawBuffer->Xmax)
|
---|
| 158 | drawWidth -= (destX + drawWidth - ctx->DrawBuffer->Xmax - 1);
|
---|
[2938] | 159 | if (drawWidth <= 0)
|
---|
| 160 | return GL_TRUE;
|
---|
| 161 |
|
---|
| 162 | /* vertical clipping */
|
---|
[3598] | 163 | if (destY < ctx->DrawBuffer->Ymin) {
|
---|
| 164 | skipRows += (ctx->DrawBuffer->Ymin - destY);
|
---|
| 165 | drawHeight -= (ctx->DrawBuffer->Ymin - destY);
|
---|
| 166 | destY = ctx->DrawBuffer->Ymin;
|
---|
[2938] | 167 | }
|
---|
[3598] | 168 | if (destY + drawHeight > ctx->DrawBuffer->Ymax)
|
---|
| 169 | drawHeight -= (destY + drawHeight - ctx->DrawBuffer->Ymax - 1);
|
---|
[2938] | 170 | if (drawHeight <= 0)
|
---|
| 171 | return GL_TRUE;
|
---|
[3598] | 172 |
|
---|
| 173 | zoomY0 = 0; /* not used - silence compiler warning */
|
---|
[2938] | 174 | }
|
---|
| 175 | else {
|
---|
| 176 | /* setup array of fragment Z value to pass to zoom function */
|
---|
[3598] | 177 | GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMaxF);
|
---|
[2938] | 178 | GLint i;
|
---|
[3598] | 179 | ASSERT(drawWidth < MAX_WIDTH);
|
---|
[2938] | 180 | for (i=0; i<drawWidth; i++)
|
---|
| 181 | zSpan[i] = z;
|
---|
| 182 |
|
---|
| 183 | /* save Y value of first row */
|
---|
| 184 | zoomY0 = (GLint) (ctx->Current.RasterPos[1] + 0.5F);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | /*
|
---|
| 189 | * Ready to draw!
|
---|
| 190 | * The window region at (destX, destY) of size (drawWidth, drawHeight)
|
---|
| 191 | * will be written to.
|
---|
| 192 | * We'll take pixel data from buffer pointed to by "pixels" but we'll
|
---|
| 193 | * skip "skipRows" rows and skip "skipPixels" pixels/row.
|
---|
| 194 | */
|
---|
| 195 |
|
---|
| 196 | if (format==GL_RGBA && type==GL_UNSIGNED_BYTE) {
|
---|
| 197 | if (ctx->Visual->RGBAflag) {
|
---|
| 198 | GLubyte *src = (GLubyte *) pixels
|
---|
| 199 | + (skipRows * rowLength + skipPixels) * 4;
|
---|
| 200 | if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) {
|
---|
| 201 | /* no zooming */
|
---|
| 202 | GLint row;
|
---|
| 203 | for (row=0; row<drawHeight; row++) {
|
---|
| 204 | (*ctx->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY,
|
---|
[3598] | 205 | (const GLubyte(*)[4]) src, NULL);
|
---|
[2938] | 206 | src += rowLength * 4;
|
---|
| 207 | destY++;
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 | else {
|
---|
| 211 | /* with zooming */
|
---|
| 212 | GLint row;
|
---|
| 213 | for (row=0; row<drawHeight; row++) {
|
---|
| 214 | gl_write_zoomed_rgba_span(ctx, drawWidth, destX, destY,
|
---|
[3598] | 215 | zSpan, (const GLubyte(*)[4]) src, zoomY0);
|
---|
[2938] | 216 | src += rowLength * 4;
|
---|
| 217 | destY++;
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 | return GL_TRUE;
|
---|
| 222 | }
|
---|
| 223 | else if (format==GL_RGB && type==GL_UNSIGNED_BYTE) {
|
---|
| 224 | if (ctx->Visual->RGBAflag) {
|
---|
| 225 | GLubyte *src = (GLubyte *) pixels
|
---|
| 226 | + (skipRows * rowLength + skipPixels) * 3;
|
---|
| 227 | if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) {
|
---|
| 228 | GLint row;
|
---|
| 229 | for (row=0; row<drawHeight; row++) {
|
---|
| 230 | (*ctx->Driver.WriteRGBSpan)(ctx, drawWidth, destX, destY,
|
---|
[3598] | 231 | (const GLubyte(*)[3]) src, NULL);
|
---|
[2938] | 232 | src += rowLength * 3;
|
---|
| 233 | destY++;
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 | else {
|
---|
| 237 | /* with zooming */
|
---|
| 238 | GLint row;
|
---|
| 239 | for (row=0; row<drawHeight; row++) {
|
---|
| 240 | gl_write_zoomed_rgb_span(ctx, drawWidth, destX, destY,
|
---|
[3598] | 241 | zSpan, (const GLubyte(*)[3]) src, zoomY0);
|
---|
[2938] | 242 | src += rowLength * 3;
|
---|
| 243 | destY++;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 | return GL_TRUE;
|
---|
| 248 | }
|
---|
| 249 | else if (format==GL_LUMINANCE && type==GL_UNSIGNED_BYTE) {
|
---|
| 250 | if (ctx->Visual->RGBAflag) {
|
---|
| 251 | GLubyte *src = (GLubyte *) pixels
|
---|
| 252 | + (skipRows * rowLength + skipPixels);
|
---|
| 253 | if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) {
|
---|
| 254 | /* no zooming */
|
---|
| 255 | GLint row;
|
---|
[3598] | 256 | ASSERT(drawWidth < MAX_WIDTH);
|
---|
[2938] | 257 | for (row=0; row<drawHeight; row++) {
|
---|
| 258 | GLint i;
|
---|
| 259 | for (i=0;i<drawWidth;i++) {
|
---|
| 260 | rgb[i][0] = src[i];
|
---|
| 261 | rgb[i][1] = src[i];
|
---|
| 262 | rgb[i][2] = src[i];
|
---|
| 263 | }
|
---|
| 264 | (*ctx->Driver.WriteRGBSpan)(ctx, drawWidth, destX, destY,
|
---|
[3598] | 265 | (const GLubyte(*)[3]) rgb, NULL);
|
---|
[2938] | 266 | src += rowLength;
|
---|
| 267 | destY++;
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 | else {
|
---|
| 271 | /* with zooming */
|
---|
| 272 | GLint row;
|
---|
[3598] | 273 | ASSERT(drawWidth < MAX_WIDTH);
|
---|
[2938] | 274 | for (row=0; row<drawHeight; row++) {
|
---|
| 275 | GLint i;
|
---|
| 276 | for (i=0;i<drawWidth;i++) {
|
---|
| 277 | rgb[i][0] = src[i];
|
---|
| 278 | rgb[i][1] = src[i];
|
---|
| 279 | rgb[i][2] = src[i];
|
---|
| 280 | }
|
---|
| 281 | gl_write_zoomed_rgb_span(ctx, drawWidth, destX, destY,
|
---|
[3598] | 282 | zSpan, (const GLubyte(*)[3]) rgb, zoomY0);
|
---|
[2938] | 283 | src += rowLength;
|
---|
| 284 | destY++;
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 | return GL_TRUE;
|
---|
| 289 | }
|
---|
| 290 | else if (format==GL_LUMINANCE_ALPHA && type==GL_UNSIGNED_BYTE) {
|
---|
| 291 | if (ctx->Visual->RGBAflag) {
|
---|
| 292 | GLubyte *src = (GLubyte *) pixels
|
---|
| 293 | + (skipRows * rowLength + skipPixels)*2;
|
---|
| 294 | if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) {
|
---|
| 295 | /* no zooming */
|
---|
| 296 | GLint row;
|
---|
[3598] | 297 | ASSERT(drawWidth < MAX_WIDTH);
|
---|
[2938] | 298 | for (row=0; row<drawHeight; row++) {
|
---|
| 299 | GLint i;
|
---|
| 300 | GLubyte *ptr = src;
|
---|
| 301 | for (i=0;i<drawWidth;i++) {
|
---|
| 302 | rgba[i][0] = *ptr;
|
---|
| 303 | rgba[i][1] = *ptr;
|
---|
| 304 | rgba[i][2] = *ptr++;
|
---|
| 305 | rgba[i][3] = *ptr++;
|
---|
| 306 | }
|
---|
| 307 | (*ctx->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY,
|
---|
[3598] | 308 | (const GLubyte (*)[4]) rgba, NULL);
|
---|
[2938] | 309 | src += rowLength*2;
|
---|
| 310 | destY++;
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | else {
|
---|
| 314 | /* with zooming */
|
---|
| 315 | GLint row;
|
---|
[3598] | 316 | ASSERT(drawWidth < MAX_WIDTH);
|
---|
[2938] | 317 | for (row=0; row<drawHeight; row++) {
|
---|
| 318 | GLubyte *ptr = src;
|
---|
| 319 | GLint i;
|
---|
| 320 | for (i=0;i<drawWidth;i++) {
|
---|
| 321 | rgba[i][0] = *ptr;
|
---|
| 322 | rgba[i][1] = *ptr;
|
---|
| 323 | rgba[i][2] = *ptr++;
|
---|
| 324 | rgba[i][3] = *ptr++;
|
---|
| 325 | }
|
---|
| 326 | gl_write_zoomed_rgba_span(ctx, drawWidth, destX, destY,
|
---|
[3598] | 327 | zSpan, (const GLubyte (*)[4]) rgba, zoomY0);
|
---|
[2938] | 328 | src += rowLength*2;
|
---|
| 329 | destY++;
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
| 332 | }
|
---|
| 333 | return GL_TRUE;
|
---|
| 334 | }
|
---|
| 335 | else if (format==GL_COLOR_INDEX && type==GL_UNSIGNED_BYTE) {
|
---|
| 336 | GLubyte *src = (GLubyte *) pixels + skipRows * rowLength + skipPixels;
|
---|
| 337 | if (ctx->Visual->RGBAflag) {
|
---|
| 338 | /* convert CI data to RGBA */
|
---|
| 339 | if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) {
|
---|
| 340 | /* no zooming */
|
---|
| 341 | GLint row;
|
---|
| 342 | for (row=0; row<drawHeight; row++) {
|
---|
[3598] | 343 | ASSERT(drawWidth < MAX_WIDTH);
|
---|
[2938] | 344 | gl_map_ci8_to_rgba(ctx, drawWidth, src, rgba);
|
---|
| 345 | (*ctx->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY,
|
---|
| 346 | (const GLubyte (*)[4])rgba,
|
---|
| 347 | NULL);
|
---|
| 348 | src += rowLength;
|
---|
| 349 | destY++;
|
---|
| 350 | }
|
---|
| 351 | return GL_TRUE;
|
---|
| 352 | }
|
---|
| 353 | else {
|
---|
| 354 | /* with zooming */
|
---|
| 355 | GLint row;
|
---|
| 356 | for (row=0; row<drawHeight; row++) {
|
---|
[3598] | 357 | ASSERT(drawWidth < MAX_WIDTH);
|
---|
[2938] | 358 | gl_map_ci8_to_rgba(ctx, drawWidth, src, rgba);
|
---|
| 359 | gl_write_zoomed_rgba_span(ctx, drawWidth, destX, destY,
|
---|
[3598] | 360 | zSpan, (const GLubyte(*)[4]) rgba, zoomY0);
|
---|
[2938] | 361 | src += rowLength;
|
---|
| 362 | destY++;
|
---|
| 363 | }
|
---|
| 364 | return GL_TRUE;
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
| 367 | else {
|
---|
| 368 | /* write CI data to CI frame buffer */
|
---|
| 369 | GLint row;
|
---|
| 370 | if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) {
|
---|
| 371 | /* no zooming */
|
---|
| 372 | for (row=0; row<drawHeight; row++) {
|
---|
| 373 | (*ctx->Driver.WriteCI8Span)(ctx, drawWidth, destX, destY,
|
---|
| 374 | src, NULL);
|
---|
| 375 | src += rowLength;
|
---|
| 376 | destY++;
|
---|
| 377 | }
|
---|
| 378 | return GL_TRUE;
|
---|
| 379 | }
|
---|
| 380 | else {
|
---|
| 381 | /* with zooming */
|
---|
| 382 | return GL_FALSE;
|
---|
| 383 | }
|
---|
| 384 | }
|
---|
| 385 | }
|
---|
| 386 | else {
|
---|
| 387 | /* can't handle this pixel format and/or data type here */
|
---|
| 388 | return GL_FALSE;
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
[3598] | 391 |
|
---|
| 392 | /* can't do a simple draw, have to use slow path */
|
---|
| 393 | return GL_FALSE;
|
---|
[2938] | 394 | }
|
---|
| 395 |
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | /*
|
---|
| 399 | * Do glDrawPixels of index pixels.
|
---|
| 400 | */
|
---|
[3598] | 401 | static void
|
---|
| 402 | draw_index_pixels( GLcontext *ctx, GLint x, GLint y,
|
---|
| 403 | GLsizei width, GLsizei height,
|
---|
| 404 | GLenum type, const GLvoid *pixels )
|
---|
[2938] | 405 | {
|
---|
[3598] | 406 | const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
|
---|
[2938] | 407 | const GLint desty = y;
|
---|
[3598] | 408 | GLint row, drawWidth;
|
---|
[2938] | 409 | GLdepth zspan[MAX_WIDTH];
|
---|
| 410 |
|
---|
[3598] | 411 | drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width;
|
---|
[2938] | 412 |
|
---|
| 413 | /* Fragment depth values */
|
---|
| 414 | if (ctx->Depth.Test || ctx->Fog.Enabled) {
|
---|
[3598] | 415 | GLdepth zval = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMaxF);
|
---|
| 416 | GLint i;
|
---|
| 417 | for (i = 0; i < drawWidth; i++) {
|
---|
| 418 | zspan[i] = zval;
|
---|
[2938] | 419 | }
|
---|
| 420 | }
|
---|
| 421 |
|
---|
[3598] | 422 | /*
|
---|
| 423 | * General solution
|
---|
| 424 | */
|
---|
| 425 | for (row = 0; row < height; row++, y++) {
|
---|
| 426 | GLuint indexes[MAX_WIDTH];
|
---|
| 427 | const GLvoid *source = _mesa_image_address(&ctx->Unpack,
|
---|
| 428 | pixels, width, height, GL_COLOR_INDEX, type, 0, row, 0);
|
---|
| 429 | _mesa_unpack_index_span(ctx, drawWidth, GL_UNSIGNED_INT, indexes,
|
---|
| 430 | type, source, &ctx->Unpack, GL_TRUE);
|
---|
| 431 | if (zoom) {
|
---|
| 432 | gl_write_zoomed_index_span(ctx, drawWidth, x, y, zspan, indexes, desty);
|
---|
[2938] | 433 | }
|
---|
| 434 | else {
|
---|
[3598] | 435 | gl_write_index_span(ctx, drawWidth, x, y, zspan, indexes, GL_BITMAP);
|
---|
[2938] | 436 | }
|
---|
| 437 | }
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 |
|
---|
| 441 |
|
---|
| 442 | /*
|
---|
| 443 | * Do glDrawPixels of stencil image. The image datatype may either
|
---|
| 444 | * be GLubyte or GLbitmap.
|
---|
| 445 | */
|
---|
[3598] | 446 | static void
|
---|
| 447 | draw_stencil_pixels( GLcontext *ctx, GLint x, GLint y,
|
---|
| 448 | GLsizei width, GLsizei height,
|
---|
| 449 | GLenum type, const GLvoid *pixels )
|
---|
[2938] | 450 | {
|
---|
[3598] | 451 | const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
|
---|
[2938] | 452 | const GLint desty = y;
|
---|
[3598] | 453 | GLint row, drawWidth;
|
---|
[2938] | 454 |
|
---|
[3598] | 455 | if (type != GL_BYTE &&
|
---|
| 456 | type != GL_UNSIGNED_BYTE &&
|
---|
| 457 | type != GL_SHORT &&
|
---|
| 458 | type != GL_UNSIGNED_SHORT &&
|
---|
| 459 | type != GL_INT &&
|
---|
| 460 | type != GL_UNSIGNED_INT &&
|
---|
| 461 | type != GL_FLOAT &&
|
---|
| 462 | type != GL_BITMAP) {
|
---|
| 463 | gl_error( ctx, GL_INVALID_ENUM, "glDrawPixels(stencil type)");
|
---|
[2938] | 464 | return;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
[3598] | 467 | drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width;
|
---|
[2938] | 468 |
|
---|
[3598] | 469 | for (row = 0; row < height; row++, y++) {
|
---|
| 470 | GLstencil values[MAX_WIDTH];
|
---|
| 471 | GLenum destType = (sizeof(GLstencil) == sizeof(GLubyte))
|
---|
| 472 | ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
|
---|
| 473 | const GLvoid *source = _mesa_image_address(&ctx->Unpack,
|
---|
| 474 | pixels, width, height, GL_COLOR_INDEX, type, 0, row, 0);
|
---|
| 475 | _mesa_unpack_index_span(ctx, drawWidth, destType, values,
|
---|
| 476 | type, source, &ctx->Unpack, GL_TRUE);
|
---|
[2938] | 477 |
|
---|
| 478 | if (zoom) {
|
---|
[3598] | 479 | gl_write_zoomed_stencil_span( ctx, (GLuint) drawWidth, x, y,
|
---|
| 480 | values, desty );
|
---|
[2938] | 481 | }
|
---|
| 482 | else {
|
---|
[3598] | 483 | gl_write_stencil_span( ctx, (GLuint) drawWidth, x, y, values );
|
---|
[2938] | 484 | }
|
---|
| 485 | }
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 |
|
---|
| 489 |
|
---|
| 490 | /*
|
---|
| 491 | * Do a glDrawPixels of depth values.
|
---|
| 492 | */
|
---|
[3598] | 493 | static void
|
---|
| 494 | draw_depth_pixels( GLcontext *ctx, GLint x, GLint y,
|
---|
| 495 | GLsizei width, GLsizei height,
|
---|
| 496 | GLenum type, const GLvoid *pixels )
|
---|
[2938] | 497 | {
|
---|
[3598] | 498 | const GLboolean bias_or_scale = ctx->Pixel.DepthBias!=0.0 || ctx->Pixel.DepthScale!=1.0;
|
---|
| 499 | const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
|
---|
[2938] | 500 | const GLint desty = y;
|
---|
| 501 | GLubyte rgba[MAX_WIDTH][4];
|
---|
| 502 | GLuint ispan[MAX_WIDTH];
|
---|
[3598] | 503 | GLint drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width;
|
---|
[2938] | 504 |
|
---|
[3598] | 505 | if (type != GL_UNSIGNED_BYTE
|
---|
| 506 | && type != GL_UNSIGNED_BYTE
|
---|
| 507 | && type != GL_UNSIGNED_SHORT
|
---|
| 508 | && type != GL_UNSIGNED_SHORT
|
---|
| 509 | && type != GL_UNSIGNED_INT
|
---|
| 510 | && type != GL_UNSIGNED_INT
|
---|
| 511 | && type != GL_FLOAT) {
|
---|
| 512 | gl_error(ctx, GL_INVALID_ENUM, "glDrawPixels(type)");
|
---|
| 513 | return;
|
---|
| 514 | }
|
---|
[2938] | 515 |
|
---|
[3598] | 516 | /* Colors or indexes */
|
---|
[2938] | 517 | if (ctx->Visual->RGBAflag) {
|
---|
| 518 | GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0F);
|
---|
| 519 | GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0F);
|
---|
| 520 | GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0F);
|
---|
| 521 | GLint a = (GLint) (ctx->Current.RasterColor[3] * 255.0F);
|
---|
| 522 | GLint i;
|
---|
[3598] | 523 | for (i = 0; i < drawWidth; i++) {
|
---|
[2938] | 524 | rgba[i][RCOMP] = r;
|
---|
| 525 | rgba[i][GCOMP] = g;
|
---|
| 526 | rgba[i][BCOMP] = b;
|
---|
| 527 | rgba[i][ACOMP] = a;
|
---|
| 528 | }
|
---|
| 529 | }
|
---|
| 530 | else {
|
---|
| 531 | GLint i;
|
---|
[3598] | 532 | for (i = 0; i < drawWidth; i++) {
|
---|
| 533 | ispan[i] = ctx->Current.RasterIndex;
|
---|
[2938] | 534 | }
|
---|
| 535 | }
|
---|
| 536 |
|
---|
[3598] | 537 | if (type==GL_UNSIGNED_SHORT && sizeof(GLdepth)==sizeof(GLushort)
|
---|
[2938] | 538 | && !bias_or_scale && !zoom && ctx->Visual->RGBAflag) {
|
---|
| 539 | /* Special case: directly write 16-bit depth values */
|
---|
[3598] | 540 | GLint row;
|
---|
| 541 | for (row = 0; row < height; row++, y++) {
|
---|
| 542 | GLdepth zspan[MAX_WIDTH];
|
---|
| 543 | const GLushort *zptr = (const GLushort *)_mesa_image_address(&ctx->Unpack,
|
---|
| 544 | pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0);
|
---|
| 545 | GLint i;
|
---|
| 546 | for (i = 0; i < width; i++)
|
---|
| 547 | zspan[i] = zptr[i];
|
---|
| 548 | gl_write_rgba_span( ctx, width, x, y, zspan, rgba, GL_BITMAP );
|
---|
[2938] | 549 | }
|
---|
| 550 | }
|
---|
[3598] | 551 | else if (type==GL_UNSIGNED_INT && ctx->Visual->DepthBits == 32
|
---|
[2938] | 552 | && !bias_or_scale && !zoom && ctx->Visual->RGBAflag) {
|
---|
| 553 | /* Special case: directly write 32-bit depth values */
|
---|
[3598] | 554 | GLint row;
|
---|
| 555 | for (row = 0; row < height; row++, y++) {
|
---|
| 556 | const GLuint *zptr = (GLuint *)_mesa_image_address(&ctx->Unpack,
|
---|
| 557 | pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0);
|
---|
| 558 | gl_write_rgba_span( ctx, width, x, y, zptr, rgba, GL_BITMAP );
|
---|
[2938] | 559 | }
|
---|
| 560 | }
|
---|
| 561 | else {
|
---|
[3598] | 562 | /* General case */
|
---|
| 563 | GLint row;
|
---|
| 564 | for (row = 0; row < height; row++, y++) {
|
---|
[2938] | 565 | GLdepth zspan[MAX_WIDTH];
|
---|
[3598] | 566 | const GLvoid *src = _mesa_image_address(&ctx->Unpack,
|
---|
| 567 | pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0);
|
---|
| 568 | _mesa_unpack_depth_span( ctx, drawWidth, zspan, type, src,
|
---|
| 569 | &ctx->Unpack, GL_TRUE );
|
---|
[2938] | 570 | if (ctx->Visual->RGBAflag) {
|
---|
| 571 | if (zoom) {
|
---|
[3598] | 572 | gl_write_zoomed_rgba_span(ctx, width, x, y, zspan,
|
---|
| 573 | (const GLubyte (*)[4])rgba, desty);
|
---|
[2938] | 574 | }
|
---|
| 575 | else {
|
---|
[3598] | 576 | gl_write_rgba_span(ctx, width, x, y, zspan, rgba, GL_BITMAP);
|
---|
[2938] | 577 | }
|
---|
| 578 | }
|
---|
| 579 | else {
|
---|
| 580 | if (zoom) {
|
---|
[3598] | 581 | gl_write_zoomed_index_span(ctx, width, x, y, zspan,
|
---|
| 582 | ispan, GL_BITMAP);
|
---|
[2938] | 583 | }
|
---|
| 584 | else {
|
---|
[3598] | 585 | gl_write_index_span(ctx, width, x, y, zspan, ispan, GL_BITMAP);
|
---|
[2938] | 586 | }
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | }
|
---|
| 590 | }
|
---|
| 591 | }
|
---|
| 592 |
|
---|
| 593 |
|
---|
| 594 | /*
|
---|
| 595 | * Do glDrawPixels of RGBA pixels.
|
---|
| 596 | */
|
---|
[3598] | 597 | static void
|
---|
| 598 | draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
|
---|
| 599 | GLsizei width, GLsizei height,
|
---|
| 600 | GLenum format, GLenum type, const GLvoid *pixels )
|
---|
[2938] | 601 | {
|
---|
[3598] | 602 | const struct gl_pixelstore_attrib *unpack = &ctx->Unpack;
|
---|
| 603 | const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
|
---|
[2938] | 604 | const GLint desty = y;
|
---|
| 605 | GLdepth zspan[MAX_WIDTH];
|
---|
| 606 | GLboolean quickDraw;
|
---|
| 607 |
|
---|
| 608 | /* Try an optimized glDrawPixels first */
|
---|
[3598] | 609 | if (simple_DrawPixels(ctx, x, y, width, height, format, type, pixels))
|
---|
[2938] | 610 | return;
|
---|
| 611 |
|
---|
| 612 | /* Fragment depth values */
|
---|
| 613 | if (ctx->Depth.Test || ctx->Fog.Enabled) {
|
---|
| 614 | /* fill in array of z values */
|
---|
[3598] | 615 | GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMaxF);
|
---|
| 616 | GLint i;
|
---|
[2938] | 617 | for (i=0;i<width;i++) {
|
---|
[3598] | 618 | zspan[i] = z;
|
---|
[2938] | 619 | }
|
---|
| 620 | }
|
---|
| 621 |
|
---|
[3598] | 622 |
|
---|
| 623 | if (ctx->RasterMask == 0 && !zoom
|
---|
| 624 | && x >= 0 && y >= 0
|
---|
| 625 | && x + width <= ctx->DrawBuffer->Width
|
---|
| 626 | && y + height <= ctx->DrawBuffer->Height) {
|
---|
[2938] | 627 | quickDraw = GL_TRUE;
|
---|
| 628 | }
|
---|
| 629 | else {
|
---|
| 630 | quickDraw = GL_FALSE;
|
---|
| 631 | }
|
---|
| 632 |
|
---|
[3598] | 633 | /*
|
---|
| 634 | * General solution
|
---|
| 635 | */
|
---|
[2938] | 636 | {
|
---|
| 637 | GLubyte rgba[MAX_WIDTH][4];
|
---|
[3598] | 638 | GLint row;
|
---|
| 639 | if (width > MAX_WIDTH)
|
---|
| 640 | width = MAX_WIDTH;
|
---|
| 641 | for (row = 0; row < height; row++, y++) {
|
---|
| 642 | const GLvoid *source = _mesa_image_address(unpack,
|
---|
| 643 | pixels, width, height, format, type, 0, row, 0);
|
---|
| 644 | _mesa_unpack_ubyte_color_span(ctx, width, GL_RGBA, (GLubyte *) rgba,
|
---|
| 645 | format, type, source, unpack, GL_TRUE);
|
---|
[2938] | 646 |
|
---|
| 647 | if (quickDraw) {
|
---|
| 648 | (*ctx->Driver.WriteRGBASpan)( ctx, width, x, y,
|
---|
[3598] | 649 | (CONST GLubyte (*)[4]) rgba, NULL);
|
---|
[2938] | 650 | }
|
---|
| 651 | else if (zoom) {
|
---|
| 652 | gl_write_zoomed_rgba_span( ctx, width, x, y, zspan,
|
---|
[3598] | 653 | (CONST GLubyte (*)[4]) rgba, desty );
|
---|
[2938] | 654 | }
|
---|
| 655 | else {
|
---|
| 656 | gl_write_rgba_span( ctx, (GLuint) width, x, y, zspan, rgba, GL_BITMAP);
|
---|
| 657 | }
|
---|
| 658 | }
|
---|
| 659 | }
|
---|
| 660 | }
|
---|
| 661 |
|
---|
| 662 |
|
---|
| 663 |
|
---|
| 664 | /*
|
---|
| 665 | * Execute glDrawPixels
|
---|
| 666 | */
|
---|
[3598] | 667 | void
|
---|
| 668 | _mesa_DrawPixels( GLsizei width, GLsizei height,
|
---|
| 669 | GLenum format, GLenum type, const GLvoid *pixels )
|
---|
[2938] | 670 | {
|
---|
[3598] | 671 | GET_CURRENT_CONTEXT(ctx);
|
---|
[2938] | 672 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDrawPixels");
|
---|
| 673 |
|
---|
| 674 | if (ctx->RenderMode==GL_RENDER) {
|
---|
| 675 | GLint x, y;
|
---|
[3598] | 676 | if (!pixels || !ctx->Current.RasterPosValid) {
|
---|
| 677 | return;
|
---|
[2938] | 678 | }
|
---|
| 679 |
|
---|
| 680 | x = (GLint) (ctx->Current.RasterPos[0] + 0.5F);
|
---|
| 681 | y = (GLint) (ctx->Current.RasterPos[1] + 0.5F);
|
---|
| 682 |
|
---|
[3598] | 683 | /* see if device driver can do the drawpix */
|
---|
| 684 | if (ctx->Driver.DrawPixels
|
---|
| 685 | && (*ctx->Driver.DrawPixels)(ctx, x, y, width, height, format, type,
|
---|
| 686 | &ctx->Unpack, pixels)) {
|
---|
| 687 | return;
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 | switch (format) {
|
---|
| 691 | case GL_STENCIL_INDEX:
|
---|
| 692 | draw_stencil_pixels( ctx, x, y, width, height, type, pixels );
|
---|
| 693 | break;
|
---|
| 694 | case GL_DEPTH_COMPONENT:
|
---|
| 695 | draw_depth_pixels( ctx, x, y, width, height, type, pixels );
|
---|
| 696 | break;
|
---|
| 697 | case GL_COLOR_INDEX:
|
---|
| 698 | if (ctx->Visual->RGBAflag)
|
---|
| 699 | draw_rgba_pixels(ctx, x,y, width, height, format, type, pixels);
|
---|
| 700 | else
|
---|
| 701 | draw_index_pixels(ctx, x, y, width, height, type, pixels);
|
---|
| 702 | break;
|
---|
| 703 | case GL_RED:
|
---|
| 704 | case GL_GREEN:
|
---|
| 705 | case GL_BLUE:
|
---|
| 706 | case GL_ALPHA:
|
---|
| 707 | case GL_LUMINANCE:
|
---|
| 708 | case GL_LUMINANCE_ALPHA:
|
---|
| 709 | case GL_RGB:
|
---|
| 710 | case GL_BGR:
|
---|
| 711 | case GL_RGBA:
|
---|
| 712 | case GL_BGRA:
|
---|
| 713 | case GL_ABGR_EXT:
|
---|
| 714 | draw_rgba_pixels(ctx, x, y, width, height, format, type, pixels);
|
---|
| 715 | break;
|
---|
| 716 | default:
|
---|
| 717 | gl_error( ctx, GL_INVALID_ENUM, "glDrawPixels(format)" );
|
---|
[2938] | 718 | return;
|
---|
| 719 | }
|
---|
| 720 | }
|
---|
| 721 | else if (ctx->RenderMode==GL_FEEDBACK) {
|
---|
| 722 | if (ctx->Current.RasterPosValid) {
|
---|
| 723 | GLfloat color[4];
|
---|
[3598] | 724 | GLfloat texcoord[4], invq;
|
---|
| 725 | UBYTE_RGBA_TO_FLOAT_RGBA(color, ctx->Current.ByteColor);
|
---|
[2938] | 726 | invq = 1.0F / ctx->Current.Texcoord[0][3];
|
---|
| 727 | texcoord[0] = ctx->Current.Texcoord[0][0] * invq;
|
---|
| 728 | texcoord[1] = ctx->Current.Texcoord[0][1] * invq;
|
---|
| 729 | texcoord[2] = ctx->Current.Texcoord[0][2] * invq;
|
---|
| 730 | texcoord[3] = ctx->Current.Texcoord[0][3];
|
---|
| 731 | FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN );
|
---|
| 732 | gl_feedback_vertex( ctx,
|
---|
| 733 | ctx->Current.RasterPos,
|
---|
| 734 | color, ctx->Current.Index, texcoord );
|
---|
| 735 | }
|
---|
| 736 | }
|
---|
| 737 | else if (ctx->RenderMode==GL_SELECT) {
|
---|
| 738 | if (ctx->Current.RasterPosValid) {
|
---|
| 739 | gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
|
---|
| 740 | }
|
---|
| 741 | }
|
---|
| 742 | }
|
---|
| 743 |
|
---|