From 316004096ddb50ab79a3e9a1ae193fa75f8a157e Mon Sep 17 00:00:00 2001 From: Christopher Campbell Date: Wed, 4 Apr 2007 07:49:21 +0000 Subject: Hacked in support for setUniform() in ShaderNode. When I say hack, I mean it. Will clean it up later. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/joglutils/trunk@58 83d24430-9974-4f80-8418-2cc3294053b9 --- src/net/java/joglutils/msg/elements/GLShaderElement.java | 14 ++++++++++++++ src/net/java/joglutils/msg/nodes/ShaderNode.java | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/src/net/java/joglutils/msg/elements/GLShaderElement.java b/src/net/java/joglutils/msg/elements/GLShaderElement.java index a7abbc6..cf28c97 100644 --- a/src/net/java/joglutils/msg/elements/GLShaderElement.java +++ b/src/net/java/joglutils/msg/elements/GLShaderElement.java @@ -36,9 +36,12 @@ package net.java.joglutils.msg.elements; +import java.util.*; + 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.*; @@ -87,6 +90,17 @@ public class GLShaderElement extends ShaderElement { } if (curShader != null) { curShader.enable(); + + // FIXME: the following is a big hack... + Map fMap = shader.getUniformfMap(); + if (!fMap.isEmpty()) { + for (String name : fMap.keySet()) { + Vec4f val = fMap.get(name); + //curShader.setUniform(name, val.x(), val.y(), val.z(), val.w()); + curShader.setUniform(name, val.x()); + fMap.clear(); + } + } } } } diff --git a/src/net/java/joglutils/msg/nodes/ShaderNode.java b/src/net/java/joglutils/msg/nodes/ShaderNode.java index 73154ee..ab9ea60 100644 --- a/src/net/java/joglutils/msg/nodes/ShaderNode.java +++ b/src/net/java/joglutils/msg/nodes/ShaderNode.java @@ -45,6 +45,7 @@ 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.*; /** Represents a vertex/fragment shader. */ @@ -78,6 +79,14 @@ public class ShaderNode extends Node { this.fragmentShaderCode = fragmentShaderCode; } + private Map fMap = new HashMap(); + public void setUniform(String name, float val) { + fMap.put(name, new Vec4f(val, val, val, val)); + } + public Map getUniformfMap() { + return fMap; + } + /** Fetches the Shader object associated with this ShaderNode. It is required to call this each frame during rendering. An OpenGL context must be current at the time this method is -- cgit v1.2.3