Added support for int arrays uniforms. thanks to abies.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10495 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
3d76821f02
commit
05e080100e
@ -643,6 +643,7 @@ public class OGLESShaderRenderer implements Renderer {
|
|||||||
|
|
||||||
uniform.clearUpdateNeeded();
|
uniform.clearUpdateNeeded();
|
||||||
FloatBuffer fb;
|
FloatBuffer fb;
|
||||||
|
IntBuffer ib;
|
||||||
switch (uniform.getVarType()) {
|
switch (uniform.getVarType()) {
|
||||||
case Float:
|
case Float:
|
||||||
Float f = (Float) uniform.getValue();
|
Float f = (Float) uniform.getValue();
|
||||||
@ -683,6 +684,10 @@ public class OGLESShaderRenderer implements Renderer {
|
|||||||
assert fb.remaining() == 16;
|
assert fb.remaining() == 16;
|
||||||
GLES20.glUniformMatrix4fv(loc, 1, false, fb);
|
GLES20.glUniformMatrix4fv(loc, 1, false, fb);
|
||||||
break;
|
break;
|
||||||
|
case IntArray:
|
||||||
|
ib = (IntBuffer) uniform.getValue();
|
||||||
|
GLES20.glUniform1iv(loc, ib.limit(), ib);
|
||||||
|
break;
|
||||||
case FloatArray:
|
case FloatArray:
|
||||||
fb = (FloatBuffer) uniform.getValue();
|
fb = (FloatBuffer) uniform.getValue();
|
||||||
GLES20.glUniform1fv(loc, fb.limit(), fb);
|
GLES20.glUniform1fv(loc, fb.limit(), fb);
|
||||||
|
@ -1,340 +1,350 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
* met:
|
* met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.shader;
|
package com.jme3.shader;
|
||||||
|
|
||||||
import com.jme3.math.*;
|
import com.jme3.math.*;
|
||||||
import com.jme3.util.BufferUtils;
|
import com.jme3.util.BufferUtils;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
public class Uniform extends ShaderVariable {
|
|
||||||
|
public class Uniform extends ShaderVariable {
|
||||||
private static final Integer ZERO_INT = Integer.valueOf(0);
|
|
||||||
private static final Float ZERO_FLT = Float.valueOf(0);
|
private static final Integer ZERO_INT = Integer.valueOf(0);
|
||||||
private static final FloatBuffer ZERO_BUF = BufferUtils.createFloatBuffer(4*4);
|
private static final Float ZERO_FLT = Float.valueOf(0);
|
||||||
|
private static final FloatBuffer ZERO_BUF = BufferUtils.createFloatBuffer(4*4);
|
||||||
/**
|
|
||||||
* Currently set value of the uniform.
|
/**
|
||||||
*/
|
* Currently set value of the uniform.
|
||||||
protected Object value = null;
|
*/
|
||||||
|
protected Object value = null;
|
||||||
/**
|
|
||||||
* For arrays or matrices, efficient format
|
/**
|
||||||
* that can be sent to GL faster.
|
* For arrays or matrices, efficient format
|
||||||
*/
|
* that can be sent to GL faster.
|
||||||
protected FloatBuffer multiData = null;
|
*/
|
||||||
|
protected FloatBuffer multiData = null;
|
||||||
/**
|
|
||||||
* Type of uniform
|
/**
|
||||||
*/
|
* Type of uniform
|
||||||
protected VarType varType;
|
*/
|
||||||
|
protected VarType varType;
|
||||||
/**
|
|
||||||
* Binding to a renderer value, or null if user-defined uniform
|
/**
|
||||||
*/
|
* Binding to a renderer value, or null if user-defined uniform
|
||||||
protected UniformBinding binding;
|
*/
|
||||||
|
protected UniformBinding binding;
|
||||||
/**
|
|
||||||
* Used to track which uniforms to clear to avoid
|
/**
|
||||||
* values leaking from other materials that use that shader.
|
* Used to track which uniforms to clear to avoid
|
||||||
*/
|
* values leaking from other materials that use that shader.
|
||||||
protected boolean setByCurrentMaterial = false;
|
*/
|
||||||
|
protected boolean setByCurrentMaterial = false;
|
||||||
@Override
|
|
||||||
public String toString(){
|
@Override
|
||||||
StringBuilder sb = new StringBuilder();
|
public String toString(){
|
||||||
sb.append("Uniform[name=");
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(name);
|
sb.append("Uniform[name=");
|
||||||
if (varType != null){
|
sb.append(name);
|
||||||
sb.append(", type=");
|
if (varType != null){
|
||||||
sb.append(varType);
|
sb.append(", type=");
|
||||||
sb.append(", value=");
|
sb.append(varType);
|
||||||
sb.append(value);
|
sb.append(", value=");
|
||||||
}else{
|
sb.append(value);
|
||||||
sb.append(", value=<not set>");
|
}else{
|
||||||
}
|
sb.append(", value=<not set>");
|
||||||
sb.append("]");
|
}
|
||||||
return sb.toString();
|
sb.append("]");
|
||||||
}
|
return sb.toString();
|
||||||
|
}
|
||||||
public void setBinding(UniformBinding binding){
|
|
||||||
this.binding = binding;
|
public void setBinding(UniformBinding binding){
|
||||||
}
|
this.binding = binding;
|
||||||
|
}
|
||||||
public UniformBinding getBinding(){
|
|
||||||
return binding;
|
public UniformBinding getBinding(){
|
||||||
}
|
return binding;
|
||||||
|
}
|
||||||
public VarType getVarType() {
|
|
||||||
return varType;
|
public VarType getVarType() {
|
||||||
}
|
return varType;
|
||||||
|
}
|
||||||
public Object getValue(){
|
|
||||||
return value;
|
public Object getValue(){
|
||||||
}
|
return value;
|
||||||
|
}
|
||||||
public boolean isSetByCurrentMaterial() {
|
|
||||||
return setByCurrentMaterial;
|
public boolean isSetByCurrentMaterial() {
|
||||||
}
|
return setByCurrentMaterial;
|
||||||
|
}
|
||||||
public void clearSetByCurrentMaterial(){
|
|
||||||
setByCurrentMaterial = false;
|
public void clearSetByCurrentMaterial(){
|
||||||
}
|
setByCurrentMaterial = false;
|
||||||
|
}
|
||||||
private static void setVector4(Vector4f vec, Object value) {
|
|
||||||
if (value instanceof ColorRGBA) {
|
private static void setVector4(Vector4f vec, Object value) {
|
||||||
ColorRGBA color = (ColorRGBA) value;
|
if (value instanceof ColorRGBA) {
|
||||||
vec.set(color.r, color.g, color.b, color.a);
|
ColorRGBA color = (ColorRGBA) value;
|
||||||
} else if (value instanceof Quaternion) {
|
vec.set(color.r, color.g, color.b, color.a);
|
||||||
Quaternion quat = (Quaternion) value;
|
} else if (value instanceof Quaternion) {
|
||||||
vec.set(quat.getX(), quat.getY(), quat.getZ(), quat.getW());
|
Quaternion quat = (Quaternion) value;
|
||||||
} else if (value instanceof Vector4f) {
|
vec.set(quat.getX(), quat.getY(), quat.getZ(), quat.getW());
|
||||||
Vector4f vec4 = (Vector4f) value;
|
} else if (value instanceof Vector4f) {
|
||||||
vec.set(vec4);
|
Vector4f vec4 = (Vector4f) value;
|
||||||
} else{
|
vec.set(vec4);
|
||||||
throw new IllegalArgumentException();
|
} else{
|
||||||
}
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public void clearValue(){
|
|
||||||
updateNeeded = true;
|
public void clearValue(){
|
||||||
|
updateNeeded = true;
|
||||||
if (multiData != null){
|
|
||||||
ZERO_BUF.clear();
|
if (multiData != null){
|
||||||
multiData.clear();
|
multiData.clear();
|
||||||
|
|
||||||
while (multiData.remaining() > 0){
|
while (multiData.remaining() > 0){
|
||||||
ZERO_BUF.limit( Math.min(multiData.remaining(), 16) );
|
ZERO_BUF.clear();
|
||||||
multiData.put(ZERO_BUF);
|
ZERO_BUF.limit( Math.min(multiData.remaining(), 16) );
|
||||||
}
|
multiData.put(ZERO_BUF);
|
||||||
|
}
|
||||||
multiData.clear();
|
|
||||||
|
multiData.clear();
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if (varType == null) {
|
|
||||||
return;
|
if (varType == null) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
switch (varType){
|
|
||||||
case Int:
|
switch (varType){
|
||||||
this.value = ZERO_INT;
|
case Int:
|
||||||
break;
|
this.value = ZERO_INT;
|
||||||
case Boolean:
|
break;
|
||||||
this.value = Boolean.FALSE;
|
case Boolean:
|
||||||
break;
|
this.value = Boolean.FALSE;
|
||||||
case Float:
|
break;
|
||||||
this.value = ZERO_FLT;
|
case Float:
|
||||||
break;
|
this.value = ZERO_FLT;
|
||||||
case Vector2:
|
break;
|
||||||
this.value = Vector2f.ZERO;
|
case Vector2:
|
||||||
break;
|
this.value = Vector2f.ZERO;
|
||||||
case Vector3:
|
break;
|
||||||
this.value = Vector3f.ZERO;
|
case Vector3:
|
||||||
break;
|
this.value = Vector3f.ZERO;
|
||||||
case Vector4:
|
break;
|
||||||
this.value = Vector4f.ZERO;
|
case Vector4:
|
||||||
break;
|
this.value = Vector4f.ZERO;
|
||||||
default:
|
break;
|
||||||
// won't happen because those are either textures
|
default:
|
||||||
// or multidata types
|
// won't happen because those are either textures
|
||||||
}
|
// or multidata types
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public void setValue(VarType type, Object value){
|
|
||||||
if (location == LOC_NOT_DEFINED) {
|
public void setValue(VarType type, Object value){
|
||||||
return;
|
if (location == LOC_NOT_DEFINED) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if (varType != null && varType != type) {
|
|
||||||
throw new IllegalArgumentException("Expected a " + varType.name() + " value!");
|
if (varType != null && varType != type) {
|
||||||
}
|
throw new IllegalArgumentException("Expected a " + varType.name() + " value!");
|
||||||
|
}
|
||||||
if (value == null) {
|
|
||||||
throw new NullPointerException();
|
if (value == null) {
|
||||||
}
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
setByCurrentMaterial = true;
|
|
||||||
|
setByCurrentMaterial = true;
|
||||||
switch (type){
|
|
||||||
case Matrix3:
|
switch (type){
|
||||||
Matrix3f m3 = (Matrix3f) value;
|
case Matrix3:
|
||||||
if (multiData == null) {
|
Matrix3f m3 = (Matrix3f) value;
|
||||||
multiData = BufferUtils.createFloatBuffer(9);
|
if (multiData == null) {
|
||||||
}
|
multiData = BufferUtils.createFloatBuffer(9);
|
||||||
m3.fillFloatBuffer(multiData, true);
|
}
|
||||||
multiData.clear();
|
m3.fillFloatBuffer(multiData, true);
|
||||||
break;
|
multiData.clear();
|
||||||
case Matrix4:
|
break;
|
||||||
Matrix4f m4 = (Matrix4f) value;
|
case Matrix4:
|
||||||
if (multiData == null) {
|
Matrix4f m4 = (Matrix4f) value;
|
||||||
multiData = BufferUtils.createFloatBuffer(16);
|
if (multiData == null) {
|
||||||
}
|
multiData = BufferUtils.createFloatBuffer(16);
|
||||||
m4.fillFloatBuffer(multiData, true);
|
}
|
||||||
multiData.clear();
|
m4.fillFloatBuffer(multiData, true);
|
||||||
break;
|
multiData.clear();
|
||||||
case FloatArray:
|
break;
|
||||||
float[] fa = (float[]) value;
|
case IntArray:
|
||||||
if (multiData == null) {
|
int[] ia = (int[]) value;
|
||||||
multiData = BufferUtils.createFloatBuffer(fa);
|
if (this.value == null) {
|
||||||
} else {
|
this.value = BufferUtils.createIntBuffer(ia);
|
||||||
multiData = BufferUtils.ensureLargeEnough(multiData, fa.length);
|
} else {
|
||||||
}
|
this.value = BufferUtils.ensureLargeEnough((IntBuffer)this.value, ia.length);
|
||||||
multiData.put(fa);
|
}
|
||||||
multiData.clear();
|
((IntBuffer)this.value).clear();
|
||||||
break;
|
break;
|
||||||
case Vector2Array:
|
case FloatArray:
|
||||||
Vector2f[] v2a = (Vector2f[]) value;
|
float[] fa = (float[]) value;
|
||||||
if (multiData == null) {
|
if (multiData == null) {
|
||||||
multiData = BufferUtils.createFloatBuffer(v2a);
|
multiData = BufferUtils.createFloatBuffer(fa);
|
||||||
} else {
|
} else {
|
||||||
multiData = BufferUtils.ensureLargeEnough(multiData, v2a.length * 2);
|
multiData = BufferUtils.ensureLargeEnough(multiData, fa.length);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < v2a.length; i++) {
|
multiData.put(fa);
|
||||||
BufferUtils.setInBuffer(v2a[i], multiData, i);
|
multiData.clear();
|
||||||
}
|
break;
|
||||||
multiData.clear();
|
case Vector2Array:
|
||||||
break;
|
Vector2f[] v2a = (Vector2f[]) value;
|
||||||
case Vector3Array:
|
if (multiData == null) {
|
||||||
Vector3f[] v3a = (Vector3f[]) value;
|
multiData = BufferUtils.createFloatBuffer(v2a);
|
||||||
if (multiData == null) {
|
} else {
|
||||||
multiData = BufferUtils.createFloatBuffer(v3a);
|
multiData = BufferUtils.ensureLargeEnough(multiData, v2a.length * 2);
|
||||||
} else {
|
}
|
||||||
multiData = BufferUtils.ensureLargeEnough(multiData, v3a.length * 3);
|
for (int i = 0; i < v2a.length; i++) {
|
||||||
}
|
BufferUtils.setInBuffer(v2a[i], multiData, i);
|
||||||
for (int i = 0; i < v3a.length; i++) {
|
}
|
||||||
BufferUtils.setInBuffer(v3a[i], multiData, i);
|
multiData.clear();
|
||||||
}
|
break;
|
||||||
multiData.clear();
|
case Vector3Array:
|
||||||
break;
|
Vector3f[] v3a = (Vector3f[]) value;
|
||||||
case Vector4Array:
|
if (multiData == null) {
|
||||||
Vector4f[] v4a = (Vector4f[]) value;
|
multiData = BufferUtils.createFloatBuffer(v3a);
|
||||||
if (multiData == null) {
|
} else {
|
||||||
multiData = BufferUtils.createFloatBuffer(v4a);
|
multiData = BufferUtils.ensureLargeEnough(multiData, v3a.length * 3);
|
||||||
} else {
|
}
|
||||||
multiData = BufferUtils.ensureLargeEnough(multiData, v4a.length * 4);
|
for (int i = 0; i < v3a.length; i++) {
|
||||||
}
|
BufferUtils.setInBuffer(v3a[i], multiData, i);
|
||||||
for (int i = 0; i < v4a.length; i++) {
|
}
|
||||||
BufferUtils.setInBuffer(v4a[i], multiData, i);
|
multiData.clear();
|
||||||
}
|
break;
|
||||||
multiData.clear();
|
case Vector4Array:
|
||||||
break;
|
Vector4f[] v4a = (Vector4f[]) value;
|
||||||
case Matrix3Array:
|
if (multiData == null) {
|
||||||
Matrix3f[] m3a = (Matrix3f[]) value;
|
multiData = BufferUtils.createFloatBuffer(v4a);
|
||||||
if (multiData == null) {
|
} else {
|
||||||
multiData = BufferUtils.createFloatBuffer(m3a.length * 9);
|
multiData = BufferUtils.ensureLargeEnough(multiData, v4a.length * 4);
|
||||||
} else {
|
}
|
||||||
multiData = BufferUtils.ensureLargeEnough(multiData, m3a.length * 9);
|
for (int i = 0; i < v4a.length; i++) {
|
||||||
}
|
BufferUtils.setInBuffer(v4a[i], multiData, i);
|
||||||
for (int i = 0; i < m3a.length; i++) {
|
}
|
||||||
m3a[i].fillFloatBuffer(multiData, true);
|
multiData.clear();
|
||||||
}
|
break;
|
||||||
multiData.clear();
|
case Matrix3Array:
|
||||||
break;
|
Matrix3f[] m3a = (Matrix3f[]) value;
|
||||||
case Matrix4Array:
|
if (multiData == null) {
|
||||||
Matrix4f[] m4a = (Matrix4f[]) value;
|
multiData = BufferUtils.createFloatBuffer(m3a.length * 9);
|
||||||
if (multiData == null) {
|
} else {
|
||||||
multiData = BufferUtils.createFloatBuffer(m4a.length * 16);
|
multiData = BufferUtils.ensureLargeEnough(multiData, m3a.length * 9);
|
||||||
} else {
|
}
|
||||||
multiData = BufferUtils.ensureLargeEnough(multiData, m4a.length * 16);
|
for (int i = 0; i < m3a.length; i++) {
|
||||||
}
|
m3a[i].fillFloatBuffer(multiData, true);
|
||||||
for (int i = 0; i < m4a.length; i++) {
|
}
|
||||||
m4a[i].fillFloatBuffer(multiData, true);
|
multiData.clear();
|
||||||
}
|
break;
|
||||||
multiData.clear();
|
case Matrix4Array:
|
||||||
break;
|
Matrix4f[] m4a = (Matrix4f[]) value;
|
||||||
// Only use check if equals optimization for primitive values
|
if (multiData == null) {
|
||||||
case Int:
|
multiData = BufferUtils.createFloatBuffer(m4a.length * 16);
|
||||||
case Float:
|
} else {
|
||||||
case Boolean:
|
multiData = BufferUtils.ensureLargeEnough(multiData, m4a.length * 16);
|
||||||
if (this.value != null && this.value.equals(value)) {
|
}
|
||||||
return;
|
for (int i = 0; i < m4a.length; i++) {
|
||||||
}
|
m4a[i].fillFloatBuffer(multiData, true);
|
||||||
this.value = value;
|
}
|
||||||
break;
|
multiData.clear();
|
||||||
default:
|
break;
|
||||||
this.value = value;
|
// Only use check if equals optimization for primitive values
|
||||||
break;
|
case Int:
|
||||||
}
|
case Float:
|
||||||
|
case Boolean:
|
||||||
if (multiData != null) {
|
if (this.value != null && this.value.equals(value)) {
|
||||||
this.value = multiData;
|
return;
|
||||||
}
|
}
|
||||||
|
this.value = value;
|
||||||
varType = type;
|
break;
|
||||||
updateNeeded = true;
|
default:
|
||||||
}
|
this.value = value;
|
||||||
|
break;
|
||||||
public void setVector4Length(int length){
|
}
|
||||||
if (location == -1)
|
|
||||||
return;
|
if (multiData != null) {
|
||||||
|
this.value = multiData;
|
||||||
FloatBuffer fb = (FloatBuffer) value;
|
}
|
||||||
if (fb == null || fb.capacity() < length) {
|
|
||||||
value = BufferUtils.createFloatBuffer(length * 4);
|
varType = type;
|
||||||
}
|
updateNeeded = true;
|
||||||
|
}
|
||||||
varType = VarType.Vector4Array;
|
|
||||||
updateNeeded = true;
|
public void setVector4Length(int length){
|
||||||
setByCurrentMaterial = true;
|
if (location == -1)
|
||||||
}
|
return;
|
||||||
|
|
||||||
public void setVector4InArray(float x, float y, float z, float w, int index){
|
FloatBuffer fb = (FloatBuffer) value;
|
||||||
if (location == -1)
|
if (fb == null || fb.capacity() < length) {
|
||||||
return;
|
value = BufferUtils.createFloatBuffer(length * 4);
|
||||||
|
}
|
||||||
if (varType != null && varType != VarType.Vector4Array)
|
|
||||||
throw new IllegalArgumentException("Expected a "+varType.name()+" value!");
|
varType = VarType.Vector4Array;
|
||||||
|
updateNeeded = true;
|
||||||
FloatBuffer fb = (FloatBuffer) value;
|
setByCurrentMaterial = true;
|
||||||
fb.position(index * 4);
|
}
|
||||||
fb.put(x).put(y).put(z).put(w);
|
|
||||||
fb.rewind();
|
public void setVector4InArray(float x, float y, float z, float w, int index){
|
||||||
updateNeeded = true;
|
if (location == -1)
|
||||||
setByCurrentMaterial = true;
|
return;
|
||||||
}
|
|
||||||
|
if (varType != null && varType != VarType.Vector4Array)
|
||||||
public boolean isUpdateNeeded(){
|
throw new IllegalArgumentException("Expected a "+varType.name()+" value!");
|
||||||
return updateNeeded;
|
|
||||||
}
|
FloatBuffer fb = (FloatBuffer) value;
|
||||||
|
fb.position(index * 4);
|
||||||
public void clearUpdateNeeded(){
|
fb.put(x).put(y).put(z).put(w);
|
||||||
updateNeeded = false;
|
fb.rewind();
|
||||||
}
|
updateNeeded = true;
|
||||||
|
setByCurrentMaterial = true;
|
||||||
public void reset(){
|
}
|
||||||
setByCurrentMaterial = false;
|
|
||||||
location = -2;
|
public boolean isUpdateNeeded(){
|
||||||
updateNeeded = true;
|
return updateNeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public void clearUpdateNeeded(){
|
||||||
|
updateNeeded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset(){
|
||||||
|
setByCurrentMaterial = false;
|
||||||
|
location = -2;
|
||||||
|
updateNeeded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,88 +1,89 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
* met:
|
* met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.shader;
|
package com.jme3.shader;
|
||||||
|
|
||||||
public enum VarType {
|
public enum VarType {
|
||||||
|
|
||||||
Float("float"),
|
Float("float"),
|
||||||
Vector2("vec2"),
|
Vector2("vec2"),
|
||||||
Vector3("vec3"),
|
Vector3("vec3"),
|
||||||
Vector4("vec4"),
|
Vector4("vec4"),
|
||||||
|
|
||||||
FloatArray(true,false,"float[]"),
|
IntArray(true,false,"int[]"),
|
||||||
Vector2Array(true,false,"vec2[]"),
|
FloatArray(true,false,"float[]"),
|
||||||
Vector3Array(true,false,"vec3[]"),
|
Vector2Array(true,false,"vec2[]"),
|
||||||
Vector4Array(true,false,"vec4[]"),
|
Vector3Array(true,false,"vec3[]"),
|
||||||
|
Vector4Array(true,false,"vec4[]"),
|
||||||
Boolean("bool"),
|
|
||||||
|
Boolean("bool"),
|
||||||
Matrix3(true,false,"mat3"),
|
|
||||||
Matrix4(true,false,"mat4"),
|
Matrix3(true,false,"mat3"),
|
||||||
|
Matrix4(true,false,"mat4"),
|
||||||
Matrix3Array(true,false,"mat3[]"),
|
|
||||||
Matrix4Array(true,false,"mat4[]"),
|
Matrix3Array(true,false,"mat3[]"),
|
||||||
|
Matrix4Array(true,false,"mat4[]"),
|
||||||
TextureBuffer(false,true,"sampler1D|sampler1DShadow"),
|
|
||||||
Texture2D(false,true,"sampler2D|sampler2DShadow"),
|
TextureBuffer(false,true,"sampler1D|sampler1DShadow"),
|
||||||
Texture3D(false,true,"sampler3D"),
|
Texture2D(false,true,"sampler2D|sampler2DShadow"),
|
||||||
TextureArray(false,true,"sampler2DArray"),
|
Texture3D(false,true,"sampler3D"),
|
||||||
TextureCubeMap(false,true,"samplerCube"),
|
TextureArray(false,true,"sampler2DArray"),
|
||||||
Int("int");
|
TextureCubeMap(false,true,"samplerCube"),
|
||||||
|
Int("int");
|
||||||
private boolean usesMultiData = false;
|
|
||||||
private boolean textureType = false;
|
private boolean usesMultiData = false;
|
||||||
private String glslType;
|
private boolean textureType = false;
|
||||||
|
private String glslType;
|
||||||
|
|
||||||
VarType(String glslType){
|
|
||||||
this.glslType = glslType;
|
VarType(String glslType){
|
||||||
}
|
this.glslType = glslType;
|
||||||
|
}
|
||||||
VarType(boolean multiData, boolean textureType,String glslType){
|
|
||||||
usesMultiData = multiData;
|
VarType(boolean multiData, boolean textureType,String glslType){
|
||||||
this.textureType = textureType;
|
usesMultiData = multiData;
|
||||||
this.glslType = glslType;
|
this.textureType = textureType;
|
||||||
}
|
this.glslType = glslType;
|
||||||
|
}
|
||||||
public boolean isTextureType() {
|
|
||||||
return textureType;
|
public boolean isTextureType() {
|
||||||
}
|
return textureType;
|
||||||
|
}
|
||||||
public boolean usesMultiData() {
|
|
||||||
return usesMultiData;
|
public boolean usesMultiData() {
|
||||||
}
|
return usesMultiData;
|
||||||
|
}
|
||||||
public String getGlslType() {
|
|
||||||
return glslType;
|
public String getGlslType() {
|
||||||
}
|
return glslType;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -877,6 +877,7 @@ public class JoglRenderer implements Renderer {
|
|||||||
|
|
||||||
uniform.clearUpdateNeeded();
|
uniform.clearUpdateNeeded();
|
||||||
FloatBuffer fb;
|
FloatBuffer fb;
|
||||||
|
IntBuffer ib;
|
||||||
GL gl = GLContext.getCurrentGL();
|
GL gl = GLContext.getCurrentGL();
|
||||||
switch (uniform.getVarType()) {
|
switch (uniform.getVarType()) {
|
||||||
case Float:
|
case Float:
|
||||||
@ -918,6 +919,10 @@ public class JoglRenderer implements Renderer {
|
|||||||
assert fb.remaining() == 16;
|
assert fb.remaining() == 16;
|
||||||
gl.getGL2ES2().glUniformMatrix4fv(loc, 1, false, fb);
|
gl.getGL2ES2().glUniformMatrix4fv(loc, 1, false, fb);
|
||||||
break;
|
break;
|
||||||
|
case IntArray:
|
||||||
|
ib = (IntBuffer) uniform.getValue();
|
||||||
|
gl.getGL2ES2().glUniform1iv(loc, ib.remaining(), ib);
|
||||||
|
break;
|
||||||
case FloatArray:
|
case FloatArray:
|
||||||
fb = (FloatBuffer) uniform.getValue();
|
fb = (FloatBuffer) uniform.getValue();
|
||||||
gl.getGL2ES2().glUniform1fv(loc, fb.remaining(), fb);
|
gl.getGL2ES2().glUniform1fv(loc, fb.remaining(), fb);
|
||||||
|
@ -823,6 +823,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
|
|
||||||
uniform.clearUpdateNeeded();
|
uniform.clearUpdateNeeded();
|
||||||
FloatBuffer fb;
|
FloatBuffer fb;
|
||||||
|
IntBuffer ib;
|
||||||
switch (uniform.getVarType()) {
|
switch (uniform.getVarType()) {
|
||||||
case Float:
|
case Float:
|
||||||
Float f = (Float) uniform.getValue();
|
Float f = (Float) uniform.getValue();
|
||||||
@ -863,6 +864,10 @@ public class LwjglRenderer implements Renderer {
|
|||||||
assert fb.remaining() == 16;
|
assert fb.remaining() == 16;
|
||||||
glUniformMatrix4(loc, false, fb);
|
glUniformMatrix4(loc, false, fb);
|
||||||
break;
|
break;
|
||||||
|
case IntArray:
|
||||||
|
ib = (IntBuffer) uniform.getValue();
|
||||||
|
glUniform1(loc, ib);
|
||||||
|
break;
|
||||||
case FloatArray:
|
case FloatArray:
|
||||||
fb = (FloatBuffer) uniform.getValue();
|
fb = (FloatBuffer) uniform.getValue();
|
||||||
glUniform1(loc, fb);
|
glUniform1(loc, fb);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user