private static void updateVBO(final AbstractBufferData<? extends Buffer> data, final RendererRecord rendRecord, final int vboID, final int offsetBytes) { if (data.isNeedsRefresh()) { final GL gl = GLContext.getCurrentGL(); final Buffer dataBuffer = data.getBuffer(); dataBuffer.rewind(); JoglRendererUtil.setBoundVBO(rendRecord, vboID); gl.glBufferSubData(GL.GL_ARRAY_BUFFER, offsetBytes, dataBuffer.limit() * data.getByteCount(), dataBuffer); data.setNeedsRefresh(false); } }
public static void cleanAllVBOs(final Renderer deleter) { final Multimap<Object, Integer> idMap = ArrayListMultimap.create(); // gather up expired vbos... these don't exist in our cache gatherGCdIds(idMap); // Walk through the cached items and delete those too. for (final AbstractBufferData<?> buf : _identityCache.keySet()) { if (buf._vboIdCache != null) { if (Constants.useMultipleContexts) { final Set<Object> contextObjects = buf._vboIdCache.getContextObjects(); for (final Object o : contextObjects) { // Add id to map idMap.put(o, buf.getVBOID(o)); } } else { idMap.put(ContextManager.getCurrentContext().getGlContextRep(), buf.getVBOID(null)); } buf._vboIdCache.clear(); } } handleVBODelete(deleter, idMap); }
/** * Clean any VBO ids from the hardware, using the given utility object to do the work immediately, if given. If not, * we will delete in the next execution of the appropriate context's game task render queue. * * @param utils * the util class to use. If null, execution will not occur immediately. */ public static void cleanExpiredVBOs(final IShaderUtils utils) { // gather up expired vbos... final Multimap<RenderContextRef, Integer> idMap = gatherGCdIds(null); if (idMap != null) { // send to be deleted (perhaps on next render.) handleVBODelete(utils, idMap); } }
public static void cleanAllBuffers(final IShaderUtils utils) { final Multimap<RenderContextRef, Integer> idMap = ArrayListMultimap.create(); // gather up expired vbos... these don't exist in our cache gatherGCdIds(idMap); // Walk through the cached items and delete those too. for (final AbstractBufferData<?> buf : _identityCache.keySet()) { if (buf._bufferIdCache != null) { if (Constants.useMultipleContexts) { final Set<RenderContextRef> contextObjects = buf._bufferIdCache.getContextRefs(); for (final RenderContextRef o : contextObjects) { // Add id to map idMap.put(o, buf.getBufferIdByRef(o)); } } else { idMap.put(ContextManager.getCurrentContext().getGlContextRef(), buf.getBufferIdByRef(null)); } buf._bufferIdCache.clear(); buf.markDirty(); } } handleVBODelete(utils, idMap); }
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; }
final RenderContext context) { int id = buffer.getBufferId(context); if (id != 0 && buffer.isBufferClean(context)) { return id; final Buffer dataBuffer = buffer.getBuffer(); if (dataBuffer != null) { dataBuffer.rewind(); buffer.setBufferId(context, id); if (logger.isLoggable(Level.FINE)) { logger.fine("generated new buffer: " + id); GL15C.glBindBuffer(target, id); if (newBuffer) { GL15C.glBufferData(target, dataBuffer.capacity() * buffer.getByteCount(), getGLVBOAccessMode(buffer.getVboAccessMode())); buffer.markClean(context);
public static void updateVBO(final AbstractBufferData<? extends Buffer> data, final RendererRecord rendRecord, final int vboID, final int offsetBytes) { if (data.isNeedsRefresh()) { final Buffer dataBuffer = data.getBuffer(); dataBuffer.rewind(); LwjglRendererUtil.setBoundVBO(rendRecord, vboID); if (dataBuffer instanceof FloatBuffer) { ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, (FloatBuffer) dataBuffer); } else if (dataBuffer instanceof ByteBuffer) { ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, (ByteBuffer) dataBuffer); } else if (dataBuffer instanceof IntBuffer) { ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, (IntBuffer) dataBuffer); } else if (dataBuffer instanceof ShortBuffer) { ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, (ShortBuffer) dataBuffer); } data.setNeedsRefresh(false); } }
public void deleteVBOs(final AbstractBufferData<?> buffer) { if (buffer == null) { return; } // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final int id = buffer.getVBOID(context.getGlContextRep()); if (id == 0) { // Not on card... return. return; } buffer.removeVBOID(context.getGlContextRep()); final IntBuffer idBuff = BufferUtils.createIntBuffer(1); idBuff.put(id); idBuff.flip(); ARBBufferObject.glDeleteBuffersARB(idBuff); }
@Override public void bindVertexAttribute(final int location, final AbstractBufferData<? extends Buffer> buffer) { GL20C.glVertexAttribPointer(location, buffer.getValuesPerTuple(), getGLDataType(buffer.getBuffer()), false, 0, 0); GL20C.glEnableVertexAttribArray(location); }
/** * Gets the nio buffer associated with the given key. * * @return the buffer for the associated buffer data */ public <T extends Buffer> T getBuffer(final String key) { @SuppressWarnings("unchecked") final AbstractBufferData<T> coords = getCoords(key); if (coords == null) { return null; } return coords.getBuffer(); }
/** * Handle detecting and scheduling cleanup of OpenGL assets. This method will place delete calls on the task queue * of appropriate RenderContexts when an asset such as a Texture is determined to no longer be reachable by Java. * * @param immediateDelete * an optional Renderer to use for immediate cleanup when the asset is owned by the current context. In * general this is best used in single context applications, and null is a perfectly acceptable value. */ public static void doRuntimeCleanup(final Renderer immediateDelete) { TextureManager.cleanExpiredTextures(immediateDelete, null); AbstractBufferData.cleanExpiredVBOs(immediateDelete); DisplayListDelegate.cleanExpiredDisplayLists(immediateDelete); }
@Override public void read(final InputCapsule capsule) throws IOException { super.read(capsule); _buffer = capsule.readFloatBuffer("buffer", null); _valuesPerTuple = capsule.readInt("valuesPerTuple", 0); }
if (buffer.isBufferClean(context)) { continue;
int vboID = data.getVBOID(context.getGlContextRep()); if (vboID != 0) { updateVBO(data, rendRecord, vboID, 0); final Buffer dataBuffer = data.getBuffer(); if (dataBuffer != null) { data.setVBOID(context.getGlContextRep(), vboID); if (dataBuffer instanceof FloatBuffer) { ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, (FloatBuffer) dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else if (dataBuffer instanceof ByteBuffer) { ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, (ByteBuffer) dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else if (dataBuffer instanceof IntBuffer) { ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, (IntBuffer) dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else if (dataBuffer instanceof ShortBuffer) { ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, (ShortBuffer) dataBuffer, getGLVBOAccessMode(data.getVboAccessMode()));
/** * Clean any VBO ids from the hardware, using the given Renderer object to do the work immediately, if given. If * not, we will delete in the next execution of the appropriate context's game task render queue. * * @param deleter * the Renderer to use. If null, execution will not occur immediately. */ public static void cleanExpiredVBOs(final Renderer deleter) { // gather up expired vbos... final Multimap<Object, Integer> idMap = gatherGCdIds(null); if (idMap != null) { // send to be deleted (perhaps on next render.) handleVBODelete(deleter, idMap); } }
public void deleteVBOs(final AbstractBufferData<?> buffer) { if (buffer == null) { return; } final GL gl = GLContext.getCurrentGL(); // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final int id = buffer.getVBOID(context.getGlContextRep()); if (id == 0) { // Not on card... return. return; } buffer.removeVBOID(context.getGlContextRep()); final IntBuffer idBuff = BufferUtils.createIntBuffer(1); idBuff.put(id); idBuff.flip(); gl.glDeleteBuffers(1, idBuff); }
/** * Handle detecting and scheduling cleanup of OpenGL assets. This method will place delete calls on the task queue * of appropriate RenderContexts when an asset such as a Texture is determined to no longer be reachable by Java. * * @param renderer * an optional Renderer to use for immediate cleanup when the asset is owned by the current context. In * general this is best used in single context applications, and null is a perfectly acceptable value. */ public static void doRuntimeCleanup(final Renderer renderer) { TextureManager.cleanExpiredTextures(renderer.getTextureUtils(), null); AbstractBufferData.cleanExpiredVBOs(renderer.getShaderUtils()); }
@Override public void read(final InputCapsule capsule) throws IOException { super.read(capsule); _buffer = capsule.readFloatBuffer("buffer", null); _valuesPerTuple = capsule.readInt("valuesPerTuple", 0); }
public static void cleanAllVBOs(final Renderer deleter, final RenderContext context) { final Multimap<Object, Integer> idMap = ArrayListMultimap.create(); // gather up expired vbos... these don't exist in our cache gatherGCdIds(idMap); final Object glRep = context.getGlContextRep(); // Walk through the cached items and delete those too. for (final AbstractBufferData<?> buf : _identityCache.keySet()) { // only worry about buffers that have received ids. if (buf._vboIdCache != null) { final Integer id = buf._vboIdCache.removeValue(glRep); if (id != null && id.intValue() != 0) { idMap.put(context.getGlContextRep(), id); } } } handleVBODelete(deleter, idMap); }
public static void cleanAllBuffers(final IShaderUtils utils, final RenderContext context) { final Multimap<RenderContextRef, Integer> idMap = ArrayListMultimap.create(); // gather up expired vbos... these don't exist in our cache gatherGCdIds(idMap); final RenderContextRef glRef = context.getGlContextRef(); // Walk through the cached items and delete those too. for (final AbstractBufferData<?> buf : _identityCache.keySet()) { // only worry about buffers that have received ids. if (buf._bufferIdCache != null) { final Integer id = buf._bufferIdCache.removeValue(glRef); if (id != null && id.intValue() != 0) { idMap.put(context.getGlContextRef(), id); } } } handleVBODelete(utils, idMap); }