From 04518ac15d9b4f8cd52a87cc13f89689bf4217f1 Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 29 Dec 2012 15:29:51 +0000 Subject: [PATCH] openGL image rendering fix. --- .../opengl/juce_OpenGLGraphicsContext.cpp | 20 ++++++++----------- .../juce_opengl/opengl/juce_OpenGLTexture.cpp | 9 +++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index 610756a9a6..08f48b464a 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -457,11 +457,7 @@ public: const GLfloat m[] = { t.mat00, t.mat01, t.mat02, t.mat10, t.mat11, t.mat12 }; matrix.set (m, 6); - const float halfPixelX = 0.5f / imageWidth; - const float halfPixelY = 0.5f / imageHeight; - imageLimits.set (halfPixelX, halfPixelY, - fullWidthProportion - halfPixelX, - fullHeightProportion - halfPixelY); + imageLimits.set (fullWidthProportion, fullHeightProportion); } void setMatrix (const AffineTransform& trans, const OpenGLTextureFromImage& im, @@ -477,11 +473,11 @@ public: }; #define JUCE_DECLARE_IMAGE_UNIFORMS "uniform sampler2D imageTexture;" \ - "uniform " JUCE_MEDIUMP " vec4 imageLimits;" \ + "uniform " JUCE_MEDIUMP " vec2 imageLimits;" \ JUCE_DECLARE_MATRIX_UNIFORM JUCE_DECLARE_VARYING_COLOUR JUCE_DECLARE_VARYING_PIXELPOS #define JUCE_GET_IMAGE_PIXEL "swizzleRGBOrder (texture2D (imageTexture, vec2 (texturePos.x, 1.0 - texturePos.y)))" - #define JUCE_CLAMP_TEXTURE_COORD JUCE_HIGHP " vec2 texturePos = clamp (" JUCE_MATRIX_TIMES_FRAGCOORD ", imageLimits.xy, imageLimits.zw);" - #define JUCE_MOD_TEXTURE_COORD JUCE_HIGHP " vec2 texturePos = clamp (mod (" JUCE_MATRIX_TIMES_FRAGCOORD ", imageLimits.zw + imageLimits.xy), imageLimits.xy, imageLimits.zw);" + #define JUCE_CLAMP_TEXTURE_COORD JUCE_HIGHP " vec2 texturePos = clamp (" JUCE_MATRIX_TIMES_FRAGCOORD ", vec2 (0, 0), imageLimits);" + #define JUCE_MOD_TEXTURE_COORD JUCE_HIGHP " vec2 texturePos = mod (" JUCE_MATRIX_TIMES_FRAGCOORD ", imageLimits);" struct ImageProgram : public ShaderBase { @@ -570,10 +566,10 @@ public: "{" JUCE_HIGHP " vec2 texturePos = " JUCE_MATRIX_TIMES_FRAGCOORD ";" JUCE_HIGHP " float roundingError = 0.00001;" - "if (texturePos.x >= imageLimits.x - roundingError" - "&& texturePos.y >= imageLimits.y - roundingError" - "&& texturePos.x <= imageLimits.z + roundingError" - "&& texturePos.y <= imageLimits.w + roundingError)" + "if (texturePos.x >= -roundingError" + "&& texturePos.y >= -roundingError" + "&& texturePos.x <= imageLimits.x + roundingError" + "&& texturePos.y <= imageLimits.y + roundingError)" "gl_FragColor = frontColour * " JUCE_GET_IMAGE_PIXEL ".a;" "else " "gl_FragColor = vec4 (0, 0, 0, 0);" diff --git a/modules/juce_opengl/opengl/juce_OpenGLTexture.cpp b/modules/juce_opengl/opengl/juce_OpenGLTexture.cpp index defcbd1d00..550c353ad3 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLTexture.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLTexture.cpp @@ -91,8 +91,17 @@ struct Flipper for (int x = 0; x < w; ++x) dst[x].set (src[x]); + if (textureW > w) + dst[w].set (PixelARGB (0)); + srcData += lineStride; } + + // for textures which are larger than the area of interest, clear the pixels that lie + // just outside the actual image, so that the texture interpolation doesn't read junk. + if (textureH > h) + zeromem (dataCopy + textureW * (textureH - 1 - h), + sizeof (PixelARGB) * jmin (textureW, w + 1)); } };