From 896c0d31a577675038a39787ea714ec16cb8eff5 Mon Sep 17 00:00:00 2001 From: "Sha..rd" Date: Sun, 5 Aug 2012 05:41:49 +0000 Subject: [PATCH] * Forgot to commit this quite crucial class .. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9619 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/texture/Image.java | 44 +++++++++++++++++++ engine/src/core/com/jme3/texture/Texture.java | 17 ++++--- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/engine/src/core/com/jme3/texture/Image.java b/engine/src/core/com/jme3/texture/Image.java index 2cb3f7df7..99b2dd703 100644 --- a/engine/src/core/com/jme3/texture/Image.java +++ b/engine/src/core/com/jme3/texture/Image.java @@ -324,10 +324,54 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ { protected transient Object efficientData; protected int multiSamples = 1; // protected int mipOffset = 0; + + // attributes relating to GL object + protected boolean mipsWereGenerated = false; + protected boolean needGeneratedMips = false; + /** + * Internal use only. + * The renderer marks which images have generated mipmaps in VRAM + * and which do not, so it can generate them as needed. + * + * @param generated If mipmaps were generated or not. + */ + public void setMipmapsGenerated(boolean generated) { + this.mipsWereGenerated = generated; + } + + /** + * Internal use only. + * Check if the renderer has generated mipmaps for this image in VRAM + * or not. + * + * @return If mipmaps were generated already. + */ + public boolean isMipmapsGenerated() { + return mipsWereGenerated; + } + + /** + * (Package private) Called by {@link Texture} when + * {@link #isMipmapsGenerated() } is false in order to generate + * mipmaps for this image. + */ + void setNeedGeneratedMipmaps() { + needGeneratedMips = true; + } + + /** + * @return True if the image needs to have mipmaps generated + * for it (as requested by the texture). + */ + public boolean isGeneratedMipmapsRequired() { + return needGeneratedMips; + } + @Override public void resetObject() { this.id = -1; + this.mipsWereGenerated = false; setUpdateNeeded(); } diff --git a/engine/src/core/com/jme3/texture/Texture.java b/engine/src/core/com/jme3/texture/Texture.java index cbd4c5832..f5f66275e 100644 --- a/engine/src/core/com/jme3/texture/Texture.java +++ b/engine/src/core/com/jme3/texture/Texture.java @@ -339,6 +339,9 @@ public abstract class Texture implements CloneableSmartAsset, Savable, Cloneable "minificationFilter can not be null."); } this.minificationFilter = minificationFilter; + if (minificationFilter.usesMipMapLevels() && image != null && !image.isGeneratedMipmapsRequired()) { + image.setNeedGeneratedMipmaps(); + } } /** @@ -393,6 +396,9 @@ public abstract class Texture implements CloneableSmartAsset, Savable, Cloneable */ public void setImage(Image image) { this.image = image; + + // Test if mipmap generation required. + setMinFilter(getMinFilter()); } /** @@ -474,22 +480,23 @@ public abstract class Texture implements CloneableSmartAsset, Savable, Cloneable * the anisotropic filtering level for this texture. */ public void setAnisotropicFilter(int level) { - if (level < 1) + if (level < 1) { anisotropicFilter = 1; - else + } else { anisotropicFilter = level; + } } @Override - public String toString(){ + public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append("[name=").append(name); - if (image != null) + if (image != null) { sb.append(", image=").append(image.toString()); + } sb.append("]"); - return sb.toString(); }