Replace Texture.java with the following. I have only included the portions that have significant changes. i also highlighted these sections with the comment tag "MSLI". I have only tested the fix in my own code, which takes advantage of context switching to achieve multiple views of multiple models. Others will have to confirm if ithe fixes negatively impact other aspects of JME.
Also, I tweaked DisplaySystem.java so that it does not use "com.sun…" packages. I posted that separately.
–jon
=========Texture.java=====================
package com.jme.image;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.jme.math.FastMath;
import com.jme.math.Matrix4f;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.util.TextureKey;
import com.jme.util.TextureManager;
import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;
/**
- <code>Texture</code> defines a texture object to be used to display an image
- on a piece of geometry. The image to be displayed is defined by the
- <code>Image</code> class. All attributes required for texture mapping are
- contained within this class. This includes mipmapping if desired,
- magnificationFilter options, apply options and correction options. Default
- values are as follows: minificationFilter - NearestNeighborNoMipMaps,
- magnificationFilter - NearestNeighbor, wrap - EdgeClamp on S,T and R, apply -
- Modulate, enivoronment - None.
- <p>
- MSLI:
- <b>The problem:</b> Currently, the texture ID is the ID that is actually bound in
- OpenGL. However, OpenGL is context aware, whereas the texture ID maintained
- by texture is not. As such, when the system applies texture state and a
- texture is found with a non-zero texture ID, it is assumed bound regardless
- of the context, which means it actually may not be bound within the current
- context, or it may be bound with a different texture ID.
- <p>
- <b>The solution:</b> Ideally, texture ID should be associated with the texture
- state, which is context aware, not the texture. As an expedient workaround,
- the texture ID accessors in Texture are modified to be context aware, and a
- static useContext() method is added to globally establish the current
- context.
-
@author Jon Barrilleaux
- :MSLI
- <p>
-
@see com.jme.image.Image
-
@author Mark Powell
-
@author Joshua Slack
-
@version $Id: Texture.java 4131 2009-03-19 20:15:28Z blaine.dev $
*/
public abstract class Texture implements Savable {
private static final long serialVersionUID = -3642148179543729674L;
// MSLI:
/**
- Establishes the current "render context" for all textures. Specifically
- affects the mapping of texture ID by context.
-
@param contextKey Shared opaque context "key". Never null. Should be the
- same object used for all other context switching, which is typically the
- JME canvas object.
-
@see {@link #setTextureId(int)}
-
@see {@link #getTextureId()}
*/
public static void useContext(Object contextKey) {
if(contextKey == null) throw new IllegalArgumentException();
CONTEXT_KEY = contextKey;
}
private static Object CONTEXT_KEY = null; // null until first use
private Map<Object,Integer> _textureIdMap =
new HashMap<Object,Integer>(); // maps context key to texture ID
// :MSLI
//MSLI:
/**
- Gets the texture ID associated with this texture and the current global
- texture context.
-
@return The texture ID (>=0). If zero, the texture has not been loaded.
- If non-zero, the texture is assumed to be bindable to that ID in the
- current render context.
-
@see #useContext(Object)
-
@throws IllegalStateException if setContext() has not yet been called.
*/
public int getTextureId() {
if(CONTEXT_KEY == null) throw new IllegalStateException(
"Must first call setContext().");
Integer textureId = _textureIdMap.get(CONTEXT_KEY);
if (textureId == null) return 0;
return textureId;
}
/**
- Sets the texture ID associated with this texture and the current global
- texture context.
-
@param The texture ID (>=0). If zero, the texture will be forced to
- reload. If non-zero, the texture is assumed to be bindable to that ID in
- the current render context.
-
@see #useContext(Object)
-
@throws IllegalStateException if setContext() has not yet been called.
*/
public void setTextureId(int textureId) {
if(CONTEXT_KEY == null) throw new IllegalStateException(
"Must first call setContext().");
if (textureId < 0) throw new IllegalArgumentException();
_textureIdMap.put(CONTEXT_KEY, textureId);
}
// /
// * <code>getTextureId</code> returns the texture id of this texture. This
// * id is required to be unique to any other texture objects running in the
// * same JVM. However, no guarantees are made that it will be unique, and as
// * such, the user is responsible for this.
// *
// * @return the id of the texture.
// */
// public int getTextureId() {
// return textureId;
// }
//
// /
// * <code>setTextureId</code> sets the texture id for this texture. Zero
// * means no id is set.
// *
// * @param textureId
// * the texture id of this texture.
// */
// public void setTextureId(int textureId) {
// this.textureId = textureId;
// }
//:MSLI