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