summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2007-03-27 05:03:00 +0000
committerKenneth Russel <[email protected]>2007-03-27 05:03:00 +0000
commit53ed5970f6025e819c191e5f5f40d180c688b93d (patch)
tree8d13d794c73269309bad1b8821ea8730f928b774
parent96a0041f4b46bba34d044ade4d55b6ab58176336 (diff)
Made TextureElement refer to the Texture2 node rather than the Texture
it contains git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/joglutils/trunk@48 83d24430-9974-4f80-8418-2cc3294053b9
-rw-r--r--build/joglutils.jarbin148347 -> 148416 bytes
-rw-r--r--src/net/java/joglutils/msg/elements/GLTextureElement.java33
-rw-r--r--src/net/java/joglutils/msg/elements/TextureElement.java35
-rw-r--r--src/net/java/joglutils/msg/nodes/Texture2.java2
-rw-r--r--src/net/java/joglutils/msg/nodes/TriangleSet.java5
5 files changed, 41 insertions, 34 deletions
diff --git a/build/joglutils.jar b/build/joglutils.jar
index e46dd2a..9d8c3b5 100644
--- a/build/joglutils.jar
+++ b/build/joglutils.jar
Binary files differ
diff --git a/src/net/java/joglutils/msg/elements/GLTextureElement.java b/src/net/java/joglutils/msg/elements/GLTextureElement.java
index 5241b09..b5a196d 100644
--- a/src/net/java/joglutils/msg/elements/GLTextureElement.java
+++ b/src/net/java/joglutils/msg/elements/GLTextureElement.java
@@ -64,25 +64,36 @@ public class GLTextureElement extends TextureElement {
public void pop(State state, Element previousTopElement) {
// Put things back the way they were
- switchTextures(((GLTextureElement) previousTopElement).texture, texture, texEnvMode);
+ switchTextures(((GLTextureElement) previousTopElement).texture, texture);
}
- public void setElt(Texture texture, int texEnvMode) {
- Texture prev = this.texture;
- super.setElt(texture, texEnvMode);
- switchTextures(prev, texture, texEnvMode);
+ public void setElt(Texture2 texture) {
+ Texture2 prev = this.texture;
+ super.setElt(texture);
+ switchTextures(prev, texture);
}
- private void switchTextures(Texture prev, Texture texture, int texEnvMode) {
+ private void switchTextures(Texture2 prev, Texture2 texture) {
GL gl = GLU.getCurrentGL();
- // FIXME: should be smarter about this; if the target is the same
- // for the previous and current textures, just bind the new one
+ Texture prevTexture = null;
+ Texture curTexture = null;
+ int texEnvMode = 0;
if (prev != null) {
- prev.disable();
+ prevTexture = prev.getTexture();
}
if (texture != null) {
- texture.enable();
- texture.bind();
+ curTexture = texture.getTexture();
+ texEnvMode = texture.getTexEnvMode();
+ }
+
+ // FIXME: should be smarter about this; if the target is the same
+ // for the previous and current textures, just bind the new one
+ if (prevTexture != null) {
+ prevTexture.disable();
+ }
+ if (curTexture != null) {
+ curTexture.enable();
+ curTexture.bind();
int glEnvMode = 0;
switch (texEnvMode) {
case Texture2.MODULATE: glEnvMode = GL.GL_MODULATE; break;
diff --git a/src/net/java/joglutils/msg/elements/TextureElement.java b/src/net/java/joglutils/msg/elements/TextureElement.java
index 199a113..413be67 100644
--- a/src/net/java/joglutils/msg/elements/TextureElement.java
+++ b/src/net/java/joglutils/msg/elements/TextureElement.java
@@ -39,13 +39,9 @@ package net.java.joglutils.msg.elements;
import java.nio.*;
import javax.media.opengl.*;
-import com.sun.opengl.util.texture.*;
import net.java.joglutils.msg.misc.*;
-
-// FIXME: the TextureElement / GLTextureElement distinction doesn't
-// make much sense here, because the Texture object the TextureElement
-// contains already implicitly relies on OpenGL
+import net.java.joglutils.msg.nodes.*;
/** Represents the current texture, which is applied to any drawn
geometry if texture coordinates are also supplied. */
@@ -73,26 +69,24 @@ public class TextureElement extends Element {
return (state.getDefaults().getElement(index) != null);
}
- // The actual Texture object
- protected Texture texture;
- // The texture environment mode
- protected int texEnvMode;
+ // This particular element refers to the Texture2 node directly.
+ // Having it refer to the Texture object doesn't really make sense,
+ // because the Texture object implicitly relies on OpenGL and the
+ // intent is to make the base element class not reliant on GL.
+
+ // The Texture2 node
+ protected Texture2 texture;
- /** Sets the texture and environment mode in the given state. */
- public static void set(State state, Texture texture, int texEnvMode) {
- getInstance(state).setElt(texture, texEnvMode);
+ /** Sets the texture in the given state. */
+ public static void set(State state, Texture2 texture) {
+ getInstance(state).setElt(texture);
}
/** Returns the current texture in the state. */
- public static Texture get(State state) {
+ public static Texture2 get(State state) {
return getInstance(state).texture;
}
- /** Returns the texture environment mode in the state. */
- public static int getEnvMode(State state) {
- return getInstance(state).texEnvMode;
- }
-
public void push(State state) {
TextureElement prev = (TextureElement) getNextInStack();
if (prev != null) {
@@ -101,9 +95,8 @@ public class TextureElement extends Element {
}
}
- /** Sets the texture and environment mode in this element. */
- public void setElt(Texture texture, int texEnvMode) {
+ /** Sets the texture in this element. */
+ public void setElt(Texture2 texture) {
this.texture = texture;
- this.texEnvMode = texEnvMode;
}
}
diff --git a/src/net/java/joglutils/msg/nodes/Texture2.java b/src/net/java/joglutils/msg/nodes/Texture2.java
index 29ed969..c454884 100644
--- a/src/net/java/joglutils/msg/nodes/Texture2.java
+++ b/src/net/java/joglutils/msg/nodes/Texture2.java
@@ -143,7 +143,7 @@ public class Texture2 extends Node {
public void doAction(Action action) {
if (TextureElement.isEnabled(action.getState())) {
- TextureElement.set(action.getState(), getTexture(), getTexEnvMode());
+ TextureElement.set(action.getState(), this);
}
}
diff --git a/src/net/java/joglutils/msg/nodes/TriangleSet.java b/src/net/java/joglutils/msg/nodes/TriangleSet.java
index 8f708cb..d7c55bb 100644
--- a/src/net/java/joglutils/msg/nodes/TriangleSet.java
+++ b/src/net/java/joglutils/msg/nodes/TriangleSet.java
@@ -80,7 +80,10 @@ public class TriangleSet extends TriangleBasedShape {
if (GLTextureElement.isEnabled(state) &&
GLTextureCoordinateElement.isEnabled(state)) {
- tex = GLTextureElement.get(state);
+ Texture2 texNode = GLTextureElement.get(state);
+ if (texNode != null) {
+ tex = texNode.getTexture();
+ }
haveTexCoords = (GLTextureCoordinateElement.get(state) != null);
}