aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/javax/media/opengl/GLUniformData.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/javax/media/opengl/GLUniformData.java')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLUniformData.java78
1 files changed, 56 insertions, 22 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLUniformData.java b/src/jogl/classes/javax/media/opengl/GLUniformData.java
index 412bfb0a9..fac8b7a1f 100644
--- a/src/jogl/classes/javax/media/opengl/GLUniformData.java
+++ b/src/jogl/classes/javax/media/opengl/GLUniformData.java
@@ -15,7 +15,7 @@ public class GLUniformData {
*
*/
public GLUniformData(String name, int val) {
- init(name, 1, new Integer(val));
+ initScalar(name, 1, new Integer(val));
}
/**
@@ -25,7 +25,7 @@ public class GLUniformData {
*
*/
public GLUniformData(String name, float val) {
- init(name, 1, new Float(val));
+ initScalar(name, 1, new Float(val));
}
/**
@@ -36,7 +36,7 @@ public class GLUniformData {
* @param components number of elements of one object, ie 4 for GL_FLOAT_VEC4,
*/
public GLUniformData(String name, int components, IntBuffer data) {
- init(name, components, data);
+ initBuffer(name, components, data);
}
/**
@@ -47,7 +47,19 @@ public class GLUniformData {
* @param components number of elements of one object, ie 4 for GL_FLOAT_VEC4,
*/
public GLUniformData(String name, int components, FloatBuffer data) {
- init(name, components, data);
+ initBuffer(name, components, data);
+ }
+
+ private GLUniformData(int components, String name) {
+ initBuffer(name, components, null);
+ }
+
+ public static GLUniformData creatEmptyVector(String name, int components) {
+ return new GLUniformData(components, name);
+ }
+
+ public static GLUniformData creatEmptyMatrix(String name, int rows, int columns) {
+ return new GLUniformData(name, rows, columns, null);
}
/**
@@ -59,13 +71,13 @@ public class GLUniformData {
* @param column the matrix column
*/
public GLUniformData(String name, int rows, int columns, FloatBuffer data) {
- init(name, rows, columns, data);
+ initBuffer(name, rows, columns, data);
}
- public GLUniformData setData(int data) { init(new Integer(data)); return this; }
- public GLUniformData setData(float data) { init(new Float(data)); return this; }
- public GLUniformData setData(IntBuffer data) { init(data); return this; }
- public GLUniformData setData(FloatBuffer data) { init(data); return this; }
+ public GLUniformData setData(final int data) { initScalar(new Integer(data)); return this; }
+ public GLUniformData setData(final float data) { initScalar(new Float(data)); return this; }
+ public GLUniformData setData(final IntBuffer data) { initBuffer(data); return this; }
+ public GLUniformData setData(final FloatBuffer data) { initBuffer(data); return this; }
public int intValue() { return ((Integer)data).intValue(); };
public float floatValue() { return ((Float)data).floatValue(); };
@@ -102,7 +114,7 @@ public class GLUniformData {
return toString(null).toString();
}
- private void init(String name, int rows, int columns, Object data) {
+ private void initBuffer(String name, int rows, int columns, Buffer buffer) {
if( 2>rows || rows>4 || 2>columns || columns>4 ) {
throw new GLException("rowsXcolumns must be within [2..4]X[2..4], is: "+rows+"X"+columns);
}
@@ -111,10 +123,20 @@ public class GLUniformData {
this.columns=columns;
this.isMatrix=true;
this.location=-1;
- init(data);
+ initBuffer(buffer);
}
-
- private void init(String name, int components, Object data) {
+ private void initScalar(String name, int components, Object data) {
+ if( 1>components || components>4 ) {
+ throw new GLException("components must be within [1..4], is: "+components);
+ }
+ this.name=name;
+ this.columns=components;
+ this.rows=1;
+ this.isMatrix=false;
+ this.location=-1;
+ initScalar(data);
+ }
+ private void initBuffer(String name, int components, Buffer buffer) {
if( 1>components || components>4 ) {
throw new GLException("components must be within [1..4], is: "+components);
}
@@ -123,24 +145,36 @@ public class GLUniformData {
this.rows=1;
this.isMatrix=false;
this.location=-1;
- init(data);
+ initBuffer(buffer);
}
- private void init(Object data) {
+ private void initScalar(Object data) {
if(data instanceof Buffer) {
+ initBuffer((Buffer)data);
+ } else if( null != data ) {
+ if(isMatrix) {
+ throw new GLException("Atom type not allowed for matrix : "+this);
+ }
+ this.count=1;
+ this.data=data;
+ } else {
+ this.count=0;
+ this.data=data;
+ }
+ }
+
+ private void initBuffer(final Buffer buffer) {
+ if( null != buffer ) {
final int sz = rows*columns;
- final Buffer buffer = (Buffer)data;
if(buffer.remaining()<sz || 0!=buffer.remaining()%sz) {
throw new GLException("remaining data buffer size invalid: buffer: "+buffer.toString()+"\n\t"+this);
}
- this.count=buffer.remaining()/(rows*columns);
+ this.count=buffer.remaining()/sz;
+ this.data=buffer;
} else {
- if(isMatrix) {
- throw new GLException("Atom type not allowed for matrix : "+this);
- }
- this.count=1;
+ this.count=0;
+ this.data=null;
}
- this.data=data;
}
public String getName() { return name; }