From c240ca4eaf547cdf5c30fbb8ca642797eabae82c Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 26 Mar 2015 18:12:07 +0000 Subject: [PATCH] Added a method OpenGLContext::setImageCacheSize to provide explicit control over the amount of GPU space that is used for the internal image cache. --- modules/juce_opengl/opengl/juce_OpenGLContext.cpp | 4 ++++ modules/juce_opengl/opengl/juce_OpenGLContext.h | 7 +++++++ modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 2c55c85911..36937b8669 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -596,6 +596,7 @@ private: OpenGLContext::OpenGLContext() : nativeContext (nullptr), renderer (nullptr), currentRenderScale (1.0), contextToShareWith (nullptr), versionRequired (OpenGLContext::defaultGLVersion), + imageCacheMaxSize (8 * 1024 * 1024), renderComponents (true), useMultisampling (false), continuousRepaint (false) { } @@ -812,6 +813,9 @@ void OpenGLContext::setAssociatedObject (const char* name, ReferenceCountedObjec } } +void OpenGLContext::setImageCacheSize (size_t newSize) noexcept { imageCacheMaxSize = newSize; } +size_t OpenGLContext::getImageCacheSize() const noexcept { return imageCacheMaxSize; } + void OpenGLContext::copyTexture (const Rectangle& targetClipArea, const Rectangle& anchorPosAndTextureSize, const int contextWidth, const int contextHeight, diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.h b/modules/juce_opengl/opengl/juce_OpenGLContext.h index c72e47c00b..7aee2b36ea 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.h @@ -262,6 +262,12 @@ public: bool textureOriginIsBottomLeft); + /** Changes the amount of GPU memory that the internal cache for Images is allowed to use. */ + void setImageCacheSize (size_t cacheSizeBytes) noexcept; + + /** Returns the amount of GPU memory that the internal cache for Images is allowed to use. */ + size_t getImageCacheSize() const noexcept; + //============================================================================== #ifndef DOXYGEN class NativeContext; @@ -277,6 +283,7 @@ private: OpenGLPixelFormat pixelFormat; void* contextToShareWith; OpenGLVersion versionRequired; + size_t imageCacheMaxSize; bool renderComponents, useMultisampling, continuousRepaint; CachedImage* getCachedImage() const noexcept; diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index 659d6fef7d..6aa593679d 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -38,8 +38,8 @@ struct TextureInfo struct CachedImageList : public ReferenceCountedObject, private ImagePixelData::Listener { - CachedImageList (OpenGLContext& c, size_t totalCacheSizeInPixels = 8 * 1024 * 1024) noexcept - : context (c), totalSize (0), maxCacheSize (totalCacheSizeInPixels) {} + CachedImageList (OpenGLContext& c) noexcept + : context (c), totalSize (0), maxCacheSize (c.getImageCacheSize()) {} static CachedImageList* get (OpenGLContext& c) {