Screw it, routing all the GL state stuff through own class, forcing state changes in addition to calling GlStateManager.

Its caching is just too horribad (and I'm pretty sure that's not me anymore; aside from that, other mods may mess up the state, too, and then everything goes down the drain anyway).
This commit is contained in:
Florian Nücke 2015-02-12 17:05:13 +01:00
parent 1ded875cbc
commit 2129fef8db
40 changed files with 356 additions and 284 deletions

View File

@ -10,11 +10,11 @@
"to": [ 16, 7, 16 ],
"faces": {
"up": { "uv": [ 0, 0, 16, 16 ], "texture": "#top" },
"down": { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom", "cullface": "down" },
"north": { "uv": [ 0, 0, 16, 7 ], "texture": "#side", "cullface": "north" },
"south": { "uv": [ 0, 0, 16, 7 ], "texture": "#side", "cullface": "south" },
"west": { "uv": [ 0, 0, 16, 7 ], "texture": "#side", "cullface": "west" },
"east": { "uv": [ 0, 0, 16, 7 ], "texture": "#side", "cullface": "east" }
"down": { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom" },
"north": { "uv": [ 0, 0, 16, 7 ], "texture": "#side" },
"south": { "uv": [ 0, 0, 16, 7 ], "texture": "#side" },
"west": { "uv": [ 0, 0, 16, 7 ], "texture": "#side" },
"east": { "uv": [ 0, 0, 16, 7 ], "texture": "#side" }
}
},
{ "from": [ 2, 7, 2 ],
@ -31,12 +31,12 @@
{ "from": [ 0, 9, 0 ],
"to": [ 16, 16, 16 ],
"faces": {
"up": { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "cullface": "up" },
"up": { "uv": [ 0, 0, 16, 16 ], "texture": "#top" },
"down": { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom" },
"north": { "uv": [ 0, 9, 16, 16 ], "texture": "#side", "cullface": "north" },
"south": { "uv": [ 0, 9, 16, 16 ], "texture": "#side", "cullface": "south" },
"west": { "uv": [ 0, 9, 16, 16 ], "texture": "#side", "cullface": "west" },
"east": { "uv": [ 0, 9, 16, 16 ], "texture": "#side", "cullface": "east" }
"north": { "uv": [ 0, 9, 16, 16 ], "texture": "#side" },
"south": { "uv": [ 0, 9, 16, 16 ], "texture": "#side" },
"west": { "uv": [ 0, 9, 16, 16 ], "texture": "#side" },
"east": { "uv": [ 0, 9, 16, 16 ], "texture": "#side" }
}
}
]

View File

@ -502,7 +502,7 @@ object Textures {
// So we do it manually.
val texture = manager.getTexture(location)
if (texture != null) {
GL11.glBindTexture (GL11.GL_TEXTURE_2D, texture.getGlTextureId)
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getGlTextureId)
}
}

View File

@ -10,8 +10,8 @@ import li.cil.oc.common.container
import li.cil.oc.common.container.ComponentSlot
import li.cil.oc.common.template.AssemblerTemplates
import li.cil.oc.common.tileentity
import li.cil.oc.util.RenderState
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.inventory.Slot
import net.minecraft.util.IChatComponent
@ -61,7 +61,7 @@ class Assembler(playerInventory: InventoryPlayer, val assembler: tileentity.Asse
}
override def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) = {
GlStateManager.pushAttrib()
RenderState.pushAttrib()
if (!assemblerContainer.isAssembling) {
val message =
if (!assemblerContainer.getSlot(0).getHasStack) {
@ -90,7 +90,7 @@ class Assembler(playerInventory: InventoryPlayer, val assembler: tileentity.Asse
tooltip.add(Localization.Assembler.Progress(assemblerContainer.assemblyProgress, timeRemaining))
copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj)
}
GlStateManager.popAttrib()
RenderState.popAttrib()
}
private def formatTime(seconds: Int) = {
@ -100,7 +100,7 @@ class Assembler(playerInventory: InventoryPlayer, val assembler: tileentity.Asse
}
override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
GlStateManager.color(1, 1, 1) // Required under Linux.
RenderState.color(1, 1, 1) // Required under Linux.
Textures.bind(Textures.GUI.RobotAssembler)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
if (assemblerContainer.isAssembling) progress.level = assemblerContainer.assemblyProgress / 100.0

View File

@ -7,10 +7,9 @@ import li.cil.oc.client.Textures
import li.cil.oc.client.{PacketSender => ClientPacketSender}
import li.cil.oc.common.container
import li.cil.oc.common.tileentity
import li.cil.oc.util.RenderState
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.player.InventoryPlayer
import org.lwjgl.opengl.GL11
class Case(playerInventory: InventoryPlayer, val computer: tileentity.Case) extends DynamicGuiContainer(new container.Case(playerInventory, computer)) {
protected var powerButton: ImageButton = _
@ -47,7 +46,7 @@ class Case(playerInventory: InventoryPlayer, val computer: tileentity.Case) exte
}
override def drawSecondaryBackgroundLayer() {
GlStateManager.color(1, 1, 1)
RenderState.color(1, 1, 1)
Textures.bind(Textures.GUI.Computer)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
}

View File

@ -6,8 +6,6 @@ import li.cil.oc.client.gui.widget.WidgetContainer
import li.cil.oc.util.RenderState
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.RenderHelper
import net.minecraft.inventory.Container
import scala.collection.convert.WrapAsScala._
@ -30,10 +28,9 @@ abstract class CustomGuiContainer(container: Container) extends GuiContainer(con
protected def copiedDrawHoveringText(text: util.List[_], x: Int, y: Int, font: FontRenderer): Unit = {
if (!text.isEmpty) {
GlStateManager.disableRescaleNormal()
RenderHelper.disableStandardItemLighting()
GlStateManager.disableLighting()
GlStateManager.disableDepth()
RenderState.disableRescaleNormal()
RenderState.disableEntityLighting()
RenderState.disableDepth()
val textWidth = text.map(line => font.getStringWidth(line.asInstanceOf[String])).max
@ -73,10 +70,9 @@ abstract class CustomGuiContainer(container: Container) extends GuiContainer(con
}
zLevel = 0f
GlStateManager.enableLighting()
GlStateManager.enableDepth()
RenderHelper.enableStandardItemLighting()
GlStateManager.enableRescaleNormal()
RenderState.enableEntityLighting()
RenderState.enableDepth()
RenderState.enableRescaleNormal()
}
}

View File

@ -4,7 +4,7 @@ import li.cil.oc.client.Textures
import li.cil.oc.common.Tier
import li.cil.oc.common.container
import li.cil.oc.common.inventory.DatabaseInventory
import net.minecraft.client.renderer.GlStateManager
import li.cil.oc.util.RenderState
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.inventory.Slot
@ -14,7 +14,7 @@ class Database(playerInventory: InventoryPlayer, val databaseInventory: Database
override def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) {}
override protected def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
Textures.bind(Textures.GUI.Database)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)

View File

@ -5,7 +5,7 @@ import li.cil.oc.client.Textures
import li.cil.oc.client.gui.widget.ProgressBar
import li.cil.oc.common.container
import li.cil.oc.common.tileentity
import net.minecraft.client.renderer.GlStateManager
import li.cil.oc.util.RenderState
import net.minecraft.entity.player.InventoryPlayer
class Disassembler(playerInventory: InventoryPlayer, val disassembler: tileentity.Disassembler) extends DynamicGuiContainer(new container.Disassembler(playerInventory, disassembler)) {
@ -20,7 +20,7 @@ class Disassembler(playerInventory: InventoryPlayer, val disassembler: tileentit
}
override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
GlStateManager.color(1, 1, 1)
RenderState.color(1, 1, 1)
Textures.bind(Textures.GUI.Disassembler)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
progress.level = disassemblerContainer.disassemblyProgress / 100.0

View File

@ -14,7 +14,6 @@ import li.cil.oc.util.PackedColor
import li.cil.oc.util.RenderState
import li.cil.oc.util.TextBuffer
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.entity.player.InventoryPlayer
import org.lwjgl.opengl.GL11
@ -74,21 +73,21 @@ class Drone(playerInventory: InventoryPlayer, val drone: entity.Drone) extends D
override protected def drawBuffer() {
GL11.glTranslatef(bufferX, bufferY, 0)
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
GL11.glScaled(scale, scale, 1)
GL11.glPushAttrib(GL11.GL_DEPTH_BUFFER_BIT)
GL11.glDepthMask(false)
GlStateManager.color(0.5f, 0.5f, 1f)
RenderState.pushAttrib(GL11.GL_DEPTH_BUFFER_BIT)
RenderState.disableDepthMask()
RenderState.color(0.5f, 0.5f, 1f)
TextBufferRenderCache.render(bufferRenderer)
GlStateManager.popAttrib()
RenderState.popAttrib()
}
override protected def changeSize(w: Double, h: Double, recompile: Boolean) = 2.0
override protected def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) {
drawBufferLayer()
GlStateManager.pushAttrib()
RenderState.pushAttrib()
if (isPointInRegion(power.x, power.y, power.width, power.height, mouseX, mouseY)) {
val tooltip = new java.util.ArrayList[String]
val format = Localization.Computer.Power + ": %d%% (%d/%d)"
@ -103,11 +102,11 @@ class Drone(playerInventory: InventoryPlayer, val drone: entity.Drone) extends D
tooltip.add(if (drone.isRunning) Localization.Computer.TurnOff else Localization.Computer.TurnOn)
copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj)
}
GlStateManager.popAttrib()
RenderState.popAttrib()
}
override protected def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
GlStateManager.color(1, 1, 1)
RenderState.color(1, 1, 1)
Textures.bind(Textures.GUI.Drone)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
power.level = drone.globalBuffer.toDouble / math.max(drone.globalBufferSize.toDouble, 1.0)

View File

@ -11,7 +11,6 @@ import li.cil.oc.integration.Mods
import li.cil.oc.integration.util.NEI
import li.cil.oc.util.RenderState
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.inventory.Container
import net.minecraft.inventory.Slot
@ -33,7 +32,7 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
}
override protected def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) {
GlStateManager.pushAttrib()
RenderState.pushAttrib()
drawSecondaryForegroundLayer(mouseX, mouseY)
@ -41,32 +40,32 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
drawSlotHighlight(inventorySlots.inventorySlots.get(slot).asInstanceOf[Slot])
}
GlStateManager.popAttrib()
RenderState.popAttrib()
}
protected def drawSecondaryBackgroundLayer() {}
override protected def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
Textures.bind(Textures.GUI.Background)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
drawSecondaryBackgroundLayer()
RenderState.makeItBlend()
GL11.glDisable(GL11.GL_LIGHTING)
RenderState.disableLighting()
drawInventorySlots()
}
protected def drawInventorySlots(): Unit = {
GlStateManager.pushMatrix()
RenderState.pushMatrix()
GL11.glTranslatef(guiLeft, guiTop, 0)
GL11.glDisable(GL11.GL_DEPTH_TEST)
for (slot <- 0 until inventorySlots.inventorySlots.size()) {
drawSlotInventory(inventorySlots.inventorySlots.get(slot).asInstanceOf[Slot])
}
GL11.glEnable(GL11.GL_DEPTH_TEST)
GlStateManager.popMatrix()
RenderState.popMatrix()
RenderState.makeItBlend()
RenderState.makeItBlend()
}
@ -80,9 +79,9 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
super.drawScreen(mouseX, mouseY, dt)
if (Mods.NotEnoughItems.isAvailable) {
GlStateManager.pushAttrib()
RenderState.pushAttrib()
drawNEIHighlights()
GlStateManager.popAttrib()
RenderState.popAttrib()
}
}
@ -148,13 +147,13 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
}
protected def drawDisabledSlot(slot: ComponentSlot) {
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
Textures.bind(slot.tierIcon)
Gui.drawModalRectWithCustomSizedTexture(slot.xDisplayPosition, slot.yDisplayPosition, 0, 0, 16, 16, 16, 16)
}
protected def drawSlotBackground(x: Int, y: Int) {
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
Textures.bind(Textures.GUI.Slot)
val t = Tessellator.getInstance
val r = t.getWorldRenderer

View File

@ -1,9 +1,9 @@
package li.cil.oc.client.gui
import li.cil.oc.client.Textures
import li.cil.oc.util.RenderState
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.util.ResourceLocation
import net.minecraftforge.fml.relauncher.Side
@ -25,7 +25,7 @@ class ImageButton(id: Int, x: Int, y: Int, w: Int, h: Int,
override def drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) {
if (visible) {
Textures.bind(image)
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
hovered = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height
val x0 = xPosition

View File

@ -4,7 +4,7 @@ import li.cil.oc.Localization
import li.cil.oc.client.Textures
import li.cil.oc.common.container
import li.cil.oc.common.tileentity
import net.minecraft.client.renderer.GlStateManager
import li.cil.oc.util.RenderState
import net.minecraft.entity.player.InventoryPlayer
class Raid(playerInventory: InventoryPlayer, val raid: tileentity.Raid) extends DynamicGuiContainer(new container.Raid(playerInventory, raid)) {
@ -20,7 +20,7 @@ class Raid(playerInventory: InventoryPlayer, val raid: tileentity.Raid) extends
}
override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
GlStateManager.color(1, 1, 1) // Required under Linux.
RenderState.color(1, 1, 1) // Required under Linux.
Textures.bind(Textures.GUI.Raid)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
}

View File

@ -15,7 +15,6 @@ import li.cil.oc.common.tileentity
import li.cil.oc.integration.opencomputers
import li.cil.oc.util.RenderState
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.entity.player.InventoryPlayer
import org.lwjgl.input.Keyboard
@ -105,12 +104,12 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
override def drawBuffer() {
if (buffer != null) {
GL11.glTranslatef(bufferX, bufferY, 0)
RenderState.disableLighting()
GlStateManager.pushMatrix()
RenderState.disableEntityLighting()
RenderState.pushMatrix()
GL11.glTranslatef(-3, -3, 0)
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
BufferRenderer.drawBackground()
GlStateManager.popMatrix()
RenderState.popMatrix()
RenderState.makeItBlend()
val scaleX = bufferRenderWidth / buffer.renderWidth
val scaleY = bufferRenderHeight / buffer.renderHeight
@ -129,7 +128,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
override protected def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) {
drawBufferLayer()
GlStateManager.pushAttrib()
RenderState.pushAttrib()
if (isPointInRegion(power.x, power.y, power.width, power.height, mouseX, mouseY)) {
val tooltip = new java.util.ArrayList[String]
val format = Localization.Computer.Power + ": %d%% (%d/%d)"
@ -144,11 +143,11 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
tooltip.add(if (robot.isRunning) Localization.Computer.TurnOff else Localization.Computer.TurnOn)
copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj)
}
GlStateManager.popAttrib()
RenderState.popAttrib()
}
override protected def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) {
GlStateManager.color(1, 1, 1)
RenderState.color(1, 1, 1)
if (buffer != null) Textures.bind(Textures.GUI.Robot)
else Textures.bind(Textures.GUI.RobotNoScreen)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)

View File

@ -4,7 +4,7 @@ import li.cil.oc.Localization
import li.cil.oc.client.Textures
import li.cil.oc.common.container
import li.cil.oc.common.inventory.ServerInventory
import net.minecraft.client.renderer.GlStateManager
import li.cil.oc.util.RenderState
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.inventory.Slot
@ -17,7 +17,7 @@ class Server(playerInventory: InventoryPlayer, serverInventory: ServerInventory)
}
override def drawSecondaryBackgroundLayer() {
GlStateManager.color(1, 1, 1)
RenderState.color(1, 1, 1)
Textures.bind(Textures.GUI.Server)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
}

