mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
render system: abstract viewport
Its not opengl specific
This commit is contained in:
parent
8fbd5f8c14
commit
59b40e23b0
@ -36,6 +36,7 @@ import de.bixilon.minosoft.gui.rendering.system.dummy.shader.DummyNativeShader
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.dummy.texture.DummyTextureManager
|
import de.bixilon.minosoft.gui.rendering.system.dummy.texture.DummyTextureManager
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshOrder
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshOrder
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||||
import java.nio.FloatBuffer
|
import java.nio.FloatBuffer
|
||||||
|
|
||||||
class DummyRenderSystem(
|
class DummyRenderSystem(
|
||||||
@ -47,6 +48,8 @@ class DummyRenderSystem(
|
|||||||
override var framebuffer: Framebuffer? = null
|
override var framebuffer: Framebuffer? = null
|
||||||
override val active: Boolean = true
|
override val active: Boolean = true
|
||||||
|
|
||||||
|
override var viewport = Vec2i.EMPTY
|
||||||
|
|
||||||
override fun init() {
|
override fun init() {
|
||||||
vendor = DummyVendor
|
vendor = DummyVendor
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
* Copyright (C) 2020-2023 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 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.
|
||||||
*
|
*
|
||||||
@ -14,7 +14,10 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.system.dummy
|
package de.bixilon.minosoft.gui.rendering.system.dummy
|
||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.GPUVendor
|
import de.bixilon.minosoft.gui.rendering.system.base.GPUVendor
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.driver.DriverHacks
|
||||||
|
|
||||||
object DummyVendor : GPUVendor {
|
object DummyVendor : GPUVendor {
|
||||||
override val shaderDefine: String = "__DUMMY"
|
override val shaderDefine: String = "__DUMMY"
|
||||||
|
|
||||||
|
override val hacks = DriverHacks.set()
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,13 @@ import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
|||||||
import de.bixilon.kutil.unit.UnitFormatter.formatNanos
|
import de.bixilon.kutil.unit.UnitFormatter.formatNanos
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderUtil.pause
|
import de.bixilon.minosoft.gui.rendering.RenderUtil.pause
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderUtil.runAsync
|
import de.bixilon.minosoft.gui.rendering.RenderUtil.runAsync
|
||||||
|
import de.bixilon.minosoft.gui.rendering.events.ResizeWindowEvent
|
||||||
import de.bixilon.minosoft.gui.rendering.font.manager.FontManager
|
import de.bixilon.minosoft.gui.rendering.font.manager.FontManager
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.input.key.DebugKeyBindings
|
import de.bixilon.minosoft.gui.rendering.input.key.DebugKeyBindings
|
||||||
import de.bixilon.minosoft.gui.rendering.input.key.DefaultKeyBindings
|
import de.bixilon.minosoft.gui.rendering.input.key.DefaultKeyBindings
|
||||||
import de.bixilon.minosoft.gui.rendering.renderer.renderer.DefaultRenderer
|
import de.bixilon.minosoft.gui.rendering.renderer.renderer.DefaultRenderer
|
||||||
|
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
|
||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates
|
||||||
import de.bixilon.minosoft.util.Stopwatch
|
import de.bixilon.minosoft.util.Stopwatch
|
||||||
import de.bixilon.minosoft.util.delegate.RenderingDelegate.observeRendering
|
import de.bixilon.minosoft.util.delegate.RenderingDelegate.observeRendering
|
||||||
@ -130,6 +132,7 @@ object RenderLoader {
|
|||||||
input.init()
|
input.init()
|
||||||
DefaultKeyBindings.register(this)
|
DefaultKeyBindings.register(this)
|
||||||
DebugKeyBindings.register(this)
|
DebugKeyBindings.register(this)
|
||||||
|
connection.events.listen<ResizeWindowEvent> { system.viewport = it.size }
|
||||||
|
|
||||||
this::state.observe(this) {
|
this::state.observe(this) {
|
||||||
if (it == RenderingStates.PAUSED || it == RenderingStates.SLOW || it == RenderingStates.STOPPED) {
|
if (it == RenderingStates.PAUSED || it == RenderingStates.SLOW || it == RenderingStates.STOPPED) {
|
||||||
@ -137,7 +140,6 @@ object RenderLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
window.postInit()
|
window.postInit()
|
||||||
|
|
||||||
textures.dynamic.activate()
|
textures.dynamic.activate()
|
||||||
|
@ -153,7 +153,6 @@ interface RenderSystem {
|
|||||||
|
|
||||||
fun polygonOffset(factor: Float, unit: Float)
|
fun polygonOffset(factor: Float, unit: Float)
|
||||||
|
|
||||||
|
|
||||||
fun resetBlending() {
|
fun resetBlending() {
|
||||||
disable(RenderingCapabilities.BLENDING)
|
disable(RenderingCapabilities.BLENDING)
|
||||||
setBlendFunction(BlendingFunctions.ONE, BlendingFunctions.ONE_MINUS_SOURCE_ALPHA, BlendingFunctions.ONE, BlendingFunctions.ZERO)
|
setBlendFunction(BlendingFunctions.ONE, BlendingFunctions.ONE_MINUS_SOURCE_ALPHA, BlendingFunctions.ONE, BlendingFunctions.ZERO)
|
||||||
@ -165,4 +164,6 @@ interface RenderSystem {
|
|||||||
shader.reload()
|
shader.reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var viewport: Vec2i
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
|||||||
import de.bixilon.minosoft.data.text.formatting.color.Colors
|
import de.bixilon.minosoft.data.text.formatting.color.Colors
|
||||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderContext
|
import de.bixilon.minosoft.gui.rendering.RenderContext
|
||||||
import de.bixilon.minosoft.gui.rendering.events.ResizeWindowEvent
|
|
||||||
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.*
|
import de.bixilon.minosoft.gui.rendering.system.base.*
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer
|
||||||
@ -34,10 +33,10 @@ import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform.FloatOpenG
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform.IntOpenGLUniformBuffer
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform.IntOpenGLUniformBuffer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.vertex.FloatOpenGLVertexBuffer
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.vertex.FloatOpenGLVertexBuffer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.texture.OpenGLTextureManager
|
import de.bixilon.minosoft.gui.rendering.system.opengl.texture.OpenGLTextureManager
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.vendor.*
|
import de.bixilon.minosoft.gui.rendering.system.opengl.vendor.OpenGLVendor
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshOrder
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshOrder
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
||||||
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||||
import de.bixilon.minosoft.terminal.RunConfiguration
|
import de.bixilon.minosoft.terminal.RunConfiguration
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
import de.bixilon.minosoft.util.logging.LogLevels
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
@ -118,12 +117,7 @@ class OpenGLRenderSystem(
|
|||||||
this.vendorString = glGetString(GL_VENDOR) ?: "UNKNOWN"
|
this.vendorString = glGetString(GL_VENDOR) ?: "UNKNOWN"
|
||||||
val vendorString = vendorString.lowercase()
|
val vendorString = vendorString.lowercase()
|
||||||
|
|
||||||
vendor = when {
|
vendor = OpenGLVendor.of(vendorString)
|
||||||
vendorString.contains("nvidia") -> NvidiaOpenGLVendor
|
|
||||||
vendorString.contains("intel") -> MesaOpenGLVendor
|
|
||||||
vendorString.contains("amd") || vendorString.contains("ati") -> ATIOpenGLVendor
|
|
||||||
else -> OtherOpenGLVendor
|
|
||||||
}
|
|
||||||
if (context.preferQuads && DriverHacks.USE_QUADS_OVER_TRIANGLE !in vendor.hacks) {
|
if (context.preferQuads && DriverHacks.USE_QUADS_OVER_TRIANGLE !in vendor.hacks) {
|
||||||
throw IllegalStateException("Your GPU driver does not support the `prefer_quads` config option!")
|
throw IllegalStateException("Your GPU driver does not support the `prefer_quads` config option!")
|
||||||
}
|
}
|
||||||
@ -131,11 +125,6 @@ class OpenGLRenderSystem(
|
|||||||
this.version = glGetString(GL_VERSION) ?: "UNKNOWN"
|
this.version = glGetString(GL_VERSION) ?: "UNKNOWN"
|
||||||
this.gpuType = glGetString(GL_RENDERER) ?: "UNKNOWN"
|
this.gpuType = glGetString(GL_RENDERER) ?: "UNKNOWN"
|
||||||
|
|
||||||
context.connection.events.listen<ResizeWindowEvent> {
|
|
||||||
context.queue += {
|
|
||||||
glViewport(0, 0, it.size.x, it.size.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (DEBUG_MODE) {
|
if (DEBUG_MODE) {
|
||||||
glEnable(GL_DEBUG_OUTPUT)
|
glEnable(GL_DEBUG_OUTPUT)
|
||||||
glDebugMessageCallback({ source, type, id, severity, length, message, userParameter ->
|
glDebugMessageCallback({ source, type, id, severity, length, message, userParameter ->
|
||||||
@ -332,6 +321,13 @@ class OpenGLRenderSystem(
|
|||||||
Log.log(LogMessageType.RENDERING, LogLevels.VERBOSE) { "[OpenGL] ${builder.invoke()}" }
|
Log.log(LogMessageType.RENDERING, LogLevels.VERBOSE) { "[OpenGL] ${builder.invoke()}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var viewport: Vec2i = Vec2i.EMPTY
|
||||||
|
set(value) {
|
||||||
|
if (field == value) return
|
||||||
|
field = Vec2i(value)
|
||||||
|
glViewport(0, 0, viewport.x, viewport.y)
|
||||||
|
}
|
||||||
|
|
||||||
companion object : RenderSystemFactory {
|
companion object : RenderSystemFactory {
|
||||||
const val DEBUG_MODE = false
|
const val DEBUG_MODE = false
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ import de.bixilon.minosoft.gui.rendering.system.base.driver.DriverHacks
|
|||||||
import org.lwjgl.opengl.ATIMeminfo.GL_VBO_FREE_MEMORY_ATI
|
import org.lwjgl.opengl.ATIMeminfo.GL_VBO_FREE_MEMORY_ATI
|
||||||
import org.lwjgl.opengl.GL11.glGetInteger
|
import org.lwjgl.opengl.GL11.glGetInteger
|
||||||
|
|
||||||
object ATIOpenGLVendor : OpenGLVendor {
|
object AMDOpenGLVendor : OpenGLVendor {
|
||||||
override val shaderDefine: String = "__ATI"
|
override val shaderDefine: String = "__AMD"
|
||||||
|
|
||||||
override val availableVRAM: Long
|
override val availableVRAM: Long
|
||||||
get() = glGetInteger(GL_VBO_FREE_MEMORY_ATI).toLong() * 1024
|
get() = glGetInteger(GL_VBO_FREE_MEMORY_ATI).toLong() * 1024
|
@ -15,8 +15,8 @@ package de.bixilon.minosoft.gui.rendering.system.opengl.vendor
|
|||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.driver.DriverHacks
|
import de.bixilon.minosoft.gui.rendering.system.base.driver.DriverHacks
|
||||||
|
|
||||||
object MesaOpenGLVendor : OpenGLVendor {
|
object IntelOpenGLVendor : OpenGLVendor {
|
||||||
override val shaderDefine: String = "__MESA"
|
override val shaderDefine: String = "__INTEL"
|
||||||
|
|
||||||
override val hacks = DriverHacks.set()
|
override val hacks = DriverHacks.set()
|
||||||
}
|
}
|
@ -22,4 +22,15 @@ interface OpenGLVendor : GPUVendor {
|
|||||||
get() = -1L
|
get() = -1L
|
||||||
val maximumVRAM: Long
|
val maximumVRAM: Long
|
||||||
get() = -1L
|
get() = -1L
|
||||||
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun of(vendor: String): OpenGLVendor = when {
|
||||||
|
vendor.contains("nvidia") -> NvidiaOpenGLVendor
|
||||||
|
vendor.contains("intel") -> IntelOpenGLVendor
|
||||||
|
vendor.contains("amd") || vendor.contains("ati") -> AMDOpenGLVendor
|
||||||
|
else -> OtherOpenGLVendor
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user