mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 23:34:04 +09:00
GraphicsAdapter will inquire the external Framebuffer if any and will try to play nicely with it
This commit is contained in:
29
tsvm_core/src/net/torvald/tsvm/FBM.kt
Normal file
29
tsvm_core/src/net/torvald/tsvm/FBM.kt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package net.torvald.tsvm
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nested FBOs are just not a thing in GL!
|
||||||
|
*
|
||||||
|
* Created by minjaesong on 2018-07-03.
|
||||||
|
*
|
||||||
|
* @link https://stackoverflow.com/questions/25471727/libgdx-nested-framebuffer
|
||||||
|
*/
|
||||||
|
internal object FBM {
|
||||||
|
private val stack = Stack<FrameBuffer>()
|
||||||
|
|
||||||
|
fun begin(buffer: FrameBuffer) {
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
stack.peek().end()
|
||||||
|
}
|
||||||
|
stack.push(buffer).begin()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun end() {
|
||||||
|
stack.pop().end()
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
stack.peek().begin()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package net.torvald.tsvm.peripheral
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong
|
||||||
import net.torvald.tsvm.TsvmTextureRegionPack
|
import net.torvald.tsvm.TsvmTextureRegionPack
|
||||||
import net.torvald.tsvm.VM
|
import net.torvald.tsvm.VM
|
||||||
@@ -29,16 +30,23 @@ class CharacterLCDdisplay(assetsRoot: String, vm: VM) : GraphicsAdapter(assetsRo
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
override fun render(delta: Float, batch: SpriteBatch, xoff: Float, yoff: Float, flipY: Boolean) {
|
override fun render(
|
||||||
|
delta: Float,
|
||||||
|
batch: SpriteBatch,
|
||||||
|
xoff: Float,
|
||||||
|
yoff: Float,
|
||||||
|
flipY: Boolean,
|
||||||
|
uiFBO: FrameBuffer?
|
||||||
|
) {
|
||||||
batch.shader = null
|
batch.shader = null
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
batch.draw(machine, xoff, yoff)
|
batch.draw(machine, xoff, yoff)
|
||||||
}
|
}
|
||||||
if (!flipY)
|
if (!flipY)
|
||||||
super.render(delta, batch, xoff+74, yoff+102, flipY)
|
super.render(delta, batch, xoff+74, yoff+102, flipY, uiFBO)
|
||||||
else
|
else
|
||||||
super.render(delta, batch, xoff+74, yoff+72, flipY)
|
super.render(delta, batch, xoff+74, yoff+72, flipY, uiFBO)
|
||||||
|
|
||||||
// draw BMS and RTC
|
// draw BMS and RTC
|
||||||
val batPerc = "89"
|
val batPerc = "89"
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import com.badlogic.gdx.graphics.g2d.Gdx2DPixmap
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import com.badlogic.gdx.graphics.glutils.PixmapTextureData
|
|
||||||
import com.badlogic.gdx.math.Matrix4
|
import com.badlogic.gdx.math.Matrix4
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
|
||||||
import net.torvald.UnsafeHelper
|
import net.torvald.UnsafeHelper
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint
|
||||||
|
import net.torvald.tsvm.FBM
|
||||||
import net.torvald.tsvm.LoadShader
|
import net.torvald.tsvm.LoadShader
|
||||||
import net.torvald.tsvm.VM
|
import net.torvald.tsvm.VM
|
||||||
import net.torvald.tsvm.kB
|
import net.torvald.tsvm.kB
|
||||||
@@ -710,7 +709,10 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
|
|||||||
unusedArea[1].toInt().and(15).toFloat() / 15f,
|
unusedArea[1].toInt().and(15).toFloat() / 15f,
|
||||||
unusedArea[2].toInt().and(15).toFloat() / 15f, 1f)
|
unusedArea[2].toInt().and(15).toFloat() / 15f, 1f)
|
||||||
|
|
||||||
open fun render(delta: Float, uiBatch: SpriteBatch, xoff: Float, yoff: Float, flipY: Boolean = false) {
|
open fun render(delta: Float, uiBatch: SpriteBatch, xoff: Float, yoff: Float, flipY: Boolean = false, uiFBO: FrameBuffer? = null) {
|
||||||
|
uiFBO?.end()
|
||||||
|
|
||||||
|
|
||||||
// must reset positions as pixmaps expect them to be zero
|
// must reset positions as pixmaps expect them to be zero
|
||||||
framebuffer.pixels.position(0)
|
framebuffer.pixels.position(0)
|
||||||
chrrom.pixels.position(0)
|
chrrom.pixels.position(0)
|
||||||
@@ -880,6 +882,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
|
|||||||
outFBObatch.draw(outFBOregion[0], 0f, HEIGHT.toFloat(), WIDTH.toFloat(), -HEIGHT.toFloat())
|
outFBObatch.draw(outFBOregion[0], 0f, HEIGHT.toFloat(), WIDTH.toFloat(), -HEIGHT.toFloat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
uiFBO?.begin()
|
||||||
|
|
||||||
uiBatch.inUse {
|
uiBatch.inUse {
|
||||||
uiBatch.shader = null
|
uiBatch.shader = null
|
||||||
@@ -1753,9 +1756,9 @@ internal infix fun Int.fmod(other: Int): Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun FrameBuffer.inUse(action: () -> Unit) {
|
internal fun FrameBuffer.inUse(action: () -> Unit) {
|
||||||
this.begin()
|
FBM.begin(this)
|
||||||
action()
|
action()
|
||||||
this.end()
|
FBM.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun SpriteBatch.inUse(action: () -> Unit) {
|
internal fun SpriteBatch.inUse(action: () -> Unit) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.GL20
|
import com.badlogic.gdx.graphics.GL20
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import net.torvald.tsvm.VM
|
import net.torvald.tsvm.VM
|
||||||
import net.torvald.tsvm.kB
|
import net.torvald.tsvm.kB
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
@@ -38,9 +39,16 @@ open class TexticsAdapterBase(assetsRoot: String, vm: VM, config: AdapterConfig)
|
|||||||
private val ALIGN = (HEIGHT - TEX_HEIGHT).absoluteValue / 2f
|
private val ALIGN = (HEIGHT - TEX_HEIGHT).absoluteValue / 2f
|
||||||
private val phosphorCol = crtColor[theme.substring(4)] ?: crtColor["white"]
|
private val phosphorCol = crtColor[theme.substring(4)] ?: crtColor["white"]
|
||||||
|
|
||||||
override fun render(delta: Float, batch: SpriteBatch, xoff: Float, yoff: Float, flipY: Boolean) {
|
override fun render(
|
||||||
|
delta: Float,
|
||||||
|
batch: SpriteBatch,
|
||||||
|
xoff: Float,
|
||||||
|
yoff: Float,
|
||||||
|
flipY: Boolean,
|
||||||
|
uiFBO: FrameBuffer?
|
||||||
|
) {
|
||||||
|
|
||||||
super.render(delta, batch, xoff, yoff, flipY)
|
super.render(delta, batch, xoff, yoff, flipY, uiFBO)
|
||||||
|
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
batch.enableBlending()
|
batch.enableBlending()
|
||||||
|
|||||||
Reference in New Issue
Block a user