acc2.c File Reference

Include dependency graph for acc2.c:

Go to the source code of this file.

Defines

#define UNCLAMPED_FLOAT_TO_SHORT(us, f)   us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )

Functions

static void acc_get_tile_rgba (struct pipe_context *pipe, struct pipe_surface *acc_ps, uint x, uint y, uint w, uint h, float *p)
 For hardware that supports deep color buffers, we could accelerate most/all the accum operations with blending/texturing.
static void acc_put_tile_rgba (struct pipe_context *pipe, struct pipe_surface *acc_ps, uint x, uint y, uint w, uint h, const float *p)
void st_clear_accum_buffer (GLcontext *ctx, struct gl_renderbuffer *rb)
static void accum_mad (struct pipe_context *pipe, GLfloat scale, GLfloat bias, GLint xpos, GLint ypos, GLint width, GLint height, struct pipe_surface *acc_ps)
 For ADD/MULT.
static void accum_accum (struct pipe_context *pipe, GLfloat value, GLint xpos, GLint ypos, GLint width, GLint height, struct pipe_surface *acc_ps, struct pipe_surface *color_ps)
static void accum_load (struct pipe_context *pipe, GLfloat value, GLint xpos, GLint ypos, GLint width, GLint height, struct pipe_surface *acc_ps, struct pipe_surface *color_ps)
static void accum_return (GLcontext *ctx, GLfloat value, GLint xpos, GLint ypos, GLint width, GLint height, struct pipe_surface *acc_ps, struct pipe_surface *color_ps)
static void st_Accum (GLcontext *ctx, GLenum op, GLfloat value)
void st_init_accum_functions (struct dd_function_table *functions)


Define Documentation

#define UNCLAMPED_FLOAT_TO_SHORT ( us,
 )     us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )

Definition at line 48 of file acc2.c.


Function Documentation

static void acc_get_tile_rgba ( struct pipe_context pipe,
struct pipe_surface acc_ps,
uint  x,
uint  y,
uint  w,
uint  h,
float *  p 
) [static]

For hardware that supports deep color buffers, we could accelerate most/all the accum operations with blending/texturing.

For now, just use the get/put_tile() functions and do things in software.

Definition at line 60 of file acc2.c.

References pipe_surface::format, PIPE_FORMAT_R16G16B16A16_SNORM, and pipe_get_tile_rgba().

00062 {
00063    const enum pipe_format f = acc_ps->format;
00064    const int cpp = acc_ps->cpp;
00065 
00066    acc_ps->format = PIPE_FORMAT_R16G16B16A16_SNORM;
00067    acc_ps->cpp = 8;
00068 
00069    pipe_get_tile_rgba(pipe, acc_ps, x, y, w, h, p);
00070 
00071    acc_ps->format = f;
00072    acc_ps->cpp = cpp;
00073 }

static void acc_put_tile_rgba ( struct pipe_context pipe,
struct pipe_surface acc_ps,
uint  x,
uint  y,
uint  w,
uint  h,
const float *  p 
) [static]

Definition at line 77 of file acc2.c.

References pipe_surface::format, PIPE_FORMAT_R16G16B16A16_SNORM, and pipe_put_tile_rgba().

00079 {
00080    enum pipe_format f = acc_ps->format;
00081    const int cpp = acc_ps->cpp;
00082 
00083    acc_ps->format = PIPE_FORMAT_R16G16B16A16_SNORM;
00084    acc_ps->cpp = 8;
00085 
00086    pipe_put_tile_rgba(pipe, acc_ps, x, y, w, h, p);
00087 
00088    acc_ps->format = f;
00089    acc_ps->cpp = cpp;
00090 }

static void accum_accum ( struct pipe_context pipe,
GLfloat  value,
GLint  xpos,
GLint  ypos,
GLint  width,
GLint  height,
struct pipe_surface acc_ps,
struct pipe_surface color_ps 
) [static]

Definition at line 178 of file acc2.c.

References acc_get_tile_rgba(), acc_put_tile_rgba(), and pipe_get_tile_rgba().

