29package com.jogamp.opengl.util;
31import java.lang.reflect.Constructor;
32import java.nio.Buffer;
33import java.nio.ByteBuffer;
34import java.nio.FloatBuffer;
35import java.nio.IntBuffer;
36import java.nio.ShortBuffer;
38import com.jogamp.opengl.GL;
39import com.jogamp.opengl.GLException;
40import com.jogamp.opengl.fixedfunc.GLPointerFuncUtil;
42import jogamp.opengl.util.GLArrayHandler;
43import jogamp.opengl.util.GLFixedArrayHandler;
44import jogamp.opengl.util.glsl.GLSLArrayHandler;
46import com.jogamp.common.nio.Buffers;
47import com.jogamp.opengl.util.glsl.ShaderState;
77 return new GLArrayDataClient(
null,
index, comps, dataType,
normalized, 0,
null, initialElementCount,
DEFAULT_GROWTH_FACTOR, 0 ,
78 false, GLFixedArrayHandler.class, 0, 0, 0, 0,
false);
106 return new GLArrayDataClient(
null,
index, comps, dataType,
normalized, stride,
buffer, comps*comps,
DEFAULT_GROWTH_FACTOR, 0 ,
107 false, GLFixedArrayHandler.class, 0, 0, 0, 0,
false);
120 final int dataType,
final boolean normalized,
final int initialElementCount)
123 return new GLArrayDataClient(
name, -1, comps, dataType,
normalized, 0,
null, initialElementCount,
DEFAULT_GROWTH_FACTOR, 0 ,
124 true, GLSLArrayHandler.class, 0, 0, 0, 0,
true);
138 final int dataType,
final boolean normalized,
final int stride,
final Buffer
buffer)
141 return new GLArrayDataClient(
name, -1, comps, dataType,
normalized, stride,
buffer, comps*comps,
DEFAULT_GROWTH_FACTOR, 0 ,
142 true, GLSLArrayHandler.class, 0, 0, 0, 0,
true);
146 public void associate(
final Object obj,
final boolean enable) {
245 }
else if (
null !=
buffer ) {
262 while(doneInByteSize<
strideB) {
263 Buffers.putb(
buffer, (
byte)0);
275 public void put(
final Buffer v) {
286 public void putb(
final byte v) {
293 public void put3b(
final byte v1,
final byte v2,
final byte v3) {
296 Buffers.put3b(
buffer, v1, v2, v3);
300 public void put4b(
final byte v1,
final byte v2,
final byte v3,
final byte v4) {
303 Buffers.put4b(
buffer, v1, v2, v3, v4);
307 public void putb(
final byte[] src,
final int offset,
final int length) {
310 Buffers.putb(
buffer, src, offset, length);
314 public void puts(
final short v) {
321 public void put3s(
final short v1,
final short v2,
final short v3) {
324 Buffers.put3s(
buffer, v1, v2, v3);
328 public void put4s(
final short v1,
final short v2,
final short v3,
final short v4) {
331 Buffers.put4s(
buffer, v1, v2, v3, v4);
335 public void puts(
final short[] src,
final int offset,
final int length) {
338 Buffers.puts(
buffer, src, offset, length);
342 public void puti(
final int v) {
349 public void put3i(
final int v1,
final int v2,
final int v3) {
352 Buffers.put3i(
buffer, v1, v2, v3);
356 public void put4i(
final int v1,
final int v2,
final int v3,
final int v4) {
359 Buffers.put4i(
buffer, v1, v2, v3, v4);
363 public void puti(
final int[] src,
final int offset,
final int length) {
366 Buffers.puti(
buffer, src, offset, length);
370 public void putx(
final int v) {
375 public void putf(
final float v) {
382 public void put3f(
final float v1,
final float v2,
final float v3) {
385 Buffers.put3f(
buffer, v1, v2, v3);
389 public void put4f(
final float v1,
final float v2,
final float v3,
final float v4) {
392 Buffers.put4f(
buffer, v1, v2, v3, v4);
396 public void putf(
final float[] src,
final int offset,
final int length) {
399 Buffers.putf(
buffer, src, offset, length);
404 return "GLArrayDataClient["+
name+
410 ", dataType 0x"+Integer.toHexString(
compType)+
440 if(
null ==
buffer ||
buffer.remaining() < spareComponents ) {
442 throw new GLException(
"Mapped buffer can't grow. Insufficient storage size: Needed "+spareComponents+
" components, "+
444 ", has mapped buffer "+
buffer+
"; "+
this);
450 final int has_comps =
buffer.capacity();
453 final int elementCount = Math.max( new_elems, required_elems );
454 return reserve( elementCount );
469 public final boolean reserve(
int elementCount) {
477 final int osize = (
buffer!=
null) ?
buffer.capacity() : 0;
479 if( nsize <= osize ) {
482 final Buffer oldBuffer =
buffer;
485 final ByteBuffer newBBuffer = Buffers.newDirectByteBuffer( nsize );
486 if(oldBuffer!=
null) {
488 newBBuffer.put((ByteBuffer)oldBuffer);
491 }
else if(
compClazz==ShortBuffer.class) {
492 final ShortBuffer newSBuffer = Buffers.newDirectShortBuffer( nsize );
493 if(oldBuffer!=
null) {
495 newSBuffer.put((ShortBuffer)oldBuffer);
499 final IntBuffer newIBuffer = Buffers.newDirectIntBuffer( nsize );
500 if(oldBuffer!=
null) {
502 newIBuffer.put((IntBuffer)oldBuffer);
505 }
else if(
compClazz==FloatBuffer.class) {
506 final FloatBuffer newFBuffer = Buffers.newDirectFloatBuffer( nsize );
507 if(oldBuffer!=
null) {
509 newFBuffer.put((FloatBuffer)oldBuffer);
517 "; "+oldBuffer+
" -> "+
buffer+
"; "+
this);
530 throw new GLException(
"Not Sealed yet, seal first:\n\t"+
this);
532 throw new GLException(
"Already Sealed, can't modify VBO:\n\t"+
this);
538 final int initialElementCount,
final float growthFactor,
540 final Class<? extends GLArrayHandler> handlerClass,
547 if( 0<mappedElementCount && 0<initialElementCount ) {
548 throw new IllegalArgumentException(
"mappedElementCount:="+mappedElementCount+
" specified, but passing non zero initialElementSize");
552 this.initElemCount = initialElementCount;
555 final Constructor<? extends GLArrayHandler> ctor = handlerClass.getConstructor(
GLArrayDataEditable.class);
556 this.glArrayHandler = ctor.newInstance(
this);
557 }
catch (
final Exception e) {
558 throw new RuntimeException(
"Could not ctor "+handlerClass.getName()+
"("+
this.getClass().getName()+
")", e);
566 this.bufferWritten = ( 0 == mappedElementCount ) ?
false :
true;
568 if(
null==
buffer && initialElementCount>0) {
595 final Class<? extends GLArrayHandler> clazz = src.
glArrayHandler.getClass();
597 final Constructor<? extends GLArrayHandler> ctor = clazz.getConstructor(
GLArrayDataEditable.class);
598 this.glArrayHandler = ctor.newInstance(
this);
599 }
catch (
final Exception e) {
600 throw new RuntimeException(
"Could not ctor "+clazz.getName()+
"("+
this.getClass().getName()+
")", e);
603 this.glArrayHandler =
null;
609 this.isValidated = src.isValidated;
644 private boolean isValidated =
false;
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
final boolean isVBOWritten()
Is the buffer written to the VBO ?
void put4b(final byte v1, final byte v2, final byte v3, final byte v4)
void puts(final short[] src, final int offset, final int length)
static GLArrayDataClient createGLSL(final String name, final int comps, final int dataType, final boolean normalized, final int initialElementCount)
Create a client side buffer object, using a custom GLSL array attribute name and starting with a new ...
final boolean growIfNeeded(final int spareComponents)
Increase the capacity of the buffer if necessary to add given spareComponents components.
GLArrayDataClient(final String name, final int index, final int comps, final int dataType, final boolean normalized, final int stride, final Buffer data, final int initialElementCount, final float growthFactor, final int mappedElementCount, final boolean isVertexAttribute, final Class<? extends GLArrayHandler > handlerClass, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget, final boolean usesGLSL)
void put4f(final float v1, final float v2, final float v3, final float v4)
final GLArrayHandler glArrayHandler
float getGrowthFactor()
Returns this buffer's growth factor.
void destroy(final GL gl)
static GLArrayDataClient createFixed(final int index, final int comps, final int dataType, final boolean normalized, final int stride, final Buffer buffer)
Create a client side buffer object, using a predefined fixed function array index and starting with a...
void put4s(final short v1, final short v2, final short v3, final short v4)
void setGrowthFactor(final float v)
Sets a new growth factor for this buffer.
final void checkSeal(final boolean test)
static GLArrayDataClient createGLSL(final String name, final int comps, final int dataType, final boolean normalized, final int stride, final Buffer buffer)
Create a client side buffer object, using a custom GLSL array attribute name and starting with a give...
void put4i(final int v1, final int v2, final int v3, final int v4)
static final float DEFAULT_GROWTH_FACTOR
Default growth factor using the golden ratio 1.618.
void put3b(final byte v1, final byte v2, final byte v3)
void clear()
Clears this buffer and resets states accordingly.
void padding(int doneInByteSize)
void put3s(final short v1, final short v2, final short v3)
void associate(final Object obj, final boolean enable)
Implementation and type dependent object association.
final boolean reserve(int elementCount)
Increase the capacity of the buffer to given elementCount element size, i.e.
final void setVBOWritten(final boolean written)
Marks the buffer written to the VBO.
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
static GLArrayDataClient createFixed(final int index, final int comps, final int dataType, final boolean normalized, final int initialElementCount)
Create a client side buffer object, using a predefined fixed function array index and starting with a...
boolean bindBuffer(final GL gl, final boolean bind)
if bind is true and the data uses VBO, the latter will be bound and data written to the GPU if requir...
GLArrayDataClient(final GLArrayDataClient src)
Copy Constructor.
int compsToElemCount(final int componentCount)
Returning element-count from given componentCount, rounding up to componentsPerElement.
void putb(final byte[] src, final int offset, final int length)
void put3i(final int v1, final int v2, final int v3)
void put3f(final float v1, final float v2, final float v3)
void rewind()
Rewinds this buffer.
void puti(final int[] src, final int offset, final int length)
boolean enableBufferAlways
void put(final Buffer v)
Generic buffer relative put method.
void seal(final boolean seal)
void init_vbo(final GL gl)
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
void clear(final GL gl)
Clears this buffer and resets states accordingly.
void putf(final float[] src, final int offset, final int length)
void setEnableAlways(final boolean always)
Affects the behavior of 'enableBuffer'.
String elemStatsToString()
Returns a string with detailed buffer element stats, i.e.
final boolean isVertexAttribute()
Returns true if this data set is intended for a GLSL vertex shader attribute, otherwise false,...
final int strideB
stride in bytes; strideB >= compsPerElement * bytesPerComp
final boolean isVertexAttr
final int strideL
stride in logical components
final int mappedElemCount
final int compsPerElement
static final boolean DEBUG
final boolean validate(final GLProfile glp, final boolean throwException)
Validates this instance's parameter.
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
The total number of bytes hold by the referenced buffer is: getComponentSize()* getComponentNumber() ...