mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
framebuffer fixes
This commit is contained in:
parent
13ce836539
commit
52a1a119da
@ -23,4 +23,6 @@ object Colors {
|
|||||||
val TRUE_YELLOW = RGBColor(255, 255, 0)
|
val TRUE_YELLOW = RGBColor(255, 255, 0)
|
||||||
|
|
||||||
val DARK_RED = RGBColor(255, 50, 30)
|
val DARK_RED = RGBColor(255, 50, 30)
|
||||||
|
|
||||||
|
val TRANSPARENT = RGBColor(0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
|
@ -246,6 +246,7 @@ class RenderWindow(
|
|||||||
),
|
),
|
||||||
)) {
|
)) {
|
||||||
val nextMode = it.decide(PolygonModes.LINE, PolygonModes.FILL)
|
val nextMode = it.decide(PolygonModes.LINE, PolygonModes.FILL)
|
||||||
|
renderSystem.framebuffer = framebufferManager.default.framebuffer
|
||||||
renderSystem.polygonMode = nextMode
|
renderSystem.polygonMode = nextMode
|
||||||
sendDebugMessage("Polygon mode: ${nextMode.format()}")
|
sendDebugMessage("Polygon mode: ${nextMode.format()}")
|
||||||
}
|
}
|
||||||
@ -319,7 +320,9 @@ class RenderWindow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderStats.startFrame()
|
renderStats.startFrame()
|
||||||
|
renderSystem.framebuffer = null
|
||||||
renderSystem.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER)
|
renderSystem.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER)
|
||||||
|
framebufferManager.clear()
|
||||||
|
|
||||||
|
|
||||||
val currentTickTime = TimeUtil.time
|
val currentTickTime = TimeUtil.time
|
||||||
@ -343,11 +346,11 @@ class RenderWindow(
|
|||||||
renderer.prepareDraw()
|
renderer.prepareDraw()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (renderer in rendererList) {
|
for (phase in RenderPhases.VALUES) { // ToDo: Move this up after frame buffers
|
||||||
if (renderer is SkipAll && renderer.skipAll) {
|
for (renderer in rendererList) {
|
||||||
continue
|
if (renderer is SkipAll && renderer.skipAll) {
|
||||||
}
|
continue
|
||||||
for (phase in RenderPhases.VALUES) { // ToDo: Move this up after frame buffers
|
}
|
||||||
if (!phase.type.java.isAssignableFrom(renderer::class.java)) {
|
if (!phase.type.java.isAssignableFrom(renderer::class.java)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -360,6 +363,7 @@ class RenderWindow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
framebufferManager.draw()
|
framebufferManager.draw()
|
||||||
|
renderSystem.framebuffer = null
|
||||||
renderSystem.reset() // Reset to enable depth mask, etc again
|
renderSystem.reset() // Reset to enable depth mask, etc again
|
||||||
|
|
||||||
renderStats.endDraw()
|
renderStats.endDraw()
|
||||||
|
@ -3,25 +3,38 @@ package de.bixilon.minosoft.gui.rendering.framebuffer
|
|||||||
import de.bixilon.minosoft.gui.rendering.Drawable
|
import de.bixilon.minosoft.gui.rendering.Drawable
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.framebuffer.defaultf.DefaultFramebuffer
|
import de.bixilon.minosoft.gui.rendering.framebuffer.defaultf.DefaultFramebuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.framebuffer.gui.GUIFramebuffer
|
||||||
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
|
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.IntegratedBufferTypes
|
||||||
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
||||||
|
|
||||||
class FramebufferManager(
|
class FramebufferManager(
|
||||||
private val renderWindow: RenderWindow,
|
private val renderWindow: RenderWindow,
|
||||||
) : Drawable {
|
) : Drawable {
|
||||||
val default = DefaultFramebuffer(renderWindow)
|
val default = DefaultFramebuffer(renderWindow)
|
||||||
|
val gui = GUIFramebuffer(renderWindow)
|
||||||
|
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
default.init()
|
default.init()
|
||||||
|
gui.init()
|
||||||
|
|
||||||
renderWindow.connection.registerEvent(CallbackEventInvoker.of<ResizeWindowEvent> {
|
renderWindow.connection.registerEvent(CallbackEventInvoker.of<ResizeWindowEvent> {
|
||||||
default.framebuffer.resize(it.size)
|
default.framebuffer.resize(it.size)
|
||||||
|
gui.framebuffer.resize(it.size)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
default.clear()
|
||||||
|
gui.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun draw() {
|
override fun draw() {
|
||||||
default.draw()
|
default.draw()
|
||||||
|
renderWindow.renderSystem.clear(IntegratedBufferTypes.DEPTH_BUFFER, IntegratedBufferTypes.STENCIL_BUFFER)
|
||||||
|
gui.draw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.framebuffer.defaultf
|
package de.bixilon.minosoft.gui.rendering.framebuffer
|
||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
@ -6,7 +6,7 @@ import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
|||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
||||||
|
|
||||||
|
|
||||||
class DefaultFramebufferMesh(renderWindow: RenderWindow) : Mesh(renderWindow, DefaultFramebufferMeshStruct) {
|
class FramebufferMesh(renderWindow: RenderWindow) : Mesh(renderWindow, DefaultFramebufferMeshStruct) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val vertices = arrayOf(
|
val vertices = arrayOf(
|
@ -0,0 +1,36 @@
|
|||||||
|
package de.bixilon.minosoft.gui.rendering.framebuffer
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.Drawable
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.IntegratedBufferTypes
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.shader.Shader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
|
|
||||||
|
interface IntegratedFramebuffer : Drawable {
|
||||||
|
val renderWindow: RenderWindow
|
||||||
|
val shader: Shader
|
||||||
|
val framebuffer: Framebuffer
|
||||||
|
val mesh: Mesh
|
||||||
|
|
||||||
|
|
||||||
|
fun init() {
|
||||||
|
framebuffer.init()
|
||||||
|
shader.load()
|
||||||
|
shader.use()
|
||||||
|
shader.setInt("uTexture", 0)
|
||||||
|
mesh.load()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
renderWindow.renderSystem.framebuffer = framebuffer
|
||||||
|
renderWindow.renderSystem.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER, IntegratedBufferTypes.STENCIL_BUFFER)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw() {
|
||||||
|
renderWindow.renderSystem.framebuffer = null
|
||||||
|
framebuffer.bindTexture()
|
||||||
|
shader.use()
|
||||||
|
mesh.draw()
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +1,15 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.framebuffer.defaultf
|
package de.bixilon.minosoft.gui.rendering.framebuffer.defaultf
|
||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.Drawable
|
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
import de.bixilon.minosoft.gui.rendering.framebuffer.FramebufferMesh
|
||||||
|
import de.bixilon.minosoft.gui.rendering.framebuffer.IntegratedFramebuffer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer
|
||||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
|
|
||||||
class DefaultFramebuffer(
|
class DefaultFramebuffer(
|
||||||
private val renderWindow: RenderWindow,
|
override val renderWindow: RenderWindow,
|
||||||
) : Drawable {
|
) : IntegratedFramebuffer {
|
||||||
private var shader = renderWindow.renderSystem.createShader("minosoft:framebuffer/default".toResourceLocation())
|
override val shader = renderWindow.renderSystem.createShader("minosoft:framebuffer/default".toResourceLocation())
|
||||||
val framebuffer: Framebuffer = renderWindow.renderSystem.createFramebuffer()
|
override val framebuffer: Framebuffer = renderWindow.renderSystem.createFramebuffer()
|
||||||
private val mesh = DefaultFramebufferMesh(renderWindow)
|
override val mesh = FramebufferMesh(renderWindow)
|
||||||
|
|
||||||
fun init() {
|
|
||||||
framebuffer.init()
|
|
||||||
shader.load()
|
|
||||||
mesh.load()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun draw() {
|
|
||||||
renderWindow.renderSystem.framebuffer = null
|
|
||||||
framebuffer.bindTexture()
|
|
||||||
shader.use()
|
|
||||||
shader.setInt("uTexture", 0)
|
|
||||||
mesh.draw()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package de.bixilon.minosoft.gui.rendering.framebuffer.gui
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
import de.bixilon.minosoft.gui.rendering.framebuffer.FramebufferMesh
|
||||||
|
import de.bixilon.minosoft.gui.rendering.framebuffer.IntegratedFramebuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer
|
||||||
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
|
|
||||||
|
class GUIFramebuffer(
|
||||||
|
override val renderWindow: RenderWindow,
|
||||||
|
) : IntegratedFramebuffer {
|
||||||
|
override val shader = renderWindow.renderSystem.createShader("minosoft:framebuffer/gui".toResourceLocation())
|
||||||
|
override val framebuffer: Framebuffer = renderWindow.renderSystem.createFramebuffer()
|
||||||
|
override val mesh = FramebufferMesh(renderWindow)
|
||||||
|
}
|
@ -44,6 +44,7 @@ import de.bixilon.minosoft.gui.rendering.gui.hud.elements.title.TitleHUDElement
|
|||||||
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
|
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.IntegratedBufferTypes
|
import de.bixilon.minosoft.gui.rendering.system.base.IntegratedBufferTypes
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.phases.OtherDrawable
|
import de.bixilon.minosoft.gui.rendering.system.base.phases.OtherDrawable
|
||||||
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
@ -66,8 +67,8 @@ class HUDRenderer(
|
|||||||
private var enabled = true
|
private var enabled = true
|
||||||
var matrixChange = true
|
var matrixChange = true
|
||||||
private set
|
private set
|
||||||
// override val framebuffer: Framebuffer
|
override val framebuffer: Framebuffer
|
||||||
// get() = renderWindow.framebufferManager.gui
|
get() = renderWindow.framebufferManager.gui.framebuffer
|
||||||
|
|
||||||
private val hudElements: MutableMap<ResourceLocation, HUDElement> = synchronizedMapOf()
|
private val hudElements: MutableMap<ResourceLocation, HUDElement> = synchronizedMapOf()
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ interface RenderSystem {
|
|||||||
sourceAlpha: BlendingFunctions = BlendingFunctions.SOURCE_ALPHA,
|
sourceAlpha: BlendingFunctions = BlendingFunctions.SOURCE_ALPHA,
|
||||||
destinationAlpha: BlendingFunctions = BlendingFunctions.ONE_MINUS_SOURCE_ALPHA,
|
destinationAlpha: BlendingFunctions = BlendingFunctions.ONE_MINUS_SOURCE_ALPHA,
|
||||||
depth: DepthFunctions = DepthFunctions.LESS,
|
depth: DepthFunctions = DepthFunctions.LESS,
|
||||||
clearColor: RGBColor = Colors.TRUE_YELLOW,
|
clearColor: RGBColor = Colors.TRANSPARENT,
|
||||||
) {
|
) {
|
||||||
setBlendFunc(sourceAlpha, destinationAlpha, BlendingFunctions.ONE, BlendingFunctions.ZERO)
|
setBlendFunc(sourceAlpha, destinationAlpha, BlendingFunctions.ONE, BlendingFunctions.ZERO)
|
||||||
this[RenderingCapabilities.DEPTH_TEST] = depthTest
|
this[RenderingCapabilities.DEPTH_TEST] = depthTest
|
||||||
|
@ -243,7 +243,7 @@ class OpenGLRenderSystem(
|
|||||||
if (value == field) {
|
if (value == field) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
glClearColor(clearColor.floatRed, clearColor.floatGreen, clearColor.floatBlue, clearColor.floatAlpha)
|
glClearColor(value.floatRed, value.floatGreen, value.floatBlue, value.floatAlpha)
|
||||||
|
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,6 @@ class OpenGLFramebuffer(var size: Vec2i) : Framebuffer {
|
|||||||
glBindFramebuffer(GL_FRAMEBUFFER, id)
|
glBindFramebuffer(GL_FRAMEBUFFER, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unbind() {
|
|
||||||
check(state == FramebufferState.COMPLETE) { "Framebuffer is incomplete!" }
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun attach(renderbuffer: Renderbuffer) {
|
override fun attach(renderbuffer: Renderbuffer) {
|
||||||
check(renderbuffer is OpenGLRenderbuffer) { "Can not attach non OpenGL renderbuffer!" }
|
check(renderbuffer is OpenGLRenderbuffer) { "Can not attach non OpenGL renderbuffer!" }
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer.id)
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer.id)
|
||||||
@ -71,6 +66,7 @@ class OpenGLFramebuffer(var size: Vec2i) : Framebuffer {
|
|||||||
|
|
||||||
override fun bindTexture() {
|
override fun bindTexture() {
|
||||||
check(state == FramebufferState.COMPLETE) { "Framebuffer is incomplete!" }
|
check(state == FramebufferState.COMPLETE) { "Framebuffer is incomplete!" }
|
||||||
|
glActiveTexture(GL_TEXTURE0)
|
||||||
glBindTexture(GL_TEXTURE_2D, texture.id)
|
glBindTexture(GL_TEXTURE_2D, texture.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ class OpenGLFramebufferTexture(
|
|||||||
glBindTexture(GL_TEXTURE_2D, id)
|
glBindTexture(GL_TEXTURE_2D, id)
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?)
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?)
|
||||||
//glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT24, size.x, size.y, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
//glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT24, size.x, size.y, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unload() {
|
override fun unload() {
|
||||||
|
@ -22,5 +22,4 @@ uniform sampler2D uTexture;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
foutColor = texture(uTexture, finUV);
|
foutColor = texture(uTexture, finUV);
|
||||||
// foutColor = vec4(1.0f, 0.0f, 1.0f, 1.0f);
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#version 330 core
|
||||||
|
|
||||||
|
in vec2 finUV;
|
||||||
|
|
||||||
|
out vec4 foutColor;
|
||||||
|
|
||||||
|
uniform sampler2D uTexture;
|
||||||
|
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
foutColor = texture(uTexture, finUV);
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout (location = 0) in vec2 vinPosition;
|
||||||
|
layout (location = 1) in vec2 vinUV;
|
||||||
|
|
||||||
|
out vec2 finUV;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(vinPosition, 0.0f, 1.0f);
|
||||||
|
finUV = vinUV;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user