/** * <p> * Clears all currently associated texture ids for this texture. * </p> * <p> * Note: This does not remove the texture from the card and is provided for use by code that does remove textures * from the card. * </p> */ public void removeFromIdCache() { _idCache.clear(); }
/** * @return a Set of context objects that currently reference this texture. */ public Set<Object> getContextObjects() { return _idCache.getContextObjects(); }
/** * @param glContext * the object representing the OpenGL context a texture belongs to. See * {@link RenderContext#getGlContextRep()} * @return the texture id of a texture in the given context. If the texture is not found in the given context, 0 is * returned. */ public Integer getTextureIdForContext(final Object glContext) { final Integer id = _idCache.getValue(glContext); if (id != null) { return id; } return ZERO; }
@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; }
/** * Sets the id for a vbo based on this buffer's data in regards to the given OpenGL context. * * @param glContextRep * the object representing the OpenGL context a vbo belongs to. See * {@link RenderContext#getGlContextRep()} * @param vboId * the vbo id of a vbo. To be valid, this must be not equals to 0. * @throws IllegalArgumentException * if vboId is less than or equal to 0. */ public void setVBOID(final Object glContextRep, final int vboId) { if (vboId == 0) { throw new IllegalArgumentException("vboId must != 0"); } if (_vboIdCache == null) { _vboIdCache = new ContextIdReference<AbstractBufferData<T>>(this, _vboRefQueue); } _vboIdCache.put(glContextRep, vboId); }
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); }
/** * Removes any vbo id from this buffer's data for the given OpenGL context. * * @param glContext * the object representing the OpenGL context a vbo would belong to. See * {@link RenderContext#getGlContextRep()} * @return the id removed or 0 if not found. */ public int removeVBOID(final Object glContext) { if (_vboIdCache != null) { return _vboIdCache.removeValue(glContext); } else { return 0; } }
/** * Sets the id for a texture in regards to the given OpenGL context. * * @param glContext * the object representing the OpenGL context a texture belongs to. See * {@link RenderContext#getGlContextRep()} * @param textureId * the texture id of a texture. To be valid, this must not be 0. * @throws IllegalArgumentException * if textureId is equal to 0. */ public void setTextureIdForContext(final Object glContext, final int textureId) { if (textureId == 0) { throw new IllegalArgumentException("textureId must != 0"); } _idCache.put(glContext, textureId); }
@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; }
/** * <p> * Removes any texture id for this texture for the given OpenGL context. * </p> * <p> * Note: This does not remove the texture from the card and is provided for use by code that does remove textures * from the card. * </p> * * @param glContext * the object representing the OpenGL context this texture belongs to. See * {@link RenderContext#getGlContextRep()} */ public void removeFromIdCache(final Object glContext) { _idCache.removeValue(glContext); }
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 void setDirty() { if (Constants.useMultipleContexts) { synchronized (_dirtyContexts) { _dirtyContexts.clear(); // grab all contexts we currently have ids for and add them all as dirty for (final Object context : _idCache.getContextObjects()) { final WeakReference<Object> ref = new WeakReference<Object>(context); _dirtyContexts.add(ref); } } } else { _dirty = true; } }
/** * @param glContext * the object representing the OpenGL context a vbo belongs to. See * {@link RenderContext#getGlContextRep()} * @return the vbo id of a vbo in the given context. If the vbo is not found in the given context, 0 is returned. */ public int getVBOID(final Object glContext) { if (_vboIdCache != null) { final Integer id = _vboIdCache.getValue(glContext); if (id != null) { return id.intValue(); } } return 0; }