removing default batch on blendxxx() funs

This commit is contained in:
minjaesong
2019-01-20 03:09:23 +09:00
parent d1a2e6b8f2
commit be20fd8328
16 changed files with 44 additions and 44 deletions

View File

@@ -161,7 +161,7 @@ object LoadScreen : ScreenAdapter() {
Terrarum.batch.inUse {
blendNormal()
blendNormal(Terrarum.batch)
Terrarum.fontGame
it.color = Color.WHITE
@@ -169,7 +169,7 @@ object LoadScreen : ScreenAdapter() {
Terrarum.fontGame.draw(it, textToPrint, ((textFbo.width - textWidth) / 2).toInt().toFloat(), 0f)
blendMul()
blendMul(Terrarum.batch)
// draw colour overlay, flipped
it.draw(textOverlayTex,
(textFbo.width - textWidth) / 2f,
@@ -184,7 +184,7 @@ object LoadScreen : ScreenAdapter() {
Terrarum.batch.inUse {
initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT) // dunno, no render without this
it.projectionMatrix = camera.combined
blendNormal()
blendNormal(Terrarum.batch)
// almost black background
@@ -251,7 +251,7 @@ object LoadScreen : ScreenAdapter() {
initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT) // dunno, no render without this
it.projectionMatrix = camera.combined
blendNormal()
blendNormal(Terrarum.batch)

View File

@@ -576,25 +576,25 @@ fun SpriteBatch.drawStraightLine(x: Float, y: Float, otherEnd: Float, thickness:
infix fun Color.mul(other: Color): Color = this.cpy().mul(other)
fun blendMul(batch: SpriteBatch? = null) {
fun blendMul(batch: SpriteBatch) {
// will break if the colour image contains semitransparency
(batch ?: Terrarum.batch).enableBlending()
(batch ?: Terrarum.batch).setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
batch.enableBlending()
batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
}
fun blendScreen(batch: SpriteBatch? = null) {
fun blendScreen(batch: SpriteBatch) {
// will break if the colour image contains semitransparency
(batch ?: Terrarum.batch).enableBlending()
(batch ?: Terrarum.batch).setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR)
batch.enableBlending()
batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR)
}
fun blendDisable(batch: SpriteBatch? = null) {
(batch ?: Terrarum.batch).disableBlending()
fun blendDisable(batch: SpriteBatch) {
batch.disableBlending()
}
fun blendNormal(batch: SpriteBatch? = null) {
(batch ?: Terrarum.batch).enableBlending()
(batch ?: Terrarum.batch).setBlendFunctionSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_SRC_ALPHA, GL20.GL_ONE)
fun blendNormal(batch: SpriteBatch) {
batch.enableBlending()
batch.setBlendFunctionSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_SRC_ALPHA, GL20.GL_ONE)
// ALPHA *MUST BE* PREMULTIPLIED //
@@ -648,7 +648,7 @@ object BlendMode {
const val NORMAL = "normal"
//const val MAX = "GL_MAX" // not supported by GLES -- use shader
fun resolve(mode: String, batch: SpriteBatch? = null) {
fun resolve(mode: String, batch: SpriteBatch) {
when (mode) {
SCREEN -> blendScreen(batch)
MULTIPLY -> blendMul(batch)

View File

@@ -261,7 +261,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
private fun renderOverlayTexts() {
setCameraPosition(0f, 0f)
blendNormal()
blendNormal(batch)
batch.shader = null
batch.color = Color.LIGHT_GRAY

View File

@@ -74,12 +74,12 @@ class UIItemInventoryElem(
if (item != null || drawBackOnNull) {
// do not highlight even if drawBackOnNull is true
if (mouseUp && item != null) {
BlendMode.resolve(mouseoverBackBlendMode)
BlendMode.resolve(mouseoverBackBlendMode, batch)
batch.color = mouseoverBackCol
}
// if drawBackOnNull, just draw background
else {
BlendMode.resolve(backBlendMode)
BlendMode.resolve(backBlendMode, batch)
batch.color = backCol
}
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
@@ -87,7 +87,7 @@ class UIItemInventoryElem(
if (item != null && itemImage != null) {
blendNormal()
blendNormal(batch)
// item image
batch.color = Color.WHITE

View File

@@ -56,12 +56,12 @@ class UIItemInventoryElemSimple(
if (item != null || drawBackOnNull) {
// do not highlight even if drawBackOnNull is true
if (mouseUp && item != null || equippedSlot != null) { // "equippedSlot != null": also highlight back if equipped
BlendMode.resolve(mouseoverBackBlendMode)
BlendMode.resolve(mouseoverBackBlendMode, batch)
batch.color = mouseoverBackCol
}
// if drawBackOnNull, just draw background
else {
BlendMode.resolve(backBlendMode)
BlendMode.resolve(backBlendMode, batch)
batch.color = backCol
}
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
@@ -72,7 +72,7 @@ class UIItemInventoryElemSimple(
// and you can clearly see the quickslot UI anyway
if (item != null && itemImage != null) {
blendNormal()
blendNormal(batch)
// item image
batch.color = Color.WHITE

View File

@@ -3,9 +3,9 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.Second
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -36,7 +36,7 @@ class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
blendNormal()
blendNormal(batch)
val textWidth = messagesList.map { Terrarum.fontGame.getWidth(it) }.sorted()[1]

View File

@@ -114,7 +114,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// light overlay or EL
if (ELon) {
blendNormal()
blendNormal(batch)
batch.draw(atlas.get(0, 2), 0f, 0f)
}
else {
@@ -124,7 +124,7 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
}
// LCD back
blendNormal()
blendNormal(batch)
batch.draw(atlas.get(0, 3), 0f, 0f)

View File

@@ -188,7 +188,7 @@ class UIInventoryFull(
)
// encumbrance bar background
blendMul()
blendMul(batch)
batch.color = Color(0xa0a0a0_ff.toInt())
batch.fillRect(
xEnd - 3 - weightBarWidth,
@@ -197,7 +197,7 @@ class UIInventoryFull(
controlHelpHeight - 6f
)
// encumbrance bar
blendNormal()
blendNormal(batch)
batch.color = if (isEncumbered) Color(0xff0000_cc.toInt()) else Color(0x00ff00_cc.toInt())
batch.fillRect(
xEnd - 3 - weightBarWidth,

View File

@@ -62,7 +62,7 @@ class UIItemInventoryEquippedView(
override fun render(batch: SpriteBatch, camera: Camera) {
// sprite background
blendNormal()
blendNormal(batch)
batch.color = spriteViewBackCol
batch.fillRect(
posX.toFloat(), posY.toFloat(),

View File

@@ -23,7 +23,7 @@ class UIItemModuleInfoCell(
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal()
blendNormal(batch)
if (ModMgr.moduleInfo.containsKey(moduleName)) {
val modInfo = ModMgr.moduleInfo[moduleName]!!

View File

@@ -63,7 +63,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// light overlay or EL
if (ELon) {
blendNormal()
blendNormal(batch)
batch.draw(atlas.get(0, 2), 0f, 0f)
}
else {
@@ -73,7 +73,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
}
// LCD back
blendNormal()
blendNormal(batch)
batch.draw(atlas.get(0, 3), 0f, 0f)

View File

@@ -51,7 +51,7 @@ class UITitleCharactersList : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.color = Color.WHITE
blendNormal()
blendNormal(batch)
mouduleArea.render(batch, camera)
}

View File

@@ -58,7 +58,7 @@ class UITitleModules : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.color = Color.WHITE
blendNormal()
blendNormal(batch)
mouduleArea.render(batch, camera)
}

View File

@@ -272,7 +272,7 @@ class BasicDebugInfoWindow : UICanvas() {
Terrarum.fontSmallNumbers.draw(batch, "255", x.toFloat() + w + 1 - 8 * 3, y.toFloat() + h + 2)
Terrarum.fontSmallNumbers.draw(batch, "Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2)
blendScreen()
blendScreen(batch)
for (c in 0..2) {
for (i in 0..255) {
var histogram_value = if (i == 255) 0 else histogram.get(c)[i]
@@ -291,7 +291,7 @@ class BasicDebugInfoWindow : UICanvas() {
batch.fillRect(bar_x, bar_y, bar_w, bar_h)
}
}
blendNormal()
blendNormal(batch)
}
private fun drawGamepadAxis(batch: SpriteBatch, axisX: Float, axisY: Float, uiX: Int, uiY: Int) {
@@ -307,7 +307,7 @@ class BasicDebugInfoWindow : UICanvas() {
val padName = if (Terrarum.controller!!.name.isEmpty()) "Gamepad"
else Terrarum.controller!!.name
blendNormal()
blendNormal(batch)
batch.end()
Terrarum.inShapeRenderer {

View File

@@ -40,11 +40,11 @@ open class UIItemImageButton(
override fun render(batch: SpriteBatch, camera: Camera) {
// draw background
if (mouseUp) {
BlendMode.resolve(activeBackBlendMode)
BlendMode.resolve(activeBackBlendMode, batch)
batch.color = activeBackCol
}
else {
BlendMode.resolve(buttonBackBlendMode)
BlendMode.resolve(buttonBackBlendMode, batch)
batch.color = buttonBackCol
}
@@ -52,7 +52,7 @@ open class UIItemImageButton(
// draw image
blendNormal()
blendNormal(batch)
batch.color = if (highlighted) highlightCol
else if (mouseUp) activeCol

View File

@@ -4,8 +4,8 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.Second
import net.torvald.terrarum.fillRect
/**
@@ -106,11 +106,11 @@ class UIItemList<Item: UIItem>(
override fun render(batch: SpriteBatch, camera: Camera) {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode)
BlendMode.resolve(backgroundBlendMode, batch)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
batch.color = highlightBackCol
BlendMode.resolve(highlightBackBlendMode)
BlendMode.resolve(highlightBackBlendMode, batch)
if (highlightY != null) {
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
}