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.GLBufferStorage;
41import com.jogamp.opengl.GLException;
42import com.jogamp.opengl.fixedfunc.GLPointerFuncUtil;
44import com.jogamp.common.nio.Buffers;
46import jogamp.opengl.util.GLArrayHandler;
47import jogamp.opengl.util.GLArrayHandlerInterleaved;
48import jogamp.opengl.util.GLDataArrayHandler;
49import jogamp.opengl.util.GLFixedArrayHandler;
50import jogamp.opengl.util.GLFixedArrayHandlerFlat;
51import jogamp.opengl.util.glsl.GLSLArrayHandler;
52import jogamp.opengl.util.glsl.GLSLArrayHandlerFlat;
53import jogamp.opengl.util.glsl.GLSLArrayHandlerInterleaved;
88 return new GLArrayDataServer(
null,
index,
compsPerElement, dataType,
normalized, stride,
buffer,
buffer.limit(),
DEFAULT_GROWTH_FACTOR, 0 ,
117 return new GLArrayDataServer(
null,
index,
compsPerElement, dataType,
normalized, 0,
null, initialElementCount,
DEFAULT_GROWTH_FACTOR, 0 ,
132 final int dataType,
final boolean normalized,
final int initialElementCount,
final int vboUsage)
150 final int dataType,
final boolean normalized,
final int mappedElementCount,
final int vboUsage)
171 final int dataType,
final boolean normalized,
final int stride,
final Buffer
buffer,
175 return new GLArrayDataServer(
name, -1,
compsPerElement, dataType,
normalized, stride,
buffer,
buffer.limit(),
DEFAULT_GROWTH_FACTOR, 0 ,
196 return new GLArrayDataServer(
null, -1,
compsPerElement, dataType,
false, stride,
buffer,
buffer.limit(),
DEFAULT_GROWTH_FACTOR, 0 ,
215 return new GLArrayDataServer(
null, -1,
compsPerElement, dataType,
false, 0,
null, initialElementCount,
DEFAULT_GROWTH_FACTOR, 0 ,
236 return new GLArrayDataServer(
null, -1,
compsPerElement, dataType,
false, 0,
null, 0 ,
DEFAULT_GROWTH_FACTOR, mappedElementCount,
255 return new GLArrayDataServer(
GLPointerFuncUtil.
mgl_InterleaveArray, -1,
compsPerElement, dataType,
false, 0,
null, initialElementCount,
DEFAULT_GROWTH_FACTOR, 0 ,
274 final GLArrayDataServer ads =
new GLArrayDataServer(
GLPointerFuncUtil.
mgl_InterleaveArray, -1,
compsPerElement, dataType,
false, 0,
null, 0 ,
DEFAULT_GROWTH_FACTOR, mappedElementCount,
296 return new GLArrayDataServer(
GLPointerFuncUtil.
mgl_InterleaveArray, -1,
compsPerElement, dataType,
normalized, stride,
buffer,
buffer.limit(),
DEFAULT_GROWTH_FACTOR, 0 ,
358 return new GLArrayDataServer(
GLPointerFuncUtil.
mgl_InterleaveArray, -1,
compsPerElement, dataType,
normalized, 0,
null, initialElementCount,
DEFAULT_GROWTH_FACTOR, 0 ,
376 final GLArrayDataServer ads =
new GLArrayDataServer(
GLPointerFuncUtil.
mgl_InterleaveArray, -1,
compsPerElement, dataType,
normalized, 0,
null, 0 ,
DEFAULT_GROWTH_FACTOR, mappedElementCount,
398 return new GLArrayDataServer(
GLPointerFuncUtil.
mgl_InterleaveArray, -1,
compsPerElement, dataType,
normalized, stride,
buffer,
buffer.limit(),
DEFAULT_GROWTH_FACTOR, 0 ,
421 throw new GLException(
"buffer uses fixed function");
445 this.interleavedOffset = interleavedOffset;
449 return interleavedOffset;
468 final int[] tmp =
new int[] { _vboName } ;
491 throw new IllegalStateException(
"user buffer not null");
493 if(
null != mappedStorage ) {
494 throw new IllegalStateException(
"already mapped: "+mappedStorage);
500 setMappedBuffer(storage);
508 throw new IllegalStateException(
"user buffer not null");
510 if(
null != mappedStorage ) {
511 throw new IllegalStateException(
"already mapped: "+mappedStorage);
517 setMappedBuffer(storage);
524 mappedStorage = storage;
528 }
else if(
compClazz==ShortBuffer.class) {
529 buffer = bb.asShortBuffer();
531 buffer = bb.asIntBuffer();
532 }
else if(
compClazz==FloatBuffer.class) {
533 buffer = bb.asFloatBuffer();
535 throw new GLException(
"Given Buffer Class not supported: "+
compClazz+
":\n\t"+
this);
540 if(
null == mappedStorage ) {
541 throw new IllegalStateException(
"not mapped");
543 mappedStorage =
null;
553 return "GLArrayDataServer["+
name+
559 ", dataType 0x"+Integer.toHexString(
compType)+
566 ", mappedStorage "+mappedStorage+
569 ", vboUsage 0x"+Integer.toHexString(
vboUsage)+
570 ", vboTarget 0x"+Integer.toHexString(
vboTarget)+
584 final int stride,
final Buffer data,
final int initialElementCount,
final float growthFactor,
589 super(
name,
index, comps, dataType,
normalized, stride, data, initialElementCount,
growthFactor, mappedElementCount,
599 final int[] tmp =
new int[1];
602 if(0 < interleavedOffset) {
619 this.interleavedOffset = src.interleavedOffset;
620 this.mappedStorage = src.mappedStorage;
623 private int interleavedOffset = 0;
OpenGL buffer storage object reflecting it's.
final ByteBuffer getMappedBuffer()
Returns the mapped ByteBuffer, or null if not mapped.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
static final String mgl_InterleaveArray
final GLArrayHandler glArrayHandler
final void checkSeal(final boolean test)
static final float DEFAULT_GROWTH_FACTOR
Default growth factor using the golden ratio 1.618.
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
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...
void rewind()
Rewinds this buffer.
static GLArrayDataServer createGLSLInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int stride, final Buffer buffer, final int vboUsage)
Create a VBO for GLSL interleaved array data starting with a given Buffer object incl it's stride.
final void setInterleavedOffset(final int interleavedOffset)
static GLArrayDataServer createFixedInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int stride, final Buffer buffer, final int vboUsage)
Create a VBO for fixed function interleaved array data starting with a given Buffer object incl it's ...
static GLArrayDataServer createFixedInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO for fixed function interleaved array data starting with a new created Buffer object with...
void unmapStorage(final GL gl)
static GLArrayDataServer createGLSLInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO for GLSL interleaved array data starting with a new created Buffer object with initialEl...
void init_vbo(final GL gl)
static GLArrayDataServer createGLSL(final String name, final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO, using a custom GLSL array attribute name and starting with a new created Buffer object ...
static GLArrayDataServer createGLSLMapped(final String name, final int compsPerElement, final int dataType, final boolean normalized, final int mappedElementCount, final int vboUsage)
Create a VBO, using a custom GLSL array attribute name intended for GPU buffer storage mapping,...
GLBufferStorage mapStorage(final GL gl, final int access)
static GLArrayDataServer createData(final int compsPerElement, final int dataType, final int stride, final Buffer buffer, final int vboUsage, final int vboTarget)
Create a VBO data object for any target w/o render pipeline association, ie GL#GL_ELEMENT_ARRAY_BUFFE...
static GLArrayDataServer createFixed(final int index, final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO, using a predefined fixed function array index and starting with a new created Buffer ob...
GLArrayDataServer(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)
static GLArrayDataServer createGLSL(final String name, final int compsPerElement, final int dataType, final boolean normalized, final int stride, final Buffer buffer, final int vboUsage)
Create a VBO, using a custom GLSL array attribute name and starting with a given Buffer object incl i...
GLArrayData addFixedSubArray(final int index, final int comps, final int vboTarget)
Configure a segment of this fixed function interleaved array (see createFixedInterleaved(int,...
void destroy(final GL gl)
GLArrayDataWrapper addGLSLSubArray(final String name, final int comps, final int vboTarget)
Configure a segment of this GLSL interleaved array (see createGLSLInterleaved(int,...
final int getInterleavedOffset()
static GLArrayDataServer createData(final int compsPerElement, final int dataType, final int initialElementCount, final int vboUsage, final int vboTarget)
Create a VBO data object for any target w/o render pipeline association, ie GL#GL_ELEMENT_ARRAY_BUFFE...
void setVBOEnabled(final boolean vboUsage)
Convenient way do disable the VBO behavior and switch to client side data one Only possible if buffer...
static GLArrayDataServer createGLSLInterleavedMapped(final int compsPerElement, final int dataType, final boolean normalized, final int mappedElementCount, final int vboUsage)
Create a VBO for GLSL interleaved array data intended for GPU buffer storage mapping,...
static GLArrayDataServer createFixed(final int index, final int compsPerElement, final int dataType, final boolean normalized, final int stride, final Buffer buffer, final int vboUsage)
Create a VBO, using a predefined fixed function array index and starting with a given Buffer object i...
static GLArrayDataServer createFixedInterleavedMapped(final int compsPerElement, final int dataType, final boolean normalized, final int mappedElementCount, final int vboUsage)
Create a VBO for fixed function interleaved array data intended for GPU buffer storage mapping,...
static GLArrayDataServer createDataMapped(final int compsPerElement, final int dataType, final int mappedElementCount, final int vboUsage, final int vboTarget)
Create a VBO data object for any target w/o render pipeline association, i.e.
GLArrayDataServer(final GLArrayDataServer src)
Copy Constructor.
GLBufferStorage mapStorage(final GL gl, final long offset, final long length, final int access)
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.
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 strideB
stride in bytes; strideB >= compsPerElement * bytesPerComp
final boolean isVertexAttr
void setVBOEnabled(final boolean vboEnabled)
Enable or disable use of VBO.
final int strideL
stride in logical components
final int mappedElemCount
final int compsPerElement
The total number of bytes hold by the referenced buffer is: getComponentSize()* getComponentNumber() ...
int getVBOTarget()
The VBO target or 0 if not a VBO.
int getCompsPerElem()
The number of components per element.
String elemStatsToString()
Returns a string with detailed buffer element stats, i.e.
boolean getNormalized()
True, if GL shall normalize fixed point data while converting them into float.
boolean isVBO()
Determines whether the data is server side (VBO) and enabled, or a client side array (false).
int getVBOUsage()
The VBO usage or 0 if not a VBO.
Buffer getBuffer()
The Buffer holding the data, may be null if a GPU buffer without client bound data.
boolean isVertexAttribute()
Returns true if this data set is intended for a GLSL vertex shader attribute, otherwise false,...
int getVBOName()
The VBO name or 0 if not a VBO.
int getBytesPerComp()
The component's size in bytes.
int getCompType()
The component's GL data type, ie.
int getByteCount()
Returns the byte position (written elements) if not sealed() or the byte limit (available to read) af...
GLBufferStorage mapBufferRange(final int target, final long offset, final long length, final int access)
Returns the GLBufferStorage instance as mapped via OpenGL's native glMapBufferRange(....
GLBufferStorage mapBuffer(int target, int access)
Returns the GLBufferStorage instance as mapped via OpenGL's native glMapBuffer(..) implementation.
void glGenBuffers(int n, IntBuffer buffers)
Entry point to C language function: void {@native glGenBuffers}(GLsizei n, GLuint * buffers) Part ...
boolean glUnmapBuffer(int target)
Entry point to C language function: GLboolean {@native glUnmapBuffer}(GLenum target) Part of GL_VE...
void glDeleteBuffers(int n, IntBuffer buffers)
Entry point to C language function: void {@native glDeleteBuffers}(GLsizei n, const GLuint * buffers...
void glBufferData(int target, long size, Buffer data, int usage)
Entry point to C language function: void {@native glBufferData}(GLenum target, GLsizeiptr size,...
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...
The total number of bytes hold by the referenced buffer is: getComponentSize()* getComponentNumber() ...