001package net.minecraft.client.renderer; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import org.lwjgl.opengl.ARBMultitexture; 006import org.lwjgl.opengl.GL13; 007import org.lwjgl.opengl.GLContext; 008 009@SideOnly(Side.CLIENT) 010public 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 /* Stores the last values sent into setLightmapTextureCoords */ 030 public static float lastBrightnessX = 0.0f; 031 public static float lastBrightnessY = 0.0f; 032 033 /** 034 * Initializes the texture constants to be used when rendering lightmap values 035 */ 036 public static void initializeTextures() 037 { 038 useMultitextureARB = GLContext.getCapabilities().GL_ARB_multitexture && !GLContext.getCapabilities().OpenGL13; 039 040 if (useMultitextureARB) 041 { 042 defaultTexUnit = 33984; 043 lightmapTexUnit = 33985; 044 } 045 else 046 { 047 defaultTexUnit = 33984; 048 lightmapTexUnit = 33985; 049 } 050 } 051 052 /** 053 * Sets the current lightmap texture to the specified OpenGL constant 054 */ 055 public static void setActiveTexture(int par0) 056 { 057 if (useMultitextureARB) 058 { 059 ARBMultitexture.glActiveTextureARB(par0); 060 } 061 else 062 { 063 GL13.glActiveTexture(par0); 064 } 065 } 066 067 /** 068 * Sets the current lightmap texture to the specified OpenGL constant 069 */ 070 public static void setClientActiveTexture(int par0) 071 { 072 if (useMultitextureARB) 073 { 074 ARBMultitexture.glClientActiveTextureARB(par0); 075 } 076 else 077 { 078 GL13.glClientActiveTexture(par0); 079 } 080 } 081 082 /** 083 * Sets the current coordinates of the given lightmap texture 084 */ 085 public static void setLightmapTextureCoords(int par0, float par1, float par2) 086 { 087 if (useMultitextureARB) 088 { 089 ARBMultitexture.glMultiTexCoord2fARB(par0, par1, par2); 090 } 091 else 092 { 093 GL13.glMultiTexCoord2f(par0, par1, par2); 094 } 095 096 if (par0 == lightmapTexUnit) 097 { 098 lastBrightnessX = par1; 099 lastBrightnessY = par2; 100 } 101 } 102}