mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
render system: abstract polygon mode
This commit is contained in:
parent
2c900298aa
commit
0576f1920f
@ -29,6 +29,7 @@ import de.bixilon.minosoft.gui.rendering.modding.events.*
|
|||||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
||||||
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.PolygonModes
|
||||||
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.opengl.OpenGLRenderSystem
|
import de.bixilon.minosoft.gui.rendering.system.opengl.OpenGLRenderSystem
|
||||||
import de.bixilon.minosoft.gui.rendering.system.window.BaseWindow
|
import de.bixilon.minosoft.gui.rendering.system.window.BaseWindow
|
||||||
@ -206,12 +207,9 @@ class RenderWindow(
|
|||||||
|
|
||||||
private fun registerGlobalKeyCombinations() {
|
private fun registerGlobalKeyCombinations() {
|
||||||
inputHandler.registerKeyCallback(KeyBindingsNames.DEBUG_POLYGON) {
|
inputHandler.registerKeyCallback(KeyBindingsNames.DEBUG_POLYGON) {
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, if (it) {
|
val nextMode = it.decide(PolygonModes.LINE, PolygonModes.FILL)
|
||||||
GL_LINE
|
renderSystem.polygonMode = nextMode
|
||||||
} else {
|
sendDebugMessage("Set polygon to: $nextMode")
|
||||||
GL_FILL
|
|
||||||
})
|
|
||||||
sendDebugMessage("Toggled polygon mode!")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inputHandler.registerKeyCallback(KeyBindingsNames.QUIT_RENDERING) { window.close() }
|
inputHandler.registerKeyCallback(KeyBindingsNames.QUIT_RENDERING) { window.close() }
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 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.gui.rendering.system.base
|
||||||
|
|
||||||
|
enum class FaceTypes {
|
||||||
|
FRONT_LEFT,
|
||||||
|
FRONT_RIGHT,
|
||||||
|
BACK_LEFT,
|
||||||
|
BACK_RIGHT,
|
||||||
|
FRONT,
|
||||||
|
BACK,
|
||||||
|
LEFT,
|
||||||
|
RIGHT,
|
||||||
|
FRONT_AND_BACK,
|
||||||
|
;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 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.gui.rendering.system.base
|
||||||
|
|
||||||
|
enum class PolygonModes {
|
||||||
|
FILL,
|
||||||
|
LINE,
|
||||||
|
POINT,
|
||||||
|
;
|
||||||
|
}
|
@ -49,6 +49,7 @@ interface RenderSystem {
|
|||||||
var depth: DepthFunctions
|
var depth: DepthFunctions
|
||||||
var depthMask: Boolean
|
var depthMask: Boolean
|
||||||
|
|
||||||
fun readPixels(start: Vec2i, end: Vec2i, type: PixelTypes): ByteBuffer
|
var polygonMode: PolygonModes
|
||||||
|
|
||||||
|
fun readPixels(start: Vec2i, end: Vec2i, type: PixelTypes): ByteBuffer
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,15 @@ class OpenGLRenderSystem(
|
|||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var polygonMode: PolygonModes = PolygonModes.FILL
|
||||||
|
set(value) {
|
||||||
|
if (field == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
glPolygonMode(FaceTypes.FRONT_AND_BACK.gl, value.gl)
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
override fun readPixels(start: Vec2i, end: Vec2i, type: PixelTypes): ByteBuffer {
|
override fun readPixels(start: Vec2i, end: Vec2i, type: PixelTypes): ByteBuffer {
|
||||||
val buffer: ByteBuffer = BufferUtils.createByteBuffer((end.x - start.x) * (end.y - start.y) * type.bytes)
|
val buffer: ByteBuffer = BufferUtils.createByteBuffer((end.x - start.x) * (end.y - start.y) * type.bytes)
|
||||||
glReadPixels(start.x, start.y, end.x, end.y, type.gl, GL_UNSIGNED_BYTE, buffer)
|
glReadPixels(start.x, start.y, end.x, end.y, type.gl, GL_UNSIGNED_BYTE, buffer)
|
||||||
@ -178,5 +187,31 @@ class OpenGLRenderSystem(
|
|||||||
else -> throw IllegalArgumentException("OpenGL does not support pixel type: $this")
|
else -> throw IllegalArgumentException("OpenGL does not support pixel type: $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val PolygonModes.gl: Int
|
||||||
|
get() {
|
||||||
|
return when (this) {
|
||||||
|
PolygonModes.FILL -> GL_FILL
|
||||||
|
PolygonModes.LINE -> GL_LINE
|
||||||
|
PolygonModes.POINT -> GL_POINT
|
||||||
|
else -> throw IllegalArgumentException("OpenGL does not support polygon mode: $this")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val FaceTypes.gl: Int
|
||||||
|
get() {
|
||||||
|
return when (this) {
|
||||||
|
FaceTypes.FRONT_LEFT -> GL_FRONT_LEFT
|
||||||
|
FaceTypes.FRONT_RIGHT -> GL_FRONT_RIGHT
|
||||||
|
FaceTypes.BACK_LEFT -> GL_BACK_LEFT
|
||||||
|
FaceTypes.BACK_RIGHT -> GL_BACK_RIGHT
|
||||||
|
FaceTypes.FRONT -> GL_FRONT
|
||||||
|
FaceTypes.BACK -> GL_BACK
|
||||||
|
FaceTypes.LEFT -> GL_LEFT
|
||||||
|
FaceTypes.RIGHT -> GL_RIGHT
|
||||||
|
FaceTypes.FRONT_AND_BACK -> GL_FRONT_AND_BACK
|
||||||
|
else -> throw IllegalArgumentException("OpenGL does not face type: $this")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import de.bixilon.minosoft.config.StaticConfiguration
|
|||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.PixelTypes
|
import de.bixilon.minosoft.gui.rendering.system.base.PixelTypes
|
||||||
import de.bixilon.minosoft.util.Util
|
import de.bixilon.minosoft.util.Util
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
|
||||||
import glm_.vec2.Vec2i
|
import glm_.vec2.Vec2i
|
||||||
import java.awt.image.BufferedImage
|
import java.awt.image.BufferedImage
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -36,6 +35,10 @@ class ScreenshotTaker(
|
|||||||
var i = 1
|
var i = 1
|
||||||
while (File(path).exists()) {
|
while (File(path).exists()) {
|
||||||
path = "${basePath}_${i++}.png"
|
path = "${basePath}_${i++}.png"
|
||||||
|
if (i > 10) {
|
||||||
|
screenshotFail(StackOverflowError())
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val width = renderWindow.window.size.x
|
val width = renderWindow.window.size.x
|
||||||
@ -63,7 +66,6 @@ class ScreenshotTaker(
|
|||||||
|
|
||||||
val message = "§aScreenshot saved to §f${file.name}"
|
val message = "§aScreenshot saved to §f${file.name}"
|
||||||
renderWindow.sendDebugMessage(message)
|
renderWindow.sendDebugMessage(message)
|
||||||
Log.game(message)
|
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
screenshotFail(exception)
|
screenshotFail(exception)
|
||||||
}
|
}
|
||||||
@ -73,7 +75,7 @@ class ScreenshotTaker(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun screenshotFail(exception: Exception?) {
|
private fun screenshotFail(exception: Throwable?) {
|
||||||
exception?.printStackTrace()
|
exception?.printStackTrace()
|
||||||
renderWindow.sendDebugMessage("§cFailed to make a screenshot!")
|
renderWindow.sendDebugMessage("§cFailed to make a screenshot!")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user