diff --git a/src/main/java/grondag/canvas/apiimpl/mesh/MutableQuadViewImpl.java b/src/main/java/grondag/canvas/apiimpl/mesh/MutableQuadViewImpl.java index 1c439b763..ffa258531 100644 --- a/src/main/java/grondag/canvas/apiimpl/mesh/MutableQuadViewImpl.java +++ b/src/main/java/grondag/canvas/apiimpl/mesh/MutableQuadViewImpl.java @@ -145,6 +145,7 @@ public final MutableQuadViewImpl fromVanilla(int[] quadData, int startIndex, boo return this; } + @Override public final MutableQuadViewImpl fromVanilla(BakedQuad quad, RenderMaterial material, Direction cullFace) { return fromVanilla(quad, material, ModelHelper.toFaceIndex(cullFace)); } @@ -283,7 +284,6 @@ private void unmapSprite(int textureIndex) { /** * Same as logic in SpriteFinder but can assume sprites are mapped - avoids checks */ - @SuppressWarnings("resource") private Sprite findSprite(int textureIndex) { float u = 0; float v = 0; @@ -293,7 +293,7 @@ private Sprite findSprite(int textureIndex) { v += spriteFloatV(i, textureIndex); } - return SpriteInfoTexture.instance().spriteFinder.find(u * 0.25f, v * 0.25f); + return SpriteInfoTexture.spriteFinder().find(u * 0.25f, v * 0.25f); } @Override diff --git a/src/main/java/grondag/canvas/apiimpl/mesh/QuadViewImpl.java b/src/main/java/grondag/canvas/apiimpl/mesh/QuadViewImpl.java index 6917335fe..2ce924e72 100644 --- a/src/main/java/grondag/canvas/apiimpl/mesh/QuadViewImpl.java +++ b/src/main/java/grondag/canvas/apiimpl/mesh/QuadViewImpl.java @@ -316,7 +316,7 @@ public int lightmap(int vertexIndex) { protected int colorOffset(int vertexIndex, int spriteIndex) { return spriteIndex == 0 ? vertexIndex * BASE_VERTEX_STRIDE + VERTEX_COLOR - : TEXTURE_OFFSET_MINUS + spriteIndex * TEXTURE_QUAD_STRIDE + vertexIndex * TEXTURE_VERTEX_STRIDE; + : TEXTURE_OFFSET_MINUS + spriteIndex * TEXTURE_QUAD_STRIDE + vertexIndex * TEXTURE_VERTEX_STRIDE; } @Override @@ -339,15 +339,15 @@ protected final float spriteFloatV(int vertexIndex, int spriteIndex) { @Override public float spriteU(int vertexIndex, int spriteIndex) { return isSpriteUnmapped(spriteIndex) - ? SpriteInfoTexture.instance().mapU(spriteId(spriteIndex), spriteFloatU(vertexIndex, spriteIndex)) - : spriteFloatU(vertexIndex, spriteIndex); + ? SpriteInfoTexture.mapU(spriteId(spriteIndex), spriteFloatU(vertexIndex, spriteIndex)) + : spriteFloatU(vertexIndex, spriteIndex); } @Override public float spriteV(int vertexIndex, int spriteIndex) { return isSpriteUnmapped(spriteIndex) - ? SpriteInfoTexture.instance().mapV(spriteId(spriteIndex), spriteFloatV(vertexIndex, spriteIndex)) - : spriteFloatV(vertexIndex, spriteIndex); + ? SpriteInfoTexture.mapV(spriteId(spriteIndex), spriteFloatV(vertexIndex, spriteIndex)) + : spriteFloatV(vertexIndex, spriteIndex); } /** diff --git a/src/main/java/grondag/canvas/apiimpl/rendercontext/AbstractRenderContext.java b/src/main/java/grondag/canvas/apiimpl/rendercontext/AbstractRenderContext.java index 281234756..db1051fe7 100644 --- a/src/main/java/grondag/canvas/apiimpl/rendercontext/AbstractRenderContext.java +++ b/src/main/java/grondag/canvas/apiimpl/rendercontext/AbstractRenderContext.java @@ -41,6 +41,7 @@ import net.minecraft.util.math.Matrix4f; import javax.annotation.Nullable; + import java.util.Random; import java.util.function.Consumer; @@ -100,7 +101,7 @@ void mapMaterials(MutableQuadViewImpl quad) { return; } - final Sprite sprite = materialMap.needsSprite() ? SpriteInfoTexture.instance().fromId(quad.spriteId(0)) : null; + final Sprite sprite = materialMap.needsSprite() ? SpriteInfoTexture.fromId(quad.spriteId(0)) : null; final RenderMaterial mapped = materialMap.getMapped(sprite); if (mapped != null) { diff --git a/src/main/java/grondag/canvas/buffer/encoding/EncoderUtils.java b/src/main/java/grondag/canvas/buffer/encoding/EncoderUtils.java index db4261756..a7bf6bd34 100644 --- a/src/main/java/grondag/canvas/buffer/encoding/EncoderUtils.java +++ b/src/main/java/grondag/canvas/buffer/encoding/EncoderUtils.java @@ -487,7 +487,6 @@ static void bufferQuadDirect1(MutableQuadViewImpl quad, AbstractRenderContext co final MeshMaterialLayer mat0 = mat.getLayer(0); final VertexCollectorImpl buff0 = context.collectors.get(mat0); final int[] appendData = context.appendData; - final SpriteInfoTexture spriteInfo = SpriteInfoTexture.instance(); assert mat.blendMode() != BlendMode.DEFAULT; @@ -504,7 +503,7 @@ static void bufferQuadDirect1(MutableQuadViewImpl quad, AbstractRenderContext co transformedNormal = normalMatrix.canvas_transform(packedNormal); } - final int spriteIdCoord = spriteInfo.coordinate(quad.spriteId(0)); + final int spriteIdCoord = SpriteInfoTexture.coordinate(quad.spriteId(0)); assert spriteIdCoord <= 0xFFFF; @@ -547,7 +546,6 @@ static void bufferQuadDirect2(MutableQuadViewImpl quad, AbstractRenderContext co final MeshMaterialLayer mat0 = mat.getLayer(0); final VertexCollectorImpl buff0 = context.collectors.get(mat0); final int shaderFlags0 = mat0.shaderFlags << 16; - final SpriteInfoTexture spriteInfo = SpriteInfoTexture.instance(); final int[] appendData = context.appendData; final float[] aoData = quad.ao; @@ -588,7 +586,7 @@ static void bufferQuadDirect2(MutableQuadViewImpl quad, AbstractRenderContext co normalAo2 |= aoData == null ? NO_AO_SHADE : ((Math.round(aoData[2] * 254) - 127) << 24); normalAo3 |= aoData == null ? NO_AO_SHADE : ((Math.round(aoData[3] * 254) - 127) << 24); - final int spriteIdCoord0 = spriteInfo.coordinate(quad.spriteId(0)); + final int spriteIdCoord0 = SpriteInfoTexture.coordinate(quad.spriteId(0)); appendData[3] = quad.spriteColor(0, 0); appendData[4] = quad.spriteBufferU(0, 0) | (quad.spriteBufferV(0, 0) << 16); @@ -619,7 +617,7 @@ static void bufferQuadDirect2(MutableQuadViewImpl quad, AbstractRenderContext co final MeshMaterialLayer mat1 = mat.getLayer(1); final VertexCollectorImpl buff1 = context.collectors.get(mat1); final int shaderFlags1 = mat1.shaderFlags << 16; - final int spriteIdCoord1 = spriteInfo.coordinate(quad.spriteId(1)); + final int spriteIdCoord1 = SpriteInfoTexture.coordinate(quad.spriteId(1)); appendData[3] = quad.spriteColor(0, 1); appendData[4] = quad.spriteBufferU(0, 1) | (quad.spriteBufferV(0, 1) << 16); @@ -652,7 +650,6 @@ static void bufferQuadDirect3(MutableQuadViewImpl quad, AbstractRenderContext co final Matrix4fExt matrix = (Matrix4fExt) (Object) context.matrix(); final Matrix3fExt normalMatrix = context.normalMatrix(); final MeshMaterial mat = quad.material().get(); - final SpriteInfoTexture spriteInfo = SpriteInfoTexture.instance(); final MeshMaterialLayer mat0 = mat.getLayer(0); final VertexCollectorImpl buff0 = context.collectors.get(mat0); @@ -698,7 +695,7 @@ static void bufferQuadDirect3(MutableQuadViewImpl quad, AbstractRenderContext co normalAo2 |= aoData == null ? NO_AO_SHADE : ((Math.round(aoData[2] * 254) - 127) << 24); normalAo3 |= aoData == null ? NO_AO_SHADE : ((Math.round(aoData[3] * 254) - 127) << 24); - final int spriteIdCoord0 = spriteInfo.coordinate(quad.spriteId(0)); + final int spriteIdCoord0 = SpriteInfoTexture.coordinate(quad.spriteId(0)); appendData[3] = quad.spriteColor(0, 0); appendData[4] = quad.spriteBufferU(0, 0) | (quad.spriteBufferV(0, 0) << 16); @@ -729,7 +726,7 @@ static void bufferQuadDirect3(MutableQuadViewImpl quad, AbstractRenderContext co final MeshMaterialLayer mat1 = mat.getLayer(1); final VertexCollectorImpl buff1 = context.collectors.get(mat1); final int shaderFlags1 = mat1.shaderFlags << 16; - final int spriteIdCoord1 = spriteInfo.coordinate(quad.spriteId(1)); + final int spriteIdCoord1 = SpriteInfoTexture.coordinate(quad.spriteId(1)); appendData[3] = quad.spriteColor(0, 1); appendData[4] = quad.spriteBufferU(0, 1) | (quad.spriteBufferV(0, 1) << 16); @@ -760,7 +757,7 @@ static void bufferQuadDirect3(MutableQuadViewImpl quad, AbstractRenderContext co final MeshMaterialLayer mat2 = mat.getLayer(2); final VertexCollectorImpl buff2 = context.collectors.get(mat2); final int shaderFlags2 = mat2.shaderFlags << 16; - final int spriteIdCoord2 = spriteInfo.coordinate(quad.spriteId(2)); + final int spriteIdCoord2 = SpriteInfoTexture.coordinate(quad.spriteId(2)); appendData[3] = quad.spriteColor(0, 2); appendData[4] = quad.spriteBufferU(0, 2) | (quad.spriteBufferV(0, 2) << 16); diff --git a/src/main/java/grondag/canvas/mixin/MixinSpriteAtlasTexture.java b/src/main/java/grondag/canvas/mixin/MixinSpriteAtlasTexture.java index 2a963080c..647805c35 100644 --- a/src/main/java/grondag/canvas/mixin/MixinSpriteAtlasTexture.java +++ b/src/main/java/grondag/canvas/mixin/MixinSpriteAtlasTexture.java @@ -16,7 +16,6 @@ package grondag.canvas.mixin; -import grondag.canvas.mixinterface.SpriteAtlasTextureExt; import grondag.canvas.mixinterface.SpriteExt; import grondag.canvas.texture.SpriteInfoTexture; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -32,33 +31,24 @@ import java.util.Map; @Mixin(SpriteAtlasTexture.class) -public class MixinSpriteAtlasTexture implements SpriteAtlasTextureExt { - private final ObjectArrayList spriteIndex = new ObjectArrayList<>(); +public class MixinSpriteAtlasTexture { @Shadow private Identifier id; @Shadow private Map sprites; - @Override - public Map canvas_spriteMap() { - return sprites; - } - - @Override - public ObjectArrayList canvas_spriteIndex() { - return spriteIndex; - } - @Inject(at = @At("RETURN"), method = "upload") private void afterUpload(SpriteAtlasTexture.Data input, CallbackInfo info) { if (id.equals(SpriteAtlasTexture.BLOCK_ATLAS_TEX)) { - SpriteInfoTexture.reset(input); int index = 0; + final ObjectArrayList spriteIndex = new ObjectArrayList<>(); for (final Sprite sprite : sprites.values()) { spriteIndex.add(sprite); ((SpriteExt) sprite).canvas_id(index++); } + + SpriteInfoTexture.reset(input, spriteIndex, (SpriteAtlasTexture)(Object) this); } } } diff --git a/src/main/java/grondag/canvas/mixinterface/SpriteAtlasTextureExt.java b/src/main/java/grondag/canvas/mixinterface/SpriteAtlasTextureExt.java deleted file mode 100644 index c1625e37c..000000000 --- a/src/main/java/grondag/canvas/mixinterface/SpriteAtlasTextureExt.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2019, 2020 grondag - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package grondag.canvas.mixinterface; - -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import net.minecraft.client.texture.Sprite; -import net.minecraft.util.Identifier; - -import java.util.Map; - -public interface SpriteAtlasTextureExt { - Map canvas_spriteMap(); - - ObjectArrayList canvas_spriteIndex(); -} diff --git a/src/main/java/grondag/canvas/render/DrawHandlers.java b/src/main/java/grondag/canvas/render/DrawHandlers.java index 398715329..9d666bdb3 100644 --- a/src/main/java/grondag/canvas/render/DrawHandlers.java +++ b/src/main/java/grondag/canvas/render/DrawHandlers.java @@ -66,7 +66,7 @@ private static class SolidHandler extends DrawHandler { @SuppressWarnings("resource") @Override protected void setupInner() { - SpriteInfoTexture.instance().enable(); + SpriteInfoTexture.enable(); RenderSystem.enableTexture(); final TextureManager textureManager = MinecraftClient.getInstance().getTextureManager(); textureManager.bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX); @@ -88,7 +88,7 @@ protected void teardownInner() { RenderSystem.disableCull(); MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().disable(); RenderSystem.disableFog(); - SpriteInfoTexture.instance().disable(); + SpriteInfoTexture.disable(); } @@ -102,7 +102,7 @@ private static class DecalHandler extends DrawHandler { @SuppressWarnings("resource") @Override protected void setupInner() { - SpriteInfoTexture.instance().enable(); + SpriteInfoTexture.enable(); RenderSystem.enableTexture(); final TextureManager textureManager = MinecraftClient.getInstance().getTextureManager(); textureManager.bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX); @@ -128,7 +128,7 @@ protected void teardownInner() { RenderSystem.disableFog(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); - SpriteInfoTexture.instance().disable(); + SpriteInfoTexture.disable(); } } @@ -140,7 +140,7 @@ private static class TranslucentHandler extends DrawHandler { @SuppressWarnings("resource") @Override protected void setupInner() { - SpriteInfoTexture.instance().enable(); + SpriteInfoTexture.enable(); RenderSystem.enableTexture(); final TextureManager textureManager = MinecraftClient.getInstance().getTextureManager(); textureManager.bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX); @@ -165,7 +165,7 @@ protected void teardownInner() { RenderSystem.disableFog(); RenderSystem.disableBlend(); RenderSystem.defaultBlendFunc(); - SpriteInfoTexture.instance().disable(); + SpriteInfoTexture.disable(); } } } diff --git a/src/main/java/grondag/canvas/shader/GlShader.java b/src/main/java/grondag/canvas/shader/GlShader.java index b44fdebcf..2452781f2 100644 --- a/src/main/java/grondag/canvas/shader/GlShader.java +++ b/src/main/java/grondag/canvas/shader/GlShader.java @@ -225,16 +225,14 @@ public String getSource() { result = StringUtils.replace(result, "#define _CV_HAS_VERTEX_END", "//#define _CV_HAS_VERTEX_END"); } - final SpriteInfoTexture sit = SpriteInfoTexture.instance(); - - result = StringUtils.replace(result, "#define _CV_SPRITE_INFO_TEXTURE_SIZE 1024", "#define _CV_SPRITE_INFO_TEXTURE_SIZE " + sit.textureSize()); - result = StringUtils.replace(result, "#define _CV_ATLAS_WIDTH 1024", "#define _CV_ATLAS_WIDTH " + sit.atlasWidth); - result = StringUtils.replace(result, "#define _CV_ATLAS_HEIGHT 1024", "#define _CV_ATLAS_HEIGHT " + sit.atlasHeight); + result = StringUtils.replace(result, "#define _CV_SPRITE_INFO_TEXTURE_SIZE 1024", "#define _CV_SPRITE_INFO_TEXTURE_SIZE " + SpriteInfoTexture.textureSize()); + result = StringUtils.replace(result, "#define _CV_ATLAS_WIDTH 1024", "#define _CV_ATLAS_WIDTH " + SpriteInfoTexture.atlasWidth()); + result = StringUtils.replace(result, "#define _CV_ATLAS_HEIGHT 1024", "#define _CV_ATLAS_HEIGHT " + SpriteInfoTexture.atlasHeight()); } if (context.pass != ShaderPass.SOLID) { result = StringUtils.replace(result, "#define SHADER_PASS SHADER_PASS_SOLID", - "#define SHADER_PASS SHADER_PASS_" + context.pass.name()); + "#define SHADER_PASS SHADER_PASS_" + context.pass.name()); } if (context.materialContext.isBlock) { @@ -255,7 +253,7 @@ public String getSource() { if (Configurator.fogMode != FogMode.VANILLA && !context.materialContext.isGui) { result = StringUtils.replace(result, "#define _CV_FOG_CONFIG _CV_FOG_CONFIG_VANILLA", - "#define _CV_FOG_CONFIG _CV_FOG_CONFIG_" + Configurator.fogMode.name()); + "#define _CV_FOG_CONFIG _CV_FOG_CONFIG_" + Configurator.fogMode.name()); } if ((context.pass == ShaderPass.SOLID || context.pass == ShaderPass.DECAL) && Configurator.enableBloom) { @@ -272,15 +270,15 @@ public String getSource() { if (!MinecraftClient.isAmbientOcclusionEnabled()) { result = StringUtils.replace(result, "#define AO_SHADING_MODE AO_MODE_NORMAL", - "#define AO_SHADING_MODE AO_MODE_" + AoMode.NONE.name()); + "#define AO_SHADING_MODE AO_MODE_" + AoMode.NONE.name()); } else if (Configurator.aoShadingMode != AoMode.NORMAL) { result = StringUtils.replace(result, "#define AO_SHADING_MODE AO_MODE_NORMAL", - "#define AO_SHADING_MODE AO_MODE_" + Configurator.aoShadingMode.name()); + "#define AO_SHADING_MODE AO_MODE_" + Configurator.aoShadingMode.name()); } if (Configurator.diffuseShadingMode != DiffuseMode.NORMAL) { result = StringUtils.replace(result, "#define DIFFUSE_SHADING_MODE DIFFUSE_MODE_NORMAL", - "#define DIFFUSE_SHADING_MODE DIFFUSE_MODE_" + Configurator.diffuseShadingMode.name()); + "#define DIFFUSE_SHADING_MODE DIFFUSE_MODE_" + Configurator.diffuseShadingMode.name()); } if (CanvasGlHelper.useGpuShader4()) { diff --git a/src/main/java/grondag/canvas/texture/SpriteInfoTexture.java b/src/main/java/grondag/canvas/texture/SpriteInfoTexture.java index 4970fc91b..61dcbacae 100644 --- a/src/main/java/grondag/canvas/texture/SpriteInfoTexture.java +++ b/src/main/java/grondag/canvas/texture/SpriteInfoTexture.java @@ -19,13 +19,12 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import grondag.canvas.CanvasMod; +import grondag.canvas.Configurator; import grondag.canvas.mixinterface.SpriteAtlasTextureDataExt; -import grondag.canvas.mixinterface.SpriteAtlasTextureExt; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.renderer.v1.model.SpriteFinder; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.SpriteAtlasTexture; import net.minecraft.client.texture.SpriteAtlasTexture.Data; @@ -35,61 +34,44 @@ import org.lwjgl.opengl.GL21; @Environment(EnvType.CLIENT) -public class SpriteInfoTexture implements AutoCloseable { - private static SpriteInfoTexture instance; - private static Data atlasData; - public final SpriteAtlasTexture atlas; - public final int atlasWidth; - public final int atlasHeight; - public final SpriteFinder spriteFinder; - final ObjectArrayList spriteIndex; - private final int textureSize; - protected int glId = -1; - - private SpriteInfoTexture(Data atlasData) { - final SpriteAtlasTexture atlas = (SpriteAtlasTexture) MinecraftClient.getInstance().getTextureManager().getTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX); - this.atlas = atlas; - atlasWidth = ((SpriteAtlasTextureDataExt) atlasData).canvas_atlasWidth(); - atlasHeight = ((SpriteAtlasTextureDataExt) atlasData).canvas_atlasHeight(); - spriteFinder = SpriteFinder.get(atlas); - - final ObjectArrayList spriteIndex = ((SpriteAtlasTextureExt) atlas).canvas_spriteIndex(); - this.spriteIndex = spriteIndex; - - final int spriteCount = spriteIndex.size(); - textureSize = MathHelper.smallestEncompassingPowerOfTwo(spriteCount); - - if (!RenderSystem.isOnRenderThread()) { - RenderSystem.recordRenderCall(() -> { - createImage(spriteCount); - }); - } else { - createImage(spriteCount); +public class SpriteInfoTexture { + private static ObjectArrayList spriteIndex = null; + private static SpriteAtlasTexture atlas; + private static SpriteFinder spriteFinder; + private static int atlasWidth; + private static int atlasHeight; + private static int spriteCount = -1; + private static int textureSize = -1; + private static int glId = -1; + + public static void reset(Data dataIn, ObjectArrayList spriteIndexIn, SpriteAtlasTexture atlasIn) { + if (Configurator.enableLifeCycleDebug) { + CanvasMod.LOG.info("Lifecycle Event: SpriteInfoTexture init"); } - } - - public static SpriteInfoTexture instance() { - SpriteInfoTexture result = instance; - if (result == null) { - result = new SpriteInfoTexture(atlasData); - instance = result; - atlasData = null; + if (glId != -1) { + disable(); + TextureUtil.deleteId(glId); + glId = -1; } - return result; + atlas = atlasIn; + spriteFinder = SpriteFinder.get(atlas); + spriteIndex = spriteIndexIn; + spriteCount = spriteIndex.size(); + textureSize = MathHelper.smallestEncompassingPowerOfTwo(spriteCount); + atlasWidth = ((SpriteAtlasTextureDataExt) dataIn).canvas_atlasWidth(); + atlasHeight = ((SpriteAtlasTextureDataExt) dataIn).canvas_atlasHeight(); } - public static void reset(Data input) { - if (instance != null) { - instance.close(); + private static void createImageIfNeeded() { + if (glId == -1) { + assert RenderSystem.isOnRenderThread(); + createImage(); } - - instance = null; - atlasData = input; } - private void createImage(int spriteCount) { + private static void createImage() { try (final SpriteInfoImage image = new SpriteInfoImage(spriteIndex, spriteCount, textureSize)) { glId = TextureUtil.generateId(); @@ -135,50 +117,73 @@ private void createImage(int spriteCount) { } } - @Override - public void close() { - if (glId != -1) { - disable(); - TextureUtil.deleteId(glId); - glId = -1; - } - } - - public void disable() { + public static void disable() { GlStateManager.activeTexture(TextureData.SPRITE_INFO); GlStateManager.bindTexture(0); GlStateManager.disableTexture(); GlStateManager.activeTexture(TextureData.MC_SPRITE_ATLAS); } - public void enable() { + public static void enable() { + createImageIfNeeded(); GlStateManager.activeTexture(TextureData.SPRITE_INFO); GlStateManager.bindTexture(glId); GlStateManager.enableTexture(); GlStateManager.activeTexture(TextureData.MC_SPRITE_ATLAS); } - public int coordinate(int spriteId) { + public static int coordinate(int spriteId) { return spriteId; } - public Sprite fromId(int spriteId) { + public static Sprite fromId(int spriteId) { + // TODO: remove + if (spriteIndex == null) { + new RuntimeException().printStackTrace(); + } + return spriteIndex.get(spriteId); } - public float mapU(int spriteId, float unmappedU) { + public static float mapU(int spriteId, float unmappedU) { + // TODO: remove + if (spriteIndex == null) { + new RuntimeException().printStackTrace(); + } + final Sprite sprite = spriteIndex.get(spriteId); final float u0 = sprite.getMinU(); return u0 + unmappedU * (sprite.getMaxU() - u0); } - public float mapV(int spriteId, float unmappedV) { + public static float mapV(int spriteId, float unmappedV) { + // TODO: remove + if (spriteIndex == null) { + new RuntimeException().printStackTrace(); + } + final Sprite sprite = spriteIndex.get(spriteId); final float v0 = sprite.getMinV(); return v0 + unmappedV * (sprite.getMaxV() - v0); } - public int textureSize() { + public static int textureSize() { return textureSize; } + + public static int atlasWidth() { + return atlasWidth; + } + + public static int atlasHeight() { + return atlasHeight; + } + + public static SpriteAtlasTexture atlas() { + return atlas; + } + + public static SpriteFinder spriteFinder() { + return spriteFinder; + } }