PageRenderTime 157ms CodeModel.GetById 18ms RepoModel.GetById 6ms app.codeStats 1ms

/src/minecraft/net/minecraft/client/renderer/OpenGlHelper.java

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