28package com.jogamp.opengl;
30import java.nio.Buffer;
31import java.nio.FloatBuffer;
32import java.nio.IntBuffer;
34import com.jogamp.common.nio.Buffers;
35import com.jogamp.math.FloatUtil;
36import com.jogamp.math.util.SyncAction;
37import com.jogamp.math.util.SyncBuffer;
52 initScalar(name, 1, Integer.valueOf(val));
63 initScalar(name, 1, Float.valueOf(val));
114 return new GLUniformData(name, rows, columns, (FloatBuffer)
null);
127 public GLUniformData(
final String name,
final int rows,
final int columns,
final FloatBuffer data) {
128 initBuffer(name, rows, columns, data,
null);
152 public int intValue() {
return ((Integer)data).intValue(); };
153 public float floatValue() {
return ((Float)data).floatValue(); };
157 @SuppressWarnings(
"deprecation")
160 sb =
new StringBuilder();
162 sb.append(
"GLUniformData[name ").append(name).
163 append(
", location ").append(location).
164 append(
", size ").append(rows).append(
"x").append(columns).
165 append(
", count ").append(count).
167 if(
isMatrix() && data instanceof FloatBuffer) {
169 final FloatBuffer fb = (FloatBuffer)
getBuffer();
170 for(
int i=0; i<count; i++) {
188 private void initBuffer(
final String name,
final int rows,
final int columns,
final Buffer buffer,
final SyncAction syncAction) {
189 if( 2>rows || rows>4 || 2>columns || columns>4 ) {
190 throw new GLException(
"rowsXcolumns must be within [2..4]X[2..4], is: "+rows+
"X"+columns);
194 this.columns=columns;
195 this.bits=BIT_MATRIX;
197 initBuffer(buffer, syncAction);
199 private void initScalar(
final String name,
final int components,
final Object data) {
201 throw new GLException(
"components must be within [1..4], is: "+
components);
210 private void initBuffer(
final String name,
final int components,
final Buffer buffer,
final SyncAction syncAction) {
212 throw new GLException(
"components must be within [1..4], is: "+
components);
219 initBuffer(buffer, syncAction);
222 private void initScalar(
final Object data) {
223 if(data instanceof Buffer) {
224 initBuffer((Buffer)data,
null);
225 }
else if(
null != data ) {
227 throw new GLException(
"Atom type not allowed for matrix : "+
this);
237 private void initBuffer(
final Buffer buffer,
final SyncAction syncAction) {
238 if(
null != buffer ) {
239 this.bits |= BIT_BUFFER;
240 final int sz = rows*columns;
241 if(buffer.remaining()<sz || 0!=buffer.remaining()%sz) {
242 throw new GLException(
"remaining data buffer size invalid: buffer: "+buffer.toString()+
"\n\t"+
this);
244 this.count=buffer.remaining()/sz;
250 this.syncAction = syncAction;
262 public int setLocation(
final int location) { this.location=location;
return location; }
289 if(
null != syncAction ) {
305 if(
null != syncAction ) {
308 return (data instanceof Buffer)?(Buffer)data:
null;
311 public boolean isMatrix() {
return 0 != ( BIT_MATRIX & bits ); }
312 public boolean isBuffer() {
return 0 != ( BIT_BUFFER & bits ); }
319 private static final short BIT_MATRIX = 0b0000000000000001;
320 private static final short BIT_BUFFER = 0b0000000000000010;
323 private int location;
324 private int rows, columns;
Basic Float math utility functions.
static StringBuilder matrixToString(StringBuilder sb, final String rowPrefix, final String f, final FloatBuffer a, final int aOffset, final int rows, final int columns, final boolean rowMajorOrder)
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specific data synchronization action implemented by the data provider to update the buffer with the u...
Convenient tuple of a SyncAction and Buffer.
Buffer getBuffer()
Return the Buffer, i.e.
SyncAction getAction()
Return the SyncAction.
int glGetUniformLocation(int program, String name)
Entry point to C language function: GLint {@native glGetUniformLocation}(GLuint program,...