⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s_accum.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Mesa 3-D graphics library * Version:  6.5.2 * * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */#include "glheader.h"#include "context.h"#include "macros.h"#include "imports.h"#include "fbobject.h"#include "s_accum.h"#include "s_context.h"#include "s_masking.h"#include "s_span.h"/* XXX this would have to change for accum buffers with more or less * than 16 bits per color channel. */#define ACCUM_SCALE16 32767.0/* * Accumulation buffer notes * * Normally, accumulation buffer values are GLshorts with values in * [-32767, 32767] which represent floating point colors in [-1, 1], * as defined by the OpenGL specification. * * We optimize for the common case used for full-scene antialiasing: *    // start with accum buffer cleared to zero *    glAccum(GL_LOAD, w);   // or GL_ACCUM the first image *    glAccum(GL_ACCUM, w); *    ... *    glAccum(GL_ACCUM, w); *    glAccum(GL_RETURN, 1.0); * That is, we start with an empty accumulation buffer and accumulate * n images, each with weight w = 1/n. * In this scenario, we can simply store unscaled integer values in * the accum buffer instead of scaled integers.  We'll also keep track * of the w value so when we do GL_RETURN we simply divide the accumulated * values by n (n=1/w). * This lets us avoid _many_ int->float->int conversions. */#if CHAN_BITS == 8/* enable the optimization */#define USE_OPTIMIZED_ACCUM  1#else#define USE_OPTIMIZED_ACCUM  0#endif/** * This is called when we fall out of optimized/unscaled accum buffer mode. * That is, we convert each unscaled accum buffer value into a scaled value * representing the range[-1, 1]. */static voidrescale_accum( GLcontext *ctx ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   struct gl_renderbuffer *rb      = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;   const GLfloat s = swrast->_IntegerAccumScaler * (32767.0F / CHAN_MAXF);   assert(rb);   assert(rb->_BaseFormat == GL_RGBA);   /* add other types in future? */   assert(rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT);   assert(swrast->_IntegerAccumMode);   if (rb->GetPointer(ctx, rb, 0, 0)) {      /* directly-addressable memory */      GLuint y;      for (y = 0; y < rb->Height; y++) {         GLuint i;         GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, 0, y);         for (i = 0; i < 4 * rb->Width; i++) {            acc[i] = (GLshort) (acc[i] * s);         }      }   }   else {      /* use get/put row funcs */      GLuint y;      for (y = 0; y < rb->Height; y++) {         GLshort accRow[MAX_WIDTH * 4];         GLuint i;         rb->GetRow(ctx, rb, rb->Width, 0, y, accRow);         for (i = 0; i < 4 * rb->Width; i++) {            accRow[i] = (GLshort) (accRow[i] * s);         }         rb->PutRow(ctx, rb, rb->Width, 0, y, accRow, NULL);      }   }   swrast->_IntegerAccumMode = GL_FALSE;}/** * Clear the accumulation Buffer. */void_swrast_clear_accum_buffer( GLcontext *ctx, struct gl_renderbuffer *rb ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   GLuint x, y, width, height;   if (ctx->Visual.accumRedBits == 0) {      /* No accumulation buffer! Not an error. */      return;   }   if (!rb || !rb->Data)      return;   assert(rb->_BaseFormat == GL_RGBA);   /* add other types in future? */   assert(rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT);   /* bounds, with scissor */   x = ctx->DrawBuffer->_Xmin;   y = ctx->DrawBuffer->_Ymin;   width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;   height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;   if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {      const GLfloat accScale = 32767.0;      GLshort clearVal[4];      GLuint i;      clearVal[0] = (GLshort) (ctx->Accum.ClearColor[0] * accScale);      clearVal[1] = (GLshort) (ctx->Accum.ClearColor[1] * accScale);      clearVal[2] = (GLshort) (ctx->Accum.ClearColor[2] * accScale);      clearVal[3] = (GLshort) (ctx->Accum.ClearColor[3] * accScale);      for (i = 0; i < height; i++) {         rb->PutMonoRow(ctx, rb, width, x, y + i, clearVal, NULL);      }   }   else {      /* someday support other sizes */   }   /* update optimized accum state vars */   if (ctx->Accum.ClearColor[0] == 0.0 && ctx->Accum.ClearColor[1] == 0.0 &&       ctx->Accum.ClearColor[2] == 0.0 && ctx->Accum.ClearColor[3] == 0.0) {#if USE_OPTIMIZED_ACCUM      swrast->_IntegerAccumMode = GL_TRUE;#else      swrast->_IntegerAccumMode = GL_FALSE;#endif      swrast->_IntegerAccumScaler = 0.0;  /* denotes empty accum buffer */   }   else {      swrast->_IntegerAccumMode = GL_FALSE;   }}static voidaccum_add(GLcontext *ctx, GLfloat value,          GLint xpos, GLint ypos, GLint width, GLint height ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   struct gl_renderbuffer *rb      = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;   assert(rb);   /* Leave optimized accum buffer mode */   if (swrast->_IntegerAccumMode)      rescale_accum(ctx);   if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {      const GLshort incr = (GLshort) (value * ACCUM_SCALE16);      if (rb->GetPointer(ctx, rb, 0, 0)) {         GLint i, j;         for (i = 0; i < height; i++) {            GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i);            for (j = 0; j < 4 * width; j++) {               acc[j] += incr;            }         }      }      else {         GLint i, j;         for (i = 0; i < height; i++) {            GLshort accRow[4 * MAX_WIDTH];            rb->GetRow(ctx, rb, width, xpos, ypos + i, accRow);            for (j = 0; j < 4 * width; j++) {               accRow[j] += incr;            }            rb->PutRow(ctx, rb, width, xpos, ypos + i, accRow, NULL);         }      }   }   else {      /* other types someday */   }}static voidaccum_mult(GLcontext *ctx, GLfloat mult,           GLint xpos, GLint ypos, GLint width, GLint height ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   struct gl_renderbuffer *rb      = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;   assert(rb);   /* Leave optimized accum buffer mode */   if (swrast->_IntegerAccumMode)      rescale_accum(ctx);   if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {      if (rb->GetPointer(ctx, rb, 0, 0)) {         GLint i, j;         for (i = 0; i < height; i++) {            GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i);            for (j = 0; j < 4 * width; j++) {               acc[j] = (GLshort) (acc[j] * mult);            }         }      }      else {         GLint i, j;         for (i = 0; i < height; i++) {            GLshort accRow[4 * MAX_WIDTH];            rb->GetRow(ctx, rb, width, xpos, ypos + i, accRow);            for (j = 0; j < 4 * width; j++) {               accRow[j] = (GLshort) (accRow[j] * mult);            }            rb->PutRow(ctx, rb, width, xpos, ypos + i, accRow, NULL);         }      }   }   else {      /* other types someday */   }}static voidaccum_accum(GLcontext *ctx, GLfloat value,            GLint xpos, GLint ypos, GLint width, GLint height ){   SWcontext *swrast = SWRAST_CONTEXT(ctx);   struct gl_renderbuffer *rb      = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer;   const GLboolean directAccess = (rb->GetPointer(ctx, rb, 0, 0) != NULL);   assert(rb);   if (!ctx->ReadBuffer->_ColorReadBuffer) {      /* no read buffer - OK */      return;   }   /* May have to leave optimized accum buffer mode */   if (swrast->_IntegerAccumScaler == 0.0 && value > 0.0 && value <= 1.0)      swrast->_IntegerAccumScaler = value;   if (swrast->_IntegerAccumMode && value != swrast->_IntegerAccumScaler)      rescale_accum(ctx);   if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) {      const GLfloat scale = value * ACCUM_SCALE16 / CHAN_MAXF;      GLshort accumRow[4 * MAX_WIDTH];      GLchan rgba[MAX_WIDTH][4];      GLint i;      for (i = 0; i < height; i++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -