summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-10-14 12:34:55 -0600
committerBrian <[email protected]>2007-10-14 12:34:55 -0600
commite7af94416240f79ac609ff096690a1929664944e (patch)
tree53590e602a6f85472bc579f3ee518e785fc202f4 /src
parenta7611dce40e532f6c768ed7011725fcfb6424883 (diff)
implement accum ops
Diffstat (limited to 'src')
-rw-r--r--src/mesa/state_tracker/st_cb_accum.c170
1 files changed, 162 insertions, 8 deletions
diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c
index c8fef6c1355..03c65db70ba 100644
--- a/src/mesa/state_tracker/st_cb_accum.c
+++ b/src/mesa/state_tracker/st_cb_accum.c
@@ -35,21 +35,175 @@
#include "main/macros.h"
#include "st_context.h"
-#include "st_atom.h"
#include "st_cache.h"
-#include "st_draw.h"
-#include "st_program.h"
#include "st_cb_accum.h"
+#include "st_cb_fbo.h"
#include "st_draw.h"
#include "st_format.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
+/**
+ * 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.
+ */
+
+
+/** For ADD/MULT */
+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)
+{
+ GLfloat *accBuf;
+ GLint i;
+
+ accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+
+ (void) pipe->region_map(pipe, acc_ps->region);
+
+ acc_ps->get_tile(acc_ps, xpos, ypos, width, height, accBuf);
+
+ for (i = 0; i < 4 * width * height; i++) {
+ GLfloat val = accBuf[i] * scale + bias;
+ accBuf[i] = CLAMP(val, 0.0, 1.0);
+ }
+
+ acc_ps->put_tile(acc_ps, xpos, ypos, width, height, accBuf);
+
+ _mesa_free(accBuf);
+
+ pipe->region_unmap(pipe, acc_ps->region);
+}
+
+
+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)
+{
+ ubyte *colorMap, *accMap;
+ GLfloat *colorBuf, *accBuf;
+ GLint i;
+
+ colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+ accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+
+ colorMap = pipe->region_map(pipe, color_ps->region);
+ accMap = pipe->region_map(pipe, acc_ps->region);
+
+ color_ps->get_tile(color_ps, xpos, ypos, width, height, colorBuf);
+ acc_ps->get_tile(acc_ps, xpos, ypos, width, height, accBuf);
+
+ for (i = 0; i < 4 * width * height; i++) {
+ GLfloat val = accBuf[i] + colorBuf[i] * value;
+ accBuf[i] = CLAMP(val, 0.0, 1.0);
+ }
+
+ acc_ps->put_tile(acc_ps, xpos, ypos, width, height, accBuf);
+
+ _mesa_free(colorBuf);
+ _mesa_free(accBuf);
+
+ pipe->region_unmap(pipe, color_ps->region);
+ pipe->region_unmap(pipe, acc_ps->region);
+}
+
+
+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)
+{
+ GLfloat *buf;
+ GLint i;
+
+ buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+
+ (void) pipe->region_map(pipe, color_ps->region);
+ (void) pipe->region_map(pipe, acc_ps->region);
+
+ color_ps->get_tile(color_ps, xpos, ypos, width, height, buf);
+
+ for (i = 0; i < 4 * width * height; i++) {
+ GLfloat val = buf[i] * value;
+ buf[i] = CLAMP(val, 0.0, 1.0);
+ }
+
+ acc_ps->put_tile(acc_ps, xpos, ypos, width, height, buf);
+
+ _mesa_free(buf);
+
+ pipe->region_unmap(pipe, color_ps->region);
+ pipe->region_unmap(pipe, acc_ps->region);
+}
+
+
+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)
+{
+ struct pipe_context *pipe = ctx->st->pipe;
+ const GLboolean writeR = ctx->Color.ColorMask[0];
+ const GLboolean writeG = ctx->Color.ColorMask[1];
+ const GLboolean writeB = ctx->Color.ColorMask[2];
+ const GLboolean writeA = ctx->Color.ColorMask[3];
+ GLfloat *buf;
+ GLint i;
+
+ buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+
+ (void) pipe->region_map(pipe, color_ps->region);
+ (void) pipe->region_map(pipe, acc_ps->region);
+
+ acc_ps->get_tile(acc_ps, xpos, ypos, width, height, buf);
+
+ for (i = 0; i < width * height; i++) {
+ if (writeR) {
+ GLfloat r = buf[i * 4 + 0] * value;
+ buf[i * 4 + 0] = CLAMP(r, 0.0, 1.0);
+ }
+ if (writeG) {
+ GLfloat g = buf[i * 4 + 1] * value;
+ buf[i * 4 + 1] = CLAMP(g, 0.0, 1.0);
+ }
+ if (writeB) {
+ GLfloat b = buf[i * 4 + 2] * value;
+ buf[i * 4 + 2] = CLAMP(b, 0.0, 1.0);
+ }
+ if (writeA) {
+ GLfloat a = buf[i * 4 + 3] * value;
+ buf[i * 4 + 3] = CLAMP(a, 0.0, 1.0);
+ }
+ }
+
+ color_ps->put_tile(color_ps, xpos, ypos, width, height, buf);
+
+ _mesa_free(buf);
+
+ pipe->region_unmap(pipe, color_ps->region);
+ pipe->region_unmap(pipe, acc_ps->region);
+}
+
static void
st_Accum(GLcontext *ctx, GLenum op, GLfloat value)
{
+ struct st_context *st = ctx->st;
+ struct pipe_context *pipe = st->pipe;
+ struct st_renderbuffer *acc_strb
+ = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
+ struct st_renderbuffer *color_strb
+ = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
+ struct pipe_surface *acc_ps = acc_strb->surface;
+ struct pipe_surface *color_ps = color_strb->surface;
+
const GLint xpos = ctx->DrawBuffer->_Xmin;
const GLint ypos = ctx->DrawBuffer->_Ymin;
const GLint width = ctx->DrawBuffer->_Xmax - xpos;
@@ -58,24 +212,24 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value)
switch (op) {
case GL_ADD:
if (value != 0.0F) {
- accum_add(ctx, value, xpos, ypos, width, height);
+ accum_mad(pipe, 1.0, value, xpos, ypos, width, height, acc_ps);
}
break;
case GL_MULT:
if (value != 1.0F) {
- accum_mult(ctx, value, xpos, ypos, width, height);
+ accum_mad(pipe, value, 0.0, xpos, ypos, width, height, acc_ps);
}
break;
case GL_ACCUM:
if (value != 0.0F) {
- accum_accum(ctx, value, xpos, ypos, width, height);
+ accum_accum(pipe, value, xpos, ypos, width, height, acc_ps, color_ps);
}
break;
case GL_LOAD:
- accum_load(ctx, value, xpos, ypos, width, height);
+ accum_load(pipe, value, xpos, ypos, width, height, acc_ps, color_ps);
break;
case GL_RETURN:
- accum_return(ctx, value, xpos, ypos, width, height);
+ accum_return(ctx, value, xpos, ypos, width, height, acc_ps, color_ps);
break;
default:
assert(0);