Changeset 3598 for trunk/src/opengl/mesa/accum.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/accum.c
r2962 r3598 1 /* $Id: accum.c,v 1. 2 2000-03-01 18:49:22jeroen Exp $ */1 /* $Id: accum.c,v 1.3 2000-05-23 20:40:20 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. … … 26 26 27 27 28 /* $XFree86: xc/lib/GL/mesa/src/accum.c,v 1.3 1999/04/04 00:20:17 dawes Exp $ */29 30 28 #ifdef PC_HEADER 31 29 #include "all.h" 32 30 #else 33 #ifndef XFree86Server 34 #include <assert.h> 35 #include <limits.h> 36 #include <stdlib.h> 37 #include <string.h> 38 #else 39 #include "GL/xf86glx.h" 40 #endif 31 #include "glheader.h" 41 32 #include "accum.h" 42 33 #include "types.h" 43 34 #include "context.h" 44 #include "macros.h" 35 #include "mem.h" 36 #include "state.h" 45 37 #include "masking.h" 46 38 #include "span.h" … … 72 64 73 65 74 #define USE_OPTIMIZED_ACCUM /* enable the optimization */ 75 76 77 78 void gl_alloc_accum_buffer( GLcontext *ctx ) 66 #define USE_OPTIMIZED_ACCUM /* enable the optimization */ 67 68 69 70 void 71 _mesa_alloc_accum_buffer( GLcontext *ctx ) 79 72 { 80 73 GLint n; 81 74 82 if (ctx-> Buffer->Accum) {83 FREE( ctx-> Buffer->Accum );84 ctx-> Buffer->Accum = NULL;75 if (ctx->DrawBuffer->Accum) { 76 FREE( ctx->DrawBuffer->Accum ); 77 ctx->DrawBuffer->Accum = NULL; 85 78 } 86 79 87 80 /* allocate accumulation buffer if not already present */ 88 n = ctx-> Buffer->Width * ctx->Buffer->Height * 4 * sizeof(GLaccum);89 ctx-> Buffer->Accum = (GLaccum *) MALLOC( n );90 if (!ctx-> Buffer->Accum) {81 n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height * 4 * sizeof(GLaccum); 82 ctx->DrawBuffer->Accum = (GLaccum *) MALLOC( n ); 83 if (!ctx->DrawBuffer->Accum) { 91 84 /* unable to setup accumulation buffer */ 92 85 gl_error( ctx, GL_OUT_OF_MEMORY, "glAccum" ); … … 102 95 103 96 104 void gl_ClearAccum( GLcontext *ctx,105 97 void 98 _mesa_ClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ) 106 99 { 100 GET_CURRENT_CONTEXT(ctx); 107 101 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glAccum"); 108 102 … … 122 116 static void rescale_accum( GLcontext *ctx ) 123 117 { 124 const GLuint n = ctx-> Buffer->Width * ctx->Buffer->Height * 4;118 const GLuint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height * 4; 125 119 const GLfloat fChanMax = (1 << (sizeof(GLchan) * 8)) - 1; 126 120 const GLfloat s = ctx->IntegerAccumScaler * (32767.0 / fChanMax); 127 GLaccum *accum = ctx-> Buffer->Accum;121 GLaccum *accum = ctx->DrawBuffer->Accum; 128 122 GLuint i; 129 123 130 assert(ctx->IntegerAccumMode);131 assert(accum);124 ASSERT(ctx->IntegerAccumMode); 125 ASSERT(accum); 132 126 133 127 for (i = 0; i < n; i++) { … … 140 134 141 135 142 void gl_Accum( GLcontext *ctx, GLenum op, GLfloat value ) 136 void 137 _mesa_Accum( GLenum op, GLfloat value ) 143 138 { 139 GET_CURRENT_CONTEXT(ctx); 144 140 GLuint xpos, ypos, width, height, width4; 145 141 GLfloat acc_scale; … … 150 146 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glAccum"); 151 147 152 if (ctx->Visual->AccumBits==0 || !ctx->Buffer->Accum) { 153 /* No accumulation buffer! */ 154 gl_warning(ctx, "Calling glAccum() without an accumulation buffer"); 148 if (ctx->Visual->AccumBits == 0 || ctx->DrawBuffer != ctx->ReadBuffer) { 149 gl_error(ctx, GL_INVALID_OPERATION, "glAccum"); 155 150 return; 156 151 } 157 152 158 switch(sizeof(GLaccum)) 159 { 160 case 1: 161 acc_scale=127.0; 162 break; 163 164 case 2: 165 acc_scale=32767.0; 166 break; 167 168 default: /* Cray*/ 169 acc_scale = (float) SHRT_MAX; 170 break; 171 } 172 /* 153 if (!ctx->DrawBuffer->Accum) { 154 gl_warning(ctx, "Calling glAccum() without an accumulation buffer (low memory?)"); 155 return; 156 } 157 173 158 if (sizeof(GLaccum)==1) { 174 159 acc_scale = 127.0; … … 178 163 } 179 164 else { 165 /* sizeof(GLaccum) > 2 (Cray) */ 180 166 acc_scale = (float) SHRT_MAX; 181 167 } 182 */ 168 183 169 if (ctx->NewState) 184 170 gl_update_state( ctx ); … … 195 181 xpos = 0; 196 182 ypos = 0; 197 width = ctx-> Buffer->Width;198 height = ctx-> Buffer->Height;183 width = ctx->DrawBuffer->Width; 184 height = ctx->DrawBuffer->Height; 199 185 } 200 186 … … 210 196 rescale_accum(ctx); 211 197 for (j = 0; j < height; j++) { 212 GLaccum * acc = ctx-> Buffer->Accum + ypos * width4 + 4 * xpos;198 GLaccum * acc = ctx->DrawBuffer->Accum + ypos * width4 + 4 * xpos; 213 199 GLuint i; 214 200 for (i = 0; i < width4; i++) { … … 227 213 rescale_accum(ctx); 228 214 for (j = 0; j < height; j++) { 229 GLaccum *acc = ctx-> Buffer->Accum + ypos * width4 + 4 * xpos;215 GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + 4 * xpos; 230 216 GLuint i; 231 217 for (i = 0; i < width4; i++) { … … 238 224 239 225 case GL_ACCUM: 240 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 226 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 227 ctx->Pixel.DriverReadBuffer ); 241 228 242 229 /* May have to leave optimized accum buffer mode */ … … 249 236 /* simply add integer color values into accum buffer */ 250 237 GLuint j; 251 GLaccum *acc = ctx-> Buffer->Accum + ypos * width4 + xpos * 4;252 assert(ctx->IntegerAccumScaler > 0.0);253 assert(ctx->IntegerAccumScaler <= 1.0);238 GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; 239 ASSERT(ctx->IntegerAccumScaler > 0.0); 240 ASSERT(ctx->IntegerAccumScaler <= 1.0); 254 241 for (j = 0; j < height; j++) { 255 242 256 243 GLuint i, i4; 257 gl_read_rgba_span(ctx, width, xpos, ypos, rgba);244 gl_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba); 258 245 for (i = i4 = 0; i < width; i++, i4+=4) { 259 246 acc[i4+0] += rgba[i][RCOMP]; … … 274 261 GLuint j; 275 262 for (j=0;j<height;j++) { 276 GLaccum *acc = ctx-> Buffer->Accum + ypos * width4 + xpos * 4;263 GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; 277 264 GLuint i; 278 gl_read_rgba_span(ctx, width, xpos, ypos, rgba);265 gl_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba); 279 266 for (i=0;i<width;i++) { 280 267 *acc += (GLaccum) ( (GLfloat) rgba[i][RCOMP] * rscale ); acc++; … … 286 273 } 287 274 } 288 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer ); 275 /* restore read buffer = draw buffer (the default) */ 276 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, 277 ctx->Color.DriverDrawBuffer ); 289 278 break; 290 279 291 280 case GL_LOAD: 292 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer ); 281 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, 282 ctx->Pixel.DriverReadBuffer ); 293 283 294 284 /* This is a change to go into optimized accum buffer mode */ … … 309 299 /* just copy values into accum buffer */ 310 300 GLuint j; 311 GLaccum *acc = ctx-> Buffer->Accum + ypos * width4 + xpos * 4;312 assert(ctx->IntegerAccumScaler > 0.0);313 assert(ctx->IntegerAccumScaler <= 1.0);301 GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; 302 ASSERT(ctx->IntegerAccumScaler > 0.0); 303 ASSERT(ctx->IntegerAccumScaler <= 1.0); 314 304 for (j = 0; j < height; j++) { 315 305 GLuint i, i4; 316 gl_read_rgba_span(ctx, width, xpos, ypos, rgba);306 gl_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba); 317 307 for (i = i4 = 0; i < width; i++, i4 += 4) { 318 308 acc[i4+0] = rgba[i][RCOMP]; … … 334 324 GLuint i, j; 335 325 for (j = 0; j < height; j++) { 336 GLaccum *acc = ctx-> Buffer->Accum + ypos * width4 + xpos * 4;337 gl_read_rgba_span(ctx, width, xpos, ypos, rgba);326 GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; 327 gl_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba); 338 328 for (i=0;i<width;i++) { 339 329 *acc++ = (GLaccum) ((GLfloat) rgba[i][RCOMP] * rscale + d); … … 345 335 } 346 336 } 347 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer ); 337 338 /* restore read buffer = draw buffer (the default) */ 339 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, 340 ctx->Color.DriverDrawBuffer ); 348 341 break; 349 342 … … 353 346 rescale_accum(ctx); 354 347 355 if (ctx->IntegerAccumMode ) {348 if (ctx->IntegerAccumMode && ctx->IntegerAccumScaler > 0) { 356 349 /* build lookup table to avoid many floating point multiplies */ 357 350 const GLfloat mult = ctx->IntegerAccumScaler; … … 361 354 const GLint max = (GLint) (256 / mult); 362 355 if (mult != prevMult) { 363 assert(max <= 32768);356 ASSERT(max <= 32768); 364 357 for (j = 0; j < max; j++) 365 358 multTable[j] = (GLint) ((GLfloat) j * mult + 0.5F); … … 367 360 } 368 361 369 assert(ctx->IntegerAccumScaler > 0.0);370 assert(ctx->IntegerAccumScaler <= 1.0);362 ASSERT(ctx->IntegerAccumScaler > 0.0); 363 ASSERT(ctx->IntegerAccumScaler <= 1.0); 371 364 for (j = 0; j < height; j++) { 372 const GLaccum *acc = ctx-> Buffer->Accum + ypos * width4 + xpos*4;365 const GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos*4; 373 366 GLuint i, i4; 374 367 for (i = i4 = 0; i < width; i++, i4 += 4) { … … 397 390 GLuint i, j; 398 391 for (j=0;j<height;j++) { 399 const GLaccum *acc = ctx-> Buffer->Accum + ypos * width4 + xpos*4;392 const GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos*4; 400 393 for (i=0;i<width;i++) { 401 394 GLint r, g, b, a; … … 429 422 * Clear the accumulation Buffer. 430 423 */ 431 void gl_clear_accum_buffer( GLcontext *ctx ) 424 void 425 _mesa_clear_accum_buffer( GLcontext *ctx ) 432 426 { 433 427 GLuint buffersize; … … 439 433 } 440 434 441 switch(sizeof(GLaccum))442 {443 case 1:444 acc_scale=127.0;445 break;446 447 case 2:448 acc_scale=32767.0;449 break;450 451 default: /* Cray*/452 acc_scale = (float) SHRT_MAX;453 break;454 }455 /*456 435 if (sizeof(GLaccum)==1) { 457 436 acc_scale = 127.0; … … 461 440 } 462 441 else { 442 /* sizeof(GLaccum) > 2 (Cray) */ 463 443 acc_scale = (float) SHRT_MAX; 464 444 } 465 */ 445 466 446 /* number of pixels */ 467 buffersize = ctx-> Buffer->Width * ctx->Buffer->Height;468 469 if (!ctx-> Buffer->Accum) {447 buffersize = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height; 448 449 if (!ctx->DrawBuffer->Accum) { 470 450 /* try to alloc accumulation buffer */ 471 ctx-> Buffer->Accum = (GLaccum *)451 ctx->DrawBuffer->Accum = (GLaccum *) 472 452 MALLOC( buffersize * 4 * sizeof(GLaccum) ); 473 453 } 474 454 475 if (ctx-> Buffer->Accum) {455 if (ctx->DrawBuffer->Accum) { 476 456 if (ctx->Scissor.Enabled) { 477 457 /* Limit clear to scissor box */ … … 485 465 a = (GLaccum) (ctx->Accum.ClearColor[3] * acc_scale); 486 466 /* size of region to clear */ 487 width = 4 * (ctx-> Buffer->Xmax - ctx->Buffer->Xmin + 1);488 height = ctx-> Buffer->Ymax - ctx->Buffer->Ymin + 1;467 width = 4 * (ctx->DrawBuffer->Xmax - ctx->DrawBuffer->Xmin + 1); 468 height = ctx->DrawBuffer->Ymax - ctx->DrawBuffer->Ymin + 1; 489 469 /* ptr to first element to clear */ 490 row = ctx-> Buffer->Accum491 + 4 * (ctx-> Buffer->Ymin * ctx->Buffer->Width492 + ctx-> Buffer->Xmin);470 row = ctx->DrawBuffer->Accum 471 + 4 * (ctx->DrawBuffer->Ymin * ctx->DrawBuffer->Width 472 + ctx->DrawBuffer->Xmin); 493 473 for (j=0;j<height;j++) { 494 474 for (i=0;i<width;i+=4) { … … 498 478 row[i+3] = a; 499 479 } 500 row += 4 * ctx-> Buffer->Width;480 row += 4 * ctx->DrawBuffer->Width; 501 481 } 502 482 } … … 508 488 ctx->Accum.ClearColor[3]==0.0) { 509 489 /* Black */ 510 MEMSET( ctx-> Buffer->Accum, 0, buffersize * 4 * sizeof(GLaccum) );490 MEMSET( ctx->DrawBuffer->Accum, 0, buffersize * 4 * sizeof(GLaccum) ); 511 491 } 512 492 else { … … 515 495 GLuint i; 516 496 517 acc = ctx-> Buffer->Accum;497 acc = ctx->DrawBuffer->Accum; 518 498 r = (GLaccum) (ctx->Accum.ClearColor[0] * acc_scale); 519 499 g = (GLaccum) (ctx->Accum.ClearColor[1] * acc_scale);
Note:
See TracChangeset
for help on using the changeset viewer.