From 159ffb5fb99adaf3ceeed27ca32370c12752f56c Mon Sep 17 00:00:00 2001 From: hogliux Date: Tue, 24 Oct 2017 09:13:19 +0100 Subject: [PATCH] OpenGL: Added method OpenGLContext::setTextureMagnificationFilter to change GL's texture magnification filter --- .../juce_opengl/opengl/juce_OpenGLContext.cpp | 5 +++++ .../juce_opengl/opengl/juce_OpenGLContext.h | 19 +++++++++++++++++++ .../juce_opengl/opengl/juce_OpenGLTexture.cpp | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index f916d55780..db829f090a 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -836,6 +836,11 @@ void OpenGLContext::setPixelFormat (const OpenGLPixelFormat& preferredPixelForma openGLPixelFormat = preferredPixelFormat; } +void OpenGLContext::setTextureMagnificationFilter (OpenGLContext::TextureMagnificationFilter magFilterMode) noexcept +{ + texMagFilter = magFilterMode; +} + void OpenGLContext::setNativeSharedContext (void* nativeContextToShareWith) noexcept { // This method must not be called when the context has already been attached! diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.h b/modules/juce_opengl/opengl/juce_OpenGLContext.h index 8fc460cc09..64db4afeb2 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.h @@ -27,6 +27,8 @@ namespace juce { +class OpenGLTexture; + //============================================================================== /** Creates an OpenGL context, which can be attached to a component. @@ -97,6 +99,20 @@ public: */ void setPixelFormat (const OpenGLPixelFormat& preferredPixelFormat) noexcept; + /** Texture magnification filters, used by setTextureMagnificationFilter(). */ + enum TextureMagnificationFilter + { + nearest, + linear + }; + + /** Sets the texture magnification filter. By default the texture magnification + filter is linear. However, for faster rendering you may want to use the + 'nearest' magnification filter. This option will not affect any textures + created before this function was called. */ + void setTextureMagnificationFilter (TextureMagnificationFilter magFilterMode) noexcept; + + //============================================================================== /** Provides a context with which you'd like this context's resources to be shared. The object passed-in here is a platform-dependent native context object, and must not be deleted while this context may still be using it! To turn off sharing, @@ -298,6 +314,8 @@ public: #endif private: + friend class OpenGLTexture; + class CachedImage; class Attachment; NativeContext* nativeContext = nullptr; @@ -309,6 +327,7 @@ private: OpenGLVersion versionRequired = defaultGLVersion; size_t imageCacheMaxSize = 8 * 1024 * 1024; bool renderComponents = true, useMultisampling = false, continuousRepaint = false, overrideCanAttach = false; + TextureMagnificationFilter texMagFilter = linear; //============================================================================== struct AsyncWorker : public ReferenceCountedObject diff --git a/modules/juce_opengl/opengl/juce_OpenGLTexture.cpp b/modules/juce_opengl/opengl/juce_OpenGLTexture.cpp index 4fdeeee745..8cc0acf58f 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLTexture.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLTexture.cpp @@ -65,7 +65,9 @@ void OpenGLTexture::create (const int w, const int h, const void* pixels, GLenum glGenTextures (1, &textureID); glBindTexture (GL_TEXTURE_2D, textureID); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + auto glMagFilter = (ownerContext->texMagFilter == OpenGLContext::linear ? GL_LINEAR : GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glMagFilter); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); JUCE_CHECK_OPENGL_ERROR