#include "st_format.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "pipe/util/p_tile.h"
+
+
+#define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
+ us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
/**
*/
+void
+st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
+{
+ struct pipe_context *pipe = ctx->st->pipe;
+ struct st_renderbuffer *acc_strb = st_renderbuffer(rb);
+ struct pipe_surface *acc_ps = acc_strb->surface;
+ const GLint xpos = ctx->DrawBuffer->_Xmin;
+ const GLint ypos = ctx->DrawBuffer->_Ymin;
+ const GLint width = ctx->DrawBuffer->_Xmax - xpos;
+ const GLint height = ctx->DrawBuffer->_Ymax - ypos;
+ const GLfloat r = ctx->Accum.ClearColor[0];
+ const GLfloat g = ctx->Accum.ClearColor[1];
+ const GLfloat b = ctx->Accum.ClearColor[2];
+ const GLfloat a = ctx->Accum.ClearColor[3];
+ GLfloat *accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+ int i;
+
+ for (i = 0; i < width * height; i++) {
+ accBuf[i*4+0] = r;
+ accBuf[i*4+1] = g;
+ accBuf[i*4+2] = b;
+ accBuf[i*4+3] = a;
+ }
+
+ pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf);
+}
+
+
/** For ADD/MULT */
static void
accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias,
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);
+ pipe_get_tile_rgba(pipe, 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);
+ accBuf[i] = accBuf[i] * scale + bias;
}
- acc_ps->put_tile(acc_ps, xpos, ypos, width, height, accBuf);
-
- _mesa_free(accBuf);
+ pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf);
- pipe->region_unmap(pipe, acc_ps->region);
+ free(accBuf);
}
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);
+ pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf);
+ pipe_get_tile_rgba(pipe, 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);
+ accBuf[i] = accBuf[i] + colorBuf[i] * value;
}
- acc_ps->put_tile(acc_ps, xpos, ypos, width, height, accBuf);
-
- _mesa_free(colorBuf);
- _mesa_free(accBuf);
+ pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf);
- pipe->region_unmap(pipe, color_ps->region);
- pipe->region_unmap(pipe, acc_ps->region);
+ free(colorBuf);
+ free(accBuf);
}
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);
+ pipe_get_tile_rgba(pipe, 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);
+ buf[i] = buf[i] * value;
}
- acc_ps->put_tile(acc_ps, xpos, ypos, width, height, buf);
-
- _mesa_free(buf);
+ pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, buf);
- pipe->region_unmap(pipe, color_ps->region);
- pipe->region_unmap(pipe, acc_ps->region);
+ free(buf);
}
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;
+ const GLubyte *colormask = ctx->Color.ColorMask;
+ GLfloat *abuf, *cbuf = NULL;
+ GLint i, ch;
- buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+ abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
- (void) pipe->region_map(pipe, color_ps->region);
- (void) pipe->region_map(pipe, acc_ps->region);
+ pipe_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf);
- acc_ps->get_tile(acc_ps, xpos, ypos, width, height, buf);
+ if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) {
+ cbuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+ pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, cbuf);
+ }
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);
+ for (ch = 0; ch < 4; ch++) {
+ if (colormask[ch]) {
+ GLfloat val = abuf[i * 4 + ch] * value;
+ abuf[i * 4 + ch] = CLAMP(val, 0.0, 1.0);
+ }
+ else {
+ abuf[i * 4 + ch] = cbuf[i * 4 + ch];
+ }
}
}
- color_ps->put_tile(color_ps, xpos, ypos, width, height, buf);
-
- _mesa_free(buf);
+ pipe_put_tile_rgba(pipe, color_ps, xpos, ypos, width, height, abuf);
- pipe->region_unmap(pipe, color_ps->region);
- pipe->region_unmap(pipe, acc_ps->region);
+ free(abuf);
+ if (cbuf)
+ free(cbuf);
}
const GLint width = ctx->DrawBuffer->_Xmax - xpos;
const GLint height = ctx->DrawBuffer->_Ymax - ypos;
+ /* make sure color bufs aren't cached */
+ pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE);
+
switch (op) {
case GL_ADD:
if (value != 0.0F) {