hot shader reloading

This commit is contained in:
Bixilon 2022-11-04 12:43:43 +01:00
parent c669a1dafe
commit db2e9c5c86
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 69 additions and 0 deletions

View File

@ -130,6 +130,14 @@ interface RenderSystem {
setBlendFunction(BlendingFunctions.ONE, BlendingFunctions.ONE_MINUS_SOURCE_ALPHA, BlendingFunctions.ONE, BlendingFunctions.ZERO)
}
@Deprecated("Highly unstable")
fun reloadShaders() {
val copy = shaders.toMutableSet()
for (shader in copy) {
shader.reload()
}
}
companion object {

View File

@ -34,6 +34,10 @@ interface Shader {
val log: String
fun load()
fun unload()
@Deprecated("Highly buggy, do not use in normal environment")
fun reload()
fun use(): Shader {
renderWindow.renderSystem.shader = this

View File

@ -105,6 +105,19 @@ class OpenGLShader(
renderWindow.renderSystem.shaders += this
}
override fun unload() {
check(loaded) { "Not loaded!" }
glDeleteProgram(this.shader)
loaded = false
this.shader = -1
renderWindow.renderSystem.shaders -= this
}
override fun reload() {
unload()
load()
}
private fun getUniformLocation(uniformName: String): Int {
val location = uniformLocations.getOrPut(uniformName) {

View File

@ -14,11 +14,13 @@
package de.bixilon.minosoft.terminal.commands
import de.bixilon.minosoft.terminal.commands.connection.SayCommand
import de.bixilon.minosoft.terminal.commands.rendering.ReloadCommand
object Commands {
val COMMANDS: List<Command> = listOf(
HelpCommand,
SayCommand,
ConnectionManageCommand,
ReloadCommand,
)
}

View File

@ -0,0 +1,24 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.terminal.commands.rendering
import de.bixilon.minosoft.commands.nodes.LiteralNode
object ReloadCommand : RenderingCommand {
override var node = LiteralNode("reload", setOf("rl"))
.addChild(LiteralNode("shaders", executor = {
it.connection.rendering!!.renderWindow.renderSystem.reloadShaders()
it.connection.util.sendDebugMessage("Shaders reloaded!")
}))
}

View File

@ -0,0 +1,18 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.terminal.commands.rendering
import de.bixilon.minosoft.terminal.commands.Command
interface RenderingCommand : Command