View File

@ -8,9 +8,9 @@ import li.cil.oc.client.Textures
import li.cil.oc.client.{PacketSender => ClientPacketSender}
import li.cil.oc.common.container
import li.cil.oc.common.tileentity
import li.cil.oc.util.RenderState
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.util.EnumFacing
@ -96,7 +96,7 @@ class ServerRack(playerInventory: InventoryPlayer, val rack: tileentity.ServerRa
override def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) = {
super.drawSecondaryForegroundLayer(mouseX, mouseY)
GlStateManager.pushAttrib()
RenderState.pushAttrib()
fontRendererObj.drawString(
Localization.localizeImmediately(rack.getName),
@ -114,15 +114,15 @@ class ServerRack(playerInventory: InventoryPlayer, val rack: tileentity.ServerRa
val t = Tessellator.getInstance
val r = t.getWorldRenderer
Textures.bind(Textures.GUI.Range)
GlStateManager.color(1, 1, 1)
GlStateManager.depthMask(false)
RenderState.color(1, 1, 1)
RenderState.disableDepthMask()
r.startDrawingQuads()
r.addVertexWithUV(tx, ty + h, zLevel, 0, 1)
r.addVertexWithUV(tx + w, ty + h, zLevel, 1, 1)
r.addVertexWithUV(tx + w, ty, zLevel, 1, 0)
r.addVertexWithUV(tx, ty, zLevel, 0, 0)
t.draw()
GlStateManager.depthMask(true)
RenderState.enableDepthMask()
}
drawCenteredString(fontRendererObj,
@ -135,6 +135,6 @@ class ServerRack(playerInventory: InventoryPlayer, val rack: tileentity.ServerRa
copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj)
}
GlStateManager.popAttrib()
RenderState.popAttrib()
}
}

