Added support for int arrays uniforms. thanks to abies.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10495 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 12 years ago
parent 3d76821f02
commit 05e080100e
  1. 5
      engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java
  2. 12
      engine/src/core/com/jme3/shader/Uniform.java
  3. 1
      engine/src/core/com/jme3/shader/VarType.java
  4. 18
      engine/src/core/com/jme3/util/BufferUtils.java
  5. 5
      engine/src/jogl/com/jme3/renderer/jogl/JoglRenderer.java
  6. 5
      engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java

@ -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);

@ -34,6 +34,7 @@ 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 {
@ -128,10 +129,10 @@ public class Uniform extends ShaderVariable {
updateNeeded = true; updateNeeded = true;
if (multiData != null){ if (multiData != null){
ZERO_BUF.clear();
multiData.clear(); multiData.clear();
while (multiData.remaining() > 0){ while (multiData.remaining() > 0){
ZERO_BUF.clear();
ZERO_BUF.limit( Math.min(multiData.remaining(), 16) ); ZERO_BUF.limit( Math.min(multiData.remaining(), 16) );
multiData.put(ZERO_BUF); multiData.put(ZERO_BUF);
} }
@ -202,6 +203,15 @@ public class Uniform extends ShaderVariable {
m4.fillFloatBuffer(multiData, true); m4.fillFloatBuffer(multiData, true);
multiData.clear(); multiData.clear();
break; break;
case IntArray:
int[] ia = (int[]) value;
if (this.value == null) {
this.value = BufferUtils.createIntBuffer(ia);
} else {
this.value = BufferUtils.ensureLargeEnough((IntBuffer)this.value, ia.length);
}
((IntBuffer)this.value).clear();
break;
case FloatArray: case FloatArray:
float[] fa = (float[]) value; float[] fa = (float[]) value;
if (multiData == null) { if (multiData == null) {

@ -38,6 +38,7 @@ public enum VarType {
Vector3("vec3"), Vector3("vec3"),
Vector4("vec4"), Vector4("vec4"),
IntArray(true,false,"int[]"),
FloatArray(true,false,"float[]"), FloatArray(true,false,"float[]"),
Vector2Array(true,false,"vec2[]"), Vector2Array(true,false,"vec2[]"),
Vector3Array(true,false,"vec3[]"), Vector3Array(true,false,"vec3[]"),

@ -1121,6 +1121,24 @@ public final class BufferUtils {
return buffer; return buffer;
} }
public static IntBuffer ensureLargeEnough(IntBuffer buffer, int required) {
if (buffer != null) {
buffer.limit(buffer.capacity());
}
if (buffer == null || (buffer.remaining() < required)) {
int position = (buffer != null ? buffer.position() : 0);
IntBuffer newVerts = createIntBuffer(position + required);
if (buffer != null) {
buffer.flip();
newVerts.put(buffer);
newVerts.position(position);
}
buffer = newVerts;
}
return buffer;
}
public static ShortBuffer ensureLargeEnough(ShortBuffer buffer, int required) { public static ShortBuffer ensureLargeEnough(ShortBuffer buffer, int required) {
if (buffer != null) { if (buffer != null) {
buffer.limit(buffer.capacity()); buffer.limit(buffer.capacity());

@ -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…
Cancel
Save