/** * Find the first context we manage that uses the given shared opengl context. * * @param glref * @return */ public static RenderContext getContextForRef(final Object glref) { if (glref == null) { return null; } for (final RenderContext context : contextStore.values()) { if (glref.equals(context.getGlContextRep())) { return context; } } return null; }
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); }
/** * Grab the render delegate for this spatial based on the currently set RenderContext. * * @return the delegate or null if a delegate was not found. */ protected RenderDelegate getCurrentRenderDelegate() { // short circuit... ignore if no delegates at all. if (_delegateMap == null || _delegateMap.isEmpty()) { return null; } // otherwise... grab our current context final RenderContext context = ContextManager.getCurrentContext(); // get the delegate for this context RenderDelegate delegate = getRenderDelegate(context.getGlContextRep()); // if none, check for a default delegate. if (delegate == null) { delegate = getRenderDelegate(null); } return delegate; }
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); }
@SuppressWarnings("unchecked") private static Multimap<Object, Integer> gatherGCdIds() { Multimap<Object, Integer> idMap = null; // Pull all expired textures from ref queue and add to an id multimap. ContextIdReference<TextureKey> ref; Integer id; while ((ref = (ContextIdReference<TextureKey>) _textureRefQueue.poll()) != null) { // lazy init if (idMap == null) { idMap = ArrayListMultimap.create(); } if (Constants.useMultipleContexts) { final Set<Object> contextObjects = ref.getContextObjects(); for (final Object o : contextObjects) { id = ref.getValue(o); if (id != null && id.intValue() != 0) { // Add id to map idMap.put(o, id); } } } else { id = ref.getValue(null); if (id != null && id.intValue() != 0) { idMap.put(ContextManager.getCurrentContext().getGlContextRep(), id); } } ref.clear(); } return idMap; }
@SuppressWarnings("unchecked") private static final Multimap<Object, Integer> gatherGCdIds(Multimap<Object, Integer> store) { // Pull all expired vbos from ref queue and add to an id multimap. ContextIdReference<AbstractBufferData<?>> ref; while ((ref = (ContextIdReference<AbstractBufferData<?>>) _vboRefQueue.poll()) != null) { if (Constants.useMultipleContexts) { final Set<Object> contextObjects = ref.getContextObjects(); for (final Object o : contextObjects) { // Add id to map final Integer id = ref.getValue(o); if (id != null) { if (store == null) { // lazy init store = ArrayListMultimap.create(); } store.put(o, id); } } } else { final Integer id = ref.getValue(null); if (id != null) { if (store == null) { // lazy init store = ArrayListMultimap.create(); } store.put(ContextManager.getCurrentContext().getGlContextRep(), id); } } ref.clear(); } return store; }
public static void deleteTexture(final Texture texture) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture); final Integer id = texture.getTextureIdForContextAsInteger(context.getGlContextRep()); if (id.intValue() == 0) { // Not on card... return. return; } final IntBuffer idBuffer = BufferUtils.createIntBuffer(1); idBuffer.clear(); idBuffer.put(id.intValue()); idBuffer.rewind(); GL11.glDeleteTextures(idBuffer); record.removeTextureRecord(id); texture.removeFromIdCache(context.getGlContextRep()); }
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); }
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); }
private static void handleTextureDelete(final Renderer deleter, final Multimap<Object, Integer> idMap, final Map<Object, Future<Void>> futureStore) { Object currentGLRef = null; // Grab the current context, if any. if (deleter != null && ContextManager.getCurrentContext() != null) { currentGLRef = ContextManager.getCurrentContext().getGlContextRep(); } // For each affected context... for (final Object glref : idMap.keySet()) { // If we have a deleter and the context is current, immediately delete if (currentGLRef != null && (!Constants.useMultipleContexts || glref.equals(currentGLRef))) { deleter.deleteTextureIds(idMap.get(glref)); } // Otherwise, add a delete request to that context's render task queue. else { final Future<Void> future = GameTaskQueueManager.getManager(ContextManager.getContextForRef(glref)) .render(new RendererCallable<Void>() { public Void call() throws Exception { getRenderer().deleteTextureIds(idMap.get(glref)); return null; } }); if (futureStore != null) { futureStore.put(glref, future); } } } }
private static void handleVBODelete(final Renderer deleter, final Multimap<Object, Integer> idMap) { Object currentGLRef = null; // Grab the current context, if any. if (deleter != null && ContextManager.getCurrentContext() != null) { currentGLRef = ContextManager.getCurrentContext().getGlContextRep(); } // For each affected context... for (final Object glref : idMap.keySet()) { // If we have a deleter and the context is current, immediately delete if (deleter != null && glref.equals(currentGLRef)) { deleter.deleteVBOs(idMap.get(glref)); } // Otherwise, add a delete request to that context's render task queue. else { GameTaskQueueManager.getManager(ContextManager.getContextForRef(glref)).render( new RendererCallable<Void>() { public Void call() throws Exception { getRenderer().deleteVBOs(idMap.get(glref)); return null; } }); } } }
private static void handleDisplayListDelete(final Renderer deleter, final Multimap<Object, Integer> idMap) { Object currentGLRef = null; // Grab the current context, if any. if (deleter != null && ContextManager.getCurrentContext() != null) { currentGLRef = ContextManager.getCurrentContext().getGlContextRep(); } // For each affected context... for (final Object glref : idMap.keySet()) { // If we have a deleter and the context is current, immediately delete if (deleter != null && glref.equals(currentGLRef)) { deleter.deleteDisplayLists(idMap.get(glref)); } // Otherwise, add a delete request to that context's render task queue. else { GameTaskQueueManager.getManager(ContextManager.getContextForRef(glref)).render( new RendererCallable<Void>() { public Void call() throws Exception { getRenderer().deleteDisplayLists(idMap.get(glref)); return null; } }); } } } }
public static void deleteTexture(final Texture texture) { final GL gl = GLContext.getCurrentGL(); // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture); final Integer id = texture.getTextureIdForContextAsInteger(context.getGlContextRep()); if (id.intValue() == 0) { // Not on card... return. return; } final IntBuffer idBuffer = BufferUtils.createIntBuffer(1); idBuffer.clear(); idBuffer.put(id.intValue()); idBuffer.rewind(); gl.glDeleteTextures(idBuffer.limit(), idBuffer); record.removeTextureRecord(id); texture.removeFromIdCache(context.getGlContextRep()); }
TextureManager.addToCache(texture); } else { final int textureId = cached.getTextureIdForContext(context.getGlContextRep()); if (textureId != 0) { doTextureBind(cached, unit, false); texture.setTextureIdForContext(context.getGlContextRep(), textureId);
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; }
int vboID = data.getVBOID(context.getGlContextRep()); if (vboID != 0) { if (data.isNeedsRefresh()) { data.setVBOID(context.getGlContextRep(), vboID);
/** * Useful for external lwjgl based classes that need to safely set the current texture. */ public static void doTextureBind(final Texture texture, final int unit, final boolean invalidateState) { // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ContextCapabilities caps = context.getCapabilities(); final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture); if (invalidateState) { // Set this to null because no current state really matches anymore context.setCurrentState(StateType.Texture, null); } checkAndSetUnit(unit, record, caps); final int id = texture.getTextureIdForContext(context.getGlContextRep()); GL11.glBindTexture(getGLType(texture.getType()), id); if (Constants.stats) { StatCollector.addStat(StatType.STAT_TEXTURE_BINDS, 1); } if (record != null) { record.units[unit].boundTexture = id; } }
} else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) { throw new Ardor3dException("Texture is already setup and has id."); GL11.glGenTextures(ibuf); final int textureId = ibuf.get(0); tex.setTextureIdForContext(context.getGlContextRep(), textureId);
} else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) { throw new Ardor3dException("Texture is already setup and has id."); gl.glGenTextures(1, ibuf); final int textureId = ibuf.get(0); tex.setTextureIdForContext(context.getGlContextRep(), textureId);
/** * Useful for external jogl based classes that need to safely set the current texture. */ public static void doTextureBind(final Texture texture, final int unit, final boolean invalidateState) { final GL gl = GLContext.getCurrentGL(); // ask for the current state record final RenderContext context = ContextManager.getCurrentContext(); final ContextCapabilities caps = context.getCapabilities(); final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture); if (invalidateState) { // Set this to null because no current state really matches anymore context.setCurrentState(StateType.Texture, null); } checkAndSetUnit(unit, record, caps); final int id = texture.getTextureIdForContext(context.getGlContextRep()); gl.glBindTexture(getGLType(texture.getType()), id); if (Constants.stats) { StatCollector.addStat(StatType.STAT_TEXTURE_BINDS, 1); } if (record != null) { record.units[unit].boundTexture = id; } }