View File

@ -4,7 +4,6 @@ import li.cil.oc.client.renderer.gui.BufferRenderer
import li.cil.oc.util.RenderState
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.renderer.GlStateManager
trait DisplayBuffer extends GuiScreen {
protected def bufferX: Int
@ -36,10 +35,10 @@ trait DisplayBuffer extends GuiScreen {
RenderState.checkError(getClass.getName + ".drawBufferLayer: entering (aka: wasntme)")
GlStateManager.pushMatrix()
RenderState.disableLighting()
RenderState.pushMatrix()
RenderState.disableEntityLighting()
drawBuffer()
GlStateManager.popMatrix()
RenderState.popMatrix()
RenderState.checkError(getClass.getName + ".drawBufferLayer: buffer layer")
}

View File

@ -8,7 +8,6 @@ import li.cil.oc.util.BlockPosition
import li.cil.oc.util.ExtendedBlock._
import li.cil.oc.util.ExtendedWorld._
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.util.EnumFacing
import net.minecraft.util.MovingObjectPosition.MovingObjectType
@ -38,13 +37,13 @@ object HighlightRenderer {
val playerPos = e.player.getPositionEyes(e.partialTicks)
val renderPos = blockPos.offset(-playerPos.xCoord, -playerPos.yCoord, -playerPos.zCoord)
GlStateManager.pushMatrix()
GlStateManager.pushAttrib()
RenderState.pushMatrix()
RenderState.pushAttrib()
RenderState.makeItBlend()
Textures.bind(Textures.Model.HologramEffect)
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
GlStateManager.color(0.0F, 1.0F, 0.0F, 0.4F)
RenderState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
RenderState.color(0.0F, 1.0F, 0.0F, 0.4F)
GL11.glTranslated(renderPos.xCoord, renderPos.yCoord, renderPos.zCoord)
GL11.glScaled(1.002, 1.002, 1.002)
@ -92,8 +91,8 @@ object HighlightRenderer {
}
t.draw()
GlStateManager.popAttrib()
GlStateManager.popMatrix()
RenderState.popAttrib()
RenderState.popMatrix()
}
}
}

