From a4af3e5ab3fa0f45c25673c93d802cdff087145c Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 20 Jun 2007 11:01:04 -0600 Subject: Effectively disable _TexEnvProgram before calling _swrast_DrawPixels(). It's OK to use _TexEnvProgram regardless of the texture state, but if fog is also enabled, the fragment program is lacking the actual fog computation so fogging doesn't appear. Fixing this might involve a new _MaintainFogProgram field and related code. For now, just disable the _TexEnvProgram and let swrast handle everything. --- src/mesa/drivers/dri/i915/intel_pixel.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/mesa/drivers/dri/i915') diff --git a/src/mesa/drivers/dri/i915/intel_pixel.c b/src/mesa/drivers/dri/i915/intel_pixel.c index 535cbfcb26..a52a81bf13 100644 --- a/src/mesa/drivers/dri/i915/intel_pixel.c +++ b/src/mesa/drivers/dri/i915/intel_pixel.c @@ -440,9 +440,21 @@ intelDrawPixels( GLcontext *ctx, fprintf(stderr, "%s\n", __FUNCTION__); if (!intelTryDrawPixels( ctx, x, y, width, height, format, type, - unpack, pixels )) - _swrast_DrawPixels( ctx, x, y, width, height, format, type, - unpack, pixels ); + unpack, pixels )) { + if (ctx->FragmentProgram._Current == + ctx->FragmentProgram._TexEnvProgram) { + /* don't want the i915 texenv program to be applied to DrawPixels */ + struct gl_fragment_program *fpSave = ctx->FragmentProgram._Current; + ctx->FragmentProgram._Current = NULL; + _swrast_DrawPixels( ctx, x, y, width, height, format, type, + unpack, pixels ); + ctx->FragmentProgram._Current = fpSave; + } + else { + _swrast_DrawPixels( ctx, x, y, width, height, format, type, + unpack, pixels ); + } + } } -- cgit v1.2.3 From 171dcdfa27dda30916a7f9bfed89577feee5d350 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 21 Jun 2007 09:15:32 -0600 Subject: Another round of fixing attribute interpolation for glDraw/CopyPixels. Need to turn off FRAG_BIT_COL0 in swrast->_ActiveAttribMask when doing glRead/CopyPixels to prevent the user's colors from getting overwritten when a fragment program is active. This was happening in the DRI drivers when MaintainTexEnv program was used (the texenv fragment program was enabled when _swrast_DrawPixels was called). This still isn't an ideal solution, but fixes things for now. --- src/mesa/drivers/dri/i915/intel_pixel.c | 34 ++++++++++++++----------- src/mesa/drivers/dri/i915tex/intel_pixel_draw.c | 9 ++++--- src/mesa/swrast/s_copypix.c | 14 +++++++--- src/mesa/swrast/s_drawpix.c | 17 ++++++++++--- src/mesa/swrast/s_span.c | 16 ++++++------ 5 files changed, 57 insertions(+), 33 deletions(-) (limited to 'src/mesa/drivers/dri/i915') diff --git a/src/mesa/drivers/dri/i915/intel_pixel.c b/src/mesa/drivers/dri/i915/intel_pixel.c index a52a81bf13..d175870a0c 100644 --- a/src/mesa/drivers/dri/i915/intel_pixel.c +++ b/src/mesa/drivers/dri/i915/intel_pixel.c @@ -439,21 +439,25 @@ intelDrawPixels( GLcontext *ctx, if (INTEL_DEBUG & DEBUG_PIXEL) fprintf(stderr, "%s\n", __FUNCTION__); - if (!intelTryDrawPixels( ctx, x, y, width, height, format, type, - unpack, pixels )) { - if (ctx->FragmentProgram._Current == - ctx->FragmentProgram._TexEnvProgram) { - /* don't want the i915 texenv program to be applied to DrawPixels */ - struct gl_fragment_program *fpSave = ctx->FragmentProgram._Current; - ctx->FragmentProgram._Current = NULL; - _swrast_DrawPixels( ctx, x, y, width, height, format, type, - unpack, pixels ); - ctx->FragmentProgram._Current = fpSave; - } - else { - _swrast_DrawPixels( ctx, x, y, width, height, format, type, - unpack, pixels ); - } + if (intelTryDrawPixels( ctx, x, y, width, height, format, type, + unpack, pixels )) + return; + + if (ctx->FragmentProgram._Current == ctx->FragmentProgram._TexEnvProgram) { + /* + * We don't want the i915 texenv program to be applied to DrawPixels. + * This is really just a performance optimization (mesa will other- + * wise happily run the fragment program on each pixel in the image). + */ + struct gl_fragment_program *fpSave = ctx->FragmentProgram._Current; + ctx->FragmentProgram._Current = NULL; + _swrast_DrawPixels( ctx, x, y, width, height, format, type, + unpack, pixels ); + ctx->FragmentProgram._Current = fpSave; + } + else { + _swrast_DrawPixels( ctx, x, y, width, height, format, type, + unpack, pixels ); } } diff --git a/src/mesa/drivers/dri/i915tex/intel_pixel_draw.c b/src/mesa/drivers/dri/i915tex/intel_pixel_draw.c index 46480da1b1..77c67c821e 100644 --- a/src/mesa/drivers/dri/i915tex/intel_pixel_draw.c +++ b/src/mesa/drivers/dri/i915tex/intel_pixel_draw.c @@ -363,9 +363,12 @@ intelDrawPixels(GLcontext * ctx, if (INTEL_DEBUG & DEBUG_PIXEL) _mesa_printf("%s: fallback to swrast\n", __FUNCTION__); - if (ctx->FragmentProgram._Current == - ctx->FragmentProgram._TexEnvProgram) { - /* don't want the i915 texenv program to be applied to DrawPixels */ + if (ctx->FragmentProgram._Current == ctx->FragmentProgram._TexEnvProgram) { + /* + * We don't want the i915 texenv program to be applied to DrawPixels. + * This is really just a performance optimization (mesa will other- + * wise happily run the fragment program on each pixel in the image). + */ struct gl_fragment_program *fpSave = ctx->FragmentProgram._Current; ctx->FragmentProgram._Current = NULL; _swrast_DrawPixels( ctx, x, y, width, height, format, type, diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c index 53e584b3b6..2383015000 100644 --- a/src/mesa/swrast/s_copypix.c +++ b/src/mesa/swrast/s_copypix.c @@ -188,6 +188,8 @@ static void copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GLint width, GLint height, GLint destx, GLint desty) { + SWcontext *swrast = SWRAST_CONTEXT(ctx); + const GLbitfield prevActiveAttribs = swrast->_ActiveAttribMask; GLfloat *tmpImage, *p; GLint sy, dy, stepy, row; const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F; @@ -197,12 +199,15 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, if (!ctx->ReadBuffer->_ColorReadBuffer) { /* no readbuffer - OK */ - return; + goto end; } + /* don't interpolate COL0 and overwrite the glDrawPixel colors! */ + swrast->_ActiveAttribMask &= ~FRAG_BIT_COL0; + if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) { copy_conv_rgba_pixels(ctx, srcx, srcy, width, height, destx, desty); - return; + goto end; } else if (ctx->Pixel.Convolution1DEnabled) { /* make sure we don't apply 1D convolution */ @@ -239,7 +244,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, tmpImage = (GLfloat *) _mesa_malloc(width * height * sizeof(GLfloat) * 4); if (!tmpImage) { _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" ); - return; + goto end; } /* read the source image as RGBA/float */ p = tmpImage; @@ -294,6 +299,9 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, if (overlapping) _mesa_free(tmpImage); + +end: + swrast->_ActiveAttribMask = prevActiveAttribs; } diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index d971d90fb9..925358d77e 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -532,16 +532,22 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels ) { + SWcontext *swrast = SWRAST_CONTEXT(ctx); + const GLbitfield prevActiveAttribs = swrast->_ActiveAttribMask; const GLint imgX = x, imgY = y; const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0; GLfloat *convImage = NULL; GLbitfield transferOps = ctx->_ImageTransferState; SWspan span; + /* don't interpolate COL0 and overwrite the glDrawPixel colors! */ + swrast->_ActiveAttribMask &= ~FRAG_BIT_COL0; + /* Try an optimized glDrawPixels first */ if (fast_draw_rgba_pixels(ctx, x, y, width, height, format, type, - unpack, pixels)) - return; + unpack, pixels)) { + goto end; + } INIT_SPAN(span, GL_BITMAP, 0, 0x0, SPAN_RGBA); _swrast_span_default_attribs(ctx, &span); @@ -559,13 +565,13 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, tmpImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); if (!tmpImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels"); - return; + goto end; } convImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); if (!convImage) { _mesa_free(tmpImage); _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels"); - return; + goto end; } /* Unpack the image and apply transfer ops up to convolution */ @@ -669,6 +675,9 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, if (convImage) { _mesa_free(convImage); } + +end: + swrast->_ActiveAttribMask = prevActiveAttribs; } diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index 3aaa3395e4..431629efb1 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -171,6 +171,11 @@ interpolate_active_attribs(GLcontext *ctx, SWspan *span, GLbitfield attrMask) { const SWcontext *swrast = SWRAST_CONTEXT(ctx); + /* for glDraw/CopyPixels() we may have turned off some bits in + * the _ActiveAttribMask - be sure to obey that mask now. + */ + attrMask &= swrast->_ActiveAttribMask; + ATTRIB_LOOP_BEGIN if (attrMask & (1 << attr)) { const GLfloat dwdx = span->attrStepX[FRAG_ATTRIB_WPOS][3]; @@ -1169,15 +1174,10 @@ shade_texture_span(GLcontext *ctx, SWspan *span) if (ctx->FragmentProgram._Current || ctx->ATIFragmentShader._Enabled) { /* programmable shading */ - if (span->primitive == GL_BITMAP) { - if (span->array->ChanType != GL_FLOAT) - convert_color_type(span, GL_FLOAT, 0); - interpolate_active_attribs(ctx, span, ~FRAG_ATTRIB_COL0); - } - else { - /* point, line, triangle */ - interpolate_active_attribs(ctx, span, ~0); + if (span->primitive == GL_BITMAP && span->array->ChanType != GL_FLOAT) { + convert_color_type(span, GL_FLOAT, 0); } + interpolate_active_attribs(ctx, span, ~0); span->array->ChanType = GL_FLOAT; if (!(span->arrayMask & SPAN_Z)) -- cgit v1.2.3 From 0bf2479aef5def4d01bfc55b08992f41664f1431 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 6 Jul 2007 16:50:13 -0600 Subject: Add case for GL_QUADS in i915_reduced_primitive_state(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The t_dd_tritemp.h code can emit GL_QUADS primitives. We need to catch that case to determine if polygon stipple should be enabled. Fixes bug reported by Carlos DiĆ³genes on 4 July 2007. --- src/mesa/drivers/dri/i915/i915_vtbl.c | 1 + src/mesa/drivers/dri/i915tex/i915_vtbl.c | 1 + 2 files changed, 2 insertions(+) (limited to 'src/mesa/drivers/dri/i915') diff --git a/src/mesa/drivers/dri/i915/i915_vtbl.c b/src/mesa/drivers/dri/i915/i915_vtbl.c index b0e5f87fc7..cc8a605e50 100644 --- a/src/mesa/drivers/dri/i915/i915_vtbl.c +++ b/src/mesa/drivers/dri/i915/i915_vtbl.c @@ -64,6 +64,7 @@ static void i915_reduced_primitive_state( intelContextPtr intel, st1 &= ~ST1_ENABLE; switch (rprim) { + case GL_QUADS: /* from RASTERIZE(GL_QUADS) in t_dd_tritemp.h */ case GL_TRIANGLES: if (intel->ctx.Polygon.StippleFlag && intel->hw_stipple) diff --git a/src/mesa/drivers/dri/i915tex/i915_vtbl.c b/src/mesa/drivers/dri/i915tex/i915_vtbl.c index f80e8d6327..ad333b490b 100644 --- a/src/mesa/drivers/dri/i915tex/i915_vtbl.c +++ b/src/mesa/drivers/dri/i915tex/i915_vtbl.c @@ -61,6 +61,7 @@ i915_reduced_primitive_state(struct intel_context *intel, GLenum rprim) st1 &= ~ST1_ENABLE; switch (rprim) { + case GL_QUADS: /* from RASTERIZE(GL_QUADS) in t_dd_tritemp.h */ case GL_TRIANGLES: if (intel->ctx.Polygon.StippleFlag && intel->hw_stipple) st1 |= ST1_ENABLE; -- cgit v1.2.3 From fb3b9060d48934ca4faa72e966c00aee627ce96d Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Mon, 16 Jul 2007 18:09:30 +0200 Subject: fix segfault with i915 drivers in swrast drawpixels path when resizing windows --- src/mesa/drivers/dri/i915/intel_pixel.c | 6 ++++++ src/mesa/drivers/dri/i915tex/intel_pixel_draw.c | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'src/mesa/drivers/dri/i915') diff --git a/src/mesa/drivers/dri/i915/intel_pixel.c b/src/mesa/drivers/dri/i915/intel_pixel.c index d175870a0c..c3030d42b0 100644 --- a/src/mesa/drivers/dri/i915/intel_pixel.c +++ b/src/mesa/drivers/dri/i915/intel_pixel.c @@ -450,10 +450,16 @@ intelDrawPixels( GLcontext *ctx, * wise happily run the fragment program on each pixel in the image). */ struct gl_fragment_program *fpSave = ctx->FragmentProgram._Current; + /* can't just set current frag prog to 0 here as on buffer resize + we'll get new state checks which will segfault. Remains a hack. */ ctx->FragmentProgram._Current = NULL; + ctx->FragmentProgram._UseTexEnvProgram = GL_FALSE; + ctx->FragmentProgram._Active = GL_FALSE; _swrast_DrawPixels( ctx, x, y, width, height, format, type, unpack, pixels ); ctx->FragmentProgram._Current = fpSave; + ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; + ctx->FragmentProgram._Active = GL_TRUE; } else { _swrast_DrawPixels( ctx, x, y, width, height, format, type, diff --git a/src/mesa/drivers/dri/i915tex/intel_pixel_draw.c b/src/mesa/drivers/dri/i915tex/intel_pixel_draw.c index 77c67c821e..e4e57cb3a7 100644 --- a/src/mesa/drivers/dri/i915tex/intel_pixel_draw.c +++ b/src/mesa/drivers/dri/i915tex/intel_pixel_draw.c @@ -370,10 +370,16 @@ intelDrawPixels(GLcontext * ctx, * wise happily run the fragment program on each pixel in the image). */ struct gl_fragment_program *fpSave = ctx->FragmentProgram._Current; + /* can't just set current frag prog to 0 here as on buffer resize + we'll get new state checks which will segfault. Remains a hack. */ ctx->FragmentProgram._Current = NULL; + ctx->FragmentProgram._UseTexEnvProgram = GL_FALSE; + ctx->FragmentProgram._Active = GL_FALSE; _swrast_DrawPixels( ctx, x, y, width, height, format, type, unpack, pixels ); ctx->FragmentProgram._Current = fpSave; + ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; + ctx->FragmentProgram._Active = GL_TRUE; } else { _swrast_DrawPixels( ctx, x, y, width, height, format, type, -- cgit v1.2.3