From b986d11291c3e352d061e42b4ee39edf9ea001c2 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 18 Mar 2013 09:41:02 +0000 Subject: [PATCH] Minor GL optimisation. --- .../opengl/juce_OpenGLGraphicsContext.cpp | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index c0c940b927..a95d025144 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -2049,29 +2049,40 @@ public: if (clip == nullptr || fillType.colour.isTransparent()) return; - const Rectangle clipBounds (clip->getClipBounds()); const AffineTransform t (transform.getTransformWith (trans)); + if (t.isSingularity()) + return; + const float alpha = fillType.colour.getFloatAlpha(); - if (t.isOnlyTranslation()) + float px0 = 0, py0 = 0; + float px1 = (float) image.getWidth(), py1 = 0; + float px2 = 0, py2 = (float) image.getHeight(); + t.transformPoints (px0, py0, px1, py1, px2, py2); + + const int ix0 = (int) (px0 * 256.0f); + const int iy0 = (int) (py0 * 256.0f); + const int ix1 = (int) (px1 * 256.0f); + const int iy1 = (int) (py1 * 256.0f); + const int ix2 = (int) (px2 * 256.0f); + const int iy2 = (int) (py2 * 256.0f); + + if (((ix0 | iy0 | ix1 | iy1 | ix2 | iy2) & 0xf8) == 0 + && ix0 == ix2 && iy0 == iy1) { - int tx = (int) (t.getTranslationX() * 256.0f); - int ty = (int) (t.getTranslationY() * 256.0f); - - if (((tx | ty) & 0xf8) == 0) - { - tx = ((tx + 128) >> 8); - ty = ((ty + 128) >> 8); - - clip->drawImage (image, t, alpha, Rectangle (tx, ty, image.getWidth(), image.getHeight()), nullptr); - return; - } + // Non-warping transform can be done as a single rectangle. + clip->drawImage (image, t, alpha, + Rectangle (Point (((ix0 + 128) >> 8), + ((iy0 + 128) >> 8)), + Point (((ix1 + 128) >> 8), + ((iy2 + 128) >> 8))), nullptr); } - - if (! t.isSingularity()) + else { Path p; p.addRectangle (image.getBounds()); + + const Rectangle clipBounds (clip->getClipBounds()); EdgeTable et (clipBounds, p, t); clip->drawImage (image, t, alpha, clipBounds, &et);