mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 00:47:26 -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.util.mesh.MeshOrder
|
||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||
import java.nio.FloatBuffer
|
||||
|
||||
class DummyRenderSystem(
|
||||
@ -47,6 +48,8 @@ class DummyRenderSystem(
|
||||
override var framebuffer: Framebuffer? = null
|
||||
override val active: Boolean = true
|
||||
|
||||
override var viewport = Vec2i.EMPTY
|
||||
|
||||
override fun init() {
|
||||
vendor = DummyVendor
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
@ -14,7 +14,10 @@
|
||||
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.driver.DriverHacks
|
||||
|
||||
object DummyVendor : GPUVendor {
|
||||
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.minosoft.gui.rendering.RenderUtil.pause
|
||||
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.gui.GUIRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.input.key.DebugKeyBindings
|
||||
import de.bixilon.minosoft.gui.rendering.input.key.DefaultKeyBindings
|
||||
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.util.Stopwatch
|
||||
import de.bixilon.minosoft.util.delegate.RenderingDelegate.observeRendering
|
||||
@ -130,6 +132,7 @@ object RenderLoader {
|
||||
input.init()
|
||||
DefaultKeyBindings.register(this)
|
||||
DebugKeyBindings.register(this)
|
||||
connection.events.listen<ResizeWindowEvent> { system.viewport = it.size }
|
||||
|
||||
this::state.observe(this) {
|
||||
if (it == RenderingStates.PAUSED || it == RenderingStates.SLOW || it == RenderingStates.STOPPED) {
|
||||
@ -137,7 +140,6 @@ object RenderLoader {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
window.postInit()
|
||||
|
||||
textures.dynamic.activate()
|
||||
|
@ -153,7 +153,6 @@ interface RenderSystem {
|
||||
|
||||
fun polygonOffset(factor: Float, unit: Float)
|
||||
|
||||
|
||||
fun resetBlending() {
|
||||
disable(RenderingCapabilities.BLENDING)
|
||||
setBlendFunction(BlendingFunctions.ONE, BlendingFunctions.ONE_MINUS_SOURCE_ALPHA, BlendingFunctions.ONE, BlendingFunctions.ZERO)
|
||||
@ -165,4 +164,6 @@ interface RenderSystem {
|
||||
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.RGBColor
|
||||
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.system.base.*
|
||||
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.vertex.FloatOpenGLVertexBuffer
|
||||
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.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.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
@ -118,12 +117,7 @@ class OpenGLRenderSystem(
|
||||
this.vendorString = glGetString(GL_VENDOR) ?: "UNKNOWN"
|
||||
val vendorString = vendorString.lowercase()
|
||||
|
||||
vendor = when {
|
||||
vendorString.contains("nvidia") -> NvidiaOpenGLVendor
|
||||
vendorString.contains("intel") -> MesaOpenGLVendor
|
||||
vendorString.contains("amd") || vendorString.contains("ati") -> ATIOpenGLVendor
|
||||
else -> OtherOpenGLVendor
|
||||
}
|
||||
vendor = OpenGLVendor.of(vendorString)
|
||||
if (context.preferQuads && DriverHacks.USE_QUADS_OVER_TRIANGLE !in vendor.hacks) {
|
||||
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.gpuType = glGetString(GL_RENDERER) ?: "UNKNOWN"
|
||||
|
||||
context.connection.events.listen<ResizeWindowEvent> {
|
||||
context.queue += {
|
||||
glViewport(0, 0, it.size.x, it.size.y)
|
||||
}
|
||||
}
|
||||
if (DEBUG_MODE) {
|
||||
glEnable(GL_DEBUG_OUTPUT)
|
||||
glDebugMessageCallback({ source, type, id, severity, length, message, userParameter ->
|
||||
@ -332,6 +321,13 @@ class OpenGLRenderSystem(
|
||||
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 {
|
||||
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.GL11.glGetInteger
|
||||
|
||||
object ATIOpenGLVendor : OpenGLVendor {
|
||||
override val shaderDefine: String = "__ATI"
|
||||
object AMDOpenGLVendor : OpenGLVendor {
|
||||
override val shaderDefine: String = "__AMD"
|
||||
|
||||
override val availableVRAM: Long
|
||||
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
|
||||
|
||||
object MesaOpenGLVendor : OpenGLVendor {
|
||||
override val shaderDefine: String = "__MESA"
|
||||
object IntelOpenGLVendor : OpenGLVendor {
|
||||
override val shaderDefine: String = "__INTEL"
|
||||
|
||||
override val hacks = DriverHacks.set()
|
||||
}
|
@ -22,4 +22,15 @@ interface OpenGLVendor : GPUVendor {
|
||||
get() = -1L
|
||||
val maximumVRAM: Long
|
||||
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