00183 {
00184    GLfloat *colorBuf, *accBuf;
00185    GLint i;
00186 
00187    colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
00188    accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
00189 
00190    pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf);
00191    acc_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf);
00192 
00193    for (i = 0; i < 4 * width * height; i++) {
00194       accBuf[i] = accBuf[i] + colorBuf[i] * value;
00195    }
00196 
00197    acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf);
00198 
00199    free(colorBuf);
00200    free(accBuf);

static void accum_load ( struct pipe_context pipe,
GLfloat  value,
GLint  xpos,
GLint  ypos,
GLint  width,
GLint  height,
struct pipe_surface acc_ps,
struct pipe_surface color_ps 
) [static]

Definition at line 204 of file acc2.c.

References acc_put_tile_rgba(), and pipe_get_tile_rgba().

00209 {
00210    GLfloat *buf;
00211    GLint i;
00212 
00213    buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
00214 
00215    pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf);
00216 
00217    for (i = 0; i < 4 * width * height; i++) {
00218       buf[i] = buf[i] * value;
00219    }
00220 
00221    acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, buf);
00222 
00223    free(buf);

static void accum_mad ( struct pipe_context pipe,
GLfloat  scale,
GLfloat  bias,
GLint  xpos,
GLint  ypos,
GLint  width,
GLint  height,
struct pipe_surface acc_ps 
) [static]

For ADD/MULT.

Definition at line 156 of file acc2.c.

References pipe_get_tile_rgba(), and pipe_put_tile_rgba().

00160 {
00161    GLfloat *accBuf;
00162    GLint i;
00163 
00164    accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
00165 
00166    pipe_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf);
00167 
00168    for (i = 0; i < 4 * width * height; i++) {
00169       accBuf[i] = accBuf[i] * scale + bias;
00170    }
00171 
00172    pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf);
00173 
00174    free(accBuf);

static void accum_return ( GLcontext *  ctx,
GLfloat  value,
GLint  xpos,
GLint  ypos,
GLint  width,
GLint  height,
struct pipe_surface acc_ps,
struct pipe_surface color_ps 
) [static]

Definition at line 227 of file acc2.c.

References acc_get_tile_rgba(), CLAMP, pipe_get_tile_rgba(), and pipe_put_tile_rgba().

00232 {
00233    struct pipe_context *pipe = ctx->st->pipe;
00234    const GLubyte *colormask = ctx->Color.ColorMask;
00235    GLfloat *abuf, *cbuf = NULL;
00236    GLint i, ch;
00237 
00238    abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
00239 
00240    acc_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf);
00241 
00242    if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) {
00243       cbuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
00244       pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, cbuf);
00245    }
00246 
00247    for (i = 0; i < width * height; i++) {
00248       for (ch = 0; ch < 4; ch++) {
00249          if (colormask[ch]) {
00250             GLfloat val = abuf[i * 4 + ch] * value;
00251             abuf[i * 4 + ch] = CLAMP(val, 0.0, 1.0);
00252          }
00253          else {
00254             abuf[i * 4 + ch] = cbuf[i * 4 + ch];
00255          }
00256       }
00257    }
00258 
00259    pipe_put_tile_rgba(pipe, color_ps, xpos, ypos, width, height, abuf);
00260 
00261    free(abuf);
00262    if (cbuf)
00263       free(cbuf);

static void st_Accum ( GLcontext *  ctx,
GLenum  op,
GLfloat  value 
) [static]

Definition at line 267 of file acc2.c.

References accum_accum(), accum_load(), accum_mad(), accum_return(), assert, pipe_context::flush, pipe_surface::height, st_context::pipe, PIPE_FLUSH_RENDER_CACHE, st_renderbuffer(), st_renderbuffer::surface, and pipe_surface::width.

