From ac0f3a107cccab19e48afe14c927fb02958766e3 Mon Sep 17 00:00:00 2001 From: "Sha..rd" Date: Sat, 4 Aug 2012 23:17:29 +0000 Subject: [PATCH] * Fix issue where setting texture on renderer with no mipmaps and then setting the same texture with mipmaps would prevent them from being generated (fixed for desktop GL1/GL2 and android) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9617 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../renderer/android/OGLESShaderRenderer.java | 12 ++++++--- .../jme3/renderer/lwjgl/LwjglGL1Renderer.java | 9 ++++--- .../jme3/renderer/lwjgl/LwjglRenderer.java | 25 +++++++++++++------ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java index 2dafbea1b..84b554ee1 100644 --- a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java +++ b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java @@ -1472,7 +1472,7 @@ public class OGLESShaderRenderer implements Renderer { * @param type * @param needMips */ - public void updateTexImageData(Image img, Texture.Type type, boolean needMips) { + public void updateTexImageData(Image img, Texture.Type type) { int texId = img.getId(); if (texId == -1) { // create texture @@ -1495,6 +1495,12 @@ public class OGLESShaderRenderer implements Renderer { GLES20.glBindTexture(target, texId); context.boundTextures[0] = img; } + + boolean needMips = false; + if (img.isGeneratedMipmapsRequired()) { + needMips = true; + img.setMipmapsGenerated(true); + } if (target == GLES20.GL_TEXTURE_CUBE_MAP) { // Upload a cube map / sky box @@ -1534,8 +1540,8 @@ public class OGLESShaderRenderer implements Renderer { public void setTexture(int unit, Texture tex) { Image image = tex.getImage(); - if (image.isUpdateNeeded()) { - updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels()); + if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) { + updateTexImageData(image, tex.getType()); } int texId = image.getId(); diff --git a/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java b/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java index 340e58b30..cd1ac611d 100644 --- a/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java +++ b/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java @@ -702,7 +702,7 @@ public class LwjglGL1Renderer implements GL1Renderer { } } - public void updateTexImageData(Image img, Texture.Type type, boolean mips, int unit) { + public void updateTexImageData(Image img, Texture.Type type, int unit) { int texId = img.getId(); if (texId == -1) { // create texture @@ -740,7 +740,7 @@ public class LwjglGL1Renderer implements GL1Renderer { } } - if (!img.hasMipmaps() && mips) { + if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) { // No pregenerated mips available, // generate from base level if required @@ -750,6 +750,7 @@ public class LwjglGL1Renderer implements GL1Renderer { } else { MipMapGenerator.generateMipMaps(img); } + img.setMipmapsGenerated(true); } else { } @@ -787,8 +788,8 @@ public class LwjglGL1Renderer implements GL1Renderer { } Image image = tex.getImage(); - if (image.isUpdateNeeded()) { - updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels(), unit); + if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) { + updateTexImageData(image, tex.getType(), unit); } int texId = image.getId(); diff --git a/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java b/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java index 2a1531564..cc51bb958 100644 --- a/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java +++ b/engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java @@ -1385,7 +1385,7 @@ public class LwjglRenderer implements Renderer { Texture tex = rb.getTexture(); Image image = tex.getImage(); if (image.isUpdateNeeded()) { - updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels(), 0); + updateTexImageData(image, tex.getType(), 0); // NOTE: For depth textures, sets nearest/no-mips mode // Required to fix "framebuffer unsupported" @@ -1775,7 +1775,15 @@ public class LwjglRenderer implements Renderer { } } - public void updateTexImageData(Image img, Texture.Type type, boolean mips, int unit) { + /** + * Uploads the given image to the GL driver. + * + * @param img The image to upload + * @param type How the data in the image argument should be interpreted. + * @param updateMipsOnly If true, then texture data is already updated for this image, only + * @param unit The texture slot to be used to upload the image, not important + */ + public void updateTexImageData(Image img, Texture.Type type, int unit) { int texId = img.getId(); if (texId == -1) { // create texture @@ -1800,13 +1808,15 @@ public class LwjglRenderer implements Renderer { statistics.onTextureUse(img, true); } - if (!img.hasMipmaps() && mips) { + if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) { // No pregenerated mips available, // generate from base level if required if (!GLContext.getCapabilities().OpenGL30) { glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE); + img.setMipmapsGenerated(true); } } 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); @@ -1871,21 +1881,22 @@ public class LwjglRenderer implements Renderer { } if (GLContext.getCapabilities().OpenGL30) { - if (!img.hasMipmaps() && mips && img.getData() != null) { + if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired() && img.getData() != null) { // XXX: Required for ATI glEnable(target); glGenerateMipmapEXT(target); glDisable(target); + img.setMipmapsGenerated(true); } } img.clearUpdateNeeded(); } - + public void setTexture(int unit, Texture tex) { Image image = tex.getImage(); - if (image.isUpdateNeeded()) { - updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels(), unit); + if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) { + updateTexImageData(image, tex.getType(), unit); } int texId = image.getId();