mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
improve some opengl texture array things
This commit is contained in:
parent
c60e488529
commit
5d2397ee5f
@ -74,6 +74,7 @@ class OpenGLTextureArray(
|
|||||||
return texture
|
return texture
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
override fun preLoad() {
|
override fun preLoad() {
|
||||||
if (state == TextureArrayStates.LOADED || state == TextureArrayStates.PRE_LOADED) {
|
if (state == TextureArrayStates.LOADED || state == TextureArrayStates.PRE_LOADED) {
|
||||||
return
|
return
|
||||||
@ -127,12 +128,9 @@ class OpenGLTextureArray(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun loadResolution(resolutionId: Int) {
|
@Synchronized
|
||||||
val resolution = TEXTURE_RESOLUTION_ID_MAP[resolutionId]
|
private fun loadSingleArray(resolution: Int, textures: MutableList<AbstractTexture>): Int {
|
||||||
val textures = texturesByResolution[resolutionId]
|
|
||||||
|
|
||||||
val textureId = glGenTextures()
|
val textureId = glGenTextures()
|
||||||
textureIds[resolutionId] = textureId
|
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, textureId)
|
glBindTexture(GL_TEXTURE_2D_ARRAY, textureId)
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
||||||
@ -146,26 +144,32 @@ class OpenGLTextureArray(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (texture in textures) {
|
for (texture in textures) {
|
||||||
|
|
||||||
val mipMaps = texture.generateMipMaps()
|
val mipMaps = texture.generateMipMaps()
|
||||||
|
|
||||||
val renderData = texture.renderData as OpenGLTextureData
|
val renderData = texture.renderData as OpenGLTextureData
|
||||||
for ((i, data) in mipMaps.withIndex()) {
|
for ((mipMapLevel, data) in mipMaps.withIndex()) {
|
||||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, 0, 0, renderData.index, data.first.x, data.first.y, i + 1, GL_RGBA, GL_UNSIGNED_BYTE, data.second)
|
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, mipMapLevel, 0, 0, renderData.index, data.first.x, data.first.y, mipMapLevel + 1, GL_RGBA, GL_UNSIGNED_BYTE, data.second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return textureId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
override fun load() {
|
override fun load() {
|
||||||
var totalLayers = 0
|
var totalLayers = 0
|
||||||
for ((index, textures) in texturesByResolution.withIndex()) {
|
for ((index, textures) in texturesByResolution.withIndex()) {
|
||||||
loadResolution(index)
|
if (textures.isEmpty()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
textureIds[index] = loadSingleArray(TEXTURE_RESOLUTION_ID_MAP[index], textures)
|
||||||
totalLayers += textures.size
|
totalLayers += textures.size
|
||||||
}
|
}
|
||||||
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Loaded ${textures.size} textures containing ${animator.animations.size} animated ones, split into $totalLayers layers!" }
|
Log.log(LogMessageType.RENDERING_LOADING, LogLevels.VERBOSE) { "Loaded ${textures.size} textures containing ${animator.animations.size} animated ones, split into $totalLayers layers!" }
|
||||||
|
|
||||||
animator.init()
|
animator.init()
|
||||||
|
state = TextureArrayStates.LOADED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -173,6 +177,9 @@ class OpenGLTextureArray(
|
|||||||
shader.use()
|
shader.use()
|
||||||
|
|
||||||
for ((index, textureId) in textureIds.withIndex()) {
|
for ((index, textureId) in textureIds.withIndex()) {
|
||||||
|
if (textureId == -1) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
glActiveTexture(GL_TEXTURE0 + index)
|
glActiveTexture(GL_TEXTURE0 + index)
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, textureId)
|
glBindTexture(GL_TEXTURE_2D_ARRAY, textureId)
|
||||||
shader.setTexture("$arrayName[$index]", index)
|
shader.setTexture("$arrayName[$index]", index)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user