View File

@ -6,16 +6,15 @@ import java.util.concurrent.TimeUnit
import com.google.common.cache.CacheBuilder
import li.cil.oc.api.event.RobotRenderEvent
import li.cil.oc.client.renderer.tileentity.RobotRenderer
import li.cil.oc.util.RenderState
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.Entity
import net.minecraftforge.client.event.RenderPlayerEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL12
import scala.collection.convert.WrapAsScala._
import scala.collection.mutable
@ -51,8 +50,8 @@ object PetRenderer {
override def call() = new PetLocation(e.entityPlayer)
})
GlStateManager.pushMatrix()
GlStateManager.pushAttrib()
RenderState.pushMatrix()
RenderState.pushAttrib()
if (e.entityPlayer != Minecraft.getMinecraft.thePlayer) {
val localPos = Minecraft.getMinecraft.thePlayer.getPositionEyes(e.partialRenderTick)
val playerPos = e.entityPlayer.getPositionEyes(e.partialRenderTick)
@ -63,10 +62,10 @@ object PetRenderer {
playerPos.zCoord - localPos.zCoord)
}
GL11.glEnable(GL11.GL_LIGHTING)
GL11.glDisable(GL11.GL_BLEND)
GL11.glEnable(GL12.GL_RESCALE_NORMAL)
GlStateManager.color(1, 1, 1, 1)
RenderState.enableEntityLighting()
RenderState.disableBlend()
RenderState.enableRescaleNormal()
RenderState.color(1, 1, 1, 1)
location.applyInterpolatedTransformations(e.partialRenderTick)
@ -75,8 +74,8 @@ object PetRenderer {
RobotRenderer.renderChassis(null, offset, isRunningOverride = true)
GlStateManager.popAttrib()
GlStateManager.popMatrix()
RenderState.popAttrib()
RenderState.popMatrix()
rendering = None
}
@ -84,7 +83,7 @@ object PetRenderer {
@SubscribeEvent(priority = EventPriority.LOWEST)
def onRobotRender(e: RobotRenderEvent) {
rendering match {
case Some((r, g, b)) => GlStateManager.color(r.toFloat, g.toFloat, b.toFloat)
case Some((r, g, b)) => RenderState.color(r.toFloat, g.toFloat, b.toFloat)
case _ =>
}
}

View File

@ -4,7 +4,6 @@ import li.cil.oc.Settings
import li.cil.oc.server.network.WirelessNetwork
import li.cil.oc.util.RenderState
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.world.World
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.ObfuscationReflectionHelper
@ -28,8 +27,8 @@ object WirelessNetworkDebugRenderer {
val py = player.lastTickPosY + (player.posY - player.lastTickPosY) * e.partialTicks
val pz = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * e.partialTicks
GlStateManager.pushAttrib()
GL11.glPushMatrix()
RenderState.pushAttrib()
RenderState.pushMatrix()
GL11.glTranslated(-px, -py, -pz)
RenderState.makeItBlend()
GL11.glDisable(GL11.GL_LIGHTING)
@ -91,8 +90,8 @@ object WirelessNetworkDebugRenderer {
}
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL)
GlStateManager.popAttrib()
GL11.glPopMatrix()
RenderState.popAttrib()
RenderState.popMatrix()
case _ =>
}

View File

