mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
dynamic textures: use weak references
This commit is contained in:
parent
e7f3891cc4
commit
942a1a8787
@ -97,4 +97,8 @@ open class DynamicImageElement(
|
||||
|
||||
override fun forceSilentApply() = Unit
|
||||
override fun silentApply(): Boolean = false
|
||||
|
||||
protected fun finalize() {
|
||||
texture?.usages?.decrementAndGet()
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class TabListEntryElement(
|
||||
|
||||
nameElement.text = displayName
|
||||
|
||||
this.prefSize = Vec2i((PADDING * 6) + skinElement.prefSize.x + nameElement.prefSize.x + INNER_MARGIN + pingElement.prefSize.x, HEIGHT)
|
||||
this.prefSize = Vec2i((PADDING * 6) + skinElement.size.x + nameElement.prefSize.x + INNER_MARGIN + pingElement.prefSize.x, HEIGHT)
|
||||
background.size = size
|
||||
cacheUpToDate = false
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import org.lwjgl.opengl.GL12.glTexSubImage3D
|
||||
import org.lwjgl.opengl.GL13.GL_TEXTURE0
|
||||
import org.lwjgl.opengl.GL13.glActiveTexture
|
||||
import org.lwjgl.opengl.GL30.GL_TEXTURE_2D_ARRAY
|
||||
import java.lang.ref.WeakReference
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.*
|
||||
|
||||
@ -37,7 +38,7 @@ class OpenGLDynamicTextureArray(
|
||||
initialSize: Int = 32,
|
||||
val resolution: Int,
|
||||
) : DynamicTextureArray {
|
||||
private val textures: Array<OpenGLDynamicTexture?> = arrayOfNulls(initialSize)
|
||||
private val textures: Array<WeakReference<OpenGLDynamicTexture>?> = arrayOfNulls(initialSize)
|
||||
private var textureId = -1
|
||||
|
||||
override val size: Int
|
||||
@ -71,14 +72,15 @@ class OpenGLDynamicTextureArray(
|
||||
override fun pushBuffer(identifier: UUID, data: () -> ByteBuffer): OpenGLDynamicTexture {
|
||||
check(textureId >= 0) { "Dynamic texture array not yet initialized!" }
|
||||
cleanup()
|
||||
for (texture in textures) {
|
||||
for (textureReference in textures) {
|
||||
val texture = textureReference?.get()
|
||||
if (texture?.uuid == identifier) {
|
||||
return texture
|
||||
}
|
||||
}
|
||||
val index = getNextIndex()
|
||||
val texture = OpenGLDynamicTexture(identifier, createShaderIdentifier(index = index))
|
||||
textures[index] = texture
|
||||
textures[index] = WeakReference(texture)
|
||||
texture.state = DynamicTextureState.LOADING
|
||||
DefaultThreadPool += {
|
||||
val bytes = data()
|
||||
@ -138,11 +140,12 @@ class OpenGLDynamicTextureArray(
|
||||
}
|
||||
|
||||
private fun cleanup() {
|
||||
for ((index, texture) in textures.withIndex()) {
|
||||
if (texture == null) {
|
||||
for ((index, textureReference) in textures.withIndex()) {
|
||||
if (textureReference == null) {
|
||||
continue
|
||||
}
|
||||
if (texture.usages.get() > 0) {
|
||||
val texture = textureReference.get()
|
||||
if (texture != null && texture.usages.get() > 0) {
|
||||
continue
|
||||
}
|
||||
textures[index] = null
|
||||
|
Loading…
x
Reference in New Issue
Block a user