From 465e2b2280858879a327e8acac3580668eaaf33e Mon Sep 17 00:00:00 2001 From: shadowislord Date: Sun, 1 Jun 2014 15:03:08 -0400 Subject: [PATCH] * Make sure to set texture max level depending on whether mipmaps are to be generated, included in texture, or not required at all - this reduces memory allocated by GPU for textures that do not use mipmaps. --- .../jme3/renderer/lwjgl/LwjglRenderer.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java index 100a07201..a51ab03a8 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java +++ b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java @@ -1850,18 +1850,24 @@ public class LwjglRenderer implements Renderer { } if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) { - // No pregenerated mips available, - // generate from base level if required + // Image does not have mipmaps, but they are required. + // Generate from base level. + if (!GLContext.getCapabilities().OpenGL30) { glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE); img.setMipmapsGenerated(true); + } else { + // For OpenGL3 and up. + // We'll generate mipmaps via glGenerateMipmapEXT (see below) } + } else if (img.hasMipmaps()) { + // Image already has mipmaps, set the max level based on the + // number of mipmaps we have. + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, img.getMipMapSizes().length - 1); } else { - // Image already has mipmaps or no mipmap generation desired. -// glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0 ); - if (img.getMipMapSizes() != null) { - glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, img.getMipMapSizes().length - 1); - } + // Image does not have mipmaps and they are not required. + // Specify that that the texture has no mipmaps. + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, 0); } int imageSamples = img.getMultiSamples();