@ -1,8 +1,8 @@
package li.cil.oc.client.renderer.entity
import li.cil.oc.client.Textures
import li.cil.oc.util.RenderState
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.entity.Render
import net.minecraft.entity.Entity
import org.lwjgl.opengl.GL11
@ -12,15 +12,15 @@ object DroneRenderer extends Render(Minecraft.getMinecraft.getRenderManager) {
override def doRender(entity: Entity, x: Double, y: Double, z: Double, yaw: Float, dt: Float) {
bindEntityTexture(entity)
GlStateManager.pushMatrix()
GlStateManager.pushAttrib()
RenderState.pushMatrix()
RenderState.pushAttrib()
GL11.glTranslated(x, y + 2 / 16f, z)
model.render(entity, 0, 0, 0, 0, 0, dt)
GlStateManager.popAttrib()
GlStateManager.popMatrix()
RenderState.popAttrib()
RenderState.popMatrix()
}
override def getEntityTexture(entity: Entity) = Textures.Model.Drone

View File

@ -4,7 +4,6 @@ import li.cil.oc.common.entity.Drone
import li.cil.oc.util.RenderState
import net.minecraft.client.model.ModelBase
import net.minecraft.client.model.ModelRenderer
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.Entity
import net.minecraft.util.Vec3
import org.lwjgl.opengl.GL11
@ -94,8 +93,8 @@ final class ModelQuadcopter extends ModelBase {
wing3.render(scale)
if (drone.isRunning) {
RenderState.disableLighting()
GL11.glDepthFunc(GL11.GL_LEQUAL)
RenderState.disableEntityLighting()
RenderState.depthFunc(GL11.GL_LEQUAL)
light0.rotateAngleX = drone.flapAngles(0)(0)
light0.rotateAngleZ = drone.flapAngles(0)(1)
@ -107,7 +106,7 @@ final class ModelQuadcopter extends ModelBase {
light3.rotateAngleZ = drone.flapAngles(3)(1)
// Additive blending for the lights.
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
RenderState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
// Light color.
val lightColor = drone.lightColor
val r = ((lightColor >>> 16) & 0xFF).toByte
@ -119,6 +118,8 @@ final class ModelQuadcopter extends ModelBase {
light1.render(scale)
light2.render(scale)
light3.render(scale)
RenderState.color(1, 1, 1, 1)
}
}
@ -141,8 +142,8 @@ final class ModelQuadcopter extends ModelBase {
wing2.render(scale)
wing3.render(scale)
RenderState.disableLighting()
GlStateManager.depthFunc(GL11.GL_LEQUAL)
RenderState.disableEntityLighting()
RenderState.depthFunc(GL11.GL_LEQUAL)
light0.rotateAngleX = tilt
light0.rotateAngleZ = tilt
@ -153,13 +154,15 @@ final class ModelQuadcopter extends ModelBase {
light3.rotateAngleX = tilt
light3.rotateAngleZ = -tilt
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
RenderState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
GL11.glColor3ub(0x66.toByte, 0xDD.toByte, 0x55.toByte)
light0.render(scale)
light1.render(scale)
light2.render(scale)
light3.render(scale)
RenderState.color(1, 1, 1, 1)
}
override def render(entity: Entity, f1: Float, f2: Float, f3: Float, f4: Float, f5: Float, f6: Float): Unit = {

View File

@ -99,6 +99,7 @@ object DynamicFontRenderer {
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST)
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST)
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, size, size, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, BufferUtils.createByteBuffer(size * size * 4))
GlStateManager.bindTexture(0)
RenderState.checkError(getClass.getName + ".<init>: create texture")

View File

@ -4,7 +4,6 @@ import li.cil.oc.Settings
import li.cil.oc.util.PackedColor
import li.cil.oc.util.RenderState
import li.cil.oc.util.TextBuffer
import net.minecraft.client.renderer.GlStateManager
import org.lwjgl.opengl.GL11
/**
@ -34,12 +33,12 @@ abstract class TextureFontRenderer {
def drawBuffer(buffer: TextBuffer) {
val format = buffer.format
GL11.glPushMatrix()
GlStateManager.pushAttrib()
RenderState.pushMatrix()
RenderState.pushAttrib()
GL11.glScalef(0.5f, 0.5f, 1)
GlStateManager.depthMask(false)
RenderState.disableDepthMask()
GL11.glDisable(GL11.GL_TEXTURE_2D)
RenderState.checkError(getClass.getName + ".drawBuffer: configure state")
@ -107,9 +106,9 @@ abstract class TextureFontRenderer {
RenderState.checkError(getClass.getName + ".drawBuffer: foreground")
GlStateManager.depthMask(true)
GlStateManager.popAttrib()
GL11.glPopMatrix()
RenderState.enableDepthMask()
RenderState.popAttrib()
RenderState.popMatrix()
RenderState.checkError(getClass.getName + ".drawBuffer: leaving")
}

View File

@ -4,7 +4,6 @@ import li.cil.oc.api.component.TextBuffer
import li.cil.oc.client.Textures
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GLAllocation
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.texture.TextureManager
import org.lwjgl.opengl.GL11
@ -89,11 +88,11 @@ object BufferRenderer {
def drawText(screen: TextBuffer) =
if (textureManager.isDefined) {
GlStateManager.pushAttrib()
GlStateManager.depthMask(false)
RenderState.pushAttrib()
RenderState.disableDepthMask()
val changed = screen.renderText()
GlStateManager.depthMask(true)
GlStateManager.popAttrib()
RenderState.enableDepthMask()
RenderState.popAttrib()
changed
}
else false

View File

@ -10,7 +10,6 @@ import li.cil.oc.integration.opencomputers.Item
import li.cil.oc.util.RenderState
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.item.ItemStack
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.EnumChatFormatting
@ -90,12 +89,12 @@ object ItemRenderer extends IItemRenderer {
}
else if (isFloppy(descriptor)) {
GlStateManager.pushAttrib()
RenderState.pushAttrib()
itemRenderer.renderItemIntoGUI(stack, 0, 0)
val res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight)
val fontRenderer = Minecraft.getMinecraft.fontRendererObj
if (fontRenderer != null && res.getScaleFactor > 1) {
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslatef(4f + 2f / res.getScaleFactor, 9f + 2f / res.getScaleFactor, 0)
GL11.glScalef(1f / res.getScaleFactor, 1f / res.getScaleFactor, 1f)
val maxLength = (res.getScaleFactor * 7.5).toInt
@ -109,19 +108,19 @@ object ItemRenderer extends IItemRenderer {
fontRenderer.drawString(line.asInstanceOf[String], 0, 0, 0)
GL11.glTranslatef(0, fontRenderer.FONT_HEIGHT, 0)
}
GL11.glPopMatrix()
RenderState.popMatrix()
}
GlStateManager.popAttrib()
RenderState.popAttrib()
RenderState.checkError("ItemRenderer.renderItem: floppy")
}
else if (descriptor == drone) {
GlStateManager.pushAttrib()
GL11.glPushMatrix()
RenderState.pushAttrib()
RenderState.pushMatrix()
Textures.bind(Textures.Model.Drone)
RenderState.makeItBlend()
GL11.glDisable(GL11.GL_CULL_FACE)
RenderState.disableCullFace()
if (renderType == ItemRenderType.INVENTORY) {
GL11.glTranslatef(8f, 9f, 0)
@ -138,8 +137,8 @@ object ItemRenderer extends IItemRenderer {
DroneRenderer.model.render()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError("ItemRenderer.renderItem: drone")
}

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity.Assembler
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -16,14 +15,13 @@ object AssemblerRenderer extends TileEntitySpecialRenderer {
val assembler = tileEntity.asInstanceOf[Assembler]
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
RenderState.setBlendAlpha(1)
GL11.glColor4f(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
val t = Tessellator.getInstance
@ -68,10 +66,10 @@ object AssemblerRenderer extends TileEntitySpecialRenderer {
GL11.glRotatef(90, 0, 1, 0)
}
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity.Case
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -15,14 +14,13 @@ object CaseRenderer extends TileEntitySpecialRenderer {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
val computer = tileEntity.asInstanceOf[Case]
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
RenderState.setBlendAlpha(1)
GL11.glColor4f(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
@ -62,10 +60,10 @@ object CaseRenderer extends TileEntitySpecialRenderer {
t.draw()
}
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity.Charger
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -16,14 +15,14 @@ object ChargerRenderer extends TileEntitySpecialRenderer {
val charger = tileEntity.asInstanceOf[Charger]
if (charger.chargeSpeed > 0) {
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
RenderState.setBlendAlpha(1)
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
@ -73,10 +72,10 @@ object ChargerRenderer extends TileEntitySpecialRenderer {
t.draw()
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
}
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -15,13 +14,13 @@ object DisassemblerRenderer extends TileEntitySpecialRenderer {
val disassembler = tileEntity.asInstanceOf[tileentity.Disassembler]
if (disassembler.isActive) {
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
GL11.glScaled(1.0025, -1.0025, 1.0025)
@ -65,10 +64,10 @@ object DisassemblerRenderer extends TileEntitySpecialRenderer {
t.draw()
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
}
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")

View File

@ -4,7 +4,6 @@ import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity.DiskDrive
import li.cil.oc.util.RenderState
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.OpenGlHelper
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
@ -18,10 +17,10 @@ object DiskDriveRenderer extends TileEntitySpecialRenderer {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
val drive = tileEntity.asInstanceOf[DiskDrive]
GlStateManager.pushAttrib()
GlStateManager.color(1, 1, 1, 1)
RenderState.pushAttrib()
RenderState.color(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
@ -34,7 +33,7 @@ object DiskDriveRenderer extends TileEntitySpecialRenderer {
drive.items(0) match {
case Some(stack) =>
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslatef(0, 3.5f / 16, 9 / 16f)
GL11.glRotatef(90, -1, 0, 0)
@ -46,7 +45,7 @@ object DiskDriveRenderer extends TileEntitySpecialRenderer {
entity.hoverStart = 0
Textures.Block.bind()
Minecraft.getMinecraft.getRenderItem.renderItemModel(entity.getEntityItem)
GL11.glPopMatrix()
RenderState.popMatrix()
case _ =>
}
@ -54,7 +53,7 @@ object DiskDriveRenderer extends TileEntitySpecialRenderer {
GL11.glTranslated(-0.5, 0.5, 0.505)
GL11.glScalef(1, -1, 1)
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
RenderState.setBlendAlpha(1)
@ -72,11 +71,11 @@ object DiskDriveRenderer extends TileEntitySpecialRenderer {
t.draw()
RenderState.enableLighting()
RenderState.enableEntityLighting()
}
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -2,7 +2,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -12,14 +11,14 @@ object GeolyzerRenderer extends TileEntitySpecialRenderer {
override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float, damage: Int) {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
RenderState.setBlendAlpha(1)
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
GL11.glScaled(1.0025, -1.0025, 1.0025)
@ -39,10 +38,10 @@ object GeolyzerRenderer extends TileEntitySpecialRenderer {
t.draw()
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -11,7 +11,6 @@ import li.cil.oc.Settings
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity.Hologram
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.EnumFacing
@ -65,17 +64,16 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
if (!hologram.hasPower) return
GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS)
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.makeItBlend()
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
GL11.glColor4f(1, 1, 1, 1)
RenderState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
val playerDistSq = x * x + y * y + z * z
val maxDistSq = hologram.getMaxRenderDistanceSquared
val fadeDistSq = hologram.getFadeStartDistanceSquared
RenderState.setBlendAlpha(0.75f * (if (playerDistSq > fadeDistSq) math.max(0, 1 - ((playerDistSq - fadeDistSq) / (maxDistSq - fadeDistSq)).toFloat) else 1))
GlStateManager.pushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
hologram.yaw match {
@ -115,12 +113,12 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
val sz = (z + 0.5) * hologram.scale
if (sx >= -1.5 && sx <= 1.5 && sz >= -1.5 && sz <= 1.5 && sy >= 0 && sy <= 2) {
// Camera is inside the hologram.
GL11.glDisable(GL11.GL_CULL_FACE)
RenderState.disableCullFace()
}
else {
// Camera is outside the hologram.
GL11.glEnable(GL11.GL_CULL_FACE)
GL11.glCullFace(GL11.GL_BACK)
RenderState.enableCullFace()
RenderState.cullFace(GL11.GL_BACK)
}
// We do two passes here to avoid weird transparency effects: in the first
@ -129,16 +127,16 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
// angles (because some faces will shine through sometimes and sometimes
// they won't), so a more... consistent look is desirable.
val glBuffer = cache.get(hologram, this)
GlStateManager.colorMask(false, false, false, false)
GlStateManager.depthMask(true)
RenderState.disableColorMask()
RenderState.enableDepthMask()
draw(glBuffer)
GlStateManager.colorMask(true, true, true, true)
GlStateManager.depthFunc(GL11.GL_EQUAL)
RenderState.enableColorMask()
RenderState.depthFunc(GL11.GL_EQUAL)
draw(glBuffer)
GlStateManager.depthFunc(GL11.GL_LEQUAL)
GlStateManager.popMatrix()
GlStateManager.popAttrib()
RenderState.depthFunc(GL11.GL_LEQUAL)
RenderState.popMatrix()
RenderState.popAttrib()
GL11.glPopClientAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")

View File

@ -14,14 +14,14 @@ object HologramRendererFallback extends TileEntitySpecialRenderer {
val fontRenderer = Minecraft.getMinecraft.fontRendererObj
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.75, z + 0.5)
GL11.glScalef(1 / 128f, -1 / 128f, 1 / 128f)
GL11.glDisable(GL11.GL_CULL_FACE)
RenderState.disableCullFace()
fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, 0, 0xFFFFFFFF)
GL11.glPopMatrix()
RenderState.popMatrix()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity.Microcontroller
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -15,14 +14,14 @@ object MicrocontrollerRenderer extends TileEntitySpecialRenderer {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
val mcu = tileEntity.asInstanceOf[Microcontroller]
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
RenderState.setBlendAlpha(1)
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
@ -60,10 +59,10 @@ object MicrocontrollerRenderer extends TileEntitySpecialRenderer {
t.draw()
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -15,14 +14,13 @@ object PowerDistributorRenderer extends TileEntitySpecialRenderer {
val distributor = tileEntity.asInstanceOf[tileentity.PowerDistributor]
if (distributor.globalBuffer > 0) {
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
RenderState.setBlendAlpha((distributor.globalBuffer / distributor.globalBufferSize).toFloat)
GL11.glColor4f(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
GL11.glScaled(1.0025, -1.0025, 1.0025)
@ -68,10 +66,10 @@ object PowerDistributorRenderer extends TileEntitySpecialRenderer {
t.draw()
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
}
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity.Raid
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.WorldRenderer
import net.minecraft.client.renderer.texture.TextureAtlasSprite
@ -17,13 +16,13 @@ object RaidRenderer extends TileEntitySpecialRenderer {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
val raid = tileEntity.asInstanceOf[Raid]
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
@ -63,10 +62,10 @@ object RaidRenderer extends TileEntitySpecialRenderer {
t.draw()
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -24,7 +24,6 @@ import net.minecraftforge.client.IItemRenderer.ItemRenderType
import net.minecraftforge.client.MinecraftForgeClient
import net.minecraftforge.common.MinecraftForge
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL12
object RobotRenderer extends TileEntitySpecialRenderer {
private val displayList = GLAllocation.generateDisplayLists(2)
@ -214,12 +213,12 @@ object RobotRenderer extends TileEntitySpecialRenderer {
if (isRunning) {
if (MinecraftForgeClient.getRenderPass == 0) {
RenderState.disableLighting()
RenderState.disableEntityLighting()
}
{
// Additive blending for the light.
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
RenderState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
// Light color.
val lightColor = if (robot != null && robot.info != null) robot.info.lightColor else 0xF23030
val r = ((lightColor >>> 16) & 0xFF).toByte
@ -253,8 +252,9 @@ object RobotRenderer extends TileEntitySpecialRenderer {
t.draw()
if (MinecraftForgeClient.getRenderPass == 0) {
RenderState.enableLighting()
RenderState.enableEntityLighting()
}
RenderState.color(1, 1, 1, 1)
}
}
}
@ -266,7 +266,7 @@ object RobotRenderer extends TileEntitySpecialRenderer {
val robot = proxy.robot
val worldTime = tileEntity.getWorld.getTotalWorldTime + f
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
// If the move started while we were rendering and we have a reference to
@ -288,12 +288,11 @@ object RobotRenderer extends TileEntitySpecialRenderer {
else -0.03f
GL11.glTranslatef(0, hover, 0)
GL11.glPushMatrix()
RenderState.pushMatrix()
GlStateManager.depthMask(true)
GL11.glEnable(GL11.GL_LIGHTING)
GL11.glDisable(GL11.GL_BLEND)
GL11.glColor4f(1, 1, 1, 1)
RenderState.enableDepthMask()
RenderState.enableEntityLighting()
RenderState.disableBlend()
if (robot.isAnimatingTurn) {
val remaining = (robot.animationTicksLeft - f) / robot.animationTicksTotal.toDouble
@ -319,13 +318,13 @@ object RobotRenderer extends TileEntitySpecialRenderer {
Option(robot.getStackInSlot(0)) match {
case Some(stack) =>
GL11.glPushMatrix()
RenderState.pushMatrix()
try {
// Copy-paste from player render code, with minor adjustments for
// robot scale.
GL11.glDisable(GL11.GL_CULL_FACE)
GL11.glEnable(GL12.GL_RESCALE_NORMAL)
RenderState.disableCullFace()
RenderState.enableRescaleNormal()
GL11.glScalef(1, -1, -1)
GL11.glTranslatef(0, -8 * 0.0625F - 0.0078125F, -0.5F)
@ -371,9 +370,9 @@ object RobotRenderer extends TileEntitySpecialRenderer {
OpenComputers.log.warn("Failed rendering equipped item.", e)
robot.renderingErrored = true
}
GL11.glEnable(GL11.GL_CULL_FACE)
GL11.glDisable(GL12.GL_RESCALE_NORMAL)
GL11.glPopMatrix()
RenderState.enableCullFace()
RenderState.disableRescaleNormal()
RenderState.popMatrix()
case _ =>
}
@ -385,13 +384,13 @@ object RobotRenderer extends TileEntitySpecialRenderer {
val r = ((tint >> 16) & 0xFF) / 255f
val g = ((tint >> 8) & 0xFF) / 255f
val b = ((tint >> 0) & 0xFF) / 255f
GL11.glColor4f(r, g, b, 1)
GL11.glPushMatrix()
RenderState.color(r, g, b, 1)
RenderState.pushMatrix()
GL11.glTranslatef(0.5f, 0.5f, 0.5f)
GL11.glRotatef(mountPoint.rotation.getW, mountPoint.rotation.getX, mountPoint.rotation.getY, mountPoint.rotation.getZ)
GL11.glTranslatef(mountPoint.offset.getX, mountPoint.offset.getY, mountPoint.offset.getZ)
itemRenderer.renderItem(Minecraft.getMinecraft.thePlayer, stack, TransformType.NONE)
GL11.glPopMatrix()
RenderState.popMatrix()
}
}
catch {
@ -401,11 +400,11 @@ object RobotRenderer extends TileEntitySpecialRenderer {
}
}
}
GL11.glPopMatrix()
RenderState.popMatrix()
val name = robot.name
if (Settings.get.robotLabels && !Strings.isNullOrEmpty(name) && x * x + y * y + z * z < RendererLivingEntity.NAME_TAG_RANGE) {
GL11.glPushMatrix()
RenderState.pushMatrix()
// This is pretty much copy-pasta from the entity's label renderer.
val t = Tessellator.getInstance
@ -424,8 +423,8 @@ object RobotRenderer extends TileEntitySpecialRenderer {
GL11.glScalef(-scale, -scale, scale)
RenderState.makeItBlend()
GlStateManager.depthMask(false)
GL11.glDisable(GL11.GL_LIGHTING)
RenderState.disableDepthMask()
RenderState.disableLighting()
GL11.glDisable(GL11.GL_TEXTURE_2D)
r.startDrawingQuads()
@ -439,14 +438,14 @@ object RobotRenderer extends TileEntitySpecialRenderer {
GL11.glEnable(GL11.GL_TEXTURE_2D) // For the font.
f.drawString(name, -halfWidth, 0, 0xFFFFFFFF)
GlStateManager.depthMask(true)
GL11.glEnable(GL11.GL_LIGHTING)
GL11.glDisable(GL11.GL_BLEND)
RenderState.enableDepthMask()
RenderState.enableLighting()
RenderState.disableBlend()
GL11.glPopMatrix()
RenderState.popMatrix()
}
GL11.glPopMatrix()
RenderState.popMatrix()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -8,7 +8,6 @@ import li.cil.oc.common.tileentity.Screen
import li.cil.oc.integration.util.Wrench
import li.cil.oc.util.RenderState
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -59,13 +58,13 @@ object ScreenRenderer extends TileEntitySpecialRenderer {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: checks")
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
@ -79,7 +78,7 @@ object ScreenRenderer extends TileEntitySpecialRenderer {
val alpha = math.max(0, 1 - ((distance - fadeDistanceSq) * fadeRatio).toFloat)
if (canUseBlendColor) {
GL14.glBlendColor(0, 0, 0, alpha)
GlStateManager.blendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE)
RenderState.blendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE)
}
}
@ -89,10 +88,10 @@ object ScreenRenderer extends TileEntitySpecialRenderer {
draw()
}
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}
@ -123,9 +122,9 @@ object ScreenRenderer extends TileEntitySpecialRenderer {
val stack = Minecraft.getMinecraft.thePlayer.getHeldItem
if (stack != null) {
if (Wrench.holdsApplicableWrench(Minecraft.getMinecraft.thePlayer, screen.getPos) || screens.contains(api.Items.get(stack))) {
GL11.glPushMatrix()
RenderState.pushMatrix()
transform()
GlStateManager.depthMask(false)
RenderState.disableDepthMask()
GL11.glTranslatef(screen.width / 2f - 0.5f, screen.height / 2f - 0.5f, 0.05f)
val t = Tessellator.getInstance
@ -142,8 +141,8 @@ object ScreenRenderer extends TileEntitySpecialRenderer {
t.draw()
GlStateManager.depthMask(true)
GL11.glPopMatrix()
RenderState.enableDepthMask()
RenderState.popMatrix()
}
}
}

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity.ServerRack
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -15,13 +14,13 @@ object ServerRackRenderer extends TileEntitySpecialRenderer {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
val rack = tileEntity.asInstanceOf[ServerRack]
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
GlStateManager.color(1, 1, 1, 1)
RenderState.color(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
@ -74,10 +73,10 @@ object ServerRackRenderer extends TileEntitySpecialRenderer {
t.draw()
}
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

View File

@ -3,7 +3,6 @@ package li.cil.oc.client.renderer.tileentity
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity
import li.cil.oc.util.RenderState
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -16,14 +15,13 @@ object SwitchRenderer extends TileEntitySpecialRenderer {
val switch = tileEntity.asInstanceOf[tileentity.Switch]
val activity = math.max(0, 1 - (System.currentTimeMillis() - switch.lastMessage) / 1000.0)
if (activity > 0) {
GlStateManager.pushAttrib()
RenderState.pushAttrib()
RenderState.disableLighting()
RenderState.disableEntityLighting()
RenderState.makeItBlend()
RenderState.setBlendAlpha(activity.toFloat)
GL11.glColor4f(1, 1, 1, 1)
GL11.glPushMatrix()
RenderState.pushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
GL11.glScaled(1.0025, -1.0025, 1.0025)
@ -58,10 +56,10 @@ object SwitchRenderer extends TileEntitySpecialRenderer {
t.draw()
RenderState.enableLighting()
RenderState.enableEntityLighting()
GL11.glPopMatrix()
GlStateManager.popAttrib()
RenderState.popMatrix()
RenderState.popAttrib()
}
RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")

View File

@ -26,21 +26,123 @@ object RenderState {
else false
}
def disableLighting() {
def pushAttrib(mask: Int = 8256): Unit = {
GL11.glPushAttrib(mask)
}
def popAttrib(): Unit = {
GlStateManager.popAttrib()
}
def pushMatrix(): Unit = {
GlStateManager.pushMatrix()
}
def popMatrix(): Unit = {
GlStateManager.popMatrix()
}
def color(r: Float, g: Float, b: Float, a: Float = 1f): Unit = {
GlStateManager.color(r, g, b, a)
GL11.glColor4f(r, g, b, a)
}
def disableColorMask(): Unit = {
GlStateManager.colorMask(false, false, false, false)
GL11.glColorMask(false, false, false, false)
}
def enableColorMask(): Unit = {
GlStateManager.colorMask(true, true, true, true)
GL11.glColorMask(true, true, true, true)
}
def disableCullFace(): Unit = {
GlStateManager.disableCull()
GL11.glDisable(GL11.GL_CULL_FACE)
}
def enableCullFace(): Unit = {
GlStateManager.enableCull()
GL11.glEnable(GL11.GL_CULL_FACE)
}
def disableDepth(): Unit = {
GlStateManager.disableDepth()
GL11.glDisable(GL11.GL_DEPTH_TEST)
}
def enableDepth(): Unit = {
GlStateManager.enableDepth()
GL11.glEnable(GL11.GL_DEPTH_TEST)
}
def disableDepthMask(): Unit = {
GlStateManager.depthMask(false)
GL11.glDepthMask(false)
}
def enableDepthMask(): Unit = {
GlStateManager.depthMask(true)
GL11.glDepthMask(true)
}
def disableLighting(): Unit = {
GlStateManager.disableLighting()
GL11.glDisable(GL11.GL_LIGHTING)
}
def enableLighting(): Unit = {
GlStateManager.enableLighting()
GL11.glEnable(GL11.GL_LIGHTING)
}
def disableEntityLighting() {
Minecraft.getMinecraft.entityRenderer.disableLightmap()
RenderHelper.disableStandardItemLighting()
}
def enableLighting() {
def enableEntityLighting() {
Minecraft.getMinecraft.entityRenderer.enableLightmap()
RenderHelper.enableStandardItemLighting()
}
def disableRescaleNormal(): Unit = {
GlStateManager.disableRescaleNormal()
GL11.glDisable(GL12.GL_RESCALE_NORMAL)
}
def enableRescaleNormal(): Unit = {
GlStateManager.enableRescaleNormal()
GL11.glEnable(GL12.GL_RESCALE_NORMAL)
}
def makeItBlend() {
GlStateManager.enableBlend()
GL11.glEnable(GL11.GL_BLEND)
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
}
def disableBlend(): Unit = {
GlStateManager.disableBlend()
GL11.glDisable(GL11.GL_BLEND)
}
def blendFunc(sFactor: Int, dFactor: Int): Unit = {
GlStateManager.blendFunc(sFactor, dFactor)
GL11.glBlendFunc(sFactor, dFactor)
}
def cullFace(mode: Int): Unit = {
GlStateManager.cullFace(mode)
GL11.glCullFace(mode)
}
def depthFunc(func: Int): Unit = {
GlStateManager.depthFunc(func)
GL11.glDepthFunc(func)
}
def setBlendAlpha(alpha: Float) = {
GlStateManager.color(1, 1, 1, alpha)
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)