From 15c4123c2b7f720e192bd4f1b0bc101bc14423ba Mon Sep 17 00:00:00 2001 From: Daniel J Sebald Date: Mon, 16 Mar 2015 02:41:37 -0500 Subject: [PATCH] swrast: correct pixel draw span endpoints computation, rid vertical lines Change the start/end indeces computation to use ceiling, not an int cast, of the encompassing rectangle. Solves problem of dropped pixels at GL_MAX_TEXTURE_SIZE/SWRAST_MAX_WIDTH intervals that created vertical lines when -1.0 < xfactor < 1.0. --- src/mesa/swrast/s_zoom.c | 61 ++++++++++++++++------------------------------ 1 files changed, 21 insertions(+), 40 deletions(-) diff --git a/src/mesa/swrast/s_zoom.c b/src/mesa/swrast/s_zoom.c index ab22652..60bec8e 100644 --- a/src/mesa/swrast/s_zoom.c +++ b/src/mesa/swrast/s_zoom.c @@ -38,7 +38,7 @@ * Compute the bounds of the region resulting from zooming a pixel span. * The resulting region will be entirely inside the window/scissor bounds * so no additional clipping is needed. - * \param imageX, imageY position of the mage being drawn (gl WindowPos) + * \param imageX, imageY position of the image being drawn (gl WindowPos) * \param spanX, spanY position of span being drawing * \param width number of pixels in span * \param x0, x1 returned X bounds of zoomed region [x0, x1) @@ -47,7 +47,7 @@ */ static GLboolean compute_zoomed_bounds(struct gl_context *ctx, GLint imageX, GLint imageY, - GLint spanX, GLint spanY, GLint width, + GLint spanX, GLint spanY, GLint spanWidth, GLint *x0, GLint *x1, GLint *y0, GLint *y1) { const struct gl_framebuffer *fb = ctx->DrawBuffer; @@ -58,35 +58,41 @@ compute_zoomed_bounds(struct gl_context *ctx, GLint imageX, GLint imageY, /* * Compute destination columns: [c0, c1) + * + * c0 - Pixels on left rectangle edge and greater are included + * c1 - Pixels on right rectangle edge and greater are excluded */ - c0 = imageX + (GLint) ((spanX - imageX) * ctx->Pixel.ZoomX); - c1 = imageX + (GLint) ((spanX + width - imageX) * ctx->Pixel.ZoomX); - if (c1 < c0) { - /* swap */ + c0 = imageX + (GLint) ceil((spanX - imageX) * ctx->Pixel.ZoomX); + c1 = imageX + (GLint) ceil((spanX + spanWidth - imageX) * ctx->Pixel.ZoomX); + if (ctx->Pixel.ZoomX < 0) { + /* swap edge roles */ GLint tmp = c1; c1 = c0; c0 = tmp; } c0 = CLAMP(c0, fb->_Xmin, fb->_Xmax); c1 = CLAMP(c1, fb->_Xmin, fb->_Xmax); - if (c0 == c1) { + if (c0 >= c1) { return GL_FALSE; /* no width */ } /* * Compute destination rows: [r0, r1) + * + * r0 - Pixels on bottom rectangle edge and greater are included + * r1 - Pixels on top rectangle edge and greater are excluded */ - r0 = imageY + (GLint) ((spanY - imageY) * ctx->Pixel.ZoomY); - r1 = imageY + (GLint) ((spanY + 1 - imageY) * ctx->Pixel.ZoomY); - if (r1 < r0) { - /* swap */ + r0 = imageY + (GLint) ceil((spanY - imageY) * ctx->Pixel.ZoomY); + r1 = imageY + (GLint) ceil((spanY + 1 - imageY) * ctx->Pixel.ZoomY); + if (ctx->Pixel.ZoomY < 0) { + /* swap edge roles */ GLint tmp = r1; r1 = r0; r0 = tmp; } r0 = CLAMP(r0, fb->_Ymin, fb->_Ymax); r1 = CLAMP(r1, fb->_Ymin, fb->_Ymax); - if (r0 == r1) { + if (r0 >= r1) { return GL_FALSE; /* no height */ } @@ -122,7 +128,6 @@ unzoom_x(GLfloat zoomX, GLint imageX, GLint zx) } - /** * Helper function called from _swrast_write_zoomed_rgba/rgb/ * index/depth_span(). @@ -213,8 +218,6 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span, GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; - assert(j >= 0); - assert(j < (GLint) span->end); COPY_4UBV(zoomed.array->rgba8[i], rgba[j]); } } @@ -223,8 +226,6 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span, GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; - assert(j >= 0); - assert(j < (GLint) span->end); COPY_4V(zoomed.array->rgba16[i], rgba[j]); } } @@ -233,8 +234,6 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span, GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; - assert(j >= 0); - assert(j < (GLint) span->end); COPY_4V(zoomed.array->attribs[VARYING_SLOT_COL0][i], rgba[j]); } } @@ -245,11 +244,7 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span, GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; - assert(j >= 0); - assert(j < (GLint) span->end); - zoomed.array->rgba8[i][0] = rgb[j][0]; - zoomed.array->rgba8[i][1] = rgb[j][1]; - zoomed.array->rgba8[i][2] = rgb[j][2]; + COPY_3V(zoomed.array->rgba8[i], rgb[j]); zoomed.array->rgba8[i][3] = 0xff; } } @@ -258,11 +253,7 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span, GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; - assert(j >= 0); - assert(j < (GLint) span->end); - zoomed.array->rgba16[i][0] = rgb[j][0]; - zoomed.array->rgba16[i][1] = rgb[j][1]; - zoomed.array->rgba16[i][2] = rgb[j][2]; + COPY_3V(zoomed.array->rgba16[i], rgb[j]); zoomed.array->rgba16[i][3] = 0xffff; } } @@ -271,11 +262,7 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span, GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; - assert(j >= 0); - assert(j < (GLint) span->end); - zoomed.array->attribs[VARYING_SLOT_COL0][i][0] = rgb[j][0]; - zoomed.array->attribs[VARYING_SLOT_COL0][i][1] = rgb[j][1]; - zoomed.array->attribs[VARYING_SLOT_COL0][i][2] = rgb[j][2]; + COPY_3V(zoomed.array->attribs[VARYING_SLOT_COL0][i], rgb[j]); zoomed.array->attribs[VARYING_SLOT_COL0][i][3] = 1.0F; } } @@ -285,8 +272,6 @@ zoom_span( struct gl_context *ctx, GLint imgX, GLint imgY, const SWspan *span, GLint i; for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x; - assert(j >= 0); - assert(j < (GLint) span->end); zoomed.array->z[i] = zValues[j]; } /* Now, fall into the RGB path below */ @@ -382,8 +367,6 @@ _swrast_write_zoomed_stencil_span(struct gl_context *ctx, GLint imgX, GLint imgY /* zoom the span horizontally */ for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - spanX; - assert(j >= 0); - assert(j < width); zoomedVals[i] = stencil[j]; } @@ -427,8 +410,6 @@ _swrast_write_zoomed_z_span(struct gl_context *ctx, GLint imgX, GLint imgY, /* zoom the span horizontally */ for (i = 0; i < zoomedWidth; i++) { GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - spanX; - assert(j >= 0); - assert(j < width); zoomedVals[i] = zVals[j]; } -- 1.7.4.4