JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
GLArrayDataClient.java
Go to the documentation of this file.
1/**
2 * Copyright 2010-2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.util;
30
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;
37
38import com.jogamp.opengl.GL;
39import com.jogamp.opengl.GLException;
40import com.jogamp.opengl.fixedfunc.GLPointerFuncUtil;
41
42import jogamp.opengl.util.GLArrayHandler;
43import jogamp.opengl.util.GLFixedArrayHandler;
44import jogamp.opengl.util.glsl.GLSLArrayHandler;
45
46import com.jogamp.common.nio.Buffers;
47import com.jogamp.opengl.util.glsl.ShaderState;
48
49
51 /** Default growth factor using the golden ratio 1.618 */
52 public static final float DEFAULT_GROWTH_FACTOR = 1.618f;
53
54 /**
55 * Create a client side buffer object, using a predefined fixed function array index
56 * and starting with a new created Buffer object with initialElementCount size
57 *
58 * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected.
59 * On profile ES2 the fixed function emulation will transform these calls to
60 * EnableVertexAttribArray and VertexAttribPointer calls,
61 * and a predefined vertex attribute variable name will be chosen.
62 *
63 * The default name mapping will be used,
64 * see {@link GLPointerFuncUtil#getPredefinedArrayIndexName(int)}.
65 *
66 * @param index The GL array index
67 * @param comps The array component number
68 * @param dataType The array index GL data type
69 * @param normalized Whether the data shall be normalized
70 * @param initialElementCount
71 *
72 * @see com.jogamp.opengl.GLContext#getPredefinedArrayIndexName(int)
73 */
74 public static GLArrayDataClient createFixed(final int index, final int comps, final int dataType, final boolean normalized, final int initialElementCount)
75 throws GLException
76 {
77 return new GLArrayDataClient(null, index, comps, dataType, normalized, 0, null, initialElementCount, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
78 false, GLFixedArrayHandler.class, 0, 0, 0, 0, false);
79 }
80
81 /**
82 * Create a client side buffer object, using a predefined fixed function array index
83 * and starting with a given Buffer object incl it's stride
84 *
85 * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected.
86 * On profile ES2 the fixed function emulation will transform these calls to
87 * EnableVertexAttribArray and VertexAttribPointer calls,
88 * and a predefined vertex attribute variable name will be chosen.
89 *
90 * The default name mapping will be used,
91 * see {@link GLPointerFuncUtil#getPredefinedArrayIndexName(int)}.
92 *
93 * @param index The GL array index
94 * @param comps The array component number
95 * @param dataType The array index GL data type
96 * @param normalized Whether the data shall be normalized
97 * @param stride
98 * @param buffer the user define data
99 *
100 * @see com.jogamp.opengl.GLContext#getPredefinedArrayIndexName(int)
101 */
102 public static GLArrayDataClient createFixed(final int index, final int comps, final int dataType, final boolean normalized, final int stride,
103 final Buffer buffer)
104 throws GLException
105 {
106 return new GLArrayDataClient(null, index, comps, dataType, normalized, stride, buffer, comps*comps, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
107 false, GLFixedArrayHandler.class, 0, 0, 0, 0, false);
108 }
109
110 /**
111 * Create a client side buffer object, using a custom GLSL array attribute name
112 * and starting with a new created Buffer object with initialElementCount size
113 * @param name The custom name for the GL attribute.
114 * @param comps The array component number
115 * @param dataType The array index GL data type
116 * @param normalized Whether the data shall be normalized
117 * @param initialElementCount
118 */
119 public static GLArrayDataClient createGLSL(final String name, final int comps,
120 final int dataType, final boolean normalized, final int initialElementCount)
121 throws GLException
122 {
123 return new GLArrayDataClient(name, -1, comps, dataType, normalized, 0, null, initialElementCount, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
124 true, GLSLArrayHandler.class, 0, 0, 0, 0, true);
125 }
126
127 /**
128 * Create a client side buffer object, using a custom GLSL array attribute name
129 * and starting with a given Buffer object incl it's stride
130 * @param name The custom name for the GL attribute.
131 * @param comps The array component number
132 * @param dataType The array index GL data type
133 * @param normalized Whether the data shall be normalized
134 * @param stride
135 * @param buffer the user define data
136 */
137 public static GLArrayDataClient createGLSL(final String name, final int comps,
138 final int dataType, final boolean normalized, final int stride, final Buffer buffer)
139 throws GLException
140 {
141 return new GLArrayDataClient(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
142 true, GLSLArrayHandler.class, 0, 0, 0, 0, true);
143 }
144
145 @Override
146 public void associate(final Object obj, final boolean enable) {
147 if(obj instanceof ShaderState) {
148 if(enable) {
150 } else {
151 shaderState = null;
152 }
153 }
154 }
155
156 //
157 // Data read access
158 //
159
160 @Override
161 public final boolean isVBOWritten() { return bufferWritten; }
162
163 @Override
164 public final boolean enabled() { return bufferEnabled; }
165
166 //
167 // Data and GL state modification ..
168 //
169
170 @Override
171 public final void setVBOWritten(final boolean written) {
172 bufferWritten = ( 0 == mappedElemCount ) ? written : true;
173 }
174
175 @Override
176 public void destroy(final GL gl) {
177 clear(gl);
178 super.destroy(gl);
179 }
180
181 @Override
182 public void clear(final GL gl) {
183 seal(gl, false);
184 clear();
185 }
186
187 @Override
188 public void seal(final GL gl, final boolean seal) {
189 seal(seal);
190 enableBuffer(gl, seal);
191 }
192
193 @Override
194 public void enableBuffer(final GL gl, final boolean enable) {
195 if( enableBufferAlways || bufferEnabled != enable ) {
196 if(enable) {
197 checkSeal(true);
198 // init/generate VBO name if not done yet
199 init_vbo(gl);
200 }
201 glArrayHandler.enableState(gl, enable, usesGLSL ? shaderState : null);
202 bufferEnabled = enable;
203 }
204 }
205
206 @Override
207 public boolean bindBuffer(final GL gl, final boolean bind) {
208 if(bind) {
209 checkSeal(true);
210 // init/generate VBO name if not done yet
211 init_vbo(gl);
212 }
213 return glArrayHandler.bindBuffer(gl, bind);
214 }
215
216 @Override
217 public void setEnableAlways(final boolean always) {
218 enableBufferAlways = always;
219 }
220
221 //
222 // Data modification ..
223 //
224
225 @Override
226 public void clear() {
227 if( buffer != null ) {
228 buffer.clear();
229 }
230 sealed = false;
231 bufferEnabled = false;
232 bufferWritten = ( 0 == mappedElemCount ) ? false : true;
233 }
234
235 @Override
236 public void seal(final boolean seal)
237 {
238 if( sealed == seal ) return;
239 sealed = seal;
240 bufferWritten = ( 0 == mappedElemCount ) ? false : true;
241 if( seal ) {
242 if ( null != buffer ) {
243 buffer.flip();
244 }
245 } else if ( null != buffer ) {
246 buffer.position(buffer.limit());
247 buffer.limit(buffer.capacity());
248 }
249 }
250
251
252 @Override
253 public void rewind() {
254 if(buffer!=null) {
255 buffer.rewind();
256 }
257 }
258
259 @Override
260 public void padding(int doneInByteSize) {
261 if ( buffer==null || sealed ) return;
262 while(doneInByteSize<strideB) {
263 Buffers.putb(buffer, (byte)0);
264 doneInByteSize++;
265 }
266 }
267
268 /**
269 * Generic buffer relative put method.
270 *
271 * This class buffer Class must match the arguments buffer class.
272 * The arguments remaining elements must be a multiple of this arrays element stride.
273 */
274 @Override
275 public void put(final Buffer v) {
276 if ( sealed ) return;
277 /** FIXME: isn't true for interleaved arrays !
278 if(0!=(v.remaining() % strideL)) {
279 throw new GLException("Buffer length ("+v.remaining()+") is not a multiple of component-stride:\n\t"+this);
280 } */
281 growIfNeeded(v.remaining());
282 Buffers.put(buffer, v);
283 }
284
285 @Override
286 public void putb(final byte v) {
287 if ( sealed ) return;
288 growIfNeeded(1);
289 Buffers.putb(buffer, v);
290 }
291
292 @Override
293 public void put3b(final byte v1, final byte v2, final byte v3) {
294 if ( sealed ) return;
295 growIfNeeded(3);
296 Buffers.put3b(buffer, v1, v2, v3);
297 }
298
299 @Override
300 public void put4b(final byte v1, final byte v2, final byte v3, final byte v4) {
301 if ( sealed ) return;
302 growIfNeeded(4);
303 Buffers.put4b(buffer, v1, v2, v3, v4);
304 }
305
306 @Override
307 public void putb(final byte[] src, final int offset, final int length) {
308 if ( sealed ) return;
309 growIfNeeded(length);
310 Buffers.putb(buffer, src, offset, length);
311 }
312
313 @Override
314 public void puts(final short v) {
315 if ( sealed ) return;
316 growIfNeeded(1);
317 Buffers.puts(buffer, v);
318 }
319
320 @Override
321 public void put3s(final short v1, final short v2, final short v3) {
322 if ( sealed ) return;
323 growIfNeeded(3);
324 Buffers.put3s(buffer, v1, v2, v3);
325 }
326
327 @Override
328 public void put4s(final short v1, final short v2, final short v3, final short v4) {
329 if ( sealed ) return;
330 growIfNeeded(4);
331 Buffers.put4s(buffer, v1, v2, v3, v4);
332 }
333
334 @Override
335 public void puts(final short[] src, final int offset, final int length) {
336 if ( sealed ) return;
337 growIfNeeded(length);
338 Buffers.puts(buffer, src, offset, length);
339 }
340
341 @Override
342 public void puti(final int v) {
343 if ( sealed ) return;
344 growIfNeeded(1);
345 Buffers.puti(buffer, v);
346 }
347
348 @Override
349 public void put3i(final int v1, final int v2, final int v3) {
350 if ( sealed ) return;
351 growIfNeeded(3);
352 Buffers.put3i(buffer, v1, v2, v3);
353 }
354
355 @Override
356 public void put4i(final int v1, final int v2, final int v3, final int v4) {
357 if ( sealed ) return;
358 growIfNeeded(4);
359 Buffers.put4i(buffer, v1, v2, v3, v4);
360 }
361
362 @Override
363 public void puti(final int[] src, final int offset, final int length) {
364 if ( sealed ) return;
365 growIfNeeded(length);
366 Buffers.puti(buffer, src, offset, length);
367 }
368
369 @Override
370 public void putx(final int v) {
371 puti(v);
372 }
373
374 @Override
375 public void putf(final float v) {
376 if ( sealed ) return;
377 growIfNeeded(1);
378 Buffers.putf(buffer, v);
379 }
380
381 @Override
382 public void put3f(final float v1, final float v2, final float v3) {
383 if ( sealed ) return;
384 growIfNeeded(3);
385 Buffers.put3f(buffer, v1, v2, v3);
386 }
387
388 @Override
389 public void put4f(final float v1, final float v2, final float v3, final float v4) {
390 if ( sealed ) return;
391 growIfNeeded(4);
392 Buffers.put4f(buffer, v1, v2, v3, v4);
393 }
394
395 @Override
396 public void putf(final float[] src, final int offset, final int length) {
397 if ( sealed ) return;
398 growIfNeeded(length);
399 Buffers.putf(buffer, src, offset, length);
400 }
401
402 @Override
403 public String toString() {
404 return "GLArrayDataClient["+name+
405 ", index "+index+
406 ", location "+location+
407 ", isVertexAttribute "+isVertexAttr+
408 ", usesGLSL "+usesGLSL+
409 ", usesShaderState "+(null!=shaderState)+
410 ", dataType 0x"+Integer.toHexString(compType)+
411 ", bufferClazz "+compClazz+
412 ", compsPerElem "+compsPerElement+
413 ", stride "+strideB+"b "+strideL+"c"+
414 ", initElemCount "+initElemCount+
415 ", mappedElemCount "+mappedElemCount+
416 ", "+elemStatsToString()+
417 ", bufferEnabled "+bufferEnabled+
418 ", bufferWritten "+bufferWritten+
419 ", buffer "+buffer+
420 ", alive "+alive+
421 "]";
422 }
423
424 /**
425 * Returning element-count from given componentCount, rounding up to componentsPerElement.
426 */
427 public int compsToElemCount(final int componentCount) {
428 return ( componentCount + compsPerElement - 1 ) / compsPerElement;
429 }
430
431 /**
432 * Increase the capacity of the buffer if necessary to add given spareComponents components.
433 * <p>
434 * Buffer will not change if remaining free slots, capacity less position, satisfy spareComponents components.
435 * </p>
436 * @param spareComponents number of components to add if necessary.
437 * @return true if buffer size has changed, i.e. grown. Otherwise false.
438 */
439 public final boolean growIfNeeded(final int spareComponents) {
440 if( null == buffer || buffer.remaining() < spareComponents ) {
441 if( 0 != mappedElemCount ) {
442 throw new GLException("Mapped buffer can't grow. Insufficient storage size: Needed "+spareComponents+" components, "+
443 "mappedElementCount "+mappedElemCount+
444 ", has mapped buffer "+buffer+"; "+this);
445 }
446 if( null == buffer ) {
447 final int required_elems = compsToElemCount(spareComponents);
448 return reserve( Math.max( initElemCount, required_elems ) );
449 } else {
450 final int has_comps = buffer.capacity();
451 final int required_elems = compsToElemCount(has_comps + spareComponents);
452 final int new_elems = compsToElemCount( (int)( has_comps * growthFactor + 0.5f ) );
453 final int elementCount = Math.max( new_elems, required_elems );
454 return reserve( elementCount );
455 }
456 }
457 return false;
458 }
459
460 /**
461 * Increase the capacity of the buffer to given elementCount element size,
462 * i.e. elementCount * componentsPerElement components.
463 * <p>
464 * Buffer will not change if given elementCount is lower or equal current capacity.
465 * </p>
466 * @param elementCount number of elements to hold.
467 * @return true if buffer size has changed, i.e. grown. Otherwise false.
468 */
469 public final boolean reserve(int elementCount) {
470 if(!alive || sealed) {
471 throw new GLException("Invalid state: "+this);
472 }
473
474 // add the stride delta
475 elementCount += (elementCount/compsPerElement)*(strideL-compsPerElement);
476
477 final int osize = (buffer!=null) ? buffer.capacity() : 0;
478 final int nsize = elementCount * compsPerElement;
479 if( nsize <= osize ) {
480 return false;
481 }
482 final Buffer oldBuffer = buffer;
483
484 if(compClazz==ByteBuffer.class) {
485 final ByteBuffer newBBuffer = Buffers.newDirectByteBuffer( nsize );
486 if(oldBuffer!=null) {
487 oldBuffer.flip();
488 newBBuffer.put((ByteBuffer)oldBuffer);
489 }
490 buffer = newBBuffer;
491 } else if(compClazz==ShortBuffer.class) {
492 final ShortBuffer newSBuffer = Buffers.newDirectShortBuffer( nsize );
493 if(oldBuffer!=null) {
494 oldBuffer.flip();
495 newSBuffer.put((ShortBuffer)oldBuffer);
496 }
497 buffer = newSBuffer;
498 } else if(compClazz==IntBuffer.class) {
499 final IntBuffer newIBuffer = Buffers.newDirectIntBuffer( nsize );
500 if(oldBuffer!=null) {
501 oldBuffer.flip();
502 newIBuffer.put((IntBuffer)oldBuffer);
503 }
504 buffer = newIBuffer;
505 } else if(compClazz==FloatBuffer.class) {
506 final FloatBuffer newFBuffer = Buffers.newDirectFloatBuffer( nsize );
507 if(oldBuffer!=null) {
508 oldBuffer.flip();
509 newFBuffer.put((FloatBuffer)oldBuffer);
510 }
511 buffer = newFBuffer;
512 } else {
513 throw new GLException("Given Buffer Class not supported: "+compClazz+":\n\t"+this);
514 }
515 if(DEBUG) {
516 System.err.println("*** Size: Reserve: comps: "+compsPerElement+", "+(osize/compsPerElement)+"/"+osize+" -> "+(nsize/compsPerElement)+"/"+nsize+
517 "; "+oldBuffer+" -> "+buffer+"; "+this);
518 }
519 return true;
520 }
521
522 // non public matters
523
524 protected final void checkSeal(final boolean test) throws GLException {
525 if(!alive) {
526 throw new GLException("Invalid state: "+this);
527 }
528 if(sealed!=test) {
529 if(test) {
530 throw new GLException("Not Sealed yet, seal first:\n\t"+this);
531 } else {
532 throw new GLException("Already Sealed, can't modify VBO:\n\t"+this);
533 }
534 }
535 }
536
537 protected GLArrayDataClient(final String name, final int index, final int comps, final int dataType, final boolean normalized, final int stride, final Buffer data,
538 final int initialElementCount, final float growthFactor,
539 final int mappedElementCount, final boolean isVertexAttribute,
540 final Class<? extends GLArrayHandler> handlerClass,
541 final int vboName, final long vboOffset, final int vboUsage, final int vboTarget, final boolean usesGLSL)
542 throws GLException
543 {
544 super(name, index, comps, dataType, normalized, stride, data, mappedElementCount,
546
547 if( 0<mappedElementCount && 0<initialElementCount ) { // null!=buffer case validated in super.init(..)
548 throw new IllegalArgumentException("mappedElementCount:="+mappedElementCount+" specified, but passing non zero initialElementSize");
549 }
550
551 // immutable types
552 this.initElemCount = initialElementCount;
553 this.growthFactor = growthFactor;
554 try {
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);
559 }
560 this.usesGLSL = usesGLSL;
561
562 // mutable types
563 this.sealed=false;
564 this.bufferEnabled=false;
565 this.enableBufferAlways=false;
566 this.bufferWritten = ( 0 == mappedElementCount ) ? false : true;
567
568 if(null==buffer && initialElementCount>0) {
569 reserve(initialElementCount);
570 }
571 }
572
573 protected void init_vbo(final GL gl) {
574 if(!isValidated ) {
575 isValidated = true;
576 validate(gl.getGLProfile(), true);
577 }
578 }
579
580 /**
581 * Copy Constructor
582 * <p>
583 * Buffer is {@link Buffers#slice(Buffer) sliced}, i.e. sharing content but using own state.
584 * </p>
585 * <p>
586 * All other values are simply copied.
587 * </p>
588 */
590 super(src);
591
592 // immutable types
593 this.initElemCount = src.initElemCount;
594 if( null != src.glArrayHandler ) {
595 final Class<? extends GLArrayHandler> clazz = src.glArrayHandler.getClass();
596 try {
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);
601 }
602 } else {
603 this.glArrayHandler = null;
604 }
605 this.usesGLSL = src.usesGLSL;
606
607 // mutable types
608 this.growthFactor = src.growthFactor;
609 this.isValidated = src.isValidated;
610 this.bufferEnabled = src.bufferEnabled;
611 this.bufferWritten = src.bufferWritten;
612 this.enableBufferAlways = src.enableBufferAlways;
613 this.shaderState = src.shaderState;
614 }
615
616 /**
617 * Returns this buffer's growth factor.
618 * <p>
619 * Default is {@link #DEFAULT_GROWTH_FACTOR}, i.e. the golden ratio 1.618.
620 * </p>
621 * @see #setGrowthFactor(float)
622 * @see #DEFAULT_GROWTH_FACTOR
623 */
624 public float getGrowthFactor() { return growthFactor; }
625
626 /**
627 * Sets a new growth factor for this buffer.
628 * <p>
629 * Default is {@link #DEFAULT_GROWTH_FACTOR}, i.e. the golden ratio 1.618.
630 * </p>
631 * @param v new growth factor, which will be clipped to a minimum of 1, i.e. 0% minimum growth.
632 * @see #getGrowthFactor()
633 * @see #DEFAULT_GROWTH_FACTOR
634 */
635 public void setGrowthFactor(final float v) {
636 growthFactor = Math.max(1f, v);
637 }
638
639 protected final int initElemCount;
640 protected final GLArrayHandler glArrayHandler;
641 protected final boolean usesGLSL;
642
643 protected float growthFactor;
644 private boolean isValidated = false;
645 protected boolean bufferEnabled;
646 protected boolean bufferWritten;
647 protected boolean enableBufferAlways;
648
650
651}
652
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)
float getGrowthFactor()
Returns this buffer's growth factor.
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 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 puti(final int[] src, final int offset, final int length)
void put(final Buffer v)
Generic buffer relative put method.
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 int strideL
stride in logical components
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() ...