Browse Source

Fix for GL positioning of untransformed images.

tags/2021-05-28
jules 11 years ago
parent
commit
e34b2455f0
2 changed files with 29 additions and 21 deletions
  1. +27
    -19
      modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp
  2. +2
    -2
      modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp

+ 27
- 19
modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp View File

@@ -446,8 +446,9 @@ public:
void setMatrix (const AffineTransform& trans,
const int imageWidth, const int imageHeight,
const float fullWidthProportion, const float fullHeightProportion,
const float targetX, const float targetY) const
float fullWidthProportion, float fullHeightProportion,
const float targetX, const float targetY,
const bool isForTiling) const
{
const AffineTransform t (trans.translated (-targetX, -targetY)
.inverted().scaled (fullWidthProportion / imageWidth,
@@ -456,16 +457,23 @@ public:
const GLfloat m[] = { t.mat00, t.mat01, t.mat02, t.mat10, t.mat11, t.mat12 };
matrix.set (m, 6);
if (isForTiling)
{
fullWidthProportion -= 0.5f / imageWidth;
fullHeightProportion -= 0.5f / imageHeight;
}
imageLimits.set (fullWidthProportion, fullHeightProportion);
}
void setMatrix (const AffineTransform& trans, const OpenGLTextureFromImage& im,
const float targetX, const float targetY) const
const float targetX, const float targetY,
bool isForTiling) const
{
setMatrix (trans,
im.imageWidth, im.imageHeight,
im.fullWidthProportion, im.fullHeightProportion,
targetX, targetY);
targetX, targetY, isForTiling);
}
OpenGLShaderProgram::Uniform imageTexture, matrix, imageLimits;
@@ -1248,7 +1256,7 @@ public:
}
void setShaderForTiledImageFill (const OpenGLTextureFromImage& image, const AffineTransform& transform,
const int maskTextureID, const Rectangle<int>* const maskArea, const bool clampTiledImages)
const int maskTextureID, const Rectangle<int>* const maskArea, bool isTiledFill)
{
blendMode.setPremultipliedBlendingMode (shaderQuadQueue);
@@ -1261,37 +1269,37 @@ public:
{
activeTextures.setTwoTextureMode (shaderQuadQueue, image.textureID, (GLuint) maskTextureID);
if (clampTiledImages)
{
setShader (programs->imageMasked);
imageParams = &programs->imageMasked.imageParams;
maskParams = &programs->imageMasked.maskParams;
}
else
if (isTiledFill)
{
setShader (programs->tiledImageMasked);
imageParams = &programs->tiledImageMasked.imageParams;
maskParams = &programs->tiledImageMasked.maskParams;
}
else
{
setShader (programs->imageMasked);
imageParams = &programs->imageMasked.imageParams;
maskParams = &programs->imageMasked.maskParams;
}
}
else
{
activeTextures.setSingleTextureMode (shaderQuadQueue);
activeTextures.bindTexture (image.textureID);
if (clampTiledImages)
if (isTiledFill)
{
setShader (programs->image);
imageParams = &programs->image.imageParams;
setShader (programs->tiledImage);
imageParams = &programs->tiledImage.imageParams;
}
else
{
setShader (programs->tiledImage);
imageParams = &programs->tiledImage.imageParams;
setShader (programs->image);
imageParams = &programs->image.imageParams;
}
}
imageParams->setMatrix (transform, image, (float) target.bounds.getX(), (float) target.bounds.getY());
imageParams->setMatrix (transform, image, (float) target.bounds.getX(), (float) target.bounds.getY(), isTiledFill);
if (maskParams != nullptr)
maskParams->setBounds (*maskArea, target, 1);
@@ -1425,7 +1433,7 @@ public:
{
state->shaderQuadQueue.flush();
OpenGLTextureFromImage image (src);
state->setShaderForTiledImageFill (image, trans, 0, nullptr, ! tiledFill);
state->setShaderForTiledImageFill (image, trans, 0, nullptr, tiledFill);
state->shaderQuadQueue.add (iter, PixelARGB ((uint8) alpha, (uint8) alpha, (uint8) alpha, (uint8) alpha));
state->shaderQuadQueue.flush();


+ 2
- 2
modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp View File

@@ -272,8 +272,8 @@ OpenGLTextureFromImage::OpenGLTextureFromImage (const Image& image)
texture->loadImage (image);
textureID = texture->getTextureID();
fullWidthProportion = (imageWidth - 0.5f) / texture->getWidth();
fullHeightProportion = (imageHeight - 0.5f) / texture->getHeight();
fullWidthProportion = imageWidth / (float) texture->getWidth();
fullHeightProportion = imageHeight / (float) texture->getHeight();
}
JUCE_CHECK_OPENGL_ERROR


Loading…
Cancel
Save