@Override public void putAll(Map<? extends K, ? extends V> map) { for (Entry<? extends K, ? extends V> entry : map.entrySet()){ put(entry.getKey(), entry.getValue()); } // if (map instanceof ListMap){ // ListMap<K, V> listMap = (ListMap<K, V>) map; // ArrayList<ListMapEntry<K, V>> otherEntries = listMap.entries; // for (int i = 0; i < otherEntries.size(); i++){ // ListMapEntry<K, V> entry = otherEntries.get(i); // put(entry.key, entry.value); // } // }else{ // for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()){ // put(entry.getKey(), entry.getValue()); // } // } }
public Uniform getUniform(String name){ assert name.startsWith("m_") || name.startsWith("g_"); Uniform uniform = uniforms.get(name); if (uniform == null){ uniform = new Uniform(); uniform.name = name; uniforms.put(name, uniform); } return uniform; }
/** * Gets or creates a buffer block by the name. * * @param name the buffer block's name. * @return the buffer block. */ public ShaderBufferBlock getBufferBlock(final String name) { assert name.startsWith("m_"); ShaderBufferBlock block = bufferBlocks.get(name); if (block == null) { block = new ShaderBufferBlock(); block.name = name; bufferBlocks.put(name, block); } return block; }
public void addUniformBinding(UniformBinding binding){ String uniformName = "g_" + binding.name(); Uniform uniform = uniforms.get(uniformName); if (uniform == null) { uniform = new Uniform(); uniform.name = uniformName; uniform.binding = binding; uniforms.put(uniformName, uniform); boundUniforms.add(uniform); } }
/** * Clones this material. The result is returned. */ @Override public Material clone() { try { Material mat = (Material) super.clone(); if (additionalState != null) { mat.additionalState = additionalState.clone(); } mat.technique = null; mat.techniques = new HashMap<String, Technique>(); mat.paramValues = new ListMap<String, MatParam>(); for (int i = 0; i < paramValues.size(); i++) { Map.Entry<String, MatParam> entry = paramValues.getEntry(i); mat.paramValues.put(entry.getKey(), entry.getValue().clone()); } mat.sortingId = -1; return mat; } catch (CloneNotSupportedException ex) { throw new AssertionError(ex); } }
/** * Set a texture parameter. * * @param name The name of the parameter * @param type The variable type {@link VarType} * @param value The texture value of the parameter. * * @throws IllegalArgumentException is value is null */ public void setTextureParam(String name, VarType type, Texture value) { if (value == null) { throw new IllegalArgumentException(); } checkSetParam(type, name); MatParamTexture val = getTextureParam(name); if (val == null) { checkTextureParamColorSpace(name, value); paramValues.put(name, new MatParamTexture(type, name, value, null)); } else { val.setTextureValue(value); } if (technique != null) { technique.notifyParamChanged(name, type, value); } // need to recompute sort ID sortingId = -1; }
@Test public void testListMap() { ListMap<String, String> listMap = new ListMap<String, String>(); listMap.put("bob", "hello"); assert "hello".equals(listMap.get("bob")); assert "hello".equals(listMap.remove("bob")); assert listMap.size() == 0; assert listMap.isEmpty(); listMap.put("abc", "1"); listMap.put("def", "2"); listMap.put("ghi", "3"); listMap.put("jkl", "4"); listMap.put("mno", "5"); assert "3".equals(listMap.get("ghi")); assert listMap.size() == 5; assert !listMap.isEmpty(); // check iteration order, should be consistent for (int i = 0; i < listMap.size(); i++) { String expectedValue = Integer.toString(i + 1); String key = listMap.getKey(i); String value = listMap.getValue(i); Entry<String, String> entry = listMap.getEntry(i); assert key.equals(entry.getKey()); assert value.equals(entry.getValue()); assert expectedValue.equals(value); } } }
/** * Pass a parameter to the material shader. * * @param name the name of the parameter defined in the material definition (j3md) * @param type the type of the parameter {@link VarType} * @param value the value of the parameter */ public void setParam(String name, VarType type, Object value) { checkSetParam(type, name); if (type.isTextureType()) { setTextureParam(name, type, (Texture)value); } else { MatParam val = getParam(name); if (val == null) { MatParam paramDef = def.getMaterialParam(name); paramValues.put(name, new MatParam(type, name, value)); } else { val.setValue(value); } if (technique != null) { technique.notifyParamChanged(name, type, value); } } }
} else { checkSetParam(param.getVarType(), param.getName()); paramValues.put(param.getName(), param);
public void putAll(Map<? extends K, ? extends V> map) { for (Entry<? extends K, ? extends V> entry : map.entrySet()){ put(entry.getKey(), entry.getValue()); } // if (map instanceof ListMap){ // ListMap<K, V> listMap = (ListMap<K, V>) map; // ArrayList<ListMapEntry<K, V>> otherEntries = listMap.entries; // for (int i = 0; i < otherEntries.size(); i++){ // ListMapEntry<K, V> entry = otherEntries.get(i); // put(entry.key, entry.value); // } // }else{ // for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()){ // put(entry.getKey(), entry.getValue()); // } // } }
@Override public void putAll(Map<? extends K, ? extends V> map) { for (Entry<? extends K, ? extends V> entry : map.entrySet()){ put(entry.getKey(), entry.getValue()); } // if (map instanceof ListMap){ // ListMap<K, V> listMap = (ListMap<K, V>) map; // ArrayList<ListMapEntry<K, V>> otherEntries = listMap.entries; // for (int i = 0; i < otherEntries.size(); i++){ // ListMapEntry<K, V> entry = otherEntries.get(i); // put(entry.key, entry.value); // } // }else{ // for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()){ // put(entry.getKey(), entry.getValue()); // } // } }
/** * Adds a new material parameter. * * @param type Type of the parameter * @param name Name of the parameter * @param value Default value of the parameter * @param ffBinding Fixed function binding for the parameter */ public void addMaterialParam(VarType type, String name, Object value, FixedFuncBinding ffBinding) { matParams.put(name, new MatParam(type, name, value, ffBinding)); }
public Uniform getUniform(String name){ assert name.startsWith("m_") || name.startsWith("g_"); Uniform uniform = uniforms.get(name); if (uniform == null){ uniform = new Uniform(); uniform.name = name; uniforms.put(name, uniform); } return uniform; }
public Uniform getUniform(String name){ Uniform uniform = uniforms.get(name); if (uniform == null){ uniform = new Uniform(); uniform.name = name; uniforms.put(name, uniform); } return uniform; }
public void addUniformBinding(UniformBinding binding){ String uniformName = "g_" + binding.name(); Uniform uniform = uniforms.get(uniformName); if (uniform == null) { uniform = new Uniform(); uniform.name = uniformName; uniform.binding = binding; uniforms.put(uniformName, uniform); boundUniforms.add(uniform); } }
/** * Clones this material. The result is returned. */ @Override public Material clone() { try { Material mat = (Material) super.clone(); if (additionalState != null) { mat.additionalState = additionalState.clone(); } mat.technique = null; mat.techniques = new HashMap<String, Technique>(); mat.techniqueArray = null; mat.paramValues = new ListMap<String, MatParam>(); for (int i = 0; i < paramValues.size(); i++) { Map.Entry<String, MatParam> entry = paramValues.getEntry(i); mat.paramValues.put(entry.getKey(), entry.getValue().clone()); } return mat; } catch (CloneNotSupportedException ex) { throw new AssertionError(); } }
/** * Clones this material. The result is returned. */ @Override public Material clone() { try { Material mat = (Material) super.clone(); if (additionalState != null) { mat.additionalState = additionalState.clone(); } mat.technique = null; mat.techniques = new HashMap<String, Technique>(); mat.paramValues = new ListMap<String, MatParam>(); for (int i = 0; i < paramValues.size(); i++) { Map.Entry<String, MatParam> entry = paramValues.getEntry(i); mat.paramValues.put(entry.getKey(), entry.getValue().clone()); } mat.sortingId = -1; return mat; } catch (CloneNotSupportedException ex) { throw new AssertionError(ex); } }
/** * Set a texture parameter. * * @param name The name of the parameter * @param type The variable type {@link VarType} * @param value The texture value of the parameter. * * @throws IllegalArgumentException is value is null */ public void setTextureParam(String name, VarType type, Texture value) { if (value == null) { throw new IllegalArgumentException(); } checkSetParam(type, name); MatParamTexture val = getTextureParam(name); if (val == null) { checkTextureParamColorSpace(name, value); paramValues.put(name, new MatParamTexture(type, name, value, null)); } else { val.setTextureValue(value); } if (technique != null) { technique.notifyParamChanged(name, type, value); } // need to recompute sort ID sortingId = -1; }
private void clearTextureParam(String name) { name = checkSetParam(null, name); MatParamTexture val = getTextureParam(name); if (val == null) { throw new IllegalArgumentException("The given texture for parameter \"" + name + "\" is null."); } int texUnit = val.getUnit(); // paramValues.remove(name); paramValues.put(name, null); nextTexUnit--; for (MatParam param : paramValues.values()) { if (param instanceof MatParamTexture) { MatParamTexture texParam = (MatParamTexture) param; if (texParam.getUnit() > texUnit) { texParam.setUnit(texParam.getUnit() - 1); } } } sortingId = -1; }
/** * Pass a parameter to the material shader. * * @param name the name of the parameter defined in the material definition (j3md) * @param type the type of the parameter {@link VarType} * @param value the value of the parameter */ public void setParam(String name, VarType type, Object value) { checkSetParam(type, name); if (type.isTextureType()) { setTextureParam(name, type, (Texture)value); } else { MatParam val = getParam(name); if (val == null) { MatParam paramDef = def.getMaterialParam(name); paramValues.put(name, new MatParam(type, name, value)); } else { val.setValue(value); } if (technique != null) { technique.notifyParamChanged(name, type, value); } } }