    001    package net.minecraft.client.renderer;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.nio.ByteBuffer;
    006    import java.nio.ByteOrder;
    007    import java.nio.FloatBuffer;
    008    import java.nio.IntBuffer;
    009    import java.util.ArrayList;
    010    import java.util.HashMap;
    011    import java.util.Iterator;
    012    import java.util.List;
    013    import java.util.Map;
    014    import java.util.Map.Entry;
    015    import org.lwjgl.opengl.GL11;
    016
    017    @SideOnly(Side.CLIENT)
    018    public class GLAllocation
    019    {
    020        private static final Map field_74531_a = new HashMap();
    021        private static final List field_74530_b = new ArrayList();
    022
    023        /**
    024         * Generates the specified number of display lists and returns the first index.
    025         */
    026        public static synchronized int generateDisplayLists(int par0)
    027        {
    028            int var1 = GL11.glGenLists(par0);
    029            field_74531_a.put(Integer.valueOf(var1), Integer.valueOf(par0));
    030            return var1;
    031        }
    032
    033        /**
    034         * Generates texture names and stores them in the specified buffer.
    035         */
    036        public static synchronized void generateTextureNames(IntBuffer par0IntBuffer)
    037        {
    038            GL11.glGenTextures(par0IntBuffer);
    039
    040            for (int var1 = par0IntBuffer.position(); var1 < par0IntBuffer.limit(); ++var1)
    041            {
    042                field_74530_b.add(Integer.valueOf(par0IntBuffer.get(var1)));
    043            }
    044        }
    045
    046        public static synchronized void deleteDisplayLists(int par0)
    047        {
    048            GL11.glDeleteLists(par0, ((Integer)field_74531_a.remove(Integer.valueOf(par0))).intValue());
    049        }
    050
    051        /**
    052         * Deletes all textures and display lists. Called when Minecraft is shutdown to free up resources.
    053         */
    054        public static synchronized void deleteTexturesAndDisplayLists()
    055        {
    056            Iterator var0 = field_74531_a.entrySet().iterator();
    057
    058            while (var0.hasNext())
    059            {
    060                Entry var1 = (Entry)var0.next();
    061                GL11.glDeleteLists(((Integer)var1.getKey()).intValue(), ((Integer)var1.getValue()).intValue());
    062            }
    063
    064            field_74531_a.clear();
    065
    066            for (int var2 = 0; var2 < field_74530_b.size(); ++var2)
    067            {
    068                GL11.glDeleteTextures(((Integer)field_74530_b.get(var2)).intValue());
    069            }
    070
    071            field_74530_b.clear();
    072        }
    073
    074        /**
    075         * Creates and returns a direct byte buffer with the specified capacity. Applies native ordering to speed up access.
    076         */
    077        public static synchronized ByteBuffer createDirectByteBuffer(int par0)
    078        {
    079            return ByteBuffer.allocateDirect(par0).order(ByteOrder.nativeOrder());
    080        }
    081
    082        /**
    083         * Creates and returns a direct int buffer with the specified capacity. Applies native ordering to speed up access.
    084         */
    085        public static IntBuffer createDirectIntBuffer(int par0)
    086        {
    087            return createDirectByteBuffer(par0 << 2).asIntBuffer();
    088        }
    089
    090        /**
    091         * Creates and returns a direct float buffer with the specified capacity. Applies native ordering to speed up
    092         * access.
    093         */
    094        public static FloatBuffer createDirectFloatBuffer(int par0)
    095        {
    096            return createDirectByteBuffer(par0 << 2).asFloatBuffer();
    097        }
    098    }