29package com.jogamp.opengl.util;
31import java.nio.Buffer;
32import java.nio.ByteBuffer;
33import java.nio.FloatBuffer;
34import java.nio.IntBuffer;
35import java.nio.ShortBuffer;
37import com.jogamp.opengl.GL;
38import com.jogamp.opengl.GL2ES2;
39import com.jogamp.opengl.GLArrayData;
40import com.jogamp.opengl.GLException;
41import com.jogamp.opengl.GLProfile;
42import com.jogamp.opengl.fixedfunc.GLPointerFuncUtil;
44import com.jogamp.common.nio.Buffers;
46import jogamp.opengl.Debug;
49 public static final boolean DEBUG = Debug.debug(
"GLArrayData");
174 throw new GLException(
"GLSL not supported on "+glp+
", "+
this);
184 public void associate(
final Object obj,
final boolean enable) {
254 }
else if(
null !=
buffer ) {
269 }
else if(
null !=
buffer ) {
298 }
else if(
null !=
buffer ) {
313 }
else if(
null !=
buffer ) {
342 final float filled = (float)cnt_bytes/(
float)cap_bytes;
343 return String.format(
"elements %,d cnt / %,d cap, bytes %,d cnt / %,d cap, filled %.1f%%, left %.1f%%",
350 return String.format(
"sealed %b, elements %,d cnt, [%,d pos .. %,d rem .. %,d lim .. %,d cap]",
373 return "GLArrayDataWrapper["+
name+
377 ", dataType 0x"+Integer.toHexString(
compType)+
386 ", vboUsage 0x"+Integer.toHexString(
vboUsage)+
387 ", vboTarget 0x"+Integer.toHexString(
vboTarget)+
397 return ByteBuffer.class;
400 return ShortBuffer.class;
404 return IntBuffer.class;
406 return FloatBuffer.class;
408 throw new GLException(
"Given OpenGL data type not supported: "+dataType);
453 final boolean normalized,
final int stride,
final Buffer data,
final int mappedElementCount,
457 if( 0<mappedElementCount &&
null != data ) {
458 throw new IllegalArgumentException(
"mappedElementCount:="+mappedElementCount+
" specified, but passing non null buffer");
467 if(
null == this.
name ) {
475 this.compType = componentType;
479 throw new GLException(
"Given componentType not supported: "+componentType+
":\n\t"+
this);
481 if(0 >= componentsPerElement) {
482 throw new GLException(
"Invalid number of components: " + componentsPerElement);
484 this.compsPerElement = componentsPerElement;
486 if(0<stride && stride<componentsPerElement*
bytesPerComp) {
487 throw new GLException(
"stride ("+stride+
") lower than component bytes, "+componentsPerElement+
" * "+
bytesPerComp);
498 this.normalized =
false;
500 this.mappedElemCount = mappedElementCount;
556 this.alive = src.
alive;
557 this.index = src.
index;
559 this.name = src.
name;
560 if(
null != src.
buffer ) {
561 if( src.
buffer.position() == 0 ) {
562 this.buffer = Buffers.slice(src.
buffer);
564 this.buffer = Buffers.slice(src.
buffer, 0, src.
buffer.limit());
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
final boolean hasGLSL()
Indicates whether this profile supports GLSL, i.e.
static String getPredefinedArrayIndexName(final int glArrayIndex)
final int getCompsPerElem()
The number of components per element.
final long getVBOOffset()
The VBO buffer offset or 0 if not a VBO.
void setVBOUsage(final int vboUsage)
final boolean isVBO()
Determines whether the data is server side (VBO) and enabled, or a client side array (false).
GLArrayDataWrapper(final String name, final int index, final int componentsPerElement, final int componentType, final boolean normalized, final int stride, final Buffer data, final int mappedElementCount, final boolean isVertexAttribute, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
static GLArrayDataWrapper createFixed(final int index, final int comps, final int dataType, final boolean normalized, final int stride, final Buffer buffer, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
Create a VBO, using a predefined fixed function array index, wrapping the given data.
final int bytePosition()
Returns the bytes position.
final int getByteCount()
Returns the byte position (written elements) if not sealed() or the byte limit (available to read) af...
final int getElemCount()
Returns the element position (written elements) if not sealed() or the element limit (available to re...
static GLArrayDataWrapper createGLSL(final String name, final int comps, final int dataType, final boolean normalized, final int stride, final Buffer buffer, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
Create a VBO, using a custom GLSL array attribute name, wrapping the given data.
final int elemPosition()
Returns the element position.
void setVBOName(final int vboName)
Set the VBO buffer name, if valid (!= 0) enable use of VBO, otherwise (==0) disable VBO usage.
String elemStatsToString()
Returns a string with detailed buffer element stats, i.e.
final int setLocation(final GL2ES2 gl, final int program)
Retrieves the location of the shader attribute from the linked shader program.
final boolean isVertexAttribute()
Returns true if this data set is intended for a GLSL vertex shader attribute, otherwise false,...
void associate(final Object obj, final boolean enable)
Implementation and type dependent object association.
void setName(final String newName)
Set a new name for this array.
final Class<?> getBufferClass()
final int strideB
stride in bytes; strideB >= compsPerElement * bytesPerComp
String fillStatsToString()
Returns a string with detailed buffer fill stats.
final boolean isVertexAttr
final int setLocation(final int v)
Sets the given location of the shader attribute.
void setVBOEnabled(final boolean vboEnabled)
Enable or disable use of VBO.
final int strideL
stride in logical components
final boolean getNormalized()
True, if GL shall normalize fixed point data while converting them into float.
final int getCompType()
The component's GL data type, ie.
final String getName()
The name of the reflecting shader array attribute.
final int getVBOName()
The VBO name or 0 if not a VBO.
final int getLocation()
Returns the shader attribute location for this name, -1 if not yet determined.
void setVBOTarget(final int vboTarget)
final int setLocation(final GL2ES2 gl, final int program, final int location)
Binds the location of the shader attribute to the given location for the unlinked shader program.
int remainingBytes()
The current number of remaining bytes.
final int getIndex()
The index of the predefined array index, see list below, or -1 in case of a shader attribute array.
Buffer getBuffer()
The Buffer holding the data, may be null if a GPU buffer without client bound data.
final int getBytesPerComp()
The component's size in bytes.
final int mappedElemCount
int getByteCapacity()
Return the capacity in bytes.
static GLArrayDataWrapper createFixed(final int index, final int comps, final int dataType, final boolean normalized, final int stride, final int mappedElementCount, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
Create a VBO, using a predefined fixed function array index, wrapping the mapped data characteristics...
final int compsPerElement
final int getVBOUsage()
The VBO usage or 0 if not a VBO.
final boolean sealed()
Returns true if data has been sealed (flipped to read), otherwise false (writing mode).
static final Class<?> getBufferClass(final int dataType)
final int getVBOTarget()
The VBO target or 0 if not a VBO.
static final boolean DEBUG
static GLArrayDataWrapper createGLSL(final String name, final int comps, final int dataType, final boolean normalized, final int stride, final int mappedElementCount, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
Create a VBO, using a custom GLSL array attribute name, wrapping the mapped data characteristics.
final boolean validate(final GLProfile glp, final boolean throwException)
Validates this instance's parameter.
GLArrayDataWrapper(final GLArrayDataWrapper src)
Copy Constructor.
int remainingElems()
The current number of remaining elements.
void destroy(final GL gl)
int getElemCapacity()
Return the element capacity.
Utility routines for dealing with direct buffers.
static final boolean isGLTypeFixedPoint(final int glType)
static final int sizeOfGLType(final int glType)
void glBindAttribLocation(int program, int index, String name)
Entry point to C language function: void {@native glBindAttribLocation}(GLuint program,...
static final int GL_STREAM_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_ARB_vertex_buffer_object Alias for: GL_STREAM_DRAW_ARB Define ...
int glGetAttribLocation(int program, String name)
Entry point to C language function: GLint {@native glGetAttribLocation}(GLuint program,...
static final int GL_INT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0 Define "GL_INT" with expression '0x1404',...
The total number of bytes hold by the referenced buffer is: getComponentSize()* getComponentNumber() ...
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
static final int GL_FIXED
GL_ARB_ES2_compatibility, GL_ES_VERSION_2_0, GL_VERSION_4_1, GL_VERSION_ES_1_0, GL_OES_fixed_point Al...
static final int GL_SHORT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_SHORT" with expressio...
static final int GL_UNSIGNED_INT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_OES_element_index_uint Define "GL_UNSIGNED_INT"...
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
static final int GL_UNSIGNED_SHORT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_UNSIGNED_SHORT" with ...
static final int GL_DYNAMIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_DYNAM...
static final int GL_UNSIGNED_BYTE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_UNSIGNED_BYTE" with e...
static final int GL_ELEMENT_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ELEME...
static final int GL_BYTE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_BYTE" with expression...
static final int GL_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ARRAY...