summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2010-03-17 10:13:51 -0600
committerBrian Paul <brianp@vmware.com>2010-03-17 10:13:51 -0600
commitef92fe85de114cb50ca4b3070d0594aade54526c (patch)
treeeb99edb4a122f87090cd53efd6e94620128f4d85
parentbf1974b37d6b92448b068dda8f8f4e9aab4dc537 (diff)
parent1bfc314596256b039df59f751d59dac82e3ceba1 (diff)
Merge branch '7.8'
Conflicts: src/mesa/state_tracker/st_cb_drawpixels.c
-rw-r--r--src/mesa/main/image.h2
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c90
-rw-r--r--src/mesa/swrast/s_aatriangle.c82
3 files changed, 37 insertions, 137 deletions
diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h
index 72717d6787..9b34be0dfa 100644
--- a/src/mesa/main/image.h
+++ b/src/mesa/main/image.h
@@ -303,7 +303,7 @@ _mesa_clip_drawpixels(const GLcontext *ctx,
extern GLboolean
_mesa_clip_readpixels(const GLcontext *ctx,
- GLint *destX, GLint *destY,
+ GLint *srcX, GLint *srcY,
GLsizei *width, GLsizei *height,
struct gl_pixelstore_attrib *pack);
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 75be79fd4b..72a2ddb379 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -968,39 +968,13 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
GLfloat *color;
enum pipe_format srcFormat, texFormat;
GLboolean invertTex = GL_FALSE;
+ GLint readX, readY, readW, readH;
+ struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
st_validate_state(st);
- if (srcx < 0) {
- width -= -srcx;
- dstx += -srcx;
- srcx = 0;
- }
-
- if (srcy < 0) {
- height -= -srcy;
- dsty += -srcy;
- srcy = 0;
- }
-
- if (dstx < 0) {
- width -= -dstx;
- srcx += -dstx;
- dstx = 0;
- }
-
- if (dsty < 0) {
- height -= -dsty;
- srcy += -dsty;
- dsty = 0;
- }
-
- if (width < 0 || height < 0)
- return;
-
-
if (type == GL_STENCIL) {
/* can't use texturing to do stencil */
copy_stencil_pixels(ctx, srcx, srcy, width, height, dstx, dsty);
@@ -1033,7 +1007,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT,
PIPE_TEXTURE_2D,
PIPE_TEXTURE_USAGE_DEPTH_STENCIL);
- assert(texFormat != PIPE_FORMAT_NONE); /* XXX no depth texture formats??? */
+ assert(texFormat != PIPE_FORMAT_NONE);
}
else {
/* default color format */
@@ -1043,20 +1017,26 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
}
+ /* Invert src region if needed */
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
srcy = ctx->ReadBuffer->Height - srcy - height;
-
- if (srcy < 0) {
- height -= -srcy;
- srcy = 0;
- }
-
- if (height < 0)
- return;
-
invertTex = !invertTex;
}
+ /* Clip the read region against the src buffer bounds.
+ * We'll still allocate a temporary buffer/texture for the original
+ * src region size but we'll only read the region which is on-screen.
+ * This may mean that we draw garbage pixels into the dest region, but
+ * that's expected.
+ */
+ readX = srcx;
+ readY = srcy;
+ readW = width;
+ readH = height;
+ _mesa_clip_readpixels(ctx, &readX, &readY, &readW, &readH, &unpack);
+ readW = MAX2(0, readW);
+ readH = MAX2(0, readH);
+
/* alloc temporary texture */
pt = alloc_texture(st, width, height, texFormat);
if (!pt)
@@ -1069,7 +1049,6 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
/* Make temporary texture which is a copy of the src region.
- * We'll draw a quad with this texture to draw the dest image.
*/
if (srcFormat == texFormat) {
/* copy source framebuffer surface into mipmap/texture */
@@ -1080,16 +1059,16 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
PIPE_BUFFER_USAGE_GPU_WRITE );
if (pipe->surface_copy) {
pipe->surface_copy(pipe,
- psTex, /* dest */
- 0, 0, /* destx/y */
- psRead,
- srcx, srcy, width, height);
+ psTex, /* dest surf */
+ unpack.SkipPixels, unpack.SkipRows, /* dest pos */
+ psRead, /* src surf */
+ readX, readY, readW, readH); /* src region */
} else {
util_surface_copy(pipe, FALSE,
psTex,
- 0, 0,
+ unpack.SkipPixels, unpack.SkipRows,
psRead,
- srcx, srcy, width, height);
+ readX, readY, readW, readH);
}
if (0) {
@@ -1105,8 +1084,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
/* CPU-based fallback/conversion */
struct pipe_transfer *ptRead =
st_cond_flush_get_tex_transfer(st, rbRead->texture, 0, 0, 0,
- PIPE_TRANSFER_READ, srcx, srcy, width,
- height);
+ PIPE_TRANSFER_READ,
+ readX, readY, readW, readH);
struct pipe_transfer *ptTex;
enum pipe_transfer_usage transfer_usage;
@@ -1121,20 +1100,21 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
ptTex = st_cond_flush_get_tex_transfer(st, pt, 0, 0, 0, transfer_usage,
0, 0, width, height);
+ /* copy image from ptRead surface to ptTex surface */
if (type == GL_COLOR) {
/* alternate path using get/put_tile() */
GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
-
- pipe_get_tile_rgba(pipe, ptRead, 0, 0, width, height, buf);
- pipe_put_tile_rgba(pipe, ptTex, 0, 0, width, height, buf);
-
+ pipe_get_tile_rgba(pipe, ptRead, readX, readY, readW, readH, buf);
+ pipe_put_tile_rgba(pipe, ptTex, unpack.SkipPixels, unpack.SkipRows,
+ readW, readH, buf);
free(buf);
}
else {
/* GL_DEPTH */
GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint));
- pipe_get_tile_z(pipe, ptRead, 0, 0, width, height, buf);
- pipe_put_tile_z(pipe, ptTex, 0, 0, width, height, buf);
+ pipe_get_tile_z(pipe, ptRead, readX, readY, readW, readH, buf);
+ pipe_put_tile_z(pipe, ptTex, unpack.SkipPixels, unpack.SkipRows,
+ readW, readH, buf);
free(buf);
}
@@ -1142,7 +1122,9 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
pipe->tex_transfer_destroy(pipe, ptTex);
}
- /* draw textured quad */
+ /* OK, the texture 'pt' contains the src image/pixels. Now draw a
+ * textured quad with that texture.
+ */
draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
sv,
diff --git a/src/mesa/swrast/s_aatriangle.c b/src/mesa/swrast/s_aatriangle.c
index fe3338ecef..1d90f322a3 100644
--- a/src/mesa/swrast/s_aatriangle.c
+++ b/src/mesa/swrast/s_aatriangle.c
@@ -268,88 +268,6 @@ compute_coveragef(const GLfloat v0[3], const GLfloat v1[3],
-/*
- * Compute how much (area) of the given pixel is inside the triangle.
- * Vertices MUST be specified in counter-clockwise order.
- * Return: coverage in [0, 15].
- */
-static GLint
-compute_coveragei(const GLfloat v0[3], const GLfloat v1[3],
- const GLfloat v2[3], GLint winx, GLint winy)
-{
- /* NOTE: 15 samples instead of 16. */
- static const GLfloat samples[15][2] = {
- /* start with the four corners */
- { POS(0, 2), POS(0, 0) },
- { POS(3, 3), POS(0, 2) },
- { POS(0, 0), POS(3, 1) },
- { POS(3, 1), POS(3, 3) },
- /* continue with interior samples */
- { POS(1, 1), POS(0, 1) },
- { POS(2, 0), POS(0, 3) },
- { POS(0, 3), POS(1, 3) },
- { POS(1, 2), POS(1, 0) },
- { POS(2, 3), POS(1, 2) },
- { POS(3, 2), POS(1, 1) },
- { POS(0, 1), POS(2, 2) },
- { POS(1, 0), POS(2, 1) },
- { POS(2, 1), POS(2, 3) },
- { POS(3, 0), POS(2, 0) },
- { POS(1, 3), POS(3, 0) }
- };
- const GLfloat x = (GLfloat) winx;
- const GLfloat y = (GLfloat) winy;
- const GLfloat dx0 = v1[0] - v0[0];
- const GLfloat dy0 = v1[1] - v0[1];
- const GLfloat dx1 = v2[0] - v1[0];
- const GLfloat dy1 = v2[1] - v1[1];
- const GLfloat dx2 = v0[0] - v2[0];
- const GLfloat dy2 = v0[1] - v2[1];
- GLint stop = 4, i;
- GLint insideCount = 15;
-
-#ifdef DEBUG
- {
- const GLfloat area = dx0 * dy1 - dx1 * dy0;
- ASSERT(area >= 0.0);
- }
-#endif
-
- for (i = 0; i < stop; i++) {
- const GLfloat sx = x + samples[i][0];
- const GLfloat sy = y + samples[i][1];
- const GLfloat fx0 = sx - v0[0];
- const GLfloat fy0 = sy - v0[1];
- const GLfloat fx1 = sx - v1[0];
- const GLfloat fy1 = sy - v1[1];
- const GLfloat fx2 = sx - v2[0];
- const GLfloat fy2 = sy - v2[1];
- /* cross product determines if sample is inside or outside each edge */
- GLfloat cross0 = (dx0 * fy0 - dy0 * fx0);
- GLfloat cross1 = (dx1 * fy1 - dy1 * fx1);
- GLfloat cross2 = (dx2 * fy2 - dy2 * fx2);
- /* Check if the sample is exactly on an edge. If so, let cross be a
- * positive or negative value depending on the direction of the edge.
- */
- if (cross0 == 0.0F)
- cross0 = dx0 + dy0;
- if (cross1 == 0.0F)
- cross1 = dx1 + dy1;
- if (cross2 == 0.0F)
- cross2 = dx2 + dy2;
- if (cross0 < 0.0F || cross1 < 0.0F || cross2 < 0.0F) {
- /* point is outside triangle */
- insideCount--;
- stop = 15;
- }
- }
- if (stop == 4)
- return 15;
- else
- return insideCount;
-}
-
-
static void
rgba_aa_tri(GLcontext *ctx,
const SWvertex *v0,