mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
hot shader reloading
This commit is contained in:
parent
c669a1dafe
commit
db2e9c5c86
@ -130,6 +130,14 @@ interface RenderSystem {
|
|||||||
setBlendFunction(BlendingFunctions.ONE, BlendingFunctions.ONE_MINUS_SOURCE_ALPHA, BlendingFunctions.ONE, BlendingFunctions.ZERO)
|
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 {
|
companion object {
|
||||||
|
|
||||||
|
@ -34,6 +34,10 @@ interface Shader {
|
|||||||
val log: String
|
val log: String
|
||||||
|
|
||||||
fun load()
|
fun load()
|
||||||
|
fun unload()
|
||||||
|
|
||||||
|
@Deprecated("Highly buggy, do not use in normal environment")
|
||||||
|
fun reload()
|
||||||
|
|
||||||
fun use(): Shader {
|
fun use(): Shader {
|
||||||
renderWindow.renderSystem.shader = this
|
renderWindow.renderSystem.shader = this
|
||||||
|
@ -105,6 +105,19 @@ class OpenGLShader(
|
|||||||
renderWindow.renderSystem.shaders += this
|
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 {
|
private fun getUniformLocation(uniformName: String): Int {
|
||||||
val location = uniformLocations.getOrPut(uniformName) {
|
val location = uniformLocations.getOrPut(uniformName) {
|
||||||
|
@ -14,11 +14,13 @@
|
|||||||
package de.bixilon.minosoft.terminal.commands
|
package de.bixilon.minosoft.terminal.commands
|
||||||
|
|
||||||
import de.bixilon.minosoft.terminal.commands.connection.SayCommand
|
import de.bixilon.minosoft.terminal.commands.connection.SayCommand
|
||||||
|
import de.bixilon.minosoft.terminal.commands.rendering.ReloadCommand
|
||||||
|
|
||||||
object Commands {
|
object Commands {
|
||||||
val COMMANDS: List<Command> = listOf(
|
val COMMANDS: List<Command> = listOf(
|
||||||
HelpCommand,
|
HelpCommand,
|
||||||
SayCommand,
|
SayCommand,
|
||||||
ConnectionManageCommand,
|
ConnectionManageCommand,
|
||||||
|
ReloadCommand,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -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!")
|
||||||
|
}))
|
||||||
|
}
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user