Browse Source

openGL image rendering fix.

tags/2021-05-28
jules 13 years ago
parent
commit
04518ac15d
2 changed files with 17 additions and 12 deletions
  1. +8
    -12
      modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp
  2. +9
    -0
      modules/juce_opengl/opengl/juce_OpenGLTexture.cpp

+ 8
- 12
modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp View File

@@ -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);"


+ 9
- 0
modules/juce_opengl/opengl/juce_OpenGLTexture.cpp View File

@@ -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));
}
};


Loading…
Cancel
Save