Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

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:22 jeroen Exp $ */
     1/* $Id: accum.c,v 1.3 2000-05-23 20:40:20 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    2626
    2727
    28 /* $XFree86: xc/lib/GL/mesa/src/accum.c,v 1.3 1999/04/04 00:20:17 dawes Exp $ */
    29 
    3028#ifdef PC_HEADER
    3129#include "all.h"
    3230#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"
    4132#include "accum.h"
    4233#include "types.h"
    4334#include "context.h"
    44 #include "macros.h"
     35#include "mem.h"
     36#include "state.h"
    4537#include "masking.h"
    4638#include "span.h"
     
    7264
    7365
    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
     70void
     71_mesa_alloc_accum_buffer( GLcontext *ctx )
    7972{
    8073   GLint n;
    8174
    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;
    8578   }
    8679
    8780   /* 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) {
    9184      /* unable to setup accumulation buffer */
    9285      gl_error( ctx, GL_OUT_OF_MEMORY, "glAccum" );
     
    10295
    10396
    104 void gl_ClearAccum( GLcontext *ctx,
    105                     GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
     97void
     98_mesa_ClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
    10699{
     100   GET_CURRENT_CONTEXT(ctx);
    107101   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glAccum");
    108102
     
    122116static void rescale_accum( GLcontext *ctx )
    123117{
    124    const GLuint n = ctx->Buffer->Width * ctx->Buffer->Height * 4;
     118   const GLuint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height * 4;
    125119   const GLfloat fChanMax = (1 << (sizeof(GLchan) * 8)) - 1;
    126120   const GLfloat s = ctx->IntegerAccumScaler * (32767.0 / fChanMax);
    127    GLaccum *accum = ctx->Buffer->Accum;
     121   GLaccum *accum = ctx->DrawBuffer->Accum;
    128122   GLuint i;
    129123
    130    assert(ctx->IntegerAccumMode);
    131    assert(accum);
     124   ASSERT(ctx->IntegerAccumMode);
     125   ASSERT(accum);
    132126
    133127   for (i = 0; i < n; i++) {
     
    140134
    141135
    142 void gl_Accum( GLcontext *ctx, GLenum op, GLfloat value )
     136void
     137_mesa_Accum( GLenum op, GLfloat value )
    143138{
     139   GET_CURRENT_CONTEXT(ctx);
    144140   GLuint xpos, ypos, width, height, width4;
    145141   GLfloat acc_scale;
     
    150146   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glAccum");
    151147
    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");
    155150      return;
    156151   }
    157152
    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
    173158   if (sizeof(GLaccum)==1) {
    174159      acc_scale = 127.0;
     
    178163   }
    179164   else {
     165      /* sizeof(GLaccum) > 2 (Cray) */
    180166      acc_scale = (float) SHRT_MAX;
    181167   }
    182 */
     168
    183169   if (ctx->NewState)
    184170      gl_update_state( ctx );
     
    195181      xpos = 0;
    196182      ypos = 0;
    197       width = ctx->Buffer->Width;
    198       height = ctx->Buffer->Height;
     183      width = ctx->DrawBuffer->Width;
     184      height = ctx->DrawBuffer->Height;
    199185   }
    200186
     
    210196               rescale_accum(ctx);
    211197            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;
    213199               GLuint i;
    214200               for (i = 0; i < width4; i++) {
     
    227213               rescale_accum(ctx);
    228214            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;
    230216               GLuint i;
    231217               for (i = 0; i < width4; i++) {
     
    238224
    239225      case GL_ACCUM:
    240          (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );
     226         (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
     227                                       ctx->Pixel.DriverReadBuffer );
    241228
    242229         /* May have to leave optimized accum buffer mode */
     
    249236            /* simply add integer color values into accum buffer */
    250237            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);
    254241            for (j = 0; j < height; j++) {
    255242
    256243               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);
    258245               for (i = i4 = 0; i < width; i++, i4+=4) {
    259246                  acc[i4+0] += rgba[i][RCOMP];
     
    274261            GLuint j;
    275262            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;
    277264               GLuint i;
    278                gl_read_rgba_span(ctx, width, xpos, ypos, rgba);
     265               gl_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
    279266               for (i=0;i<width;i++) {
    280267                  *acc += (GLaccum) ( (GLfloat) rgba[i][RCOMP] * rscale );  acc++;
     
    286273            }
    287274         }
    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 );
    289278         break;
    290279
    291280      case GL_LOAD:
    292          (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );
     281         (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
     282                                       ctx->Pixel.DriverReadBuffer );
    293283
    294284         /* This is a change to go into optimized accum buffer mode */
     
    309299            /* just copy values into accum buffer */
    310300            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);
    314304            for (j = 0; j < height; j++) {
    315305               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);
    317307               for (i = i4 = 0; i < width; i++, i4 += 4) {
    318308                  acc[i4+0] = rgba[i][RCOMP];
     
    334324            GLuint i, j;
    335325            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);
    338328               for (i=0;i<width;i++) {
    339329                  *acc++ = (GLaccum) ((GLfloat) rgba[i][RCOMP] * rscale + d);
     
    345335            }
    346336         }
    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 );
    348341         break;
    349342
     
    353346            rescale_accum(ctx);
    354347
    355          if (ctx->IntegerAccumMode) {
     348         if (ctx->IntegerAccumMode && ctx->IntegerAccumScaler > 0) {
    356349            /* build lookup table to avoid many floating point multiplies */
    357350            const GLfloat mult = ctx->IntegerAccumScaler;
     
    361354            const GLint max = (GLint) (256 / mult);
    362355            if (mult != prevMult) {
    363                assert(max <= 32768);
     356               ASSERT(max <= 32768);
    364357               for (j = 0; j < max; j++)
    365358                  multTable[j] = (GLint) ((GLfloat) j * mult + 0.5F);
     
    367360            }
    368361
    369             assert(ctx->IntegerAccumScaler > 0.0);
    370             assert(ctx->IntegerAccumScaler <= 1.0);
     362            ASSERT(ctx->IntegerAccumScaler > 0.0);
     363            ASSERT(ctx->IntegerAccumScaler <= 1.0);
    371364            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;
    373366               GLuint i, i4;
    374367               for (i = i4 = 0; i < width; i++, i4 += 4) {
     
    397390            GLuint i, j;
    398391            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;
    400393               for (i=0;i<width;i++) {
    401394                  GLint r, g, b, a;
     
    429422 * Clear the accumulation Buffer.
    430423 */
    431 void gl_clear_accum_buffer( GLcontext *ctx )
     424void
     425_mesa_clear_accum_buffer( GLcontext *ctx )
    432426{
    433427   GLuint buffersize;
     
    439433   }
    440434
    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 /*
    456435   if (sizeof(GLaccum)==1) {
    457436      acc_scale = 127.0;
     
    461440   }
    462441   else {
     442      /* sizeof(GLaccum) > 2 (Cray) */
    463443      acc_scale = (float) SHRT_MAX;
    464444   }
    465 */
     445
    466446   /* 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) {
    470450      /* try to alloc accumulation buffer */
    471       ctx->Buffer->Accum = (GLaccum *)
     451      ctx->DrawBuffer->Accum = (GLaccum *)
    472452                           MALLOC( buffersize * 4 * sizeof(GLaccum) );
    473453   }
    474454
    475    if (ctx->Buffer->Accum) {
     455   if (ctx->DrawBuffer->Accum) {
    476456      if (ctx->Scissor.Enabled) {
    477457         /* Limit clear to scissor box */
     
    485465         a = (GLaccum) (ctx->Accum.ClearColor[3] * acc_scale);
    486466         /* 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;
    489469         /* ptr to first element to clear */
    490          row = ctx->Buffer->Accum
    491                + 4 * (ctx->Buffer->Ymin * ctx->Buffer->Width
    492                       + ctx->Buffer->Xmin);
     470         row = ctx->DrawBuffer->Accum
     471               + 4 * (ctx->DrawBuffer->Ymin * ctx->DrawBuffer->Width
     472                      + ctx->DrawBuffer->Xmin);
    493473         for (j=0;j<height;j++) {
    494474            for (i=0;i<width;i+=4) {
     
    498478               row[i+3] = a;
    499479            }
    500             row += 4 * ctx->Buffer->Width;
     480            row += 4 * ctx->DrawBuffer->Width;
    501481         }
    502482      }
     
    508488             ctx->Accum.ClearColor[3]==0.0) {
    509489            /* Black */
    510             MEMSET( ctx->Buffer->Accum, 0, buffersize * 4 * sizeof(GLaccum) );
     490            MEMSET( ctx->DrawBuffer->Accum, 0, buffersize * 4 * sizeof(GLaccum) );
    511491         }
    512492         else {
     
    515495            GLuint i;
    516496
    517             acc = ctx->Buffer->Accum;
     497            acc = ctx->DrawBuffer->Accum;
    518498            r = (GLaccum) (ctx->Accum.ClearColor[0] * acc_scale);
    519499            g = (GLaccum) (ctx->Accum.ClearColor[1] * acc_scale);
Note: See TracChangeset for help on using the changeset viewer.