mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 12:25:12 -04:00
improve dynamic textures, fix some texture buffer bugs
This commit is contained in:
parent
75b1bebd6b
commit
888db361d9
@ -149,6 +149,7 @@ class RenderWindow(
|
||||
// Init stage
|
||||
val initLatch = CountUpAndDownLatch(1, latch)
|
||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Generating font and gathering textures (${stopwatch.labTime()})..." }
|
||||
textureManager.dynamicTextures.load(initLatch)
|
||||
textureManager.loadDefaultTextures(connection.assetsManager)
|
||||
font = FontLoader.load(this, initLatch)
|
||||
|
||||
|
@ -79,6 +79,7 @@ class GUIRenderer(
|
||||
shader.load()
|
||||
renderWindow.textureManager.staticTextures.use(shader)
|
||||
renderWindow.textureManager.staticTextures.animator.use(shader)
|
||||
renderWindow.textureManager.dynamicTextures.use(shader)
|
||||
|
||||
connection.registerEvent(CallbackEventInvoker.of<ResizeWindowEvent> { recalculateMatrices(it.size) })
|
||||
profile::scale.profileWatchRendering(this, profile = profile) { recalculateMatrices(scale = it) }
|
||||
|
@ -45,10 +45,11 @@ class TabListEntryElement(
|
||||
_parent = tabList
|
||||
}
|
||||
|
||||
// ToDo: Skin
|
||||
private val background: ColorElement
|
||||
|
||||
private val skinElement = DynamicImageElement(guiRenderer, guiRenderer.renderWindow.textureManager.alexTexture, uvStart = Vec2(0.125), uvEnd = Vec2(0.25), size = Vec2i(8, 8))
|
||||
private val skinElement = DynamicImageElement(guiRenderer, guiRenderer.renderWindow.textureManager.alexTexture, uvStart = Vec2(0.125), uvEnd = Vec2(0.25), size = Vec2i(512, 512))
|
||||
|
||||
// private val skinElement = ImageElement(guiRenderer, guiRenderer.renderWindow.textureManager.steveTexture, uvStart = Vec2(0.125), uvEnd = Vec2(0.25), size = Vec2i(512, 512))
|
||||
private val nameElement = TextElement(guiRenderer, "", background = false, parent = this)
|
||||
private lateinit var pingElement: AtlasImageElement
|
||||
|
||||
|
@ -45,6 +45,7 @@ abstract class TextureManager {
|
||||
throw IllegalStateException("Already initialized!")
|
||||
}
|
||||
debugTexture = staticTextures.createTexture(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION)
|
||||
// steveTexture = staticTextures.createTexture("minecraft:entity/steve".toResourceLocation().texture())
|
||||
whiteTexture = TextureLikeTexture(texture = staticTextures.createTexture(ResourceLocation("minosoft:textures/white.png")), uvStart = Vec2(0.0f, 0.0f), uvEnd = Vec2(0.001f, 0.001f), size = Vec2i(16, 16))
|
||||
|
||||
loadDefaultSkins(assetsManager)
|
||||
|
@ -95,7 +95,8 @@ object OpenGLTextureUtil {
|
||||
}
|
||||
}
|
||||
|
||||
buffer.rewind()
|
||||
origin.position(0)
|
||||
buffer.position(0)
|
||||
return buffer
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicText
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTextureArray
|
||||
import de.bixilon.minosoft.gui.rendering.system.opengl.texture.OpenGLTextureUtil
|
||||
import org.lwjgl.opengl.GL11.*
|
||||
import org.lwjgl.opengl.GL12
|
||||
import org.lwjgl.opengl.GL12.glTexImage3D
|
||||
import org.lwjgl.opengl.GL12.glTexSubImage3D
|
||||
import org.lwjgl.opengl.GL13.GL_TEXTURE0
|
||||
@ -32,12 +31,15 @@ import java.util.*
|
||||
|
||||
class OpenGLDynamicTextureArray(
|
||||
val renderWindow: RenderWindow,
|
||||
val index: Int = 6,
|
||||
val index: Int = 7,
|
||||
val resolution: Int,
|
||||
) : DynamicTextureArray {
|
||||
private val textures: Array<OpenGLDynamicTexture?> = arrayOfNulls(32)
|
||||
private val textures: Array<OpenGLDynamicTexture?> = arrayOfNulls(2)
|
||||
private var textureId = -1
|
||||
|
||||
@Deprecated("temp")
|
||||
private var lastTextureId = 0
|
||||
|
||||
override val size: Int
|
||||
get() = 2
|
||||
|
||||
@ -50,21 +52,25 @@ class OpenGLDynamicTextureArray(
|
||||
}
|
||||
|
||||
override fun push(identifier: UUID, data: () -> ByteBuffer): OpenGLDynamicTexture {
|
||||
check(textureId >= 0) { "Dynamic texture array not yet initialized!" }
|
||||
val bytes = data()
|
||||
|
||||
check(bytes.limit() == resolution * resolution * 4) { "Texture must have a size of ${resolution}x${resolution}" }
|
||||
|
||||
val mipmaps = OpenGLTextureUtil.generateMipMaps(bytes, Vec2i(resolution, resolution))
|
||||
val index = lastTextureId++
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, textureId)
|
||||
|
||||
for ((level, mipmap) in mipmaps.withIndex()) {
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, level, resolution, resolution, 1, GL_RGBA, GL_UNSIGNED_BYTE, mipmap)
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, index, resolution shr level, resolution shr level, 1, GL_RGBA, GL_UNSIGNED_BYTE, mipmap)
|
||||
}
|
||||
|
||||
return OpenGLDynamicTexture(identifier, createShaderIdentifier(index = 0))
|
||||
return OpenGLDynamicTexture(identifier, createShaderIdentifier(index = index))
|
||||
}
|
||||
|
||||
private fun createShaderIdentifier(array: Int = this.index, index: Int): Int {
|
||||
check(array >= 0 && index >= 0) { "Array not initialized or index < 0" }
|
||||
return (array shl 28) or (index shl 12) or 0
|
||||
}
|
||||
|
||||
@ -75,17 +81,9 @@ class OpenGLDynamicTextureArray(
|
||||
|
||||
|
||||
for (level in 0 until OpenGLTextureUtil.MAX_MIPMAP_LEVELS) {
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, level, GL12.GL_RGBA, resolution shr level, resolution shr level, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?)
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, level, GL_RGBA, resolution shr level, resolution shr level, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?)
|
||||
}
|
||||
|
||||
|
||||
for (i in textures.indices) {
|
||||
for (level in 0 until OpenGLTextureUtil.MAX_MIPMAP_LEVELS) {
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, i, resolution, resolution, 1, GL_RGBA, GL_UNSIGNED_BYTE, ByteBuffer.wrap(ByteArray(resolution * resolution * 4)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.textureId = textureId
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user