diff options
author | Sven Gothel <[email protected]> | 2019-12-31 18:23:02 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-31 18:23:02 +0100 |
commit | 332dd8550a2301427dd942d2a77cb59ebd3ec92e (patch) | |
tree | 0c860a40c05ba5b27d99770a433b922cbf685f70 /src/net/java/joglutils/msg | |
parent | 7ea189170b6ae75b7e15be43344a785eb56bb48a (diff) |
Diffstat (limited to 'src/net/java/joglutils/msg')
58 files changed, 794 insertions, 657 deletions
diff --git a/src/net/java/joglutils/msg/actions/Action.java b/src/net/java/joglutils/msg/actions/Action.java index b206cdb..1d3abf8 100644 --- a/src/net/java/joglutils/msg/actions/Action.java +++ b/src/net/java/joglutils/msg/actions/Action.java @@ -37,10 +37,12 @@ package net.java.joglutils.msg.actions; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.ActionTable; +import net.java.joglutils.msg.misc.Path; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Node; /** The base class of all actions, which are applied to nodes in the scene graph to implement operations such as rendering. <P> diff --git a/src/net/java/joglutils/msg/actions/GLRenderAction.java b/src/net/java/joglutils/msg/actions/GLRenderAction.java index b65c515..3fcad13 100644 --- a/src/net/java/joglutils/msg/actions/GLRenderAction.java +++ b/src/net/java/joglutils/msg/actions/GLRenderAction.java @@ -37,13 +37,14 @@ package net.java.joglutils.msg.actions; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.ActionTable; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Node; /** An action which performs rendering of a scene graph via OpenGL. <P> diff --git a/src/net/java/joglutils/msg/actions/GLResetAction.java b/src/net/java/joglutils/msg/actions/GLResetAction.java index e04d866..fef612e 100644 --- a/src/net/java/joglutils/msg/actions/GLResetAction.java +++ b/src/net/java/joglutils/msg/actions/GLResetAction.java @@ -37,10 +37,13 @@ package net.java.joglutils.msg.actions; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.ActionTable; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Node; +import net.java.joglutils.msg.nodes.ShaderNode; +import net.java.joglutils.msg.nodes.Texture2; /** An action which resets the OpenGL state of notes holding on to server-side OpenGL objects. This is needed to clear out for diff --git a/src/net/java/joglutils/msg/actions/RayPickAction.java b/src/net/java/joglutils/msg/actions/RayPickAction.java index ee2528a..0b32f47 100644 --- a/src/net/java/joglutils/msg/actions/RayPickAction.java +++ b/src/net/java/joglutils/msg/actions/RayPickAction.java @@ -38,12 +38,18 @@ package net.java.joglutils.msg.actions; import java.awt.Component; -import java.lang.reflect.*; -import java.util.*; - -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.java.joglutils.msg.math.Line; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.misc.ActionTable; +import net.java.joglutils.msg.misc.PickedPoint; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Camera; +import net.java.joglutils.msg.nodes.Node; public class RayPickAction extends Action { // Boilerplate diff --git a/src/net/java/joglutils/msg/collections/Vec2fCollection.java b/src/net/java/joglutils/msg/collections/Vec2fCollection.java index d0dadc1..bf4ebb8 100644 --- a/src/net/java/joglutils/msg/collections/Vec2fCollection.java +++ b/src/net/java/joglutils/msg/collections/Vec2fCollection.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.collections; -import java.nio.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.impl.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.impl.BufferFactory; +import net.java.joglutils.msg.math.Vec2f; /** Provides the abstraction of a collection of Vec2f objects while allowing access to the backing store in the form of a direct diff --git a/src/net/java/joglutils/msg/collections/Vec3fCollection.java b/src/net/java/joglutils/msg/collections/Vec3fCollection.java index 887b4c9..5714d91 100644 --- a/src/net/java/joglutils/msg/collections/Vec3fCollection.java +++ b/src/net/java/joglutils/msg/collections/Vec3fCollection.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.collections; -import java.nio.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.impl.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.impl.BufferFactory; +import net.java.joglutils.msg.math.Vec3f; /** Provides the abstraction of a collection of Vec3f objects while allowing access to the backing store in the form of a direct diff --git a/src/net/java/joglutils/msg/collections/Vec4fCollection.java b/src/net/java/joglutils/msg/collections/Vec4fCollection.java index 2f940cd..1be28ef 100644 --- a/src/net/java/joglutils/msg/collections/Vec4fCollection.java +++ b/src/net/java/joglutils/msg/collections/Vec4fCollection.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.collections; -import java.nio.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.impl.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.impl.BufferFactory; +import net.java.joglutils.msg.math.Vec4f; /** Provides the abstraction of a collection of Vec4f objects while allowing access to the backing store in the form of a direct diff --git a/src/net/java/joglutils/msg/elements/BlendElement.java b/src/net/java/joglutils/msg/elements/BlendElement.java index 422811f..9df19c2 100644 --- a/src/net/java/joglutils/msg/elements/BlendElement.java +++ b/src/net/java/joglutils/msg/elements/BlendElement.java @@ -37,12 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; - -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; +import net.java.joglutils.msg.nodes.Blend; /** Represents the blending state of the OpenGL fixed-function pipeline. */ diff --git a/src/net/java/joglutils/msg/elements/ColorElement.java b/src/net/java/joglutils/msg/elements/ColorElement.java index a3a92d4..117e026 100644 --- a/src/net/java/joglutils/msg/elements/ColorElement.java +++ b/src/net/java/joglutils/msg/elements/ColorElement.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the current set of colors, which are applied on a per-vertex basis to any drawn geometry. */ diff --git a/src/net/java/joglutils/msg/elements/CoordinateElement.java b/src/net/java/joglutils/msg/elements/CoordinateElement.java index 58a57c7..383726b 100644 --- a/src/net/java/joglutils/msg/elements/CoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/CoordinateElement.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the current set of coordinates, which are assembled to draw geometry. */ diff --git a/src/net/java/joglutils/msg/elements/DepthTestElement.java b/src/net/java/joglutils/msg/elements/DepthTestElement.java index 36a21dd..e502414 100644 --- a/src/net/java/joglutils/msg/elements/DepthTestElement.java +++ b/src/net/java/joglutils/msg/elements/DepthTestElement.java @@ -36,11 +36,8 @@ package net.java.joglutils.msg.elements; -import javax.media.opengl.*; - -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the depth test state of the OpenGL fixed-function pipeline. */ diff --git a/src/net/java/joglutils/msg/elements/Element.java b/src/net/java/joglutils/msg/elements/Element.java index 5937b65..11f2980 100644 --- a/src/net/java/joglutils/msg/elements/Element.java +++ b/src/net/java/joglutils/msg/elements/Element.java @@ -37,7 +37,8 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents an element in the global {@link net.java.joglutils.msg.misc.State state}, such as the current 3D diff --git a/src/net/java/joglutils/msg/elements/GLBlendElement.java b/src/net/java/joglutils/msg/elements/GLBlendElement.java index 16e2266..78d67b5 100644 --- a/src/net/java/joglutils/msg/elements/GLBlendElement.java +++ b/src/net/java/joglutils/msg/elements/GLBlendElement.java @@ -37,13 +37,12 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Blend; /** Represents the blending state of the OpenGL fixed-function pipeline and causes side-effects in OpenGL for rendering. */ diff --git a/src/net/java/joglutils/msg/elements/GLColorElement.java b/src/net/java/joglutils/msg/elements/GLColorElement.java index 0503e9a..16341ee 100644 --- a/src/net/java/joglutils/msg/elements/GLColorElement.java +++ b/src/net/java/joglutils/msg/elements/GLColorElement.java @@ -37,11 +37,12 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; + +import net.java.joglutils.msg.misc.State; /** Represents the current set of colors, which are applied on a per-vertex basis to any drawn geometry, and causes side-effects in diff --git a/src/net/java/joglutils/msg/elements/GLCoordinateElement.java b/src/net/java/joglutils/msg/elements/GLCoordinateElement.java index aa59690..9af15b1 100644 --- a/src/net/java/joglutils/msg/elements/GLCoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/GLCoordinateElement.java @@ -37,11 +37,12 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; + +import net.java.joglutils.msg.misc.State; /** Represents the current set of coordinates, which are assembled to draw geometry, and causes side-effects in OpenGL. */ diff --git a/src/net/java/joglutils/msg/elements/GLDepthTestElement.java b/src/net/java/joglutils/msg/elements/GLDepthTestElement.java index 80840d1..89eec47 100644 --- a/src/net/java/joglutils/msg/elements/GLDepthTestElement.java +++ b/src/net/java/joglutils/msg/elements/GLDepthTestElement.java @@ -37,13 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; /** Represents the depth test state of the OpenGL fixed-function pipeline and causes side-effects in OpenGL for rendering. */ diff --git a/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java b/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java index c10e436..93cdd72 100644 --- a/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java @@ -37,12 +37,11 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; /** Represents the model matrix, which is the transformation applied to objects in the scene, and causes side-effects in OpenGL. */ diff --git a/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java b/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java index c811ba4..f1a7a64 100644 --- a/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java @@ -37,12 +37,11 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; /** Represents the projection matrix, which transforms view-space coordinates into screen-space coordinates, and performs diff --git a/src/net/java/joglutils/msg/elements/GLShaderElement.java b/src/net/java/joglutils/msg/elements/GLShaderElement.java index 178a8f2..b939e41 100644 --- a/src/net/java/joglutils/msg/elements/GLShaderElement.java +++ b/src/net/java/joglutils/msg/elements/GLShaderElement.java @@ -36,14 +36,12 @@ package net.java.joglutils.msg.elements; -import java.util.*; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.glu.GLU; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; - -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.Shader; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.ShaderNode; /** Represents the current shader, which is applied to any drawn geometry, and performs side-effects in OpenGL. */ diff --git a/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java b/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java index 50a871c..a5d793c 100644 --- a/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java @@ -37,11 +37,12 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; + +import net.java.joglutils.msg.misc.State; /** Represents the current set of texture coordinates, which are applied on a per-vertex basis to any drawn geometry, and performs diff --git a/src/net/java/joglutils/msg/elements/GLTextureElement.java b/src/net/java/joglutils/msg/elements/GLTextureElement.java index 7f903c3..e5259bc 100644 --- a/src/net/java/joglutils/msg/elements/GLTextureElement.java +++ b/src/net/java/joglutils/msg/elements/GLTextureElement.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,22 +28,23 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * */ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; -import com.sun.opengl.util.texture.*; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.GL2ES1; +import com.jogamp.opengl.glu.GLU; +import com.jogamp.opengl.util.texture.Texture; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Texture2; /** Represents the current texture, which is applied to any drawn geometry if texture coordinates are also supplied, and performs @@ -54,54 +55,54 @@ public class GLTextureElement extends TextureElement { public Element newInstance() { return new GLTextureElement(); } - public static GLTextureElement getInstance(State state) { + public static GLTextureElement getInstance(final State state) { return (GLTextureElement) TextureElement.getInstance(state); } - public static void enable(State defaultState) { - Element tmp = new GLTextureElement(); + public static void enable(final State defaultState) { + final Element tmp = new GLTextureElement(); defaultState.setElement(tmp.getStateIndex(), tmp); } - public void pop(State state, Element previousTopElement) { + public void pop(final State state, final Element previousTopElement) { // Put things back the way they were switchTextures(((GLTextureElement) previousTopElement).texture, texture); } - public void setElt(Texture2 texture) { - Texture2 prev = this.texture; + public void setElt(final Texture2 texture) { + final Texture2 prev = this.texture; super.setElt(texture); switchTextures(prev, texture); } - private void switchTextures(Texture2 prev, Texture2 texture) { - GL2 gl = GLU.getCurrentGL().getGL2(); + private void switchTextures(final Texture2 prev, final Texture2 texture) { + final GL2 gl = GLU.getCurrentGL().getGL2(); Texture prevTexture = null; Texture curTexture = null; int texEnvMode = 0; if (prev != null) { - prevTexture = prev.getTexture(); + prevTexture = prev.getTexture(gl); } if (texture != null) { - curTexture = texture.getTexture(); + curTexture = texture.getTexture(gl); 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(); + prevTexture.disable(gl); } if (curTexture != null) { - curTexture.enable(); - curTexture.bind(); + curTexture.enable(gl); + curTexture.bind(gl); int glEnvMode = 0; switch (texEnvMode) { - case Texture2.MODULATE: glEnvMode = GL2.GL_MODULATE; break; - case Texture2.DECAL: glEnvMode = GL2.GL_DECAL; break; - case Texture2.BLEND: glEnvMode = GL2.GL_BLEND; break; - case Texture2.REPLACE: glEnvMode = GL2.GL_REPLACE; break; + case Texture2.MODULATE: glEnvMode = GL2ES1.GL_MODULATE; break; + case Texture2.DECAL: glEnvMode = GL2ES1.GL_DECAL; break; + case Texture2.BLEND: glEnvMode = GL.GL_BLEND; break; + case Texture2.REPLACE: glEnvMode = GL.GL_REPLACE; break; } - gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, glEnvMode); + gl.glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, glEnvMode); } } } diff --git a/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java b/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java index cff9fe3..ae5c0eb 100644 --- a/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java @@ -37,12 +37,11 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; /** Represents the viewing matrix, which contains the transformation between the camera and the model, and performs side-effects in diff --git a/src/net/java/joglutils/msg/elements/ModelMatrixElement.java b/src/net/java/joglutils/msg/elements/ModelMatrixElement.java index e4cdbb0..35b0cfc 100644 --- a/src/net/java/joglutils/msg/elements/ModelMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/ModelMatrixElement.java @@ -37,8 +37,9 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the model matrix, which is the transformation applied to objects in the scene. */ diff --git a/src/net/java/joglutils/msg/elements/ProjectionMatrixElement.java b/src/net/java/joglutils/msg/elements/ProjectionMatrixElement.java index 4635a83..ce12598 100644 --- a/src/net/java/joglutils/msg/elements/ProjectionMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/ProjectionMatrixElement.java @@ -37,8 +37,9 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the projection matrix, which transforms view-space coordinates into screen-space coordinates. */ diff --git a/src/net/java/joglutils/msg/elements/ShaderElement.java b/src/net/java/joglutils/msg/elements/ShaderElement.java index 8b1a3fe..a7fde42 100644 --- a/src/net/java/joglutils/msg/elements/ShaderElement.java +++ b/src/net/java/joglutils/msg/elements/ShaderElement.java @@ -37,8 +37,9 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; +import net.java.joglutils.msg.nodes.ShaderNode; /** Represents the current vertex/fragment shader, which is applied to any drawn geometry. */ diff --git a/src/net/java/joglutils/msg/elements/TextureCoordinateElement.java b/src/net/java/joglutils/msg/elements/TextureCoordinateElement.java index 8d24bfc..579bcbd 100644 --- a/src/net/java/joglutils/msg/elements/TextureCoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/TextureCoordinateElement.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the current set of texture coordinates, which are applied on a per-vertex basis to any drawn geometry. */ diff --git a/src/net/java/joglutils/msg/elements/TextureElement.java b/src/net/java/joglutils/msg/elements/TextureElement.java index 413be67..9107ef9 100644 --- a/src/net/java/joglutils/msg/elements/TextureElement.java +++ b/src/net/java/joglutils/msg/elements/TextureElement.java @@ -37,11 +37,9 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; - -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; +import net.java.joglutils.msg.nodes.Texture2; /** Represents the current texture, which is applied to any drawn geometry if texture coordinates are also supplied. */ diff --git a/src/net/java/joglutils/msg/elements/ViewingMatrixElement.java b/src/net/java/joglutils/msg/elements/ViewingMatrixElement.java index b561bd8..4c0001b 100644 --- a/src/net/java/joglutils/msg/elements/ViewingMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/ViewingMatrixElement.java @@ -37,8 +37,9 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the viewing matrix, which contains the transformation between the camera and the model. */ diff --git a/src/net/java/joglutils/msg/impl/BufferFactory.java b/src/net/java/joglutils/msg/impl/BufferFactory.java index 191c5c7..3ad80dd 100644 --- a/src/net/java/joglutils/msg/impl/BufferFactory.java +++ b/src/net/java/joglutils/msg/impl/BufferFactory.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,18 +28,22 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * */ package net.java.joglutils.msg.impl; -import java.nio.*; -import java.util.*; -import com.sun.opengl.util.*; +import java.nio.ByteBuffer; +import java.nio.DoubleBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; + +import com.jogamp.common.nio.Buffers; /** Assists in allocation of direct Buffers. On some platforms when a small direct Buffer is allocated there is a large amount of @@ -57,82 +61,82 @@ public class BufferFactory { // I believe the rounding-up size of direct Buffers on Unix platforms is 8K private static final int CHUNK_SIZE = 8 * 1024; - public static synchronized ByteBuffer newByteBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_BYTE; + public static synchronized ByteBuffer newByteBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_BYTE; if (sz > CHUNK_SIZE) { // Just allocate a fresh ByteBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newByteBuffer(numElements); + return Buffers.newDirectByteBuffer(numElements); } if (curByteBuf == null || curByteBuf.remaining() < numElements) { - curByteBuf = BufferUtil.newByteBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_BYTE); + curByteBuf = Buffers.newDirectByteBuffer(CHUNK_SIZE / Buffers.SIZEOF_BYTE); } curByteBuf.limit(curByteBuf.position() + numElements); - ByteBuffer res = curByteBuf.slice(); + final ByteBuffer res = curByteBuf.slice(); curByteBuf.position(curByteBuf.limit()); return res; } - public static synchronized ShortBuffer newShortBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_SHORT; + public static synchronized ShortBuffer newShortBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_SHORT; if (sz > CHUNK_SIZE) { // Just allocate a fresh ShortBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newShortBuffer(numElements); + return Buffers.newDirectShortBuffer(numElements); } if (curShortBuf == null || curShortBuf.remaining() < numElements) { - curShortBuf = BufferUtil.newShortBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_SHORT); + curShortBuf = Buffers.newDirectShortBuffer(CHUNK_SIZE / Buffers.SIZEOF_SHORT); } curShortBuf.limit(curShortBuf.position() + numElements); - ShortBuffer res = curShortBuf.slice(); + final ShortBuffer res = curShortBuf.slice(); curShortBuf.position(curShortBuf.limit()); return res; } - public static synchronized IntBuffer newIntBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_INT; + public static synchronized IntBuffer newIntBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_INT; if (sz > CHUNK_SIZE) { // Just allocate a fresh IntBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newIntBuffer(numElements); + return Buffers.newDirectIntBuffer(numElements); } if (curIntBuf == null || curIntBuf.remaining() < numElements) { - curIntBuf = BufferUtil.newIntBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_INT); + curIntBuf = Buffers.newDirectIntBuffer(CHUNK_SIZE / Buffers.SIZEOF_INT); } curIntBuf.limit(curIntBuf.position() + numElements); - IntBuffer res = curIntBuf.slice(); + final IntBuffer res = curIntBuf.slice(); curIntBuf.position(curIntBuf.limit()); return res; } - public static synchronized FloatBuffer newFloatBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_FLOAT; + public static synchronized FloatBuffer newFloatBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_FLOAT; if (sz > CHUNK_SIZE) { // Just allocate a fresh FloatBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newFloatBuffer(numElements); + return Buffers.newDirectFloatBuffer(numElements); } if (curFloatBuf == null || curFloatBuf.remaining() < numElements) { - curFloatBuf = BufferUtil.newFloatBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_FLOAT); + curFloatBuf = Buffers.newDirectFloatBuffer(CHUNK_SIZE / Buffers.SIZEOF_FLOAT); } curFloatBuf.limit(curFloatBuf.position() + numElements); - FloatBuffer res = curFloatBuf.slice(); + final FloatBuffer res = curFloatBuf.slice(); curFloatBuf.position(curFloatBuf.limit()); return res; } - public static synchronized DoubleBuffer newDoubleBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_DOUBLE; + public static synchronized DoubleBuffer newDoubleBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_DOUBLE; if (sz > CHUNK_SIZE) { // Just allocate a fresh DoubleBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newDoubleBuffer(numElements); + return Buffers.newDirectDoubleBuffer(numElements); } if (curDoubleBuf == null || curDoubleBuf.remaining() < numElements) { - curDoubleBuf = BufferUtil.newDoubleBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_DOUBLE); + curDoubleBuf = Buffers.newDirectDoubleBuffer(CHUNK_SIZE / Buffers.SIZEOF_DOUBLE); } curDoubleBuf.limit(curDoubleBuf.position() + numElements); - DoubleBuffer res = curDoubleBuf.slice(); + final DoubleBuffer res = curDoubleBuf.slice(); curDoubleBuf.position(curDoubleBuf.limit()); return res; } diff --git a/src/net/java/joglutils/msg/impl/RayTriangleIntersection.java b/src/net/java/joglutils/msg/impl/RayTriangleIntersection.java index 13d49e9..7af420c 100644 --- a/src/net/java/joglutils/msg/impl/RayTriangleIntersection.java +++ b/src/net/java/joglutils/msg/impl/RayTriangleIntersection.java @@ -37,7 +37,8 @@ package net.java.joglutils.msg.impl; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.math.Line; +import net.java.joglutils.msg.math.Vec3f; /** Intersection of ray with triangle. Computes parameteric t along with barycentric coordinates (u, v) indicating weight of vert1 and diff --git a/src/net/java/joglutils/msg/math/Mat4f.java b/src/net/java/joglutils/msg/math/Mat4f.java index bc7cee0..efaa417 100644 --- a/src/net/java/joglutils/msg/math/Mat4f.java +++ b/src/net/java/joglutils/msg/math/Mat4f.java @@ -37,7 +37,7 @@ package net.java.joglutils.msg.math; -import java.nio.*; +import java.nio.FloatBuffer; /** A (very incomplete) 4x4 matrix class. Representation assumes row-major order and multiplication by column vectors on the diff --git a/src/net/java/joglutils/msg/misc/ActionTable.java b/src/net/java/joglutils/msg/misc/ActionTable.java index d8b185b..5045eab 100644 --- a/src/net/java/joglutils/msg/misc/ActionTable.java +++ b/src/net/java/joglutils/msg/misc/ActionTable.java @@ -37,11 +37,13 @@ package net.java.joglutils.msg.misc; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.nodes.Node; /** Keeps track of methods which are attached to a particular Action type for a given set of Node types. This mechanism is different diff --git a/src/net/java/joglutils/msg/misc/Path.java b/src/net/java/joglutils/msg/misc/Path.java index 0743e86..811e3a4 100644 --- a/src/net/java/joglutils/msg/misc/Path.java +++ b/src/net/java/joglutils/msg/misc/Path.java @@ -37,9 +37,9 @@ package net.java.joglutils.msg.misc; -import java.util.*; +import java.util.ArrayList; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.nodes.Node; /** Represents a path through the scene graph. The topmost node is at index 0 and subsequent child nodes are at later indices. */ diff --git a/src/net/java/joglutils/msg/misc/PrimitiveVertex.java b/src/net/java/joglutils/msg/misc/PrimitiveVertex.java index 24b9e46..aab636b 100644 --- a/src/net/java/joglutils/msg/misc/PrimitiveVertex.java +++ b/src/net/java/joglutils/msg/misc/PrimitiveVertex.java @@ -37,7 +37,9 @@ package net.java.joglutils.msg.misc; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; /** Represents a vertex on a primitive, including pieces of relevant information such as location, surface normal and texture diff --git a/src/net/java/joglutils/msg/misc/Shader.java b/src/net/java/joglutils/msg/misc/Shader.java index cf32fc6..da0c9ac 100644 --- a/src/net/java/joglutils/msg/misc/Shader.java +++ b/src/net/java/joglutils/msg/misc/Shader.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,7 +28,7 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. @@ -36,9 +36,11 @@ package net.java.joglutils.msg.misc; -import javax.media.opengl.*; -import javax.media.opengl.glu.GLU; -import static javax.media.opengl.GL2.*; +import static com.jogamp.opengl.GL2.*; + +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.GLException; +import com.jogamp.opengl.glu.GLU; /** * Represents an OpenGL shader program object, which can be constructed from @@ -69,61 +71,61 @@ import static javax.media.opengl.GL2.*; * @author Chris Campbell */ public class Shader { - + /** * The handle to the OpenGL fragment program object. */ private int id; - + /** * Creates a new shader program object and compiles/links the provided * fragment shader code into that object. - * + * * @param fragmentCode a {@code String} representing the fragment shader * source code to be compiled and linked - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public Shader(String fragmentCode) + public Shader(final String fragmentCode) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); id = createProgram(gl, null, fragmentCode); } - + /** * Creates a new shader program object and compiles/links the provided * vertex shader and fragment shader code into that object. - * + * * @param vertexCode a {@code String} representing the vertex shader * source code to be compiled and linked; this may be null if only a * fragment shader is going to be needed * @param fragmentCode a {@code String} representing the fragment shader * source code to be compiled and linked; this may be null if only a * vertex shader is going to be needed - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public Shader(String vertexCode, String fragmentCode) + public Shader(final String vertexCode, final String fragmentCode) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); id = createProgram(gl, vertexCode, fragmentCode); } - + /** * Compiles and links a new shader program using the given sources. If * successful, this function returns a handle to the newly created shader * program; otherwise returns 0. - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - private static int createProgram(GL2 gl, - String vertexShaderSource, - String fragmentShaderSource) + private static int createProgram(final GL2 gl, + final String vertexShaderSource, + final String fragmentShaderSource) throws GLException { if (vertexShaderSource == null && fragmentShaderSource == null) { @@ -131,12 +133,12 @@ public class Shader { "Either vertexShaderSource or fragmentShaderSource " + "must be specified"); } - + int shaderProgram; int vertexShader = 0; int fragmentShader = 0; - int[] success = new int[1]; - int[] infoLogLength = new int[1]; + final int[] success = new int[1]; + final int[] infoLogLength = new int[1]; if (vertexShaderSource != null) { vertexShader = compileShader(gl, vertexShaderSource, true); @@ -144,7 +146,7 @@ public class Shader { return 0; } } - + if (fragmentShaderSource != null) { fragmentShader = compileShader(gl, fragmentShaderSource, false); if (fragmentShader == 0) { @@ -156,7 +158,7 @@ public class Shader { } // create the program object and attach it to the shader - shaderProgram = gl.glCreateProgramObjectARB(); + shaderProgram = (int) gl.glCreateProgramObjectARB(); // FIXME int-cast old ARM if (vertexShader != 0) { gl.glAttachObjectARB(shaderProgram, vertexShader); // it is now safe to delete the shader object @@ -179,7 +181,7 @@ public class Shader { GL_OBJECT_INFO_LOG_LENGTH_ARB, infoLogLength, 0); if (infoLogLength[0] > 1) { - byte[] infoLog = new byte[1024]; + final byte[] infoLog = new byte[1024]; gl.glGetInfoLogARB(shaderProgram, 1024, null, 0, infoLog, 0); System.err.println("Linker message: " + new String(infoLog)); @@ -192,24 +194,24 @@ public class Shader { return shaderProgram; } - + /** * Compiles the given shader program. If successful, this function returns * a handle to the newly created shader object; otherwise returns 0. - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - private static int compileShader(GL2 gl, String shaderSource, boolean vertex) + private static int compileShader(final GL2 gl, final String shaderSource, final boolean vertex) throws GLException { - int kind = vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; + final int kind = vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; int shader; - int[] success = new int[1]; - int[] infoLogLength = new int[1]; - + final int[] success = new int[1]; + final int[] infoLogLength = new int[1]; + // create the shader object and compile the shader source code - shader = gl.glCreateShaderObjectARB(kind); + shader = (int) gl.glCreateShaderObjectARB(kind); // FIXME int-cast old ARM gl.glShaderSourceARB(shader, 1, new String[] { shaderSource }, null, 0); gl.glCompileShaderARB(shader); gl.glGetObjectParameterivARB(shader, @@ -221,7 +223,7 @@ public class Shader { GL_OBJECT_INFO_LOG_LENGTH_ARB, infoLogLength, 0); if (infoLogLength[0] > 1) { - byte[] infoLog = new byte[1024]; + final byte[] infoLog = new byte[1024]; gl.glGetInfoLogARB(shader, 1024, null, 0, infoLog, 0); System.err.println((vertex ? "Vertex" : "Fragment") + " compile message: " + @@ -232,43 +234,43 @@ public class Shader { gl.glDeleteObjectARB(shader); return 0; } - + return shader; } - + /** * Returns the underlying OpenGL program object handle for this fragment * shader. Most applications will not need to access this, since it is * handled automatically by the enable() and dispose() methods. - * + * * @return the OpenGL program object handle for this fragment shader */ public int getProgramObject() { return id; } - + /** * Enables this shader program in the current GL context's state. - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ public void enable() throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); gl.glUseProgramObjectARB(id); } - + /** * Disables this shader program in the current GL context's state. - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ public void disable() throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); gl.glUseProgramObjectARB(0); } - + /** * Disposes the native resources used by this program object. * @@ -276,7 +278,7 @@ public class Shader { * OpenGL-related errors occurred */ public void dispose() throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); gl.glDeleteObjectARB(id); id = 0; } @@ -290,14 +292,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, int i0) + public void setUniform(final String name, final int i0) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1iARB(loc, i0); } - + /** * Sets the uniform variable of the given name with the provided * integer values. @@ -308,14 +310,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, int i0, int i1) + public void setUniform(final String name, final int i0, final int i1) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2iARB(loc, i0, i1); } - + /** * Sets the uniform variable of the given name with the provided * integer values. @@ -327,14 +329,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, int i0, int i1, int i2) + public void setUniform(final String name, final int i0, final int i1, final int i2) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3iARB(loc, i0, i1, i2); } - + /** * Sets the uniform variable of the given name with the provided * integer values. @@ -347,14 +349,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, int i0, int i1, int i2, int i3) + public void setUniform(final String name, final int i0, final int i1, final int i2, final int i3) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4iARB(loc, i0, i1, i2, i3); } - + /** * Sets the uniform variable of the given name with the provided * float value. @@ -364,14 +366,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, float f0) + public void setUniform(final String name, final float f0) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1fARB(loc, f0); } - + /** * Sets the uniform variable of the given name with the provided * float values. @@ -382,14 +384,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, float f0, float f1) + public void setUniform(final String name, final float f0, final float f1) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2fARB(loc, f0, f1); } - + /** * Sets the uniform variable of the given name with the provided * float values. @@ -401,14 +403,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, float f0, float f1, float f2) + public void setUniform(final String name, final float f0, final float f1, final float f2) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3fARB(loc, f0, f1, f2); } - + /** * Sets the uniform variable of the given name with the provided * float values. @@ -421,14 +423,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, float f0, float f1, float f2, float f3) + public void setUniform(final String name, final float f0, final float f1, final float f2, final float f3) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4fARB(loc, f0, f1, f2, f3); } - + /** * Sets the uniform array variable of the given name with the provided * int array values. @@ -440,14 +442,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray1i(String name, int count, int[] vals, int off) + public void setUniformArray1i(final String name, final int count, final int[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1ivARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * int array values. @@ -459,14 +461,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray2i(String name, int count, int[] vals, int off) + public void setUniformArray2i(final String name, final int count, final int[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2ivARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * int array values. @@ -478,14 +480,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray3i(String name, int count, int[] vals, int off) + public void setUniformArray3i(final String name, final int count, final int[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3ivARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * int array values. @@ -497,11 +499,11 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray4i(String name, int count, int[] vals, int off) + public void setUniformArray4i(final String name, final int count, final int[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4ivARB(loc, count, vals, off); } @@ -516,15 +518,15 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray1f(String name, - int count, float[] vals, int off) + public void setUniformArray1f(final String name, + final int count, final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1fvARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * float array values. @@ -536,15 +538,15 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray2f(String name, - int count, float[] vals, int off) + public void setUniformArray2f(final String name, + final int count, final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2fvARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * float array values. @@ -556,15 +558,15 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray3f(String name, - int count, float[] vals, int off) + public void setUniformArray3f(final String name, + final int count, final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3fvARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * float array values. @@ -576,12 +578,12 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray4f(String name, - int count, float[] vals, int off) + public void setUniformArray4f(final String name, + final int count, final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4fvARB(loc, count, vals, off); } @@ -598,13 +600,13 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformMatrices2f(String name, - int count, boolean transpose, - float[] vals, int off) + public void setUniformMatrices2f(final String name, + final int count, final boolean transpose, + final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix2fvARB(loc, count, transpose, vals, off); } @@ -621,13 +623,13 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformMatrices3f(String name, - int count, boolean transpose, - float[] vals, int off) + public void setUniformMatrices3f(final String name, + final int count, final boolean transpose, + final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix3fvARB(loc, count, transpose, vals, off); } @@ -644,13 +646,13 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformMatrices4f(String name, - int count, boolean transpose, - float[] vals, int off) + public void setUniformMatrices4f(final String name, + final int count, final boolean transpose, + final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix4fvARB(loc, count, transpose, vals, off); } } diff --git a/src/net/java/joglutils/msg/misc/State.java b/src/net/java/joglutils/msg/misc/State.java index b0279b7..948c99a 100644 --- a/src/net/java/joglutils/msg/misc/State.java +++ b/src/net/java/joglutils/msg/misc/State.java @@ -37,9 +37,10 @@ package net.java.joglutils.msg.misc; -import java.util.*; +import java.util.ArrayList; +import java.util.List; -import net.java.joglutils.msg.elements.*; +import net.java.joglutils.msg.elements.Element; /** Represents a collection of state elements, which are updated by actions during scene graph traversal. */ diff --git a/src/net/java/joglutils/msg/nodes/Blend.java b/src/net/java/joglutils/msg/nodes/Blend.java index af95e00..2a8383e 100644 --- a/src/net/java/joglutils/msg/nodes/Blend.java +++ b/src/net/java/joglutils/msg/nodes/Blend.java @@ -37,9 +37,11 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.elements.BlendElement; +import net.java.joglutils.msg.elements.GLBlendElement; +import net.java.joglutils.msg.math.Vec4f; /** Provides control over OpenGL blending modes. */ diff --git a/src/net/java/joglutils/msg/nodes/Camera.java b/src/net/java/joglutils/msg/nodes/Camera.java index 250d3d1..42f70c4 100644 --- a/src/net/java/joglutils/msg/nodes/Camera.java +++ b/src/net/java/joglutils/msg/nodes/Camera.java @@ -37,9 +37,22 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.elements.GLModelMatrixElement; +import net.java.joglutils.msg.elements.GLProjectionMatrixElement; +import net.java.joglutils.msg.elements.GLViewingMatrixElement; +import net.java.joglutils.msg.elements.ModelMatrixElement; +import net.java.joglutils.msg.elements.ProjectionMatrixElement; +import net.java.joglutils.msg.elements.ViewingMatrixElement; +import net.java.joglutils.msg.math.Line; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Rotf; +import net.java.joglutils.msg.math.SingularMatrixException; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; /** Represents a camera which is used to view the scene. The camera should be added to the scene graph before the geometry it is diff --git a/src/net/java/joglutils/msg/nodes/Color4.java b/src/net/java/joglutils/msg/nodes/Color4.java index 8d6696f..7659926 100644 --- a/src/net/java/joglutils/msg/nodes/Color4.java +++ b/src/net/java/joglutils/msg/nodes/Color4.java @@ -37,9 +37,11 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.collections.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.collections.Vec4fCollection; +import net.java.joglutils.msg.elements.ColorElement; +import net.java.joglutils.msg.elements.GLColorElement; /** Represents a set of 4-valued colors which are applied on a per-vertex basis to any drawn polygons. Currently the color can diff --git a/src/net/java/joglutils/msg/nodes/Coordinate3.java b/src/net/java/joglutils/msg/nodes/Coordinate3.java index 7cae14b..2d36636 100644 --- a/src/net/java/joglutils/msg/nodes/Coordinate3.java +++ b/src/net/java/joglutils/msg/nodes/Coordinate3.java @@ -37,9 +37,12 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.collections.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.collections.Vec3fCollection; +import net.java.joglutils.msg.elements.CoordinateElement; +import net.java.joglutils.msg.elements.GLCoordinateElement; /** Represents a set of 3-dimensional vertices which can be assembled into shapes. */ diff --git a/src/net/java/joglutils/msg/nodes/DepthTest.java b/src/net/java/joglutils/msg/nodes/DepthTest.java index 7d3963f..cdd420b 100644 --- a/src/net/java/joglutils/msg/nodes/DepthTest.java +++ b/src/net/java/joglutils/msg/nodes/DepthTest.java @@ -36,10 +36,10 @@ package net.java.joglutils.msg.nodes; -import javax.media.opengl.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.elements.DepthTestElement; +import net.java.joglutils.msg.elements.GLDepthTestElement; /** Represents depth test state. */ public class DepthTest extends Node { diff --git a/src/net/java/joglutils/msg/nodes/Group.java b/src/net/java/joglutils/msg/nodes/Group.java index 05486ab..61522ed 100644 --- a/src/net/java/joglutils/msg/nodes/Group.java +++ b/src/net/java/joglutils/msg/nodes/Group.java @@ -37,9 +37,11 @@ package net.java.joglutils.msg.nodes; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; -import net.java.joglutils.msg.actions.*; +import net.java.joglutils.msg.actions.Action; /** A node which manages other Node instances. */ diff --git a/src/net/java/joglutils/msg/nodes/IndexedTriangleSet.java b/src/net/java/joglutils/msg/nodes/IndexedTriangleSet.java index e244f17..3a79f6a 100644 --- a/src/net/java/joglutils/msg/nodes/IndexedTriangleSet.java +++ b/src/net/java/joglutils/msg/nodes/IndexedTriangleSet.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.nodes; -import java.nio.*; +import java.nio.IntBuffer; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.misc.TriangleCallback; /** An IndexedTriangleSet assembles the coordinates specified by a Coordinate3 node, and any auxiliary nodes such as a diff --git a/src/net/java/joglutils/msg/nodes/Node.java b/src/net/java/joglutils/msg/nodes/Node.java index f2ab658..8761735 100644 --- a/src/net/java/joglutils/msg/nodes/Node.java +++ b/src/net/java/joglutils/msg/nodes/Node.java @@ -37,7 +37,9 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; /** The base class for all nodes in the scene graph. */ diff --git a/src/net/java/joglutils/msg/nodes/OrthographicCamera.java b/src/net/java/joglutils/msg/nodes/OrthographicCamera.java index 28c657a..4eb09d7 100644 --- a/src/net/java/joglutils/msg/nodes/OrthographicCamera.java +++ b/src/net/java/joglutils/msg/nodes/OrthographicCamera.java @@ -37,8 +37,10 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; public class OrthographicCamera extends Camera { private static final float DEFAULT_HEIGHT = 2.0f; diff --git a/src/net/java/joglutils/msg/nodes/PerspectiveCamera.java b/src/net/java/joglutils/msg/nodes/PerspectiveCamera.java index d2eb082..bb634aa 100644 --- a/src/net/java/joglutils/msg/nodes/PerspectiveCamera.java +++ b/src/net/java/joglutils/msg/nodes/PerspectiveCamera.java @@ -37,8 +37,10 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; /** Represents a camera utilizing a perspective projection. <P> diff --git a/src/net/java/joglutils/msg/nodes/Separator.java b/src/net/java/joglutils/msg/nodes/Separator.java index fdebece..49c6f12 100644 --- a/src/net/java/joglutils/msg/nodes/Separator.java +++ b/src/net/java/joglutils/msg/nodes/Separator.java @@ -37,8 +37,8 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.misc.State; /** Represents a push / pop of OpenGL state, "separating" the sub-graph below this separator from the nodes which follow it in diff --git a/src/net/java/joglutils/msg/nodes/ShaderNode.java b/src/net/java/joglutils/msg/nodes/ShaderNode.java index c066079..fd9771d 100644 --- a/src/net/java/joglutils/msg/nodes/ShaderNode.java +++ b/src/net/java/joglutils/msg/nodes/ShaderNode.java @@ -36,17 +36,19 @@ package net.java.joglutils.msg.nodes; -import java.awt.image.*; -import java.io.*; -import java.net.*; -import java.util.*; - -import javax.media.opengl.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.jogamp.opengl.GLException; + +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.GLResetAction; +import net.java.joglutils.msg.elements.GLShaderElement; +import net.java.joglutils.msg.elements.ShaderElement; +import net.java.joglutils.msg.misc.Shader; /** Represents a vertex/fragment shader. */ public class ShaderNode extends Node { diff --git a/src/net/java/joglutils/msg/nodes/Texture2.java b/src/net/java/joglutils/msg/nodes/Texture2.java index 9c4cb60..1d171c9 100644 --- a/src/net/java/joglutils/msg/nodes/Texture2.java +++ b/src/net/java/joglutils/msg/nodes/Texture2.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,27 +28,38 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * */ package net.java.joglutils.msg.nodes; -import java.awt.image.*; -import java.io.*; -import java.net.*; -import java.util.*; - -import javax.media.opengl.*; -import com.sun.opengl.util.awt.*; -import com.sun.opengl.util.texture.*; -import com.sun.opengl.util.texture.awt.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLException; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.util.awt.TextureRenderer; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.texture.awt.AWTTextureIO; + +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.GLResetAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.elements.GLTextureElement; +import net.java.joglutils.msg.elements.TextureElement; /** Represents a two-dimensional texture which can be set up from all of the image sources supported by the JOGL TextureIO classes or @@ -77,8 +88,8 @@ public class Texture2 extends Node { // Disposed Textures and TextureRenderers, used to allow app to be // oblivious and switch back and forth between them - private List<Texture> disposedTextures = new ArrayList<Texture>(); - private List<TextureRenderer> disposedRenderers = new ArrayList<TextureRenderer>(); + private final List<Texture> disposedTextures = new ArrayList<Texture>(); + private final List<TextureRenderer> disposedRenderers = new ArrayList<TextureRenderer>(); static { // Enable the elements this node affects for known actions @@ -99,43 +110,43 @@ public class Texture2 extends Node { /** Initializes this texture from the given file. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(File file, boolean mipmap, String fileSuffix) throws IOException { + public void setTexture(final GLProfile glp, final File file, final boolean mipmap, final String fileSuffix) throws IOException { disposeTextureRenderer(); - data = TextureIO.newTextureData(file, mipmap, fileSuffix); + data = TextureIO.newTextureData(glp, file, mipmap, fileSuffix); dirty = true; } /** Initializes this texture from the given InputStream. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(InputStream stream, boolean mipmap, String fileSuffix) throws IOException { + public void setTexture(final GLProfile glp, final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException { disposeTextureRenderer(); - data = TextureIO.newTextureData(stream, mipmap, fileSuffix); + data = TextureIO.newTextureData(glp, stream, mipmap, fileSuffix); dirty = true; } /** Initializes this texture from the given URL. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(URL url, boolean mipmap, String fileSuffix) throws IOException { + public void setTexture(final GLProfile glp, final URL url, final boolean mipmap, final String fileSuffix) throws IOException { disposeTextureRenderer(); - data = TextureIO.newTextureData(url, mipmap, fileSuffix); + data = TextureIO.newTextureData(glp, url, mipmap, fileSuffix); dirty = true; } /** Initializes this texture from the given BufferedImage. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(BufferedImage image, boolean mipmap) { + public void setTexture(final GLProfile glp, final BufferedImage image, final boolean mipmap) { disposeTextureRenderer(); - data = AWTTextureIO.newTextureData(image, mipmap); + data = AWTTextureIO.newTextureData(glp, image, mipmap); dirty = true; } - + /** Initializes this texture from the given TextureData. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(TextureData data) { + public void setTexture(final TextureData data) { disposeTextureRenderer(); this.data = data; dirty = true; @@ -202,10 +213,10 @@ public class Texture2 extends Node { * @param width the width (in pixels) of the rectangle to be updated * @param height the height (in pixels) of the rectangle to be updated */ - public void updateSubImage(TextureData data, int mipmapLevel, - int dstx, int dsty, - int srcx, int srcy, - int width, int height) { + public void updateSubImage(final TextureData data, final int mipmapLevel, + final int dstx, final int dsty, + final int srcx, final int srcy, + final int width, final int height) { if (textureRenderer != null) { throw new IllegalStateException("May not call updateSubImage if a TextureRenderer has been set"); } @@ -225,7 +236,7 @@ public class Texture2 extends Node { Updates to the TextureRenderer are automatically propagated to the texture as long as <CODE>TextureRenderer.markDirty()</CODE> is used properly. */ - public void initTextureRenderer(int width, int height, boolean alpha) { + public void initTextureRenderer(final int width, final int height, final boolean alpha) { disposeTexture(); textureRenderer = new TextureRenderer(width, height, alpha); } @@ -241,8 +252,8 @@ public class Texture2 extends Node { each frame during rendering. An OpenGL context must be current at the time this method is called or a GLException will be thrown. */ - public Texture getTexture() throws GLException { - lazyDispose(); + public Texture getTexture(final GL gl) throws GLException { + lazyDispose(gl); if (textureRenderer != null) { return textureRenderer.getTexture(); @@ -250,7 +261,7 @@ public class Texture2 extends Node { if (dirty) { if (texture != null) { - texture.dispose(); + texture.destroy(gl); texture = null; } texture = TextureIO.newTexture(data); @@ -258,7 +269,7 @@ public class Texture2 extends Node { dirty = false; } if (subImageDirty) { - texture.updateSubImage(subImageData, + texture.updateSubImage(gl, subImageData, subImageMipmapLevel, subImageDstX, subImageDstY, @@ -272,7 +283,7 @@ public class Texture2 extends Node { } /** Sets the texture environment mode. Default is MODULATE. */ - public void setTexEnvMode(int mode) { + public void setTexEnvMode(final int mode) { if (mode < MODULATE || mode > REPLACE) { throw new IllegalArgumentException("Illegal texture environment mode"); } @@ -285,7 +296,7 @@ public class Texture2 extends Node { return texEnvMode; } - public void doAction(Action action) { + public void doAction(final Action action) { if (TextureElement.isEnabled(action.getState())) { TextureElement.set(action.getState(), this); } @@ -294,10 +305,10 @@ public class Texture2 extends Node { /** Disposes of the OpenGL texture and/or TextureRenderer this Texture2 node refers to. An OpenGL context must be current at the point this method is called. */ - public void dispose() throws GLException { + public void dispose(final GL gl) throws GLException { disposeTexture(); disposeTextureRenderer(); - lazyDispose(); + lazyDispose(gl); data = null; subImageData = null; dirty = false; @@ -309,7 +320,7 @@ public class Texture2 extends Node { know you are using this Texture2 node across the destruction and re-creation of OpenGL contexts and know how to re-initialize the Texture2 from its previous state. */ - public void resetGL(GLResetAction action) { + public void resetGL(final GLResetAction action) { disposeTexture(); disposeTextureRenderer(); synchronized(this) { @@ -340,13 +351,13 @@ public class Texture2 extends Node { } } - private void lazyDispose() { + private void lazyDispose(final GL gl) { while (!disposedTextures.isEmpty()) { Texture t = null; synchronized (this) { t = disposedTextures.remove(disposedTextures.size() - 1); } - t.dispose(); + t.destroy(gl); } while (!disposedRenderers.isEmpty()) { diff --git a/src/net/java/joglutils/msg/nodes/TextureCoordinate2.java b/src/net/java/joglutils/msg/nodes/TextureCoordinate2.java index 2782da1..bf8a952 100644 --- a/src/net/java/joglutils/msg/nodes/TextureCoordinate2.java +++ b/src/net/java/joglutils/msg/nodes/TextureCoordinate2.java @@ -37,9 +37,12 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.collections.*; -import net.java.joglutils.msg.elements.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.collections.Vec2fCollection; +import net.java.joglutils.msg.elements.GLTextureCoordinateElement; +import net.java.joglutils.msg.elements.TextureCoordinateElement; /** Represents a set of 2-dimensional texture coordinates which can be used to texture geometric shapes. */ diff --git a/src/net/java/joglutils/msg/nodes/Transform.java b/src/net/java/joglutils/msg/nodes/Transform.java index 044c1b7..f48ff67 100644 --- a/src/net/java/joglutils/msg/nodes/Transform.java +++ b/src/net/java/joglutils/msg/nodes/Transform.java @@ -37,9 +37,16 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.elements.GLModelMatrixElement; +import net.java.joglutils.msg.elements.GLProjectionMatrixElement; +import net.java.joglutils.msg.elements.GLViewingMatrixElement; +import net.java.joglutils.msg.elements.ModelMatrixElement; +import net.java.joglutils.msg.elements.ProjectionMatrixElement; +import net.java.joglutils.msg.elements.ViewingMatrixElement; +import net.java.joglutils.msg.math.Mat4f; /** Represents a generalized 4x4 matrix transformation. */ diff --git a/src/net/java/joglutils/msg/nodes/TriangleBasedShape.java b/src/net/java/joglutils/msg/nodes/TriangleBasedShape.java index c234695..47457cb 100644 --- a/src/net/java/joglutils/msg/nodes/TriangleBasedShape.java +++ b/src/net/java/joglutils/msg/nodes/TriangleBasedShape.java @@ -37,13 +37,16 @@ package net.java.joglutils.msg.nodes; -import java.util.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.impl.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.elements.ModelMatrixElement; +import net.java.joglutils.msg.impl.RayTriangleIntersection; +import net.java.joglutils.msg.math.Line; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.misc.PickedPoint; +import net.java.joglutils.msg.misc.PrimitiveVertex; +import net.java.joglutils.msg.misc.TriangleCallback; /** The abstract base class for all shapes in the scene graph which render themselves as a collection of triangles. */ diff --git a/src/net/java/joglutils/msg/nodes/TriangleSet.java b/src/net/java/joglutils/msg/nodes/TriangleSet.java index 4659a19..0dcad68 100644 --- a/src/net/java/joglutils/msg/nodes/TriangleSet.java +++ b/src/net/java/joglutils/msg/nodes/TriangleSet.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,25 +28,39 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * */ package net.java.joglutils.msg.nodes; -import java.nio.*; -import java.util.*; - -import javax.media.opengl.*; -import com.sun.opengl.util.texture.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import java.nio.FloatBuffer; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.opengl.fixedfunc.GLPointerFunc; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; + +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.elements.ColorElement; +import net.java.joglutils.msg.elements.CoordinateElement; +import net.java.joglutils.msg.elements.GLTextureCoordinateElement; +import net.java.joglutils.msg.elements.GLTextureElement; +import net.java.joglutils.msg.elements.TextureCoordinateElement; +import net.java.joglutils.msg.elements.TextureElement; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.misc.PrimitiveVertex; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.TriangleCallback; /** A TriangleSet assembles the coordinates specified by a Coordinate3 node, and any auxiliary nodes such as a TextureCoordinate2 node, @@ -56,7 +70,7 @@ public class TriangleSet extends TriangleBasedShape { private int numTriangles; /** Sets the number of triangles this TriangleSet references. */ - public void setNumTriangles(int numTriangles) { + public void setNumTriangles(final int numTriangles) { this.numTriangles = numTriangles; } @@ -65,65 +79,65 @@ public class TriangleSet extends TriangleBasedShape { return numTriangles; } - public void render(GLRenderAction action) { - State state = action.getState(); + public void render(final GLRenderAction action) { + final State state = action.getState(); if (!CoordinateElement.isEnabled(state)) return; if (CoordinateElement.get(state) != null) { // OK, we have coordinates to send down, at least - GL2 gl = action.getGL(); + final GL2 gl = action.getGL(); Texture tex = null; boolean haveTexCoords = false; - if (GLTextureElement.isEnabled(state) && - GLTextureCoordinateElement.isEnabled(state)) { - Texture2 texNode = GLTextureElement.get(state); + if (TextureElement.isEnabled(state) && + TextureCoordinateElement.isEnabled(state)) { + final Texture2 texNode = TextureElement.get(state); if (texNode != null) { - tex = texNode.getTexture(); + tex = texNode.getTexture(gl); } - haveTexCoords = (GLTextureCoordinateElement.get(state) != null); + haveTexCoords = (TextureCoordinateElement.get(state) != null); } if (tex != null) { // Set up the texture matrix to uniformly map [0..1] to the used // portion of the texture image - gl.glMatrixMode(GL2.GL_TEXTURE); + gl.glMatrixMode(GL.GL_TEXTURE); gl.glPushMatrix(); if (gl.isExtensionAvailable("GL_VERSION_1_3")) { gl.glLoadTransposeMatrixf(getTextureMatrix(tex).getRowMajorData(), 0); } else { - float[] tmp = new float[16]; + final float[] tmp = new float[16]; getTextureMatrix(tex).getColumnMajorData(tmp); gl.glLoadMatrixf(tmp, 0); } - gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); } else if (haveTexCoords) { // Want to turn off the use of texture coordinates to avoid errors // FIXME: not 100% sure whether we need to do this, but think we should - gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + gl.glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); } // For now, assume the triangle set and the number of available // coordinates match -- may want to add debugging information // for this later - gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 3 * getNumTriangles()); + gl.glDrawArrays(GL.GL_TRIANGLES, 0, 3 * getNumTriangles()); if (tex != null) { - gl.glMatrixMode(GL2.GL_TEXTURE); + gl.glMatrixMode(GL.GL_TEXTURE); gl.glPopMatrix(); - gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); } else if (haveTexCoords) { // Might want this the next time we render a shape - gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); } } } - public void generateTriangles(Action action, TriangleCallback cb) { - State state = action.getState(); + public void generateTriangles(final Action action, final TriangleCallback cb) { + final State state = action.getState(); FloatBuffer coords = null; FloatBuffer texCoords = null; // FIXME: normals and lighting not supported yet @@ -144,9 +158,9 @@ public class TriangleSet extends TriangleBasedShape { if (ColorElement.isEnabled(state)) { colors = ColorElement.get(state); } - PrimitiveVertex v0 = new PrimitiveVertex(); - PrimitiveVertex v1 = new PrimitiveVertex(); - PrimitiveVertex v2 = new PrimitiveVertex(); + final PrimitiveVertex v0 = new PrimitiveVertex(); + final PrimitiveVertex v1 = new PrimitiveVertex(); + final PrimitiveVertex v2 = new PrimitiveVertex(); v0.setCoord(new Vec3f()); v1.setCoord(new Vec3f()); v2.setCoord(new Vec3f()); @@ -220,14 +234,14 @@ public class TriangleSet extends TriangleBasedShape { // Helper routine for setting up a texture matrix to allow texture // coords in the scene graph to always be specified from (0..1) - private Mat4f textureMatrix = new Mat4f(); - private Mat4f getTextureMatrix(Texture texture) { + private final Mat4f textureMatrix = new Mat4f(); + private Mat4f getTextureMatrix(final Texture texture) { textureMatrix.makeIdent(); - TextureCoords coords = texture.getImageTexCoords(); + final TextureCoords coords = texture.getImageTexCoords(); // Horizontal scale textureMatrix.set(0, 0, coords.right() - coords.left()); // Vertical scale (may be negative if texture needs to be flipped vertically) - float vertScale = coords.top() - coords.bottom(); + final float vertScale = coords.top() - coords.bottom(); textureMatrix.set(1, 1, vertScale); textureMatrix.set(0, 3, coords.left()); textureMatrix.set(1, 3, coords.bottom()); diff --git a/src/net/java/joglutils/msg/test/BasicFetcher.java b/src/net/java/joglutils/msg/test/BasicFetcher.java index 277e7fb..fb6f02b 100644 --- a/src/net/java/joglutils/msg/test/BasicFetcher.java +++ b/src/net/java/joglutils/msg/test/BasicFetcher.java @@ -31,12 +31,22 @@ package net.java.joglutils.msg.test; import java.awt.EventQueue; -import java.awt.image.*; -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.concurrent.*; -import javax.imageio.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import javax.imageio.ImageIO; /** * Basic implementation of Fetcher using ImageIO and a single-threaded diff --git a/src/net/java/joglutils/msg/test/DisplayShelf.java b/src/net/java/joglutils/msg/test/DisplayShelf.java index 1e3bab7..72ca8c8 100644 --- a/src/net/java/joglutils/msg/test/DisplayShelf.java +++ b/src/net/java/joglutils/msg/test/DisplayShelf.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,11 +28,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * */ package net.java.joglutils.msg.test; @@ -42,13 +42,15 @@ import java.awt.DisplayMode; import java.awt.Frame; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; -import java.awt.event.*; -import java.net.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.net.URL; -import javax.swing.*; +import javax.swing.DefaultListModel; -import javax.media.opengl.*; -import javax.media.opengl.awt.*; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.awt.GLCanvas; /** * A test implementing a 3D display shelf component. @@ -57,11 +59,11 @@ import javax.media.opengl.awt.*; */ public class DisplayShelf { - public static void main(String[] args) { - Frame f = new Frame("Display Shelf test"); + public static void main(final String[] args) { + final Frame f = new Frame("Display Shelf test"); f.setLayout(new BorderLayout()); f.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { + public void windowClosing(final WindowEvent e) { new Thread(new Runnable() { public void run() { System.exit(0); @@ -71,7 +73,7 @@ public class DisplayShelf { }); // The images to configure the shelf with - String[] images = { + final String[] images = { "http://download.java.net/media/jogl/builds/ds_tmp/mzi.jsepedzf.200x200-75.jpg", "http://download.java.net/media/jogl/builds/ds_tmp/dj.wvbmknhn.200x200-75.jpg", "http://download.java.net/media/jogl/builds/ds_tmp/mzi.oorrjicu.200x200-75.jpg", @@ -125,23 +127,23 @@ public class DisplayShelf { "http://download.java.net/media/jogl/builds/ds_tmp/dj.zfqfgoas.200x200-75.jpg", "http://download.java.net/media/jogl/builds/ds_tmp/mzi.uswlslxx.200x200-75.jpg" }; - DefaultListModel model = new DefaultListModel(); - for (String str : images) { + final DefaultListModel model = new DefaultListModel(); + for (final String str : images) { try { model.addElement(new URL(str)); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } - DisplayShelfRenderer renderer = new DisplayShelfRenderer(model); - GLCanvas canvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()), null, renderer.getSharedContext(), null); + final DisplayShelfRenderer renderer = new DisplayShelfRenderer(model); + final GLCanvas canvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()), null, null); canvas.setFocusable(true); canvas.addGLEventListener(renderer); f.add(canvas); - GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); - DisplayMode curMode = dev.getDisplayMode(); - int height = (int) (0.5f * curMode.getWidth()); + final GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + final DisplayMode curMode = dev.getDisplayMode(); + final int height = (int) (0.5f * curMode.getWidth()); f.setSize(curMode.getWidth(), height); f.setLocation(0, (curMode.getHeight() - height) / 2); f.setVisible(true); diff --git a/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java b/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java index 5cdffc1..b868a83 100644 --- a/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java +++ b/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,11 +28,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * */ package net.java.joglutils.msg.test; @@ -40,23 +40,48 @@ package net.java.joglutils.msg.test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; -import java.awt.event.*; -import java.awt.image.*; -import java.net.*; -import java.util.*; - -import javax.swing.*; -import javax.swing.event.*; - -import javax.media.opengl.*; -import javax.media.opengl.awt.*; -import com.sun.opengl.util.awt.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.collections.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.ListModel; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLContext; +import com.jogamp.opengl.GLDrawableFactory; +import com.jogamp.opengl.GLEventListener; +import com.jogamp.opengl.GLOffscreenAutoDrawable; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.awt.AWTGLAutoDrawable; +import com.jogamp.opengl.util.awt.TextureRenderer; + +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.collections.Vec2fCollection; +import net.java.joglutils.msg.collections.Vec3fCollection; +import net.java.joglutils.msg.collections.Vec4fCollection; +import net.java.joglutils.msg.math.Rotf; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.misc.Path; +import net.java.joglutils.msg.misc.PickedPoint; +import net.java.joglutils.msg.misc.SystemTime; +import net.java.joglutils.msg.nodes.Blend; +import net.java.joglutils.msg.nodes.Color4; +import net.java.joglutils.msg.nodes.Coordinate3; +import net.java.joglutils.msg.nodes.PerspectiveCamera; +import net.java.joglutils.msg.nodes.Separator; +import net.java.joglutils.msg.nodes.Texture2; +import net.java.joglutils.msg.nodes.TextureCoordinate2; +import net.java.joglutils.msg.nodes.Transform; +import net.java.joglutils.msg.nodes.TriangleSet; /** * A test implementing a 3D display shelf component. This renderer is @@ -66,22 +91,22 @@ import net.java.joglutils.msg.nodes.*; */ public class DisplayShelfRenderer implements GLEventListener { - private float DEFAULT_ASPECT_RATIO = 0.665f; + private final float DEFAULT_ASPECT_RATIO = 0.665f; // This also affects the spacing - private float DEFAULT_HEIGHT = 1.5f; - private float DEFAULT_ON_SCREEN_FRAC = 0.5f; - private float EDITING_ON_SCREEN_FRAC = 0.95f; - private float offsetFrac; + private final float DEFAULT_HEIGHT = 1.5f; + private final float DEFAULT_ON_SCREEN_FRAC = 0.5f; + private final float EDITING_ON_SCREEN_FRAC = 0.95f; + private final float offsetFrac; - private float STACKED_SPACING_FRAC = 0.3f; - private float SELECTED_SPACING_FRAC = 0.6f; - private float EDITED_SPACING_FRAC = 1.5f; + private final float STACKED_SPACING_FRAC = 0.3f; + private final float SELECTED_SPACING_FRAC = 0.6f; + private final float EDITED_SPACING_FRAC = 1.5f; // This is how much we raise the geometry above the floor in single image mode - private float SINGLE_IMAGE_MODE_RAISE_FRAC = 2.0f; + private final float SINGLE_IMAGE_MODE_RAISE_FRAC = 2.0f; // The camera - private PerspectiveCamera camera; + private final PerspectiveCamera camera; static class TitleGraph { Object imageDescriptor; @@ -90,24 +115,24 @@ public class DisplayShelfRenderer implements GLEventListener { Texture2 texture = new Texture2(); Coordinate3 coords = new Coordinate3(); - TitleGraph(Object imageDescriptor) { + TitleGraph(final Object imageDescriptor) { this.imageDescriptor = imageDescriptor; } } // This is used to avoid having to re-initialize textures during // resizes of Swing components - private GLPbuffer sharedPbuffer; + private final GLOffscreenAutoDrawable sharedPbuffer; private boolean firstInit = true; private AWTGLAutoDrawable drawable; - private Separator root; + private final Separator root; private Separator imageRoot; - private Fetcher<Integer> fetcher; - private ListModel model; - private List<TitleGraph> titles = new ArrayList<TitleGraph>(); - private GLRenderAction ra = new GLRenderAction(); + private final Fetcher<Integer> fetcher; + private final ListModel model; + private final List<TitleGraph> titles = new ArrayList<TitleGraph>(); + private final GLRenderAction ra = new GLRenderAction(); private int targetIndex; // This encodes both the current position and the horizontal animation alpha private float currentIndex; @@ -116,7 +141,7 @@ public class DisplayShelfRenderer implements GLEventListener { private float currentZ; private float targetZ; // This is effectively a constant - private float viewingZ; + private final float viewingZ; // This is also currently effectively a constant, though we need to // compute it dynamically for each picture to get it to show up // centered @@ -128,7 +153,7 @@ public class DisplayShelfRenderer implements GLEventListener { // If the difference between the current and target values of any of // the above are > EPSILON, then we will continue repainting private static final float EPSILON = 1.0e-3f; - private SystemTime time; + private final SystemTime time; private boolean animating; private boolean forceRecompute; // Single image mode toggle @@ -144,18 +169,19 @@ public class DisplayShelfRenderer implements GLEventListener { private volatile boolean doneLoading; class DownloadListener implements ProgressListener<Integer> { - public void progressStart(ProgressEvent<Integer> evt) {} - public void progressUpdate(ProgressEvent<Integer> evt) {} - public void progressEnd(ProgressEvent<Integer> evt) { - updateImage(evt.getClientIdentifier()); + public void progressStart(final ProgressEvent<Integer> evt) {} + public void progressUpdate(final ProgressEvent<Integer> evt) {} + public void progressEnd(final ProgressEvent<Integer> evt) { + updateImage(glp, evt.getClientIdentifier()); } } - public DisplayShelfRenderer(ListModel model) { + public DisplayShelfRenderer(final ListModel model) { // Create a small pbuffer with which we share textures and display // lists to avoid having to reload textures during repeated calls // to init() - sharedPbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createGLPbuffer(new GLCapabilities(GLProfile.getDefault()), null, 1, 1, null); + final GLCapabilities glcaps = new GLCapabilities(GLProfile.getDefault()); + sharedPbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createOffscreenAutoDrawable(null, glcaps, null, 8, 8); sharedPbuffer.display(); this.fetcher = new BasicFetcher<Integer>(); @@ -184,7 +210,7 @@ public class DisplayShelfRenderer implements GLEventListener { return sharedPbuffer.getContext(); } - public void setSingleImageMode(boolean singleImageMode, boolean animateTransition) { + public void setSingleImageMode(final boolean singleImageMode, final boolean animateTransition) { this.singleImageMode = singleImageMode; if (!animating) { time.rebase(); @@ -204,7 +230,7 @@ public class DisplayShelfRenderer implements GLEventListener { return titles.size(); } - public void setTargetIndex(int index) { + public void setTargetIndex(final int index) { if (targetIndex == index) return; @@ -222,12 +248,15 @@ public class DisplayShelfRenderer implements GLEventListener { return targetIndex; } - public void init(GLAutoDrawable d) { + private GLProfile glp = null; + + public void init(final GLAutoDrawable d) { this.drawable = (AWTGLAutoDrawable) d; - GL gl = drawable.getGL(); + final GL gl = drawable.getGL(); if (firstInit) { firstInit = false; + glp = gl.getGLProfile(); // Build the scene graph @@ -241,45 +270,45 @@ public class DisplayShelfRenderer implements GLEventListener { imageRoot = new Separator(); // The mirrored images under the floor - Separator mirrorRoot = new Separator(); + final Separator mirrorRoot = new Separator(); - Transform mirrorXform = new Transform(); + final Transform mirrorXform = new Transform(); // Mirror vertically mirrorXform.getTransform().set(1, 1, -1.0f); mirrorRoot.addChild(mirrorXform); // Assume we know what we're doing here with setting per-vertex // colors for each piece of geometry in one shot - Color4 colorNode = new Color4(); - Vec4fCollection colors = new Vec4fCollection(); - Vec4f fadeTop = new Vec4f(0.75f, 0.75f, 0.75f, 0.75f); - Vec4f fadeBot = new Vec4f(0.25f, 0.25f, 0.25f, 0.25f); + final Color4 colorNode = new Color4(); + final Vec4fCollection colors = new Vec4fCollection(); + final Vec4f fadeTop = new Vec4f(0.75f, 0.75f, 0.75f, 0.75f); + final Vec4f fadeBot = new Vec4f(0.25f, 0.25f, 0.25f, 0.25f); // First triangle colors.add(fadeTop); colors.add(fadeTop); colors.add(fadeBot); - // Second triangle + // Second triangle colors.add(fadeTop); colors.add(fadeBot); colors.add(fadeBot); colorNode.setData(colors); mirrorRoot.addChild(colorNode); - TriangleSet tris = new TriangleSet(); + final TriangleSet tris = new TriangleSet(); tris.setNumTriangles(2); for (int i = 0; i < model.getSize(); i++) { - Object obj = model.getElementAt(i); - TitleGraph graph = new TitleGraph(obj); + final Object obj = model.getElementAt(i); + final TitleGraph graph = new TitleGraph(obj); titles.add(graph); computeCoords(graph.coords, DEFAULT_ASPECT_RATIO); graph.xform.getTransform().setTranslation(new Vec3f(i, 0, 0)); - Separator sep = graph.sep; + final Separator sep = graph.sep; sep.addChild(graph.xform); sep.addChild(graph.coords); // Add in the clock texture at the beginning sep.addChild(clockTexture); - TextureCoordinate2 texCoordNode = new TextureCoordinate2(); - Vec2fCollection texCoords = new Vec2fCollection(); + final TextureCoordinate2 texCoordNode = new TextureCoordinate2(); + final Vec2fCollection texCoords = new Vec2fCollection(); // Texture coordinates for two triangles // First triangle texCoords.add(new Vec2f( 1, 1)); @@ -300,46 +329,46 @@ public class DisplayShelfRenderer implements GLEventListener { } // Now produce the floor geometry - float maxSpacing = DEFAULT_HEIGHT * Math.max(STACKED_SPACING_FRAC, Math.max(SELECTED_SPACING_FRAC, EDITED_SPACING_FRAC)); - int i = model.getSize(); - float minx = -i * maxSpacing; - float maxx = 2 * i * maxSpacing; + final float maxSpacing = DEFAULT_HEIGHT * Math.max(STACKED_SPACING_FRAC, Math.max(SELECTED_SPACING_FRAC, EDITED_SPACING_FRAC)); + final int i = model.getSize(); + final float minx = -i * maxSpacing; + final float maxx = 2 * i * maxSpacing; // Furthest back from the camera - float minz = -2 * DEFAULT_HEIGHT; + final float minz = -2 * DEFAULT_HEIGHT; // Assume this will be close enough to cover all of the mirrored geometry - float maxz = DEFAULT_HEIGHT; - Separator floorRoot = new Separator(); - Blend blend = new Blend(); + final float maxz = DEFAULT_HEIGHT; + final Separator floorRoot = new Separator(); + final Blend blend = new Blend(); blend.setEnabled(true); blend.setSourceFunc(Blend.ONE); blend.setDestFunc(Blend.ONE_MINUS_SRC_ALPHA); floorRoot.addChild(blend); - Coordinate3 floorCoords = new Coordinate3(); + final Coordinate3 floorCoords = new Coordinate3(); floorCoords.setData(new Vec3fCollection()); // First triangle floorCoords.getData().add(new Vec3f(maxx, 0, minz)); floorCoords.getData().add(new Vec3f(minx, 0, minz)); floorCoords.getData().add(new Vec3f(minx, 0, maxz)); - // Second triangle + // Second triangle floorCoords.getData().add(new Vec3f(maxx, 0, minz)); floorCoords.getData().add(new Vec3f(minx, 0, maxz)); floorCoords.getData().add(new Vec3f(maxx, 0, maxz)); floorRoot.addChild(floorCoords); // Colors - Vec4f gray = new Vec4f(0.4f, 0.4f, 0.4f, 0.4f); - Vec4f clearGray = new Vec4f(0.0f, 0.0f, 0.0f, 0.0f); - Color4 floorColors = new Color4(); + final Vec4f gray = new Vec4f(0.4f, 0.4f, 0.4f, 0.4f); + final Vec4f clearGray = new Vec4f(0.0f, 0.0f, 0.0f, 0.0f); + final Color4 floorColors = new Color4(); floorColors.setData(new Vec4fCollection()); // First triangle floorColors.getData().add(gray); floorColors.getData().add(gray); floorColors.getData().add(clearGray); - // Second triangle + // Second triangle floorColors.getData().add(gray); floorColors.getData().add(clearGray); floorColors.getData().add(clearGray); floorRoot.addChild(floorColors); - + floorRoot.addChild(tris); // Now set up the overall scene graph @@ -351,7 +380,7 @@ public class DisplayShelfRenderer implements GLEventListener { // Attach listeners (this is only for testing for now) drawable.addMouseListener(new MListener()); drawable.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { + public void keyPressed(final KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_SPACE: setSingleImageMode(!getSingleImageMode(), true); @@ -379,22 +408,22 @@ public class DisplayShelfRenderer implements GLEventListener { // Get the loading started for (int j = 0; j < titles.size(); j++) { - updateImage(j); + updateImage(glp, j); } } } - public void display(GLAutoDrawable drawable) { + public void display(final GLAutoDrawable drawable) { // Recompute position of camera and orientation of images - boolean repaintAgain = recompute(); + final boolean repaintAgain = recompute(); if (!doneLoading) { if (!repaintAgain) { time.update(); } - TextureRenderer rend = clockTexture.getTextureRenderer(); - Graphics2D g = rend.createGraphics(); + final TextureRenderer rend = clockTexture.getTextureRenderer(); + final Graphics2D g = rend.createGraphics(); drawClock(g, (int) (time.time() * 30), 0, 0, rend.getWidth(), rend.getHeight()); g.dispose(); @@ -402,7 +431,7 @@ public class DisplayShelfRenderer implements GLEventListener { } // Redraw - GL gl = drawable.getGL(); + final GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); ra.apply(root); @@ -414,30 +443,30 @@ public class DisplayShelfRenderer implements GLEventListener { } } - public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } - public void dispose(GLAutoDrawable drawable) {} + public void dispose(final GLAutoDrawable drawable) {} //---------------------------------------------------------------------- // Internals only below this point // - private void computeCoords(Coordinate3 coordNode, float aspectRatio) { + private void computeCoords(final Coordinate3 coordNode, final float aspectRatio) { Vec3fCollection coords = coordNode.getData(); if (coords == null) { coords = new Vec3fCollection(); - Vec3f zero = new Vec3f(); + final Vec3f zero = new Vec3f(); for (int i = 0; i < 6; i++) { coords.add(zero); } coordNode.setData(coords); } // Now compute the actual values - Vec3f lowerLeft = new Vec3f(-0.5f * DEFAULT_HEIGHT * aspectRatio, 0, 0); - Vec3f lowerRight = new Vec3f( 0.5f * DEFAULT_HEIGHT * aspectRatio, 0, 0); - Vec3f upperLeft = new Vec3f(-0.5f * DEFAULT_HEIGHT * aspectRatio, DEFAULT_HEIGHT, 0); - Vec3f upperRight = new Vec3f( 0.5f * DEFAULT_HEIGHT * aspectRatio, DEFAULT_HEIGHT, 0); + final Vec3f lowerLeft = new Vec3f(-0.5f * DEFAULT_HEIGHT * aspectRatio, 0, 0); + final Vec3f lowerRight = new Vec3f( 0.5f * DEFAULT_HEIGHT * aspectRatio, 0, 0); + final Vec3f upperLeft = new Vec3f(-0.5f * DEFAULT_HEIGHT * aspectRatio, DEFAULT_HEIGHT, 0); + final Vec3f upperRight = new Vec3f( 0.5f * DEFAULT_HEIGHT * aspectRatio, DEFAULT_HEIGHT, 0); // First triangle coords.set(0, upperRight); coords.set(1, upperLeft); @@ -448,27 +477,27 @@ public class DisplayShelfRenderer implements GLEventListener { coords.set(5, lowerRight); } - private static void drawClock(Graphics2D g, int minsPastMidnight, - int x, int y, int width, int height) { + private static void drawClock(final Graphics2D g, final int minsPastMidnight, + final int x, final int y, final int width, final int height) { g.setColor(Color.DARK_GRAY); g.fillRect(x, y, width, height); g.setColor(Color.GRAY); - int midx = (int) (x + (width / 2.0f)); - int midy = (int) (y + (height / 2.0f)); - int sz = (int) (0.8f * Math.min(width, height)); + final int midx = (int) (x + (width / 2.0f)); + final int midy = (int) (y + (height / 2.0f)); + final int sz = (int) (0.8f * Math.min(width, height)); g.setStroke(new BasicStroke(sz / 20.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER)); - int arcSz = (int) (0.4f * sz); - int smallHandSz = (int) (0.3f * sz); - int bigHandSz = (int) (0.4f * sz); + final int arcSz = (int) (0.4f * sz); + final int smallHandSz = (int) (0.3f * sz); + final int bigHandSz = (int) (0.4f * sz); g.drawRoundRect(midx - (sz / 2), midy - (sz / 2), sz, sz, arcSz, arcSz); - float hour = minsPastMidnight / 60.0f; - int min = minsPastMidnight % 60; - float hourAngle = hour * 2.0f * (float) Math.PI / 12; - float minAngle = min * 2.0f * (float) Math.PI / 60; + final float hour = minsPastMidnight / 60.0f; + final int min = minsPastMidnight % 60; + final float hourAngle = hour * 2.0f * (float) Math.PI / 12; + final float minAngle = min * 2.0f * (float) Math.PI / 60; g.drawLine(midx, midy, midx + (int) (smallHandSz * Math.cos(hourAngle)), @@ -479,13 +508,13 @@ public class DisplayShelfRenderer implements GLEventListener { } private void startClockAnimation() { - Thread clockAnimThread = new Thread(new Runnable() { + final Thread clockAnimThread = new Thread(new Runnable() { public void run() { while (!doneLoading) { drawable.repaint(); try { Thread.sleep(100); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } } } @@ -493,19 +522,19 @@ public class DisplayShelfRenderer implements GLEventListener { clockAnimThread.start(); } - private void updateImage(int id) { - TitleGraph graph = titles.get(id); + private void updateImage(final GLProfile glp, final int id) { + final TitleGraph graph = titles.get(id); // Re-fetch - BufferedImage img = fetcher.getImage(graph.imageDescriptor, + final BufferedImage img = fetcher.getImage(graph.imageDescriptor, Integer.valueOf(id), -1); if (img != null) { // We don't need the image descriptor any more graph.imageDescriptor = null; graph.sep.replaceChild(clockTexture, graph.texture); - graph.texture.setTexture(img, false); + graph.texture.setTexture(glp, img, false); // Figure out the new aspect ratio based on the image's width and height - float aspectRatio = (float) img.getWidth() / (float) img.getHeight(); + final float aspectRatio = (float) img.getWidth() / (float) img.getHeight(); // Compute new coordinates computeCoords(graph.coords, aspectRatio); // Schedule a repaint @@ -514,7 +543,7 @@ public class DisplayShelfRenderer implements GLEventListener { // See whether we're completely done loading boolean done = true; - for (TitleGraph cur : titles) { + for (final TitleGraph cur : titles) { if (cur.imageDescriptor != null) { done = false; break; @@ -525,7 +554,7 @@ public class DisplayShelfRenderer implements GLEventListener { } } - private void recomputeTargetYZ(boolean animate) { + private void recomputeTargetYZ(final boolean animate) { if (singleImageMode) { // Compute a target Y and Z depth based on the image we want to view @@ -558,7 +587,7 @@ public class DisplayShelfRenderer implements GLEventListener { forceRecompute = false; time.update(); - float deltaT = (float) time.deltaT(); + final float deltaT = (float) time.deltaT(); // Make the animation speed independent of frame rate currentIndex = currentIndex + (targetIndex - currentIndex) * deltaT * ANIM_SCALE_FACTOR; @@ -566,32 +595,32 @@ public class DisplayShelfRenderer implements GLEventListener { currentY = currentY + (targetY - currentY) * deltaT * ANIM_SCALE_FACTOR; // An alpha of 0 indicates we're fully in viewing mode // An alpha of 1 indicates we're fully in editing mode - float zAlpha = (currentZ - viewingZ) / (editingZ - viewingZ); + final float zAlpha = (currentZ - viewingZ) / (editingZ - viewingZ); // Recompute the positions and orientations of each title, and the position of the camera - int firstIndex = (int) Math.floor(currentIndex); + final int firstIndex = (int) Math.floor(currentIndex); int secondIndex = (int) Math.ceil(currentIndex); if (secondIndex == firstIndex) { secondIndex = firstIndex + 1; } - float alpha = currentIndex - firstIndex; + final float alpha = currentIndex - firstIndex; int idx = 0; float curPos = 0.0f; - float stackedSpacing = DEFAULT_HEIGHT * (zAlpha * EDITED_SPACING_FRAC + (1.0f - zAlpha) * STACKED_SPACING_FRAC); - float selectedSpacing = DEFAULT_HEIGHT * (zAlpha * EDITED_SPACING_FRAC + (1.0f - zAlpha) * SELECTED_SPACING_FRAC); - float angle = (1.0f - zAlpha) * ROT_ANGLE; - float y = zAlpha * DEFAULT_HEIGHT * SINGLE_IMAGE_MODE_RAISE_FRAC; - Rotf posAngle = new Rotf(Vec3f.Y_AXIS, angle); - Rotf negAngle = new Rotf(Vec3f.Y_AXIS, -angle); + final float stackedSpacing = DEFAULT_HEIGHT * (zAlpha * EDITED_SPACING_FRAC + (1.0f - zAlpha) * STACKED_SPACING_FRAC); + final float selectedSpacing = DEFAULT_HEIGHT * (zAlpha * EDITED_SPACING_FRAC + (1.0f - zAlpha) * SELECTED_SPACING_FRAC); + final float angle = (1.0f - zAlpha) * ROT_ANGLE; + final float y = zAlpha * DEFAULT_HEIGHT * SINGLE_IMAGE_MODE_RAISE_FRAC; + final Rotf posAngle = new Rotf(Vec3f.Y_AXIS, angle); + final Rotf negAngle = new Rotf(Vec3f.Y_AXIS, -angle); float offset = 0; // Only bump the selected title out of the list if we're in viewing mode and close to it if (Math.abs(targetIndex - currentIndex) < 3.0) { offset = (1.0f - zAlpha) * offsetFrac * DEFAULT_HEIGHT; } - for (TitleGraph graph : titles) { + for (final TitleGraph graph : titles) { if (idx < firstIndex) { graph.xform.getTransform().setRotation(posAngle); graph.xform.getTransform().setTranslation(new Vec3f(curPos, y, 0)); @@ -605,7 +634,7 @@ public class DisplayShelfRenderer implements GLEventListener { curPos += (1.0f - alpha) * (selectedSpacing - stackedSpacing); // The camera is glued to this position - float cameraPos = curPos + alpha * selectedSpacing; + final float cameraPos = curPos + alpha * selectedSpacing; // Interpolate graph.xform.getTransform().setRotation(new Rotf(Vec3f.Y_AXIS, alpha * angle)); @@ -636,16 +665,16 @@ public class DisplayShelfRenderer implements GLEventListener { class MListener extends MouseAdapter { RayPickAction ra = new RayPickAction(); - public void mousePressed(MouseEvent e) { + public void mousePressed(final MouseEvent e) { ra.setPoint(e.getX(), e.getY(), e.getComponent()); // Apply to the scene root ra.apply(root); - List<PickedPoint> pickedPoints = ra.getPickedPoints(); + final List<PickedPoint> pickedPoints = ra.getPickedPoints(); Path p = null; if (!pickedPoints.isEmpty()) p = pickedPoints.get(0).getPath(); if (p != null && p.size() > 1) { - int idx = imageRoot.findChild(p.get(p.size() - 2)); + final int idx = imageRoot.findChild(p.get(p.size() - 2)); if (idx >= 0) { setTargetIndex(idx); // Need to keep the slider and this mechanism in sync diff --git a/src/net/java/joglutils/msg/test/Fetcher.java b/src/net/java/joglutils/msg/test/Fetcher.java index d37967c..e8c361c 100644 --- a/src/net/java/joglutils/msg/test/Fetcher.java +++ b/src/net/java/joglutils/msg/test/Fetcher.java @@ -30,7 +30,7 @@ package net.java.joglutils.msg.test; -import java.awt.image.*; +import java.awt.image.BufferedImage; /** * Defines how elements in the ListModel associated with the diff --git a/src/net/java/joglutils/msg/test/Test.java b/src/net/java/joglutils/msg/test/Test.java index d54d31b..da2a6ef 100644 --- a/src/net/java/joglutils/msg/test/Test.java +++ b/src/net/java/joglutils/msg/test/Test.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -28,40 +28,51 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * */ package net.java.joglutils.msg.test; import java.awt.Frame; -import java.awt.event.*; -import java.io.*; - -import javax.media.opengl.*; -import javax.media.opengl.awt.*; -import com.sun.opengl.util.texture.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.collections.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.nodes.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLEventListener; +import com.jogamp.opengl.awt.GLCanvas; + +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.collections.Vec2fCollection; +import net.java.joglutils.msg.collections.Vec3fCollection; +import net.java.joglutils.msg.collections.Vec4fCollection; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.nodes.Color4; +import net.java.joglutils.msg.nodes.Coordinate3; +import net.java.joglutils.msg.nodes.PerspectiveCamera; +import net.java.joglutils.msg.nodes.Separator; +import net.java.joglutils.msg.nodes.TextureCoordinate2; +import net.java.joglutils.msg.nodes.Transform; +import net.java.joglutils.msg.nodes.TriangleSet; /** A very basic test of the Minimal Scene Graph library. */ public class Test { - public static void main(String[] args) { - Frame frame = new Frame("Minimal Scene Graph (MSG) Test"); - GLCanvas canvas = new GLCanvas(); + public static void main(final String[] args) { + final Frame frame = new Frame("Minimal Scene Graph (MSG) Test"); + final GLCanvas canvas = new GLCanvas(); canvas.addGLEventListener(new Listener()); frame.add(canvas); frame.setSize(512, 512); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { + public void windowClosing(final WindowEvent e) { new Thread(new Runnable() { public void run() { System.exit(0); @@ -75,13 +86,13 @@ public class Test { private Separator root; private GLRenderAction renderAction; - public void init(GLAutoDrawable drawable) { + public void init(final GLAutoDrawable drawable) { root = new Separator(); - PerspectiveCamera cam = new PerspectiveCamera(); + final PerspectiveCamera cam = new PerspectiveCamera(); cam.setPosition(new Vec3f(0, 0, 2)); root.addChild(cam); - Coordinate3 coordNode = new Coordinate3(); - Vec3fCollection coords = new Vec3fCollection(); + final Coordinate3 coordNode = new Coordinate3(); + final Vec3fCollection coords = new Vec3fCollection(); // First triangle coords.add(new Vec3f( 1, 1, 0)); coords.add(new Vec3f(-1, 1, 0)); @@ -94,8 +105,8 @@ public class Test { root.addChild(coordNode); // Texture coordinates - TextureCoordinate2 texCoordNode = new TextureCoordinate2(); - Vec2fCollection texCoords = new Vec2fCollection(); + final TextureCoordinate2 texCoordNode = new TextureCoordinate2(); + final Vec2fCollection texCoords = new Vec2fCollection(); // First triangle texCoords.add(new Vec2f( 1, 1)); texCoords.add(new Vec2f( 0, 1)); @@ -108,8 +119,8 @@ public class Test { root.addChild(texCoordNode); // Colors - Color4 colorNode = new Color4(); - Vec4fCollection colors = new Vec4fCollection(); + final Color4 colorNode = new Color4(); + final Vec4fCollection colors = new Vec4fCollection(); // First triangle colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); @@ -121,31 +132,31 @@ public class Test { colorNode.setData(colors); root.addChild(colorNode); - TriangleSet tris = new TriangleSet(); + final TriangleSet tris = new TriangleSet(); tris.setNumTriangles(2); root.addChild(tris); // Testing transforms - Transform xform = new Transform(); + final Transform xform = new Transform(); xform.getTransform().setTranslation(new Vec3f(2, -2, 0)); // xform.getTransform().setRotation(new Rotf(new Vec3f(0, 1, 0), (float) (-Math.PI / 4))); root.addChild(xform); root.addChild(tris); - GL gl = drawable.getGL(); + final GL gl = drawable.getGL(); gl.glEnable(GL.GL_DEPTH_TEST); renderAction = new GLRenderAction(); } - public void display(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); + public void display(final GLAutoDrawable drawable) { + final GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); renderAction.apply(root); } - public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {} - public void dispose(GLAutoDrawable drawable) {} + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int w, final int h) {} + public void dispose(final GLAutoDrawable drawable) {} } } |