From 8c69c7d205ab7b0a5dab24ad110fc375f43bd230 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sun, 19 Jun 2011 19:14:27 +0000 Subject: [PATCH] * Shader now has accelerated access to attribute by using IntMap git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7671 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../renderer/android/OGLESShaderRenderer.java | 4 +-- engine/src/core/com/jme3/shader/Shader.java | 32 +++++++++++-------- .../desktop/com/jme3/util/Screenshots.java | 1 - .../jme3/renderer/lwjgl/LwjglRenderer.java | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java index 45bde8877..0c39ce216 100644 --- a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java +++ b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java @@ -2347,7 +2347,7 @@ public class OGLESShaderRenderer implements Renderer { int programId = context.boundShaderProgram; if (programId > 0) { - Attribute attrib = boundShader.getAttribute(vb.getBufferType().name()); + Attribute attrib = boundShader.getAttribute(vb.getBufferType()); int loc = attrib.getLocation(); if (loc == -1) { @@ -2874,7 +2874,7 @@ public class OGLESShaderRenderer implements Renderer { if (programId > 0) { VertexBuffer[] attribs = context.boundAttribs; - Attribute attrib = boundShader.getAttribute(vb.getBufferType().name()); + Attribute attrib = boundShader.getAttribute(vb.getBufferType()); int loc = attrib.getLocation(); if (loc == -1) { //throw new IllegalArgumentException("Location is invalid for attrib: [" + vb.getBufferType().name() + "]"); diff --git a/engine/src/core/com/jme3/shader/Shader.java b/engine/src/core/com/jme3/shader/Shader.java index 6c6109bdf..4844f639f 100644 --- a/engine/src/core/com/jme3/shader/Shader.java +++ b/engine/src/core/com/jme3/shader/Shader.java @@ -39,6 +39,9 @@ import com.jme3.export.OutputCapsule; import com.jme3.export.Savable; import com.jme3.renderer.GLObject; import com.jme3.renderer.Renderer; +import com.jme3.scene.VertexBuffer; +import com.jme3.util.IntMap; +import com.jme3.util.IntMap.Entry; import com.jme3.util.ListMap; import java.io.IOException; import java.util.ArrayList; @@ -69,7 +72,7 @@ public final class Shader extends GLObject implements Savable { /** * Maps attribute name to the location of the attribute in the shader. */ - private HashMap attribs; + private IntMap attribs; /** * Type of shader. The shader will control the pipeline of it's type. @@ -220,7 +223,7 @@ public final class Shader extends GLObject implements Savable { shaderList = new ArrayList(); // uniforms = new HashMap(); uniforms = new ListMap(); - attribs = new HashMap(); + attribs = new IntMap(); } /** @@ -235,7 +238,7 @@ public final class Shader extends GLObject implements Savable { shaderList = new ArrayList(); // uniforms = new HashMap(); uniforms = new ListMap(); - attribs = new HashMap(); + attribs = new IntMap(); for (ShaderSource source : s.shaderList){ addSource((ShaderSource) source.createDestructableClone()); } @@ -245,7 +248,7 @@ public final class Shader extends GLObject implements Savable { OutputCapsule oc = ex.getCapsule(this); oc.write(language, "language", null); oc.writeSavableArrayList(shaderList, "shaderList", null); - oc.writeStringSavableMap(attribs, "attribs", null); + oc.writeIntSavableMap(attribs, "attribs", null); oc.writeStringSavableMap(uniforms, "uniforms", null); } @@ -253,7 +256,7 @@ public final class Shader extends GLObject implements Savable { InputCapsule ic = im.getCapsule(this); language = ic.readString("language", null); shaderList = ic.readSavableArrayList("shaderList", null); - attribs = (HashMap) ic.readStringSavableMap("attribs", null); + attribs = (IntMap) ic.readIntSavableMap("attribs", null); HashMap uniMap = (HashMap) ic.readStringSavableMap("uniforms", null); uniforms = new ListMap(uniMap); @@ -331,12 +334,13 @@ public final class Shader extends GLObject implements Savable { uniforms.remove(name); } - public Attribute getAttribute(String name){ - Attribute attrib = attribs.get(name); + public Attribute getAttribute(VertexBuffer.Type attribType){ + int ordinal = attribType.ordinal(); + Attribute attrib = attribs.get(ordinal); if (attrib == null){ attrib = new Attribute(); - attrib.name = name; - attribs.put(name, attrib); + attrib.name = attribType.name(); + attribs.put(ordinal, attrib); } return attrib; } @@ -349,9 +353,9 @@ public final class Shader extends GLObject implements Savable { return uniforms; } - public Collection getAttributes() { - return attribs.values(); - } +// public Collection getAttributes() { +// return attribs. +// } public Collection getSources(){ return shaderList; @@ -402,8 +406,8 @@ public final class Shader extends GLObject implements Savable { for (Uniform uniform : uniforms.values()){ uniform.reset(); // fixes issue with re-initialization } - for (Attribute attrib : attribs.values()){ - attrib.location = -2; + for (Entry entry : attribs){ + entry.getValue().location = -2; } } diff --git a/engine/src/desktop/com/jme3/util/Screenshots.java b/engine/src/desktop/com/jme3/util/Screenshots.java index 32c4e430a..5d75f740c 100644 --- a/engine/src/desktop/com/jme3/util/Screenshots.java +++ b/engine/src/desktop/com/jme3/util/Screenshots.java @@ -1,6 +1,5 @@ package com.jme3.util; -import com.jme3.util.*; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.awt.image.WritableRaster; diff --git a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java index 3e839838a..e7870e008 100644 --- a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java +++ b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java @@ -2068,7 +2068,7 @@ public class LwjglRenderer implements Renderer { int programId = context.boundShaderProgram; if (programId > 0) { - Attribute attrib = boundShader.getAttribute(vb.getBufferType().name()); + Attribute attrib = boundShader.getAttribute(vb.getBufferType()); int loc = attrib.getLocation(); if (loc == -1) { return; // not defined