001    package net.minecraft.src;
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            var0 = field_74530_b.iterator();
066    
067            while (var0.hasNext())
068            {
069                int var2 = ((Integer)var0.next()).intValue();
070                GL11.glDeleteTextures(var2);
071            }
072    
073            field_74530_b.clear();
074        }
075    
076        /**
077         * Creates and returns a direct byte buffer with the specified capacity. Applies native ordering to speed up access.
078         */
079        public static synchronized ByteBuffer createDirectByteBuffer(int par0)
080        {
081            return ByteBuffer.allocateDirect(par0).order(ByteOrder.nativeOrder());
082        }
083    
084        /**
085         * Creates and returns a direct int buffer with the specified capacity. Applies native ordering to speed up access.
086         */
087        public static IntBuffer createDirectIntBuffer(int par0)
088        {
089            return createDirectByteBuffer(par0 << 2).asIntBuffer();
090        }
091    
092        /**
093         * Creates and returns a direct float buffer with the specified capacity. Applies native ordering to speed up
094         * access.
095         */
096        public static FloatBuffer createDirectFloatBuffer(int par0)
097        {
098            return createDirectByteBuffer(par0 << 2).asFloatBuffer();
099        }
100    }