From 447fd87d2cba353d3697ceabd91f592e4aba6d19 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sat, 18 Jun 2011 06:45:06 +0000 Subject: [PATCH] * Fixed heavy string allocation in Technique/MatParam due to m_ prefix workaround git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7656 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/material/MatParam.java | 13 ++++++++++++- .../src/core/com/jme3/material/MatParamTexture.java | 2 +- engine/src/core/com/jme3/material/Technique.java | 3 --- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/engine/src/core/com/jme3/material/MatParam.java b/engine/src/core/com/jme3/material/MatParam.java index 46cc0a293..253b98d58 100644 --- a/engine/src/core/com/jme3/material/MatParam.java +++ b/engine/src/core/com/jme3/material/MatParam.java @@ -60,6 +60,7 @@ public class MatParam implements Savable, Cloneable { protected VarType type; protected String name; + protected String prefixedName; protected Object value; protected FixedFuncBinding ffBinding; @@ -69,6 +70,7 @@ public class MatParam implements Savable, Cloneable { public MatParam(VarType type, String name, Object value, FixedFuncBinding ffBinding){ this.type = type; this.name = name; + this.prefixedName = "m_" + name; this.value = value; this.ffBinding = ffBinding; } @@ -105,6 +107,15 @@ public class MatParam implements Savable, Cloneable { return name; } + /** + * Returns the name with "m_" prefixed to it. + * + * @return the name with "m_" prefixed to it + */ + public String getPrefixedName() { + return prefixedName; + } + /** * Used internally * @param name @@ -140,7 +151,7 @@ public class MatParam implements Savable, Cloneable { void apply(Renderer r, Technique technique) { TechniqueDef techDef = technique.getDef(); if (techDef.isUsingShaders()) { - technique.updateUniformParam(getName(), getVarType(), getValue(), true); + technique.updateUniformParam(getPrefixedName(), getVarType(), getValue(), true); } if (ffBinding != null && r instanceof GL1Renderer){ ((GL1Renderer)r).setFixedFuncBinding(ffBinding, getValue()); diff --git a/engine/src/core/com/jme3/material/MatParamTexture.java b/engine/src/core/com/jme3/material/MatParamTexture.java index de6021055..fc8b4697e 100644 --- a/engine/src/core/com/jme3/material/MatParamTexture.java +++ b/engine/src/core/com/jme3/material/MatParamTexture.java @@ -45,7 +45,7 @@ public class MatParamTexture extends MatParam { TechniqueDef techDef = technique.getDef(); r.setTexture(getUnit(), getTextureValue()); if (techDef.isUsingShaders()) { - technique.updateUniformParam(getName(), getVarType(), getUnit(), true); + technique.updateUniformParam(getPrefixedName(), getVarType(), getUnit(), true); } } diff --git a/engine/src/core/com/jme3/material/Technique.java b/engine/src/core/com/jme3/material/Technique.java index be6be58e9..6ec0f6671 100644 --- a/engine/src/core/com/jme3/material/Technique.java +++ b/engine/src/core/com/jme3/material/Technique.java @@ -149,9 +149,6 @@ public class Technique implements Savable { } void updateUniformParam(String paramName, VarType type, Object value, boolean ifNotOwner) { - if (!paramName.startsWith("m_")) { - paramName = "m_" + paramName; - } Uniform u = shader.getUniform(paramName); // if (ifNotOwner && u.getLastChanger() == owner)