001    package net.minecraft.client.renderer;
002    
003    import cpw.mods.fml.relauncher.Side;
004    import cpw.mods.fml.relauncher.SideOnly;
005    import org.lwjgl.opengl.ARBMultitexture;
006    import org.lwjgl.opengl.GL13;
007    import org.lwjgl.opengl.GLContext;
008    
009    @SideOnly(Side.CLIENT)
010    public class OpenGlHelper
011    {
012        /**
013         * An OpenGL constant corresponding to GL_TEXTURE0, used when setting data pertaining to auxiliary OpenGL texture
014         * units.
015         */
016        public static int defaultTexUnit;
017    
018        /**
019         * An OpenGL constant corresponding to GL_TEXTURE1, used when setting data pertaining to auxiliary OpenGL texture
020         * units.
021         */
022        public static int lightmapTexUnit;
023    
024        /**
025         * True if the renderer supports multitextures and the OpenGL version != 1.3
026         */
027        private static boolean useMultitextureARB = false;
028    
029        /**
030         * Initializes the texture constants to be used when rendering lightmap values
031         */
032        public static void initializeTextures()
033        {
034            useMultitextureARB = GLContext.getCapabilities().GL_ARB_multitexture && !GLContext.getCapabilities().OpenGL13;
035    
036            if (useMultitextureARB)
037            {
038                defaultTexUnit = 33984;
039                lightmapTexUnit = 33985;
040            }
041            else
042            {
043                defaultTexUnit = 33984;
044                lightmapTexUnit = 33985;
045            }
046        }
047    
048        /**
049         * Sets the current lightmap texture to the specified OpenGL constant
050         */
051        public static void setActiveTexture(int par0)
052        {
053            if (useMultitextureARB)
054            {
055                ARBMultitexture.glActiveTextureARB(par0);
056            }
057            else
058            {
059                GL13.glActiveTexture(par0);
060            }
061        }
062    
063        /**
064         * Sets the current lightmap texture to the specified OpenGL constant
065         */
066        public static void setClientActiveTexture(int par0)
067        {
068            if (useMultitextureARB)
069            {
070                ARBMultitexture.glClientActiveTextureARB(par0);
071            }
072            else
073            {
074                GL13.glClientActiveTexture(par0);
075            }
076        }
077    
078        /**
079         * Sets the current coordinates of the given lightmap texture
080         */
081        public static void setLightmapTextureCoords(int par0, float par1, float par2)
082        {
083            if (useMultitextureARB)
084            {
085                ARBMultitexture.glMultiTexCoord2fARB(par0, par1, par2);
086            }
087            else
088            {
089                GL13.glMultiTexCoord2f(par0, par1, par2);
090            }
091        }
092    }