diff --git a/src/main/scala/li/cil/oc/client/Textures.scala b/src/main/scala/li/cil/oc/client/Textures.scala index 84e9c18a6..6742555aa 100644 --- a/src/main/scala/li/cil/oc/client/Textures.scala +++ b/src/main/scala/li/cil/oc/client/Textures.scala @@ -3,6 +3,7 @@ package li.cil.oc.client import li.cil.oc.Settings import li.cil.oc.common.Slot import li.cil.oc.common.Tier +import li.cil.oc.util.RenderState import net.minecraft.client.Minecraft import net.minecraft.client.renderer.texture.TextureMap import net.minecraft.util.ResourceLocation @@ -502,7 +503,7 @@ object Textures { // So we do it manually. val texture = manager.getTexture(location) if (texture != null) { - GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getGlTextureId) + RenderState.bindTexture(texture.getGlTextureId) } } diff --git a/src/main/scala/li/cil/oc/client/renderer/font/DynamicFontRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/font/DynamicFontRenderer.scala index b08791576..c63e8adb7 100644 --- a/src/main/scala/li/cil/oc/client/renderer/font/DynamicFontRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/font/DynamicFontRenderer.scala @@ -95,11 +95,11 @@ object DynamicFontRenderer { class CharTexture(val owner: DynamicFontRenderer) { private val id = GlStateManager.generateTexture() - GlStateManager.bindTexture(id) + RenderState.bindTexture(id) 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.bindTexture(0) RenderState.checkError(getClass.getName + ".: create texture") @@ -120,7 +120,7 @@ object DynamicFontRenderer { } def bind() { - GlStateManager.bindTexture(id) + RenderState.bindTexture(id) } def isFull(char: Char) = chars + FontUtil.wcwidth(char) > capacity @@ -136,7 +136,7 @@ object DynamicFontRenderer { val x = chars % cols val y = chars / cols - GlStateManager.bindTexture(id) + RenderState.bindTexture(id) GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 1 + x * cellWidth, 1 + y * cellHeight, w, h, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, owner.glyphProvider.getGlyph(char)) chars += glyphWidth diff --git a/src/main/scala/li/cil/oc/util/RenderState.scala b/src/main/scala/li/cil/oc/util/RenderState.scala index 3d67f0364..701ff9dbc 100644 --- a/src/main/scala/li/cil/oc/util/RenderState.scala +++ b/src/main/scala/li/cil/oc/util/RenderState.scala @@ -8,6 +8,14 @@ import net.minecraft.client.renderer.RenderHelper import org.lwjgl.opengl._ import org.lwjgl.util.glu.GLU +// This class has evolved into a wrapper for GlStateManager that basically does +// nothing but call the corresponding GlStateManager methods and then also +// forcefully applies whatever that call *should* do. This way the state +// manager's internal state is kept up-to-date but we also avoid issues with +// that state being incorrect causing wrong behavior (I've had too many render +// bugs where textures were not bound correctly or state was not updated +// because the state manager thought it already was in the state to change to, +// so I frankly don't care if this is less performant anymore). object RenderState { val arb = GLContext.getCapabilities.GL_ARB_multitexture && !GLContext.getCapabilities.OpenGL13 @@ -147,4 +155,9 @@ object RenderState { GlStateManager.color(1, 1, 1, alpha) GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE) } + + def bindTexture(id: Int): Unit = { + GlStateManager.bindTexture(id) + GL11.glBindTexture(GL11.GL_TEXTURE_2D, id) + } }