00269 {
00270    struct st_context *st = ctx->st;
00271    struct pipe_context *pipe = st->pipe;
00272    struct st_renderbuffer *acc_strb
00273      = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
00274    struct st_renderbuffer *color_strb
00275       = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
00276    struct pipe_surface *acc_ps = acc_strb->surface;
00277    struct pipe_surface *color_ps = color_strb->surface;
00278 
00279    const GLint xpos = ctx->DrawBuffer->_Xmin;
00280    const GLint ypos = ctx->DrawBuffer->_Ymin;
00281    const GLint width = ctx->DrawBuffer->_Xmax - xpos;
00282    const GLint height = ctx->DrawBuffer->_Ymax - ypos;
00283 
00284    /* make sure color bufs aren't cached */
00285    pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
00286 
00287    switch (op) {
00288    case GL_ADD:
00289       if (value != 0.0F) {
00290          accum_mad(pipe, 1.0, value, xpos, ypos, width, height, acc_ps);
00291       }
00292       break;
00293    case GL_MULT:
00294       if (value != 1.0F) {
00295          accum_mad(pipe, value, 0.0, xpos, ypos, width, height, acc_ps);
00296       }
00297       break;
00298    case GL_ACCUM:
00299       if (value != 0.0F) {
00300          accum_accum(pipe, value, xpos, ypos, width, height, acc_ps, color_ps);
00301       }
00302       break;
00303    case GL_LOAD:
00304       accum_load(pipe, value, xpos, ypos, width, height, acc_ps, color_ps);
00305       break;
00306    case GL_RETURN:
00307       accum_return(ctx, value, xpos, ypos, width, height, acc_ps, color_ps);
00308       break;
00309    default:
00310       assert(0);
00311    }

void st_clear_accum_buffer ( GLcontext *  ctx,
struct gl_renderbuffer *  rb 
)

Definition at line 95 of file acc2.c.

00096 {
00097    struct pipe_context *pipe = ctx->st->pipe;
00098    struct st_renderbuffer *acc_strb = st_renderbuffer(rb);
00099    struct pipe_surface *acc_ps = acc_strb->surface;
00100    const GLint xpos = ctx->DrawBuffer->_Xmin;
00101    const GLint ypos = ctx->DrawBuffer->_Ymin;
00102    const GLint width = ctx->DrawBuffer->_Xmax - xpos;
00103    const GLint height = ctx->DrawBuffer->_Ymax - ypos;
00104    const GLfloat r = ctx->Accum.ClearColor[0];
00105    const GLfloat g = ctx->Accum.ClearColor[1];
00106    const GLfloat b = ctx->Accum.ClearColor[2];
00107    const GLfloat a = ctx->Accum.ClearColor[3];
00108    GLfloat *accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
00109    int i;
00110 
00111 #if 1
00112    GLvoid *map;
00113 
00114    map = pipe_surface_map(acc_ps);
00115    switch (acc_strb->format) {
00116    case PIPE_FORMAT_R16G16B16A16_SNORM:
00117       {
00118          GLshort r = FLOAT_TO_SHORT(ctx->Accum.ClearColor[0]);
00119          GLshort g = FLOAT_TO_SHORT(ctx->Accum.ClearColor[1]);
00120          GLshort b = FLOAT_TO_SHORT(ctx->Accum.ClearColor[2]);
00121          GLshort a = FLOAT_TO_SHORT(ctx->Accum.ClearColor[3]);
00122          int i, j;
00123          for (i = 0; i < height; i++) {
00124             GLshort *dst = ((GLshort *) map
00125                             + ((ypos + i) * acc_ps->pitch + xpos) * 4);
00126             for (j = 0; j < width; j++) {
00127                dst[0] = r;
00128                dst[1] = g;
00129                dst[2] = b;
00130                dst[3] = a;
00131                dst += 4;
00132             }
00133          }
00134       }
00135       break;
00136    default:
00137       _mesa_problem(ctx, "unexpected format in st_clear_accum_buffer()");
00138    }
00139 
00140    pipe_surface_unmap(acc_ps);
00141 
00142 #else
00143    for (i = 0; i < width * height; i++) {
00144       accBuf[i*4+0] = r;
00145       accBuf[i*4+1] = g;
00146       accBuf[i*4+2] = b;
00147       accBuf[i*4+3] = a;
00148    }
00149 
00150    acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf);
00151 #endif

void st_init_accum_functions ( struct dd_function_table *  functions  ) 

Definition at line 315 of file acc2.c.

00317 {
00318    functions->Accum = st_Accum;


Generated on Tue Sep 29 06:25:51 2009 for Gallium3D by  doxygen 1.5.4