| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import java.nio.ByteBuffer;
|
| 4 | import java.nio.FloatBuffer;
|
| 5 | import java.nio.IntBuffer;
|
| 6 | import net.minecraft.client.Minecraft;
|
| 7 | import net.minecraft.client.settings.GameSettings;
|
| 8 | import org.lwjgl.opengl.ARBFramebufferObject;
|
| 9 | import org.lwjgl.opengl.ARBMultitexture;
|
| 10 | import org.lwjgl.opengl.ARBShaderObjects;
|
| 11 | import org.lwjgl.opengl.ARBVertexBufferObject;
|
| 12 | import org.lwjgl.opengl.ARBVertexShader;
|
| 13 | import org.lwjgl.opengl.ContextCapabilities;
|
| 14 | import org.lwjgl.opengl.EXTBlendFuncSeparate;
|
| 15 | import org.lwjgl.opengl.EXTFramebufferObject;
|
| 16 | import org.lwjgl.opengl.GL11;
|
| 17 | import org.lwjgl.opengl.GL13;
|
| 18 | import org.lwjgl.opengl.GL14;
|
| 19 | import org.lwjgl.opengl.GL15;
|
| 20 | import org.lwjgl.opengl.GL20;
|
| 21 | import org.lwjgl.opengl.GL30;
|
| 22 | import org.lwjgl.opengl.GLContext;
|
| 23 | import oshi.SystemInfo;
|
| 24 | import oshi.hardware.Processor;
|
| 25 |
|
| 26 | public class OpenGlHelper
|
| 27 | {
|
| 28 | public static boolean nvidia;
|
| 29 | public static boolean ati;
|
| 30 | public static int GL_FRAMEBUFFER;
|
| 31 | public static int GL_RENDERBUFFER;
|
| 32 | public static int GL_COLOR_ATTACHMENT0;
|
| 33 | public static int GL_DEPTH_ATTACHMENT;
|
| 34 | public static int GL_FRAMEBUFFER_COMPLETE;
|
| 35 | public static int GL_FB_INCOMPLETE_ATTACHMENT;
|
| 36 | public static int GL_FB_INCOMPLETE_MISS_ATTACH;
|
| 37 | public static int GL_FB_INCOMPLETE_DRAW_BUFFER;
|
| 38 | public static int GL_FB_INCOMPLETE_READ_BUFFER;
|
| 39 | private static int framebufferType;
|
| 40 | public static boolean framebufferSupported;
|
| 41 | private static boolean shadersAvailable;
|
| 42 | private static boolean arbShaders;
|
| 43 | public static int GL_LINK_STATUS;
|
| 44 | public static int GL_COMPILE_STATUS;
|
| 45 | public static int GL_VERTEX_SHADER;
|
| 46 | public static int GL_FRAGMENT_SHADER;
|
| 47 | private static boolean arbMultitexture;
|
| 48 |
|
| 49 | /**
|
| 50 | * An OpenGL constant corresponding to GL_TEXTURE0, used when setting data pertaining to auxiliary OpenGL texture
|
| 51 | * units.
|
| 52 | */
|
| 53 | public static int defaultTexUnit;
|
| 54 |
|
| 55 | /**
|
| 56 | * An OpenGL constant corresponding to GL_TEXTURE1, used when setting data pertaining to auxiliary OpenGL texture
|
| 57 | * units.
|
| 58 | */
|
| 59 | public static int lightmapTexUnit;
|
| 60 | public static int GL_TEXTURE2;
|
| 61 | private static boolean arbTextureEnvCombine;
|
| 62 | public static int GL_COMBINE;
|
| 63 | public static int GL_INTERPOLATE;
|
| 64 | public static int GL_PRIMARY_COLOR;
|
| 65 | public static int GL_CONSTANT;
|
| 66 | public static int GL_PREVIOUS;
|
| 67 | public static int GL_COMBINE_RGB;
|
| 68 | public static int GL_SOURCE0_RGB;
|
| 69 | public static int GL_SOURCE1_RGB;
|
| 70 | public static int GL_SOURCE2_RGB;
|
| 71 | public static int GL_OPERAND0_RGB;
|
| 72 | public static int GL_OPERAND1_RGB;
|
| 73 | public static int GL_OPERAND2_RGB;
|
| 74 | public static int GL_COMBINE_ALPHA;
|
| 75 | public static int GL_SOURCE0_ALPHA;
|
| 76 | public static int GL_SOURCE1_ALPHA;
|
| 77 | public static int GL_SOURCE2_ALPHA;
|
| 78 | public static int GL_OPERAND0_ALPHA;
|
| 79 | public static int GL_OPERAND1_ALPHA;
|
| 80 | public static int GL_OPERAND2_ALPHA;
|
| 81 | private static boolean openGL14;
|
| 82 | public static boolean extBlendFuncSeparate;
|
| 83 | public static boolean openGL21;
|
| 84 | public static boolean shadersSupported;
|
| 85 | private static String logText = "";
|
| 86 | private static String cpu;
|
| 87 | public static boolean vboSupported;
|
| 88 | public static boolean vboSupportedAti;
|
| 89 | private static boolean arbVbo;
|
| 90 | public static int GL_ARRAY_BUFFER;
|
| 91 | public static int GL_STATIC_DRAW;
|
| 92 |
|
| 93 | /**
|
| 94 | * Initializes the texture constants to be used when rendering lightmap values
|
| 95 | */
|
| 96 | public static void initializeTextures()
|
| 97 | {
|
| 98 | ContextCapabilities contextcapabilities = GLContext.getCapabilities();
|
| 99 | arbMultitexture = contextcapabilities.GL_ARB_multitexture && !contextcapabilities.OpenGL13;
|
| 100 | arbTextureEnvCombine = contextcapabilities.GL_ARB_texture_env_combine && !contextcapabilities.OpenGL13;
|
| 101 |
|
| 102 | if (arbMultitexture)
|
| 103 | {
|
| 104 | logText = logText + "Using ARB_multitexture.\n";
|
| 105 | defaultTexUnit = 33984;
|
| 106 | lightmapTexUnit = 33985;
|
| 107 | GL_TEXTURE2 = 33986;
|
| 108 | }
|
| 109 | else
|
| 110 | {
|
| 111 | logText = logText + "Using GL 1.3 multitexturing.\n";
|
| 112 | defaultTexUnit = 33984;
|
| 113 | lightmapTexUnit = 33985;
|
| 114 | GL_TEXTURE2 = 33986;
|
| 115 | }
|
| 116 |
|
| 117 | if (arbTextureEnvCombine)
|
| 118 | {
|
| 119 | logText = logText + "Using ARB_texture_env_combine.\n";
|
| 120 | GL_COMBINE = 34160;
|
| 121 | GL_INTERPOLATE = 34165;
|
| 122 | GL_PRIMARY_COLOR = 34167;
|
| 123 | GL_CONSTANT = 34166;
|
| 124 | GL_PREVIOUS = 34168;
|
| 125 | GL_COMBINE_RGB = 34161;
|
| 126 | GL_SOURCE0_RGB = 34176;
|
| 127 | GL_SOURCE1_RGB = 34177;
|
| 128 | GL_SOURCE2_RGB = 34178;
|
| 129 | GL_OPERAND0_RGB = 34192;
|
| 130 | GL_OPERAND1_RGB = 34193;
|
| 131 | GL_OPERAND2_RGB = 34194;
|
| 132 | GL_COMBINE_ALPHA = 34162;
|
| 133 | GL_SOURCE0_ALPHA = 34184;
|
| 134 | GL_SOURCE1_ALPHA = 34185;
|
| 135 | GL_SOURCE2_ALPHA = 34186;
|
| 136 | GL_OPERAND0_ALPHA = 34200;
|
| 137 | GL_OPERAND1_ALPHA = 34201;
|
| 138 | GL_OPERAND2_ALPHA = 34202;
|
| 139 | }
|
| 140 | else
|
| 141 | {
|
| 142 | logText = logText + "Using GL 1.3 texture combiners.\n";
|
| 143 | GL_COMBINE = 34160;
|
| 144 | GL_INTERPOLATE = 34165;
|
| 145 | GL_PRIMARY_COLOR = 34167;
|
| 146 | GL_CONSTANT = 34166;
|
| 147 | GL_PREVIOUS = 34168;
|
| 148 | GL_COMBINE_RGB = 34161;
|
| 149 | GL_SOURCE0_RGB = 34176;
|
| 150 | GL_SOURCE1_RGB = 34177;
|
| 151 | GL_SOURCE2_RGB = 34178;
|
| 152 | GL_OPERAND0_RGB = 34192;
|
| 153 | GL_OPERAND1_RGB = 34193;
|
| 154 | GL_OPERAND2_RGB = 34194;
|
| 155 | GL_COMBINE_ALPHA = 34162;
|
| 156 | GL_SOURCE0_ALPHA = 34184;
|
| 157 | GL_SOURCE1_ALPHA = 34185;
|
| 158 | GL_SOURCE2_ALPHA = 34186;
|
| 159 | GL_OPERAND0_ALPHA = 34200;
|
| 160 | GL_OPERAND1_ALPHA = 34201;
|
| 161 | GL_OPERAND2_ALPHA = 34202;
|
| 162 | }
|
| 163 |
|
| 164 | extBlendFuncSeparate = contextcapabilities.GL_EXT_blend_func_separate && !contextcapabilities.OpenGL14;
|
| 165 | openGL14 = contextcapabilities.OpenGL14 || contextcapabilities.GL_EXT_blend_func_separate;
|
| 166 | framebufferSupported = openGL14 && (contextcapabilities.GL_ARB_framebuffer_object || contextcapabilities.GL_EXT_framebuffer_object || contextcapabilities.OpenGL30);
|
| 167 |
|
| 168 | if (framebufferSupported)
|
| 169 | {
|
| 170 | logText = logText + "Using framebuffer objects because ";
|
| 171 |
|
| 172 | if (contextcapabilities.OpenGL30)
|
| 173 | {
|
| 174 | logText = logText + "OpenGL 3.0 is supported and separate blending is supported.\n";
|
| 175 | framebufferType = 0;
|
| 176 | GL_FRAMEBUFFER = 36160;
|
| 177 | GL_RENDERBUFFER = 36161;
|
| 178 | GL_COLOR_ATTACHMENT0 = 36064;
|
| 179 | GL_DEPTH_ATTACHMENT = 36096;
|
| 180 | GL_FRAMEBUFFER_COMPLETE = 36053;
|
| 181 | GL_FB_INCOMPLETE_ATTACHMENT = 36054;
|
| 182 | GL_FB_INCOMPLETE_MISS_ATTACH = 36055;
|
| 183 | GL_FB_INCOMPLETE_DRAW_BUFFER = 36059;
|
| 184 | GL_FB_INCOMPLETE_READ_BUFFER = 36060;
|
| 185 | }
|
| 186 | else if (contextcapabilities.GL_ARB_framebuffer_object)
|
| 187 | {
|
| 188 | logText = logText + "ARB_framebuffer_object is supported and separate blending is supported.\n";
|
| 189 | framebufferType = 1;
|
| 190 | GL_FRAMEBUFFER = 36160;
|
| 191 | GL_RENDERBUFFER = 36161;
|
| 192 | GL_COLOR_ATTACHMENT0 = 36064;
|
| 193 | GL_DEPTH_ATTACHMENT = 36096;
|
| 194 | GL_FRAMEBUFFER_COMPLETE = 36053;
|
| 195 | GL_FB_INCOMPLETE_MISS_ATTACH = 36055;
|
| 196 | GL_FB_INCOMPLETE_ATTACHMENT = 36054;
|
| 197 | GL_FB_INCOMPLETE_DRAW_BUFFER = 36059;
|
| 198 | GL_FB_INCOMPLETE_READ_BUFFER = 36060;
|
| 199 | }
|
| 200 | else if (contextcapabilities.GL_EXT_framebuffer_object)
|
| 201 | {
|
| 202 | logText = logText + "EXT_framebuffer_object is supported.\n";
|
| 203 | framebufferType = 2;
|
| 204 | GL_FRAMEBUFFER = 36160;
|
| 205 | GL_RENDERBUFFER = 36161;
|
| 206 | GL_COLOR_ATTACHMENT0 = 36064;
|
| 207 | GL_DEPTH_ATTACHMENT = 36096;
|
| 208 | GL_FRAMEBUFFER_COMPLETE = 36053;
|
| 209 | GL_FB_INCOMPLETE_MISS_ATTACH = 36055;
|
| 210 | GL_FB_INCOMPLETE_ATTACHMENT = 36054;
|
| 211 | GL_FB_INCOMPLETE_DRAW_BUFFER = 36059;
|
| 212 | GL_FB_INCOMPLETE_READ_BUFFER = 36060;
|
| 213 | }
|
| 214 | }
|
| 215 | else
|
| 216 | {
|
| 217 | logText = logText + "Not using framebuffer objects because ";
|
| 218 | logText = logText + "OpenGL 1.4 is " + (contextcapabilities.OpenGL14 ? "" : "not ") + "supported, ";
|
| 219 | logText = logText + "EXT_blend_func_separate is " + (contextcapabilities.GL_EXT_blend_func_separate ? "" : "not ") + "supported, ";
|
| 220 | logText = logText + "OpenGL 3.0 is " + (contextcapabilities.OpenGL30 ? "" : "not ") + "supported, ";
|
| 221 | logText = logText + "ARB_framebuffer_object is " + (contextcapabilities.GL_ARB_framebuffer_object ? "" : "not ") + "supported, and ";
|
| 222 | logText = logText + "EXT_framebuffer_object is " + (contextcapabilities.GL_EXT_framebuffer_object ? "" : "not ") + "supported.\n";
|
| 223 | }
|
| 224 |
|
| 225 | openGL21 = contextcapabilities.OpenGL21;
|
| 226 | shadersAvailable = openGL21 || contextcapabilities.GL_ARB_vertex_shader && contextcapabilities.GL_ARB_fragment_shader && contextcapabilities.GL_ARB_shader_objects;
|
| 227 | logText = logText + "Shaders are " + (shadersAvailable ? "" : "not ") + "available because ";
|
| 228 |
|
| 229 | if (shadersAvailable)
|
| 230 | {
|
| 231 | if (contextcapabilities.OpenGL21)
|
| 232 | {
|
| 233 | logText = logText + "OpenGL 2.1 is supported.\n";
|
| 234 | arbShaders = false;
|
| 235 | GL_LINK_STATUS = 35714;
|
| 236 | GL_COMPILE_STATUS = 35713;
|
| 237 | GL_VERTEX_SHADER = 35633;
|
| 238 | GL_FRAGMENT_SHADER = 35632;
|
| 239 | }
|
| 240 | else
|
| 241 | {
|
| 242 | logText = logText + "ARB_shader_objects, ARB_vertex_shader, and ARB_fragment_shader are supported.\n";
|
| 243 | arbShaders = true;
|
| 244 | GL_LINK_STATUS = 35714;
|
| 245 | GL_COMPILE_STATUS = 35713;
|
| 246 | GL_VERTEX_SHADER = 35633;
|
| 247 | GL_FRAGMENT_SHADER = 35632;
|
| 248 | }
|
| 249 | }
|
| 250 | else
|
| 251 | {
|
| 252 | logText = logText + "OpenGL 2.1 is " + (contextcapabilities.OpenGL21 ? "" : "not ") + "supported, ";
|
| 253 | logText = logText + "ARB_shader_objects is " + (contextcapabilities.GL_ARB_shader_objects ? "" : "not ") + "supported, ";
|
| 254 | logText = logText + "ARB_vertex_shader is " + (contextcapabilities.GL_ARB_vertex_shader ? "" : "not ") + "supported, and ";
|
| 255 | logText = logText + "ARB_fragment_shader is " + (contextcapabilities.GL_ARB_fragment_shader ? "" : "not ") + "supported.\n";
|
| 256 | }
|
| 257 |
|
| 258 | shadersSupported = framebufferSupported && shadersAvailable;
|
| 259 | String s = GL11.glGetString(GL11.GL_VENDOR).toLowerCase();
|
| 260 | nvidia = s.contains("nvidia");
|
| 261 | arbVbo = !contextcapabilities.OpenGL15 && contextcapabilities.GL_ARB_vertex_buffer_object;
|
| 262 | vboSupported = contextcapabilities.OpenGL15 || arbVbo;
|
| 263 | logText = logText + "VBOs are " + (vboSupported ? "" : "not ") + "available because ";
|
| 264 |
|
| 265 | if (vboSupported)
|
| 266 | {
|
| 267 | if (arbVbo)
|
| 268 | {
|
| 269 | logText = logText + "ARB_vertex_buffer_object is supported.\n";
|
| 270 | GL_STATIC_DRAW = 35044;
|
| 271 | GL_ARRAY_BUFFER = 34962;
|
| 272 | }
|
| 273 | else
|
| 274 | {
|
| 275 | logText = logText + "OpenGL 1.5 is supported.\n";
|
| 276 | GL_STATIC_DRAW = 35044;
|
| 277 | GL_ARRAY_BUFFER = 34962;
|
| 278 | }
|
| 279 | }
|
| 280 |
|
| 281 | ati = s.contains("ati");
|
| 282 |
|
| 283 | if (ati)
|
| 284 | {
|
| 285 | if (vboSupported)
|
| 286 | {
|
| 287 | vboSupportedAti = true;
|
| 288 | }
|
| 289 | else
|
| 290 | {
|
| 291 | GameSettings.Options.RENDER_DISTANCE.setValueMax(16.0F);
|
| 292 | }
|
| 293 | }
|
| 294 |
|
| 295 | try
|
| 296 | {
|
| 297 | Processor[] aprocessor = (new SystemInfo()).getHardware().getProcessors();
|
| 298 | cpu = String.format("%dx %s", new Object[] {Integer.valueOf(aprocessor.length), aprocessor[0]}).replaceAll("\\s+", " ");
|
| 299 | }
|
| 300 | catch (Throwable var3)
|
| 301 | {
|
| 302 | ;
|
| 303 | }
|
| 304 | }
|
| 305 |
|
| 306 | public static boolean areShadersSupported()
|
| 307 | {
|
| 308 | return shadersSupported;
|
| 309 | }
|
| 310 |
|
| 311 | public static String getLogText()
|
| 312 | {
|
| 313 | return logText;
|
| 314 | }
|
| 315 |
|
| 316 | public static int glGetProgrami(int program, int pname)
|
| 317 | {
|
| 318 | return arbShaders ? ARBShaderObjects.glGetObjectParameteriARB(program, pname) : GL20.glGetProgrami(program, pname);
|
| 319 | }
|
| 320 |
|
| 321 | public static void glAttachShader(int program, int shaderIn)
|
| 322 | {
|
| 323 | if (arbShaders)
|
| 324 | {
|
| 325 | ARBShaderObjects.glAttachObjectARB(program, shaderIn);
|
| 326 | }
|
| 327 | else
|
| 328 | {
|
| 329 | GL20.glAttachShader(program, shaderIn);
|
| 330 | }
|
| 331 | }
|
| 332 |
|
| 333 | public static void glDeleteShader(int p_153180_0_)
|
| 334 | {
|
| 335 | if (arbShaders)
|
| 336 | {
|
| 337 | ARBShaderObjects.glDeleteObjectARB(p_153180_0_);
|
| 338 | }
|
| 339 | else
|
| 340 | {
|
| 341 | GL20.glDeleteShader(p_153180_0_);
|
| 342 | }
|
| 343 | }
|
| 344 |
|
| 345 | /**
|
| 346 | * creates a shader with the given mode and returns the GL id. params: mode
|
| 347 | */
|
| 348 | public static int glCreateShader(int type)
|
| 349 | {
|
| 350 | return arbShaders ? ARBShaderObjects.glCreateShaderObjectARB(type) : GL20.glCreateShader(type);
|
| 351 | }
|
| 352 |
|
| 353 | public static void glShaderSource(int shaderIn, ByteBuffer string)
|
| 354 | {
|
| 355 | if (arbShaders)
|
| 356 | {
|
| 357 | ARBShaderObjects.glShaderSourceARB(shaderIn, string);
|
| 358 | }
|
| 359 | else
|
| 360 | {
|
| 361 | GL20.glShaderSource(shaderIn, string);
|
| 362 | }
|
| 363 | }
|
| 364 |
|
| 365 | public static void glCompileShader(int shaderIn)
|
| 366 | {
|
| 367 | if (arbShaders)
|
| 368 | {
|
| 369 | ARBShaderObjects.glCompileShaderARB(shaderIn);
|
| 370 | }
|
| 371 | else
|
| 372 | {
|
| 373 | GL20.glCompileShader(shaderIn);
|
| 374 | }
|
| 375 | }
|
| 376 |
|
| 377 | public static int glGetShaderi(int shaderIn, int pname)
|
| 378 | {
|
| 379 | return arbShaders ? ARBShaderObjects.glGetObjectParameteriARB(shaderIn, pname) : GL20.glGetShaderi(shaderIn, pname);
|
| 380 | }
|
| 381 |
|
| 382 | public static String glGetShaderInfoLog(int shaderIn, int maxLength)
|
| 383 | {
|
| 384 | return arbShaders ? ARBShaderObjects.glGetInfoLogARB(shaderIn, maxLength) : GL20.glGetShaderInfoLog(shaderIn, maxLength);
|
| 385 | }
|
| 386 |
|
| 387 | public static String glGetProgramInfoLog(int program, int maxLength)
|
| 388 | {
|
| 389 | return arbShaders ? ARBShaderObjects.glGetInfoLogARB(program, maxLength) : GL20.glGetProgramInfoLog(program, maxLength);
|
| 390 | }
|
| 391 |
|
| 392 | public static void glUseProgram(int program)
|
| 393 | {
|
| 394 | if (arbShaders)
|
| 395 | {
|
| 396 | ARBShaderObjects.glUseProgramObjectARB(program);
|
| 397 | }
|
| 398 | else
|
| 399 | {
|
| 400 | GL20.glUseProgram(program);
|
| 401 | }
|
| 402 | }
|
| 403 |
|
| 404 | public static int glCreateProgram()
|
| 405 | {
|
| 406 | return arbShaders ? ARBShaderObjects.glCreateProgramObjectARB() : GL20.glCreateProgram();
|
| 407 | }
|
| 408 |
|
| 409 | public static void glDeleteProgram(int program)
|
| 410 | {
|
| 411 | if (arbShaders)
|
| 412 | {
|
| 413 | ARBShaderObjects.glDeleteObjectARB(program);
|
| 414 | }
|
| 415 | else
|
| 416 | {
|
| 417 | GL20.glDeleteProgram(program);
|
| 418 | }
|
| 419 | }
|
| 420 |
|
| 421 | public static void glLinkProgram(int program)
|
| 422 | {
|
| 423 | if (arbShaders)
|
| 424 | {
|
| 425 | ARBShaderObjects.glLinkProgramARB(program);
|
| 426 | }
|
| 427 | else
|
| 428 | {
|
| 429 | GL20.glLinkProgram(program);
|
| 430 | }
|
| 431 | }
|
| 432 |
|
| 433 | public static int glGetUniformLocation(int programObj, CharSequence name)
|
| 434 | {
|
| 435 | return arbShaders ? ARBShaderObjects.glGetUniformLocationARB(programObj, name) : GL20.glGetUniformLocation(programObj, name);
|
| 436 | }
|
| 437 |
|
| 438 | public static void glUniform1(int location, IntBuffer values)
|
| 439 | {
|
| 440 | if (arbShaders)
|
| 441 | {
|
| 442 | ARBShaderObjects.glUniform1ARB(location, values);
|
| 443 | }
|
| 444 | else
|
| 445 | {
|
| 446 | GL20.glUniform1(location, values);
|
| 447 | }
|
| 448 | }
|
| 449 |
|
| 450 | public static void glUniform1i(int location, int v0)
|
| 451 | {
|
| 452 | if (arbShaders)
|
| 453 | {
|
| 454 | ARBShaderObjects.glUniform1iARB(location, v0);
|
| 455 | }
|
| 456 | else
|
| 457 | {
|
| 458 | GL20.glUniform1i(location, v0);
|
| 459 | }
|
| 460 | }
|
| 461 |
|
| 462 | public static void glUniform1(int location, FloatBuffer values)
|
| 463 | {
|
| 464 | if (arbShaders)
|
| 465 | {
|
| 466 | ARBShaderObjects.glUniform1ARB(location, values);
|
| 467 | }
|
| 468 | else
|
| 469 | {
|
| 470 | GL20.glUniform1(location, values);
|
| 471 | }
|
| 472 | }
|
| 473 |
|
| 474 | public static void glUniform2(int location, IntBuffer values)
|
| 475 | {
|
| 476 | if (arbShaders)
|
| 477 | {
|
| 478 | ARBShaderObjects.glUniform2ARB(location, values);
|
| 479 | }
|
| 480 | else
|
| 481 | {
|
| 482 | GL20.glUniform2(location, values);
|
| 483 | }
|
| 484 | }
|
| 485 |
|
| 486 | public static void glUniform2(int location, FloatBuffer values)
|
| 487 | {
|
| 488 | if (arbShaders)
|
| 489 | {
|
| 490 | ARBShaderObjects.glUniform2ARB(location, values);
|
| 491 | }
|
| 492 | else
|
| 493 | {
|
| 494 | GL20.glUniform2(location, values);
|
| 495 | }
|
| 496 | }
|
| 497 |
|
| 498 | public static void glUniform3(int location, IntBuffer values)
|
| 499 | {
|
| 500 | if (arbShaders)
|
| 501 | {
|
| 502 | ARBShaderObjects.glUniform3ARB(location, values);
|
| 503 | }
|
| 504 | else
|
| 505 | {
|
| 506 | GL20.glUniform3(location, values);
|
| 507 | }
|
| 508 | }
|
| 509 |
|
| 510 | public static void glUniform3(int location, FloatBuffer values)
|
| 511 | {
|
| 512 | if (arbShaders)
|
| 513 | {
|
| 514 | ARBShaderObjects.glUniform3ARB(location, values);
|
| 515 | }
|
| 516 | else
|
| 517 | {
|
| 518 | GL20.glUniform3(location, values);
|
| 519 | }
|
| 520 | }
|
| 521 |
|
| 522 | public static void glUniform4(int location, IntBuffer values)
|
| 523 | {
|
| 524 | if (arbShaders)
|
| 525 | {
|
| 526 | ARBShaderObjects.glUniform4ARB(location, values);
|
| 527 | }
|
| 528 | else
|
| 529 | {
|
| 530 | GL20.glUniform4(location, values);
|
| 531 | }
|
| 532 | }
|
| 533 |
|
| 534 | public static void glUniform4(int location, FloatBuffer values)
|
| 535 | {
|
| 536 | if (arbShaders)
|
| 537 | {
|
| 538 | ARBShaderObjects.glUniform4ARB(location, values);
|
| 539 | }
|
| 540 | else
|
| 541 | {
|
| 542 | GL20.glUniform4(location, values);
|
| 543 | }
|
| 544 | }
|
| 545 |
|
| 546 | public static void glUniformMatrix2(int location, boolean transpose, FloatBuffer matrices)
|
| 547 | {
|
| 548 | if (arbShaders)
|
| 549 | {
|
| 550 | ARBShaderObjects.glUniformMatrix2ARB(location, transpose, matrices);
|
| 551 | }
|
| 552 | else
|
| 553 | {
|
| 554 | GL20.glUniformMatrix2(location, transpose, matrices);
|
| 555 | }
|
| 556 | }
|
| 557 |
|
| 558 | public static void glUniformMatrix3(int location, boolean transpose, FloatBuffer matrices)
|
| 559 | {
|
| 560 | if (arbShaders)
|
| 561 | {
|
| 562 | ARBShaderObjects.glUniformMatrix3ARB(location, transpose, matrices);
|
| 563 | }
|
| 564 | else
|
| 565 | {
|
| 566 | GL20.glUniformMatrix3(location, transpose, matrices);
|
| 567 | }
|
| 568 | }
|
| 569 |
|
| 570 | public static void glUniformMatrix4(int location, boolean transpose, FloatBuffer matrices)
|
| 571 | {
|
| 572 | if (arbShaders)
|
| 573 | {
|
| 574 | ARBShaderObjects.glUniformMatrix4ARB(location, transpose, matrices);
|
| 575 | }
|
| 576 | else
|
| 577 | {
|
| 578 | GL20.glUniformMatrix4(location, transpose, matrices);
|
| 579 | }
|
| 580 | }
|
| 581 |
|
| 582 | public static int glGetAttribLocation(int p_153164_0_, CharSequence p_153164_1_)
|
| 583 | {
|
| 584 | return arbShaders ? ARBVertexShader.glGetAttribLocationARB(p_153164_0_, p_153164_1_) : GL20.glGetAttribLocation(p_153164_0_, p_153164_1_);
|
| 585 | }
|
| 586 |
|
| 587 | public static int glGenBuffers()
|
| 588 | {
|
| 589 | return arbVbo ? ARBVertexBufferObject.glGenBuffersARB() : GL15.glGenBuffers();
|
| 590 | }
|
| 591 |
|
| 592 | public static void glBindBuffer(int target, int buffer)
|
| 593 | {
|
| 594 | if (arbVbo)
|
| 595 | {
|
| 596 | ARBVertexBufferObject.glBindBufferARB(target, buffer);
|
| 597 | }
|
| 598 | else
|
| 599 | {
|
| 600 | GL15.glBindBuffer(target, buffer);
|
| 601 | }
|
| 602 | }
|
| 603 |
|
| 604 | public static void glBufferData(int target, ByteBuffer data, int usage)
|
| 605 | {
|
| 606 | if (arbVbo)
|
| 607 | {
|
| 608 | ARBVertexBufferObject.glBufferDataARB(target, data, usage);
|
| 609 | }
|
| 610 | else
|
| 611 | {
|
| 612 | GL15.glBufferData(target, data, usage);
|
| 613 | }
|
| 614 | }
|
| 615 |
|
| 616 | public static void glDeleteBuffers(int buffer)
|
| 617 | {
|
| 618 | if (arbVbo)
|
| 619 | {
|
| 620 | ARBVertexBufferObject.glDeleteBuffersARB(buffer);
|
| 621 | }
|
| 622 | else
|
| 623 | {
|
| 624 | GL15.glDeleteBuffers(buffer);
|
| 625 | }
|
| 626 | }
|
| 627 |
|
| 628 | public static boolean useVbo()
|
| 629 | {
|
| 630 | return vboSupported && Minecraft.getMinecraft().gameSettings.useVbo;
|
| 631 | }
|
| 632 |
|
| 633 | public static void glBindFramebuffer(int target, int framebufferIn)
|
| 634 | {
|
| 635 | if (framebufferSupported)
|
| 636 | {
|
| 637 | switch (framebufferType)
|
| 638 | {
|
| 639 | case 0:
|
| 640 | GL30.glBindFramebuffer(target, framebufferIn);
|
| 641 | break;
|
| 642 |
|
| 643 | case 1:
|
| 644 | ARBFramebufferObject.glBindFramebuffer(target, framebufferIn);
|
| 645 | break;
|
| 646 |
|
| 647 | case 2:
|
| 648 | EXTFramebufferObject.glBindFramebufferEXT(target, framebufferIn);
|
| 649 | }
|
| 650 | }
|
| 651 | }
|
| 652 |
|
| 653 | public static void glBindRenderbuffer(int target, int renderbuffer)
|
| 654 | {
|
| 655 | if (framebufferSupported)
|
| 656 | {
|
| 657 | switch (framebufferType)
|
| 658 | {
|
| 659 | case 0:
|
| 660 | GL30.glBindRenderbuffer(target, renderbuffer);
|
| 661 | break;
|
| 662 |
|
| 663 | case 1:
|
| 664 | ARBFramebufferObject.glBindRenderbuffer(target, renderbuffer);
|
| 665 | break;
|
| 666 |
|
| 667 | case 2:
|
| 668 | EXTFramebufferObject.glBindRenderbufferEXT(target, renderbuffer);
|
| 669 | }
|
| 670 | }
|
| 671 | }
|
| 672 |
|
| 673 | public static void glDeleteRenderbuffers(int renderbuffer)
|
| 674 | {
|
| 675 | if (framebufferSupported)
|
| 676 | {
|
| 677 | switch (framebufferType)
|
| 678 | {
|
| 679 | case 0:
|
| 680 | GL30.glDeleteRenderbuffers(renderbuffer);
|
| 681 | break;
|
| 682 |
|
| 683 | case 1:
|
| 684 | ARBFramebufferObject.glDeleteRenderbuffers(renderbuffer);
|
| 685 | break;
|
| 686 |
|
| 687 | case 2:
|
| 688 | EXTFramebufferObject.glDeleteRenderbuffersEXT(renderbuffer);
|
| 689 | }
|
| 690 | }
|
| 691 | }
|
| 692 |
|
| 693 | public static void glDeleteFramebuffers(int framebufferIn)
|
| 694 | {
|
| 695 | if (framebufferSupported)
|
| 696 | {
|
| 697 | switch (framebufferType)
|
| 698 | {
|
| 699 | case 0:
|
| 700 | GL30.glDeleteFramebuffers(framebufferIn);
|
| 701 | break;
|
| 702 |
|
| 703 | case 1:
|
| 704 | ARBFramebufferObject.glDeleteFramebuffers(framebufferIn);
|
| 705 | break;
|
| 706 |
|
| 707 | case 2:
|
| 708 | EXTFramebufferObject.glDeleteFramebuffersEXT(framebufferIn);
|
| 709 | }
|
| 710 | }
|
| 711 | }
|
| 712 |
|
| 713 | /**
|
| 714 | * Calls the appropriate glGenFramebuffers method and returns the newly created fbo, or returns -1 if not supported.
|
| 715 | */
|
| 716 | public static int glGenFramebuffers()
|
| 717 | {
|
| 718 | if (!framebufferSupported)
|
| 719 | {
|
| 720 | return -1;
|
| 721 | }
|
| 722 | else
|
| 723 | {
|
| 724 | switch (framebufferType)
|
| 725 | {
|
| 726 | case 0:
|
| 727 | return GL30.glGenFramebuffers();
|
| 728 |
|
| 729 | case 1:
|
| 730 | return ARBFramebufferObject.glGenFramebuffers();
|
| 731 |
|
| 732 | case 2:
|
| 733 | return EXTFramebufferObject.glGenFramebuffersEXT();
|
| 734 |
|
| 735 | default:
|
| 736 | return -1;
|
| 737 | }
|
| 738 | }
|
| 739 | }
|
| 740 |
|
| 741 | public static int glGenRenderbuffers()
|
| 742 | {
|
| 743 | if (!framebufferSupported)
|
| 744 | {
|
| 745 | return -1;
|
| 746 | }
|
| 747 | else
|
| 748 | {
|
| 749 | switch (framebufferType)
|
| 750 | {
|
| 751 | case 0:
|
| 752 | return GL30.glGenRenderbuffers();
|
| 753 |
|
| 754 | case 1:
|
| 755 | return ARBFramebufferObject.glGenRenderbuffers();
|
| 756 |
|
| 757 | case 2:
|
| 758 | return EXTFramebufferObject.glGenRenderbuffersEXT();
|
| 759 |
|
| 760 | default:
|
| 761 | return -1;
|
| 762 | }
|
| 763 | }
|
| 764 | }
|
| 765 |
|
| 766 | public static void glRenderbufferStorage(int target, int internalFormat, int width, int height)
|
| 767 | {
|
| 768 | if (framebufferSupported)
|
| 769 | {
|
| 770 | switch (framebufferType)
|
| 771 | {
|
| 772 | case 0:
|
| 773 | GL30.glRenderbufferStorage(target, internalFormat, width, height);
|
| 774 | break;
|
| 775 |
|
| 776 | case 1:
|
| 777 | ARBFramebufferObject.glRenderbufferStorage(target, internalFormat, width, height);
|
| 778 | break;
|
| 779 |
|
| 780 | case 2:
|
| 781 | EXTFramebufferObject.glRenderbufferStorageEXT(target, internalFormat, width, height);
|
| 782 | }
|
| 783 | }
|
| 784 | }
|
| 785 |
|
| 786 | public static void glFramebufferRenderbuffer(int target, int attachment, int renderBufferTarget, int renderBuffer)
|
| 787 | {
|
| 788 | if (framebufferSupported)
|
| 789 | {
|
| 790 | switch (framebufferType)
|
| 791 | {
|
| 792 | case 0:
|
| 793 | GL30.glFramebufferRenderbuffer(target, attachment, renderBufferTarget, renderBuffer);
|
| 794 | break;
|
| 795 |
|
| 796 | case 1:
|
| 797 | ARBFramebufferObject.glFramebufferRenderbuffer(target, attachment, renderBufferTarget, renderBuffer);
|
| 798 | break;
|
| 799 |
|
| 800 | case 2:
|
| 801 | EXTFramebufferObject.glFramebufferRenderbufferEXT(target, attachment, renderBufferTarget, renderBuffer);
|
| 802 | }
|
| 803 | }
|
| 804 | }
|
| 805 |
|
| 806 | public static int glCheckFramebufferStatus(int target)
|
| 807 | {
|
| 808 | if (!framebufferSupported)
|
| 809 | {
|
| 810 | return -1;
|
| 811 | }
|
| 812 | else
|
| 813 | {
|
| 814 | switch (framebufferType)
|
| 815 | {
|
| 816 | case 0:
|
| 817 | return GL30.glCheckFramebufferStatus(target);
|
| 818 |
|
| 819 | case 1:
|
| 820 | return ARBFramebufferObject.glCheckFramebufferStatus(target);
|
| 821 |
|
| 822 | case 2:
|
| 823 | return EXTFramebufferObject.glCheckFramebufferStatusEXT(target);
|
| 824 |
|
| 825 | default:
|
| 826 | return -1;
|
| 827 | }
|
| 828 | }
|
| 829 | }
|
| 830 |
|
| 831 | public static void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level)
|
| 832 | {
|
| 833 | if (framebufferSupported)
|
| 834 | {
|
| 835 | switch (framebufferType)
|
| 836 | {
|
| 837 | case 0:
|
| 838 | GL30.glFramebufferTexture2D(target, attachment, textarget, texture, level);
|
| 839 | break;
|
| 840 |
|
| 841 | case 1:
|
| 842 | ARBFramebufferObject.glFramebufferTexture2D(target, attachment, textarget, texture, level);
|
| 843 | break;
|
| 844 |
|
| 845 | case 2:
|
| 846 | EXTFramebufferObject.glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
|
| 847 | }
|
| 848 | }
|
| 849 | }
|
| 850 |
|
| 851 | /**
|
| 852 | * Sets the current lightmap texture to the specified OpenGL constant
|
| 853 | */
|
| 854 | public static void setActiveTexture(int texture)
|
| 855 | {
|
| 856 | if (arbMultitexture)
|
| 857 | {
|
| 858 | ARBMultitexture.glActiveTextureARB(texture);
|
| 859 | }
|
| 860 | else
|
| 861 | {
|
| 862 | GL13.glActiveTexture(texture);
|
| 863 | }
|
| 864 | }
|
| 865 |
|
| 866 | /**
|
| 867 | * Sets the current lightmap texture to the specified OpenGL constant
|
| 868 | */
|
| 869 | public static void setClientActiveTexture(int texture)
|
| 870 | {
|
| 871 | if (arbMultitexture)
|
| 872 | {
|
| 873 | ARBMultitexture.glClientActiveTextureARB(texture);
|
| 874 | }
|
| 875 | else
|
| 876 | {
|
| 877 | GL13.glClientActiveTexture(texture);
|
| 878 | }
|
| 879 | }
|
| 880 |
|
| 881 | /**
|
| 882 | * Sets the current coordinates of the given lightmap texture
|
| 883 | */
|
| 884 | public static void setLightmapTextureCoords(int target, float p_77475_1_, float p_77475_2_)
|
| 885 | {
|
| 886 | if (arbMultitexture)
|
| 887 | {
|
| 888 | ARBMultitexture.glMultiTexCoord2fARB(target, p_77475_1_, p_77475_2_);
|
| 889 | }
|
| 890 | else
|
| 891 | {
|
| 892 | GL13.glMultiTexCoord2f(target, p_77475_1_, p_77475_2_);
|
| 893 | }
|
| 894 | }
|
| 895 |
|
| 896 | public static void glBlendFunc(int sFactorRGB, int dFactorRGB, int sfactorAlpha, int dfactorAlpha)
|
| 897 | {
|
| 898 | if (openGL14)
|
| 899 | {
|
| 900 | if (extBlendFuncSeparate)
|
| 901 | {
|
| 902 | EXTBlendFuncSeparate.glBlendFuncSeparateEXT(sFactorRGB, dFactorRGB, sfactorAlpha, dfactorAlpha);
|
| 903 | }
|
| 904 | else
|
| 905 | {
|
| 906 | GL14.glBlendFuncSeparate(sFactorRGB, dFactorRGB, sfactorAlpha, dfactorAlpha);
|
| 907 | }
|
| 908 | }
|
| 909 | else
|
| 910 | {
|
| 911 | GL11.glBlendFunc(sFactorRGB, dFactorRGB);
|
| 912 | }
|
| 913 | }
|
| 914 |
|
| 915 | public static boolean isFramebufferEnabled()
|
| 916 | {
|
| 917 | return framebufferSupported && Minecraft.getMinecraft().gameSettings.fboEnable;
|
| 918 | }
|
| 919 |
|
| 920 | public static String getCpu()
|
| 921 | {
|
| 922 | return cpu == null ? "<unknown>" : cpu;
|
| 923 | }
|
| 924 | }
|
| 925 |
|