/** * allocate memory for the Buffer <br><br><i>glBufferData with null as * data</i></br></br> * <p/> * @param bsize memory size in bytes which should be allocated * @param usage Buffer usage type */ public void allocate(int bsize, Type type, Usage usage) { size = bsize; gc.getGL().glBufferData(target.glvalue, size, null, getGLConst(type, usage)); }
/** * Writes data to the buffer and allcoates as much memory as needed for the * data * <p/> * @param data data which should be written to the buffer * @param usage Buffer usage type */ public void bufferData(Buffer data, Type type, Usage usage) { int bsize = GLBuffers.sizeOfBufferElem(data); data.rewind(); size = bsize * data.limit(); gc.getGL().glBufferData(target.glvalue, size, data, getGLConst(type, usage)); }
private final void writeBuffer(final GL gl) { final int vBytes = vElems * vCompsBytes; final int cBytes = cElems * cCompsBytes; final int nBytes = nElems * nCompsBytes; final int tBytes = tElems * tCompsBytes; final int delta = buffer.limit() - (vBytes+cBytes+nBytes+tBytes); if( bufferWrittenOnce && delta > pageSize ) { if(0 < vBytes) { gl.glBufferSubData(GL.GL_ARRAY_BUFFER, vOffset, vBytes, vertexArray); } if(0 < cBytes) { gl.glBufferSubData(GL.GL_ARRAY_BUFFER, cOffset, cBytes, colorArray); } if(0 < nBytes) { gl.glBufferSubData(GL.GL_ARRAY_BUFFER, nOffset, nBytes, normalArray); } if(0 < tBytes) { gl.glBufferSubData(GL.GL_ARRAY_BUFFER, tOffset, tBytes, textCoordArray); } } else { gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit(), buffer, glBufferUsage); bufferWrittenOnce = true; } }
public static DncDeviceChunk xferChunkToDevice( DncHostChunk hChunk, GL gl ) { int verticesHandle = genBuffer( gl ); gl.glBindBuffer( GL_ARRAY_BUFFER, verticesHandle ); gl.glBufferData( GL_ARRAY_BUFFER, hChunk.verticesBuf.remaining( ) * SIZEOF_FLOAT, hChunk.verticesBuf, GL_STATIC_DRAW ); return new DncDeviceChunk( hChunk.chunkKey, hChunk.featureCount, hChunk.groups, verticesHandle ); }
public GLBufferStorage mapStorage(final GL gl, final long offset, final long length, final int access) { if( null != this.getBuffer() ) { throw new IllegalStateException("user buffer not null"); } if( null != mappedStorage ) { throw new IllegalStateException("already mapped: "+mappedStorage); } checkSeal(true); bindBuffer(gl, true); gl.glBufferData(getVBOTarget(), getSizeInBytes(), null, getVBOUsage()); final GLBufferStorage storage = gl.mapBufferRange(getVBOTarget(), offset, length, access); setMappedBuffer(storage); bindBuffer(gl, false); seal(false); rewind(); return storage; } private final void setMappedBuffer(final GLBufferStorage storage) {
public GLBufferStorage mapStorage(final GL gl, final int access) { if( null != this.getBuffer() ) { throw new IllegalStateException("user buffer not null"); } if( null != mappedStorage ) { throw new IllegalStateException("already mapped: "+mappedStorage); } checkSeal(true); bindBuffer(gl, true); gl.glBufferData(getVBOTarget(), getSizeInBytes(), null, getVBOUsage()); final GLBufferStorage storage = gl.mapBuffer(getVBOTarget(), access); setMappedBuffer(storage); bindBuffer(gl, false); seal(false); rewind(); return storage; } public GLBufferStorage mapStorage(final GL gl, final long offset, final long length, final int access) {
context.glBufferData( GL.GL_ARRAY_BUFFER, coordBuffer.capacity() * 4, coordBuffer, GL.GL_STATIC_DRAW ); context.glBufferData( GL.GL_ARRAY_BUFFER, normalBuffer.capacity() * 4, normalBuffer, GL.GL_STATIC_DRAW ); context.glBufferData( GL.GL_ARRAY_BUFFER, textureBuffer.capacity() * 4, textureBuffer, GL.GL_STATIC_DRAW );
public static DncDeviceLabelAtlas xferLabelAtlasToDevice( DncHostLabelAtlas hAtlas, GL gl ) { TexturableImage textureImage = hAtlas.textureImage; int textureHandle = genTexture( gl ); gl.glBindTexture( GL_TEXTURE_2D, textureHandle ); gl.glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); gl.glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); gl.glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); gl.glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); textureImage.pushToTexture( gl, GL_TEXTURE_2D ); int[] bufferHandles = new int[ 2 ]; gl.glGenBuffers( 2, bufferHandles, 0 ); int entriesAlignHandle = bufferHandles[ 0 ]; gl.glBindBuffer( GL_ARRAY_BUFFER, entriesAlignHandle ); gl.glBufferData( GL_ARRAY_BUFFER, hAtlas.entriesAlignBuf.remaining( ) * SIZEOF_FLOAT, hAtlas.entriesAlignBuf, GL_STATIC_DRAW ); int entriesBoundsHandle = bufferHandles[ 1 ]; gl.glBindBuffer( GL_ARRAY_BUFFER, entriesBoundsHandle ); gl.glBufferData( GL_ARRAY_BUFFER, hAtlas.entriesBoundsBuf.remaining( ) * SIZEOF_FLOAT, hAtlas.entriesBoundsBuf, GL_STATIC_DRAW ); return new DncDeviceLabelAtlas( hAtlas.chunkKey, textureImage.getWidth( ), textureImage.getHeight( ), entriesAlignHandle, entriesBoundsHandle, textureHandle ); }
@Override public final boolean bindBuffer(final GL gl, final boolean bind) { if( !ad.isVBO() ) { return false; } if(bind) { // always bind and refresh the VBO mgr, // in case more than one gl*Pointer objects are in use gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); if(!ad.isVBOWritten()) { final Buffer buffer = ad.getBuffer(); if(null!=buffer) { gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); } ad.setVBOWritten(true); } } else { gl.glBindBuffer(ad.getVBOTarget(), 0); } return true; }
public static int setupVBO(final AbstractBufferData<? extends Buffer> data, final RenderContext context) { if (data == null) { return 0; } final GL gl = GLContext.getCurrentGL(); final RendererRecord rendRecord = context.getRendererRecord(); int vboID = data.getVBOID(context.getGlContextRep()); if (vboID != 0) { updateVBO(data, rendRecord, vboID, 0); return vboID; } final Buffer dataBuffer = data.getBuffer(); if (dataBuffer != null) { // XXX: should we be rewinding? Maybe make that the programmer's responsibility. dataBuffer.rewind(); vboID = makeVBOId(); data.setVBOID(context.getGlContextRep(), vboID); rendRecord.invalidateVBO(); JoglRendererUtil.setBoundVBO(rendRecord, vboID); gl.glBufferData(GL.GL_ARRAY_BUFFER, dataBuffer.limit() * data.getByteCount(), dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else { throw new Ardor3dException("Attempting to create a vbo id for an AbstractBufferData with no Buffer value."); } return vboID; }
gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, dataBuffer.limit() * data.getByteCount(), dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else {
gl.glBufferData(GL.GL_ARRAY_BUFFER, bufferSize, null, getGLVBOAccessMode(interleaved.getVboAccessMode()));