texture manager: rename dynamic and static

This commit is contained in:
Moritz Zwerger 2023-11-26 00:10:06 +01:00
parent f7956d44f7
commit 0b078921f7
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
32 changed files with 57 additions and 57 deletions

View File

@ -34,7 +34,7 @@ class BakedFaceTest {
private fun texture(): Texture {
val manager = BakedModelTestUtil.createTextureManager(texture)
return manager.staticTextures.create(texture.toResourceLocation())
return manager.static.create(texture.toResourceLocation())
}
private fun singleMesh(): ChunkMesh {

View File

@ -18,7 +18,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
import de.bixilon.minosoft.gui.rendering.system.base.texture.array.FontTextureArray
class DummyTextureManager(val context: RenderContext) : TextureManager() {
override val dynamicTextures = DummyDynamicTextureArray(context)
override val staticTextures = DummyStaticTextureArray(context)
override val dynamic = DummyDynamicTextureArray(context)
override val static = DummyStaticTextureArray(context)
override val font: FontTextureArray = DummyFontTextureArray(context)
}

View File

@ -89,7 +89,7 @@ class RenderLoop(
lastFrame = currentFrame
context.textures.staticTextures.animator.draw()
context.textures.static.animator.draw()
context.renderer.draw()

View File

@ -73,7 +73,7 @@ object RenderLoader {
val initLatch = ParentLatch(1, renderLatch)
Log.log(LogMessageType.RENDERING, LogLevels.VERBOSE) { "Generating font, gathering textures and loading models (after ${stopwatch.labTime()})..." }
initLatch.inc(); runAsync { tints.init(connection.assetsManager); initLatch.dec() }
textures.dynamicTextures.upload(initLatch)
textures.dynamic.upload(initLatch)
textures.initializeSkins(connection)
textures.loadDefaultTextures()
font = FontManager.create(this, initLatch)
@ -96,11 +96,11 @@ object RenderLoader {
// Post init stage
Log.log(LogMessageType.RENDERING, LogLevels.VERBOSE) { "Loading textures (after ${stopwatch.labTime()})..." }
textures.staticTextures.load(renderLatch)
textures.static.load(renderLatch)
textures.font.load(renderLatch)
Log.log(LogMessageType.RENDERING, LogLevels.VERBOSE) { "Uploading textures (after ${stopwatch.labTime()})..." }
textures.staticTextures.upload(renderLatch)
textures.static.upload(renderLatch)
textures.font.upload(renderLatch)
Log.log(LogMessageType.RENDERING, LogLevels.VERBOSE) { "Baking models (after ${stopwatch.labTime()})..." }
@ -120,7 +120,7 @@ object RenderLoader {
window::focused.observeRendering(this) { state = it.decide(RenderingStates.RUNNING, RenderingStates.SLOW) }
window::iconified.observeRendering(this) { state = it.decide(RenderingStates.PAUSED, RenderingStates.RUNNING) }
profile.animations::sprites.observe(this, true) { textures.staticTextures.animator.enabled = it }
profile.animations::sprites.observe(this, true) { textures.static.animator.enabled = it }
input.init()
@ -136,8 +136,8 @@ object RenderLoader {
window.postInit()
textures.dynamicTextures.activate()
textures.staticTextures.activate()
textures.dynamic.activate()
textures.static.activate()
renderLatch.dec() // initial count from rendering

View File

@ -59,12 +59,12 @@ class WorldBorderRenderer(
shader.native.defines["MAX_DISTANCE"] = MAX_DISTANCE
shader.load()
texture = context.textures.staticTextures.create(TEXTURE)
texture = context.textures.static.create(TEXTURE)
context.camera.offset::offset.observe(this) { reload = true }
}
override fun postInit(latch: AbstractLatch) {
context.textures.staticTextures.use(shader)
context.textures.static.use(shader)
shader.textureIndexLayer = texture.renderData.shaderTextureId
}

View File

@ -43,14 +43,14 @@ class DoubleChestRenderer(
private val TEXTURE_5 = arrayOf(minecraft("left"), minecraft("right"))
private fun register(loader: ModelLoader, name: ResourceLocation, texture: ResourceLocation) {
val static = loader.context.textures.staticTextures
val static = loader.context.textures.static
val override = mapOf(TEXTURE to static.create(texture))
loader.skeletal.register(name, MODEL, override)
}
private fun register5(loader: ModelLoader, name: ResourceLocation, textures: Array<ResourceLocation>) {
if (textures.size != 2) throw IllegalStateException("Textures must be left and right!")
val static = loader.context.textures.staticTextures
val static = loader.context.textures.static
val override = mapOf(
TEXTURE_5[0] to static.create(textures[0]),
TEXTURE_5[1] to static.create(textures[1]),

View File

@ -41,7 +41,7 @@ class SingleChestRenderer(
private val named = minecraft("chest")
fun register(loader: ModelLoader, name: ResourceLocation, texture: ResourceLocation) {
val texture = loader.context.textures.staticTextures.create(texture)
val texture = loader.context.textures.static.create(texture)
val model = if (loader.packFormat < 5) MODEL else MODEL_5
loader.skeletal.register(name, model, mapOf(named to texture))
}

View File

@ -95,7 +95,7 @@ class ShulkerBoxRenderer(
}
private fun load(name: ResourceLocation, texture: ResourceLocation, loader: ModelLoader) {
val texture = loader.context.textures.staticTextures.create(texture)
val texture = loader.context.textures.static.create(texture)
loader.skeletal.register(name, TEMPLATE, override = mapOf(this.named to texture))
}
}

View File

@ -31,7 +31,7 @@ class FireOverlay(
private val config = context.connection.profiles.rendering.overlay.fire
private val player = context.connection.player
private val shader = context.shaders.genericTexture2dShader
private var texture: Texture = context.textures.staticTextures.create("block/fire_1".toResourceLocation().texture())
private var texture: Texture = context.textures.static.create("block/fire_1".toResourceLocation().texture())
private val lava = context.connection.registries.fluid[LavaFluid]
override val render: Boolean
get() {

View File

@ -23,7 +23,7 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
class PowderSnowOverlay(context: RenderContext) : SimpleOverlay(context) {
private val config = context.connection.profiles.rendering.overlay
override val texture: Texture = context.textures.staticTextures.create(OVERLAY_TEXTURE)
override val texture: Texture = context.textures.static.create(OVERLAY_TEXTURE)
private val strength = FloatAverage(1L * 1000000000L, 0.0f)
override var render: Boolean = false
get() = config.powderSnow && field

View File

@ -23,7 +23,7 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
class PumpkinOverlay(context: RenderContext) : FirstPersonOverlay(context) {
private val config = context.connection.profiles.rendering.overlay
override val texture: Texture = context.textures.staticTextures.create(OVERLAY_TEXTURE)
override val texture: Texture = context.textures.static.create(OVERLAY_TEXTURE)
override val render: Boolean
get() {
if (!config.pumpkin) {

View File

@ -24,7 +24,7 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
class WaterOverlay(context: RenderContext) : SimpleOverlay(context) {
private val player = context.connection.player
override val texture: Texture = context.textures.staticTextures.create("minecraft:misc/underwater".toResourceLocation().texture())
override val texture: Texture = context.textures.static.create("minecraft:misc/underwater".toResourceLocation().texture())
override val render: Boolean
get() = player.gamemode != Gamemodes.SPECTATOR && player.physics.submersion.eye is WaterFluid

View File

@ -22,7 +22,7 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
class WorldBorderOverlay(context: RenderContext) : SimpleOverlay(context) {
private val config = context.connection.profiles.rendering.overlay
override val texture: Texture = context.textures.staticTextures.create(OVERLAY_TEXTURE)
override val texture: Texture = context.textures.static.create(OVERLAY_TEXTURE)
override val render: Boolean
get() = config.worldBorder && context.connection.world.border.isOutside(context.connection.player.physics.position)

View File

@ -33,8 +33,8 @@ import java.util.*
class WeatherOverlay(private val context: RenderContext) : Overlay {
private val world = context.connection.world
private val config = context.connection.profiles.rendering.overlay.weather
private val rain = context.textures.staticTextures.create(RAIN)
private val snow = context.textures.staticTextures.create(SNOW)
private val rain = context.textures.static.create(RAIN)
private val snow = context.textures.static.create(SNOW)
private val precipitation get() = context.connection.player.physics.positionInfo.biome?.precipitation
override val render: Boolean
get() = world.dimension.effects.weather && world.weather.raining && when (precipitation) { // ToDo: Check if exposed to the sky
@ -92,7 +92,7 @@ class WeatherOverlay(private val context: RenderContext) : Overlay {
override fun postInit() {
shader.use()
context.textures.staticTextures.use(shader)
context.textures.static.use(shader)
}
private fun updateShader() {

View File

@ -67,7 +67,7 @@ class AtlasTextureManager(private val context: RenderContext) {
fun load() {
for (texture in textures) {
context.textures.staticTextures += texture
context.textures.static += texture
}
this.cache.clear()
this.textures.clear()

View File

@ -251,7 +251,7 @@ class DebugHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Layouted
layout += LineSpacerElement(guiRenderer)
layout += AutoTextElement(guiRenderer, 20, properties = RIGHT) { "Dynamic textures ${context.textures.dynamicTextures.size.format()}/${context.textures.dynamicTextures.capacity.format()}" }
layout += AutoTextElement(guiRenderer, 20, properties = RIGHT) { "Dynamic textures ${context.textures.dynamic.size.format()}/${context.textures.dynamic.capacity.format()}" }
layout += LineSpacerElement(guiRenderer)

View File

@ -44,14 +44,14 @@ data class BlockModel(
fun createTexture(name: String, textures: TextureManager): Texture? {
if (!name.startsWith("#")) {
return textures.staticTextures.create(name.toResourceLocation())
return textures.static.create(name.toResourceLocation())
}
val texture = this.textures?.get(name.substring(1))
if (texture == null || texture !is ResourceLocation) {
return null
}
return textures.staticTextures.create(texture)
return textures.static.create(texture)
}
fun getOrNullTexture(name: String, textures: TextureManager): Texture? {

View File

@ -27,8 +27,8 @@ class LavaFluidModel : FluidModel {
override val transparency = TextureTransparencies.OPAQUE// TODO: from texture
override fun load(context: RenderContext) {
still = context.textures.staticTextures.create(context.models.block.fixTexturePath(STILL).texture())
flowing = context.textures.staticTextures.create(context.models.block.fixTexturePath(FLOWING).texture())
still = context.textures.static.create(context.models.block.fixTexturePath(STILL).texture())
flowing = context.textures.static.create(context.models.block.fixTexturePath(FLOWING).texture())
}
companion object {

View File

@ -31,8 +31,8 @@ class WaterFluidModel : FluidModel {
override val transparency = TextureTransparencies.TRANSLUCENT// TODO: from texture
override fun load(context: RenderContext) {
still = context.textures.staticTextures.create(context.models.block.fixTexturePath(STILL).texture())
flowing = context.textures.staticTextures.create(context.models.block.fixTexturePath(FLOWING).texture())
still = context.textures.static.create(context.models.block.fixTexturePath(STILL).texture())
flowing = context.textures.static.create(context.models.block.fixTexturePath(FLOWING).texture())
}
companion object {

View File

@ -32,7 +32,7 @@ class ItemModel(
if (this.textures == null) return null
val texture = this.textures["layer0", "particle"]?.toResourceLocation()?.texture() ?: return null
return ItemModelPrototype(textures.staticTextures.create(texture))
return ItemModelPrototype(textures.static.create(texture))
}
companion object {

View File

@ -119,7 +119,7 @@ class ParticleRenderer(
translucentMesh.load()
for (particle in connection.registries.particleType) {
for (resourceLocation in particle.textures) {
context.textures.staticTextures.create(resourceLocation)
context.textures.static.create(resourceLocation)
}
}

View File

@ -21,7 +21,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.file.FileTe
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
abstract class SimpleTextureParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : TextureParticle(connection, position, velocity, data) {
override var texture = this.data.type.textures.getOrNull(0)?.let { connection.rendering?.context?.textures?.staticTextures?.get(it) }
override var texture = this.data.type.textures.getOrNull(0)?.let { connection.rendering?.context?.textures?.static?.get(it) }
var spriteDisabled = false
@ -39,13 +39,13 @@ abstract class SimpleTextureParticle(connection: PlayConnection, position: Vec3d
if (texture?.nullCast<FileTexture>()?.resourceLocation == nextTextureResourceLocation) {
return
}
texture = connection.rendering?.context?.textures?.staticTextures?.get(nextTextureResourceLocation)
texture = connection.rendering?.context?.textures?.static?.get(nextTextureResourceLocation)
}
fun setRandomSprite() {
val textures = data.type.textures
if (textures.isEmpty()) return
texture = connection.rendering?.context?.textures?.staticTextures?.get(textures.random())
texture = connection.rendering?.context?.textures?.static?.get(textures.random())
}
override fun tick() {

View File

@ -24,7 +24,7 @@ interface TextureShader : AbstractShader {
return uniform(name, textureManager) { native, name, value: TextureManager ->
value.use(native, name)
if (animated) {
textureManager.staticTextures.animator.use(native)
textureManager.static.animator.use(native)
}
}
}

View File

@ -42,7 +42,7 @@ data class SkeletalModel(
if (name in skip) continue
val file = name.texture()
if (file in skip) continue
val texture = context.textures.staticTextures.create(file)
val texture = context.textures.static.create(file)
this.loadedTextures[name] = SkeletalTextureInstance(properties, texture)
}
}

View File

@ -85,7 +85,7 @@ class SkyboxRenderer(
override fun init() {
for (properties in DefaultDimensionEffects) {
val texture = properties.fixedTexture ?: continue
textureCache[texture] = sky.context.textures.staticTextures.create(texture)
textureCache[texture] = sky.context.textures.static.create(texture)
}
}
@ -95,7 +95,7 @@ class SkyboxRenderer(
colorMesh.load()
textureMesh.load()
sky.context.textures.staticTextures.use(textureShader)
sky.context.textures.static.use(textureShader)
}
private fun updateColorShader() {

View File

@ -29,7 +29,7 @@ import java.util.*
class MoonRenderer(
sky: SkyRenderer,
) : PlanetRenderer(sky) {
override val texture = sky.context.textures.staticTextures.create(MOON_PHASES)
override val texture = sky.context.textures.static.create(MOON_PHASES)
private var phase = MoonPhases.FULL_MOON
private fun updateUV(phases: MoonPhases) {

View File

@ -27,7 +27,7 @@ import kotlin.math.pow
class SunRenderer(
sky: SkyRenderer,
) : PlanetRenderer(sky) {
override val texture = sky.context.textures.staticTextures.create(SUN)
override val texture = sky.context.textures.static.create(SUN)
public override fun calculateAngle(): Float {
val time = sky.context.connection.world.time

View File

@ -84,7 +84,7 @@ interface NativeShader {
companion object {
val DEFAULT_DEFINES: Map<String, (context: RenderContext) -> Any?> = mapOf(
"ANIMATED_TEXTURE_COUNT" to {
max(it.textures.staticTextures.animator.size, 1)
max(it.textures.static.animator.size, 1)
}
)

View File

@ -29,8 +29,8 @@ import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
abstract class TextureManager {
abstract val staticTextures: StaticTextureArray
abstract val dynamicTextures: DynamicTextureArray
abstract val static: StaticTextureArray
abstract val dynamic: DynamicTextureArray
abstract val font: FontTextureArray
lateinit var debugTexture: Texture
@ -44,8 +44,8 @@ abstract class TextureManager {
if (this::debugTexture.isInitialized) {
throw IllegalStateException("Already initialized!")
}
debugTexture = staticTextures.create(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION)
whiteTexture = CodeTexturePart(texture = staticTextures.create(minosoft("white").texture(), mipmaps = false), uvStart = Vec2(0.0f, 0.0f), uvEnd = Vec2(0.001f, 0.001f), size = Vec2i(16, 16))
debugTexture = static.create(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION)
whiteTexture = CodeTexturePart(texture = static.create(minosoft("white").texture(), mipmaps = false), uvStart = Vec2(0.0f, 0.0f), uvEnd = Vec2(0.001f, 0.001f), size = Vec2i(16, 16))
}
fun initializeSkins(connection: PlayConnection) {
@ -54,12 +54,12 @@ abstract class TextureManager {
}
fun use(shader: NativeShader, name: String = ShaderUniforms.TEXTURES) {
staticTextures.use(shader, name)
dynamicTextures.use(shader, name)
static.use(shader, name)
dynamic.use(shader, name)
font.use(shader, name)
}
fun reload() {
dynamicTextures.reload()
dynamic.reload()
}
}

View File

@ -36,7 +36,7 @@ class SkinManager(private val textureManager: TextureManager) {
private var skin: PlayerSkin? = null
fun initialize(account: Account, assets: AssetsManager) {
default = DefaultSkinProvider(this.textureManager.dynamicTextures, assets)
default = DefaultSkinProvider(this.textureManager.dynamic, assets)
default.initialize()
skin = getSkin(account.uuid, account.properties, fetch = true, async = false)
}
@ -57,7 +57,7 @@ class SkinManager(private val textureManager: TextureManager) {
private fun getSkin(uuid: UUID, properties: PlayerProperties?, async: Boolean = true): PlayerSkin? {
val texture = properties?.textures?.skin ?: return default[uuid]
return PlayerSkin(textureManager.dynamicTextures.push(texture.getHash(), async) { texture.read().readSkin() }, default[uuid]?.texture, texture.metadata.model)
return PlayerSkin(textureManager.dynamic.push(texture.getHash(), async) { texture.read().readSkin() }, default[uuid]?.texture, texture.metadata.model)
}
fun getSkin(player: PlayerEntity, properties: PlayerProperties? = null, fetch: Boolean = true, async: Boolean = true): PlayerSkin? {

View File

@ -20,7 +20,7 @@ import de.bixilon.minosoft.gui.rendering.system.opengl.texture.dynamic.OpenGLDyn
class OpenGLTextureManager(val context: RenderContext) : TextureManager() {
private val mipmaps = context.connection.profiles.rendering.textures.mipmaps
override val staticTextures = OpenGLTextureArray(context, true, mipmaps)
override val dynamicTextures = OpenGLDynamicTextureArray(context, context.system.unsafeCast(), resolution = 64, mipmaps = mipmaps)
override val static = OpenGLTextureArray(context, true, mipmaps)
override val dynamic = OpenGLDynamicTextureArray(context, context.system.unsafeCast(), resolution = 64, mipmaps = mipmaps)
override val font = OpenGLFontTextureArray(context)
}

View File

@ -49,7 +49,7 @@ class OpenGLDynamicTextureArray(
glBindTexture(GL_TEXTURE_2D_ARRAY, handle)
unsafeUpload(index, texture)
context.textures.staticTextures.activate() // TODO: why?
context.textures.static.activate() // TODO: why?
texture.state = DynamicTextureState.LOADED
}
@ -86,7 +86,7 @@ class OpenGLDynamicTextureArray(
unsafeUse(shader)
}
context.textures.staticTextures.activate() // TODO: why?
context.textures.static.activate() // TODO: why?
}