Changeset 3598 for trunk/src/opengl/mesa/copypix.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/copypix.c
r2962 r3598 1 /* $Id: copypix.c,v 1. 2 2000-03-01 18:49:25jeroen Exp $ */1 /* $Id: copypix.c,v 1.3 2000-05-23 20:40:26 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 32 32 #include "all.h" 33 33 #else 34 #ifndef XFree86Server 35 #include <string.h> 36 #else 37 #include "GL/xf86glx.h" 38 #endif 34 #include "glheader.h" 39 35 #include "types.h" 36 #include "mem.h" 40 37 #include "context.h" 41 38 #include "copypix.h" … … 46 43 #include "pixel.h" 47 44 #include "span.h" 45 #include "state.h" 48 46 #include "stencil.h" 49 47 #include "zoom.h" … … 73 71 } 74 72 } 75 76 73 77 74 … … 89 86 GLint i, j; 90 87 GLboolean changeBuffer; 91 GLubyte *save Alpha;92 const GLboolean zoom = ctx->Pixel.ZoomX !=1.0F || ctx->Pixel.ZoomY!=1.0F;93 GL boolean needbuffer;88 GLubyte *saveReadAlpha; 89 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F; 90 GLint overlapping; 94 91 95 92 /* Determine if copy should be done bottom-to-top or top-to-bottom */ 96 if (srcy <desty) {93 if (srcy < desty) { 97 94 /* top-down max-to-min */ 98 95 sy = srcy + height - 1; … … 107 104 } 108 105 109 needbuffer= regions_overlap(srcx, srcy, destx, desty, width, height,110 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);106 overlapping = regions_overlap(srcx, srcy, destx, desty, width, height, 107 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY); 111 108 112 109 if (ctx->Depth.Test || ctx->Fog.Enabled) { 113 110 /* fill in array of z values */ 114 GL int z = (GLint) (ctx->Current.RasterPos[2] * DEPTH_SCALE);111 GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMax); 115 112 for (i=0;i<width;i++) { 116 113 zspan[i] = z; … … 118 115 } 119 116 120 if (ctx->RasterMask==0 && !zoom 121 && destx>=0 && destx+width<=ctx->Buffer->Width) { 117 if (ctx->RasterMask == 0 118 && !zoom 119 && destx >= 0 120 && destx + width <= ctx->DrawBuffer->Width) { 122 121 quick_draw = GL_TRUE; 123 122 } … … 127 126 128 127 /* If read and draw buffer are different we must do buffer switching */ 129 saveAlpha = ctx->Buffer->Alpha; 130 changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer; 131 132 if (needbuffer) { 128 saveReadAlpha = ctx->ReadBuffer->Alpha; 129 changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer 130 || ctx->DrawBuffer != ctx->ReadBuffer; 131 132 if (overlapping) { 133 133 GLint ssy = sy; 134 prgba = (GLubyte *) MALLOC(width *height*sizeof(GLubyte)*4);134 prgba = (GLubyte *) MALLOC(width * height * sizeof(GLubyte) * 4); 135 135 if (!prgba) { 136 136 gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" ); … … 139 139 p = prgba; 140 140 if (changeBuffer) { 141 (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 141 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 142 ctx->Pixel.DriverReadBuffer ); 142 143 if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT) 143 ctx-> Buffer->Alpha = ctx->Buffer->FrontLeftAlpha;144 ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontLeftAlpha; 144 145 else if (ctx->Pixel.DriverReadBuffer == GL_BACK_LEFT) 145 ctx-> Buffer->Alpha = ctx->Buffer->BackLeftAlpha;146 ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackLeftAlpha; 146 147 else if (ctx->Pixel.DriverReadBuffer == GL_FRONT_RIGHT) 147 ctx-> Buffer->Alpha = ctx->Buffer->FrontRightAlpha;148 ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontRightAlpha; 148 149 else 149 ctx->Buffer->Alpha = ctx->Buffer->BackRightAlpha; 150 } 151 for (j=0; j<height; j++, ssy+=stepy) { 152 gl_read_rgba_span( ctx, width, srcx, ssy,(GLubyte (*)[4]) p ); 153 p += (width*sizeof(GLubyte)*4); 150 ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackRightAlpha; 151 } 152 for (j = 0; j < height; j++, ssy += stepy) { 153 gl_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, ssy, 154 (GLubyte (*)[4]) p ); 155 p += (width * sizeof(GLubyte) * 4); 154 156 } 155 157 p = prgba; 156 158 } 157 158 for (j=0; j<height; j++, sy+=stepy, dy+=stepy) { 159 if (needbuffer) { 159 else { 160 prgba = NULL; /* silence compiler warnings*/ 161 p = NULL; 162 } 163 164 for (j = 0; j < height; j++, sy += stepy, dy += stepy) { 165 if (overlapping) { 160 166 MEMCPY(rgba, p, width * sizeof(GLubyte) * 4); 161 167 p += (width * sizeof(GLubyte) * 4); … … 163 169 else { 164 170 if (changeBuffer) { 165 (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 166 if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT) 167 ctx->Buffer->Alpha = ctx->Buffer->FrontLeftAlpha; 168 else if (ctx->Pixel.DriverReadBuffer == GL_BACK_LEFT) 169 ctx->Buffer->Alpha = ctx->Buffer->BackLeftAlpha; 170 else if (ctx->Pixel.DriverReadBuffer == GL_FRONT_RIGHT) 171 ctx->Buffer->Alpha = ctx->Buffer->FrontRightAlpha; 172 else 173 ctx->Buffer->Alpha = ctx->Buffer->BackRightAlpha; 171 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 172 ctx->Pixel.DriverReadBuffer ); 173 if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT) { 174 ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontLeftAlpha; 175 } 176 else if (ctx->Pixel.DriverReadBuffer == GL_BACK_LEFT) { 177 ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackLeftAlpha; 178 } 179 else if (ctx->Pixel.DriverReadBuffer == GL_FRONT_RIGHT) { 180 ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontRightAlpha; 181 } 182 else { 183 ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackRightAlpha; 184 } 174 185 } 175 gl_read_rgba_span( ctx, width, srcx, sy, rgba ); 176 } 186 gl_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, sy, rgba ); 187 } 188 189 if (changeBuffer) { 190 /* read from the draw buffer again (in case of blending) */ 191 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, 192 ctx->Color.DriverDrawBuffer ); 193 ctx->ReadBuffer->Alpha = saveReadAlpha; 194 } 195 177 196 if (ctx->Pixel.ScaleOrBiasRGBA) { 178 197 gl_scale_and_bias_rgba( ctx, width, rgba ); … … 181 200 gl_map_rgba( ctx, width, rgba ); 182 201 } 183 if (quick_draw && dy >=0 && dy<ctx->Buffer->Height) {202 if (quick_draw && dy >= 0 && dy < ctx->DrawBuffer->Height) { 184 203 (*ctx->Driver.WriteRGBASpan)( ctx, width, destx, dy, 185 (const GLubyte (*)[4])rgba, NULL ); 186 204 (const GLubyte (*)[4])rgba, NULL ); 187 205 } 188 206 else if (zoom) { 189 207 gl_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 190 208 (const GLubyte (*)[4])rgba, desty); 191 209 } 192 210 else { … … 195 213 } 196 214 197 if ( needbuffer)215 if (overlapping) 198 216 FREE(prgba); 199 200 /* Restore current alpha buffer pointer */201 ctx->Buffer->Alpha = saveAlpha;202 if (changeBuffer)203 (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );204 217 } 205 218 … … 214 227 GLint i, j; 215 228 GLboolean changeBuffer; 216 const GLboolean zoom = ctx->Pixel.ZoomX !=1.0F || ctx->Pixel.ZoomY!=1.0F;229 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F; 217 230 const GLboolean shift_or_offset = ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset; 218 GL boolean needbuffer;231 GLint overlapping; 219 232 220 233 /* Determine if copy should be bottom-to-top or top-to-bottom */ … … 232 245 } 233 246 234 needbuffer= regions_overlap(srcx, srcy, destx, desty, width, height,235 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);247 overlapping = regions_overlap(srcx, srcy, destx, desty, width, height, 248 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY); 236 249 237 250 if (ctx->Depth.Test || ctx->Fog.Enabled) { 238 251 /* fill in array of z values */ 239 GL int z = (GLint) (ctx->Current.RasterPos[2] * DEPTH_SCALE);252 GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMax); 240 253 for (i=0;i<width;i++) { 241 254 zspan[i] = z; … … 244 257 245 258 /* If read and draw buffer are different we must do buffer switching */ 246 changeBuffer = ctx->Pixel.ReadBuffer!=ctx->Color.DrawBuffer; 247 248 if (needbuffer) { 259 changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer 260 || ctx->DrawBuffer != ctx->ReadBuffer; 261 262 if (overlapping) { 249 263 GLint ssy = sy; 250 264 pci = (GLuint *) MALLOC(width * height * sizeof(GLuint)); … … 255 269 p = pci; 256 270 if (changeBuffer) { 257 (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 258 } 259 for (j=0; j<height; j++, ssy+=stepy) { 260 gl_read_index_span( ctx, width, srcx, ssy, p ); 271 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 272 ctx->Pixel.DriverReadBuffer ); 273 } 274 for (j = 0; j < height; j++, ssy += stepy) { 275 gl_read_index_span( ctx, ctx->ReadBuffer, width, srcx, ssy, p ); 261 276 p += width; 262 277 } 263 278 p = pci; 264 279 } 265 266 for (j=0; j<height; j++, sy+=stepy, dy+=stepy) { 280 else { 281 pci = NULL; /* silence compiler warning*/ 282 p = NULL; 283 } 284 285 for (j = 0; j < height; j++, sy += stepy, dy += stepy) { 267 286 GLuint indexes[MAX_WIDTH]; 268 if ( needbuffer) {287 if (overlapping) { 269 288 MEMCPY(indexes, p, width * sizeof(GLuint)); 270 289 p += width; … … 272 291 else { 273 292 if (changeBuffer) { 274 (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 293 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 294 ctx->Pixel.DriverReadBuffer ); 275 295 } 276 gl_read_index_span( ctx, width, srcx, sy, indexes ); 296 gl_read_index_span( ctx, ctx->ReadBuffer, width, srcx, sy, indexes ); 297 } 298 299 if (changeBuffer) { 300 /* set read buffer back to draw buffer (in case of logicops) */ 301 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, 302 ctx->Color.DriverDrawBuffer ); 277 303 } 278 304 … … 284 310 } 285 311 286 if (changeBuffer) {287 (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DrawBuffer );288 }289 312 if (zoom) { 290 313 gl_write_zoomed_index_span( ctx, width, destx, dy, zspan, indexes, desty ); 291 314 } 292 315 else { 293 gl_write_index_span( ctx, width, destx, dy, zspan, indexes, GL_BITMAP);294 } 295 } 296 297 if ( needbuffer)316 gl_write_index_span(ctx, width, destx, dy, zspan, indexes, GL_BITMAP); 317 } 318 } 319 320 if (overlapping) 298 321 FREE(pci); 299 300 if (changeBuffer)301 (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );302 322 } 303 323 … … 318 338 GLint sy, dy, stepy; 319 339 GLint i, j; 320 const GLboolean zoom = ctx->Pixel.ZoomX !=1.0F || ctx->Pixel.ZoomY!=1.0F;321 GL boolean needbuffer;322 323 if (!ctx-> Buffer->Depth) {340 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F; 341 GLint overlapping; 342 343 if (!ctx->ReadBuffer->DepthBuffer || !ctx->DrawBuffer->DepthBuffer) { 324 344 gl_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" ); 325 345 return; … … 340 360 } 341 361 342 343 needbuffer = regions_overlap(srcx, srcy, destx, desty, width, height, 344 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY); 362 overlapping = regions_overlap(srcx, srcy, destx, desty, width, height, 363 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY); 345 364 346 365 /* setup colors or indexes */ … … 348 367 GLuint *rgba32 = (GLuint *) rgba; 349 368 GLuint color = *(GLuint*)( ctx->Current.ByteColor ); 350 for (i =0; i<width; i++) {369 for (i = 0; i < width; i++) { 351 370 rgba32[i] = color; 352 371 } 353 372 } 354 373 else { 355 for (i =0;i<width;i++) {374 for (i = 0; i < width; i++) { 356 375 indexes[i] = ctx->Current.Index; 357 376 } 358 377 } 359 378 360 if ( needbuffer) {379 if (overlapping) { 361 380 GLint ssy = sy; 362 381 pdepth = (GLfloat *) MALLOC(width * height * sizeof(GLfloat)); … … 366 385 } 367 386 p = pdepth; 368 for (j =0; j<height; j++, ssy+=stepy) {369 (*ctx->Driver.ReadDepthSpanFloat)( ctx, width, srcx, ssy, p);387 for (j = 0; j < height; j++, ssy += stepy) { 388 _mesa_read_depth_span_float(ctx, width, srcx, ssy, p); 370 389 p += width; 371 390 } 372 391 p = pdepth; 373 392 } 374 375 for (j=0; j<height; j++, sy+=stepy, dy+=stepy) { 376 if (needbuffer) { 393 else { 394 pdepth = NULL; /* silence compiler warning*/ 395 p = NULL; 396 } 397 398 for (j = 0; j < height; j++, sy += stepy, dy += stepy) { 399 if (overlapping) { 377 400 MEMCPY(depth, p, width * sizeof(GLfloat)); 378 401 p += width; 379 402 } 380 403 else { 381 (*ctx->Driver.ReadDepthSpanFloat)( ctx, width, srcx, sy, depth);382 } 383 384 for (i =0;i<width;i++) {404 _mesa_read_depth_span_float(ctx, width, srcx, sy, depth); 405 } 406 407 for (i = 0; i < width; i++) { 385 408 GLfloat d = depth[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias; 386 zspan[i] = (GL int) (CLAMP( d, 0.0F, 1.0F ) * DEPTH_SCALE);409 zspan[i] = (GLdepth) (CLAMP(d, 0.0F, 1.0F) * ctx->Visual->DepthMax); 387 410 } 388 411 … … 390 413 if (zoom) { 391 414 gl_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 392 415 (const GLubyte (*)[4])rgba, desty ); 393 416 } 394 417 else { … … 408 431 } 409 432 410 if ( needbuffer)433 if (overlapping) 411 434 FREE(pdepth); 412 435 } … … 420 443 GLint sy, dy, stepy; 421 444 GLint j; 422 GLstencil *p,*psten;423 const GLboolean zoom = (ctx->Pixel.ZoomX!=1.0F || ctx->Pixel.ZoomY!=1.0F);424 const GLboolean shift_or_offset = ctx->Pixel.IndexShift !=0 || ctx->Pixel.IndexOffset!=0;425 GL boolean needbuffer;426 427 if (!ctx-> Buffer->Stencil) {445 GLstencil *p, *psten; 446 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F; 447 const GLboolean shift_or_offset = ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset; 448 GLint overlapping; 449 450 if (!ctx->DrawBuffer->Stencil || !ctx->ReadBuffer->Stencil) { 428 451 gl_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" ); 429 452 return; … … 431 454 432 455 /* Determine if copy should be bottom-to-top or top-to-bottom */ 433 if (srcy <desty) {456 if (srcy < desty) { 434 457 /* top-down max-to-min */ 435 458 sy = srcy + height - 1; … … 444 467 } 445 468 446 needbuffer= regions_overlap(srcx, srcy, destx, desty, width, height,447 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);448 449 if ( needbuffer) {469 overlapping = regions_overlap(srcx, srcy, destx, desty, width, height, 470 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY); 471 472 if (overlapping) { 450 473 GLint ssy = sy; 451 474 psten = (GLstencil *) MALLOC(width * height * sizeof(GLstencil)); … … 455 478 } 456 479 p = psten; 457 for (j =0; j<height; j++, ssy+=stepy) {480 for (j = 0; j < height; j++, ssy += stepy) { 458 481 gl_read_stencil_span( ctx, width, srcx, ssy, p ); 459 482 p += width; … … 461 484 p = psten; 462 485 } 463 464 for (j=0; j<height; j++, sy+=stepy, dy+=stepy) { 486 else { 487 psten = NULL; /* silence compiler warning*/ 488 p = NULL; 489 } 490 491 for (j = 0; j < height; j++, sy += stepy, dy += stepy) { 465 492 GLstencil stencil[MAX_WIDTH]; 466 493 467 if ( needbuffer) {494 if (overlapping) { 468 495 MEMCPY(stencil, p, width * sizeof(GLstencil)); 469 496 p += width; … … 488 515 } 489 516 490 if ( needbuffer)517 if (overlapping) 491 518 FREE(psten); 492 519 } … … 495 522 496 523 497 void gl_CopyPixels( GLcontext* ctx, GLint srcx, GLint srcy, 498 GLsizei width, GLsizei height, GLenum type ) 524 void 525 _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height, 526 GLenum type ) 499 527 { 528 GET_CURRENT_CONTEXT(ctx); 500 529 GLint destx, desty; 501 530 502 531 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyPixels"); 503 532 504 if (width <0 || height<0) {533 if (width < 0 || height < 0) { 505 534 gl_error( ctx, GL_INVALID_VALUE, "glCopyPixels" ); 506 535 return; … … 514 543 /* Destination of copy: */ 515 544 if (!ctx->Current.RasterPosValid) { 516 545 return; 517 546 } 518 547 destx = (GLint) (ctx->Current.RasterPos[0] + 0.5F); 519 548 desty = (GLint) (ctx->Current.RasterPos[1] + 0.5F); 520 549 521 if (type==GL_COLOR && ctx->Visual->RGBAflag) { 550 if (ctx->Driver.CopyPixels && 551 (*ctx->Driver.CopyPixels)( ctx, srcx, srcy, width, height, 552 destx, desty, type )) { 553 return; 554 } 555 556 if (type == GL_COLOR && ctx->Visual->RGBAflag) { 522 557 copy_rgba_pixels( ctx, srcx, srcy, width, height, destx, desty ); 523 558 } 524 else if (type ==GL_COLOR && !ctx->Visual->RGBAflag) {559 else if (type == GL_COLOR && !ctx->Visual->RGBAflag) { 525 560 copy_ci_pixels( ctx, srcx, srcy, width, height, destx, desty ); 526 561 } 527 else if (type ==GL_DEPTH) {562 else if (type == GL_DEPTH) { 528 563 copy_depth_pixels( ctx, srcx, srcy, width, height, destx, desty ); 529 564 } 530 else if (type ==GL_STENCIL) {565 else if (type == GL_STENCIL) { 531 566 copy_stencil_pixels( ctx, srcx, srcy, width, height, destx, desty ); 532 567 } 533 568 else { 534 535 } 536 } 537 else if (ctx->RenderMode ==GL_FEEDBACK) {569 gl_error( ctx, GL_INVALID_ENUM, "glCopyPixels" ); 570 } 571 } 572 else if (ctx->RenderMode == GL_FEEDBACK) { 538 573 GLfloat color[4]; 539 574 UBYTE_RGBA_TO_FLOAT_RGBA(color, ctx->Current.ByteColor ); 540 575 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_COPY_PIXEL_TOKEN ); 541 576 gl_feedback_vertex( ctx, ctx->Current.RasterPos, 542 543 544 } 545 else if (ctx->RenderMode ==GL_SELECT) {577 color, ctx->Current.Index, 578 ctx->Current.Texcoord[0] ); 579 } 580 else if (ctx->RenderMode == GL_SELECT) { 546 581 gl_update_hitflag( ctx, ctx->Current.RasterPos[2] ); 547 582 }
Note:
See TracChangeset
for help on using the changeset viewer.