PageRenderTime 107ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/finesse/era-minecraft
Java | 702 lines | 588 code | 88 blank | 26 comment | 115 complexity | 4a40eb816f8c1fac7b129c2fdfb2ff52 MD5 | raw file
  1. package net.minecraft.client.renderer;
  2. import net.minecraft.client.Minecraft;
  3. import net.minecraft.src.Config;
  4. import org.lwjgl.opengl.*;
  5. import java.nio.ByteBuffer;
  6. import java.nio.FloatBuffer;
  7. import java.nio.IntBuffer;
  8. public class OpenGlHelper {
  9. public static boolean nvidia;
  10. public static int GL_FRAMEBUFFER;
  11. public static int GL_RENDERBUFFER;
  12. public static int GL_COLOR_ATTACHMENT0;
  13. public static int GL_DEPTH_ATTACHMENT;
  14. public static int GL_FRAMEBUFFER_COMPLETE;
  15. public static int GL_FB_INCOMPLETE_ATTACHMENT;
  16. public static int GL_FB_INCOMPLETE_MISS_ATTACH;
  17. public static int GL_FB_INCOMPLETE_DRAW_BUFFER;
  18. public static int GL_FB_INCOMPLETE_READ_BUFFER;
  19. private static int framebufferType;
  20. public static boolean framebufferSupported;
  21. private static boolean shadersAvailable;
  22. private static boolean arbShaders;
  23. public static int GL_LINK_STATUS;
  24. public static int GL_COMPILE_STATUS;
  25. public static int GL_VERTEX_SHADER;
  26. public static int GL_FRAGMENT_SHADER;
  27. private static boolean arbMultitexture;
  28. /**
  29. * An OpenGL constant corresponding to GL_TEXTURE0, used when setting data pertaining to auxiliary OpenGL texture
  30. * units.
  31. */
  32. public static int defaultTexUnit;
  33. /**
  34. * An OpenGL constant corresponding to GL_TEXTURE1, used when setting data pertaining to auxiliary OpenGL texture
  35. * units.
  36. */
  37. public static int lightmapTexUnit;
  38. public static int GL_TEXTURE2;
  39. private static boolean arbTextureEnvCombine;
  40. public static int GL_COMBINE;
  41. public static int GL_INTERPOLATE;
  42. public static int GL_PRIMARY_COLOR;
  43. public static int GL_CONSTANT;
  44. public static int GL_PREVIOUS;
  45. public static int GL_COMBINE_RGB;
  46. public static int GL_SOURCE0_RGB;
  47. public static int GL_SOURCE1_RGB;
  48. public static int GL_SOURCE2_RGB;
  49. public static int GL_OPERAND0_RGB;
  50. public static int GL_OPERAND1_RGB;
  51. public static int GL_OPERAND2_RGB;
  52. public static int GL_COMBINE_ALPHA;
  53. public static int GL_SOURCE0_ALPHA;
  54. public static int GL_SOURCE1_ALPHA;
  55. public static int GL_SOURCE2_ALPHA;
  56. public static int GL_OPERAND0_ALPHA;
  57. public static int GL_OPERAND1_ALPHA;
  58. public static int GL_OPERAND2_ALPHA;
  59. private static boolean openGL14;
  60. public static boolean extBlendFuncSeparate;
  61. public static boolean openGL21;
  62. public static boolean shadersSupported;
  63. private static String logText = "";
  64. public static boolean vboSupported;
  65. private static boolean arbVbo;
  66. public static int GL_ARRAY_BUFFER;
  67. public static int GL_STATIC_DRAW;
  68. public static float lastBrightnessX = 0.0F;
  69. public static float lastBrightnessY = 0.0F;
  70. /**
  71. * Initializes the texture constants to be used when rendering lightmap values
  72. */
  73. public static void initializeTextures() {
  74. Config.initDisplay();
  75. ContextCapabilities var0 = GLContext.getCapabilities();
  76. arbMultitexture = var0.GL_ARB_multitexture && !var0.OpenGL13;
  77. arbTextureEnvCombine = var0.GL_ARB_texture_env_combine && !var0.OpenGL13;
  78. if (arbMultitexture) {
  79. logText = logText + "Using ARB_multitexture.\n";
  80. defaultTexUnit = 33984;
  81. lightmapTexUnit = 33985;
  82. GL_TEXTURE2 = 33986;
  83. } else {
  84. logText = logText + "Using GL 1.3 multitexturing.\n";
  85. defaultTexUnit = 33984;
  86. lightmapTexUnit = 33985;
  87. GL_TEXTURE2 = 33986;
  88. }
  89. if (arbTextureEnvCombine) {
  90. logText = logText + "Using ARB_texture_env_combine.\n";
  91. GL_COMBINE = 34160;
  92. GL_INTERPOLATE = 34165;
  93. GL_PRIMARY_COLOR = 34167;
  94. GL_CONSTANT = 34166;
  95. GL_PREVIOUS = 34168;
  96. GL_COMBINE_RGB = 34161;
  97. GL_SOURCE0_RGB = 34176;
  98. GL_SOURCE1_RGB = 34177;
  99. GL_SOURCE2_RGB = 34178;
  100. GL_OPERAND0_RGB = 34192;
  101. GL_OPERAND1_RGB = 34193;
  102. GL_OPERAND2_RGB = 34194;
  103. GL_COMBINE_ALPHA = 34162;
  104. GL_SOURCE0_ALPHA = 34184;
  105. GL_SOURCE1_ALPHA = 34185;
  106. GL_SOURCE2_ALPHA = 34186;
  107. GL_OPERAND0_ALPHA = 34200;
  108. GL_OPERAND1_ALPHA = 34201;
  109. GL_OPERAND2_ALPHA = 34202;
  110. } else {
  111. logText = logText + "Using GL 1.3 texture combiners.\n";
  112. GL_COMBINE = 34160;
  113. GL_INTERPOLATE = 34165;
  114. GL_PRIMARY_COLOR = 34167;
  115. GL_CONSTANT = 34166;
  116. GL_PREVIOUS = 34168;
  117. GL_COMBINE_RGB = 34161;
  118. GL_SOURCE0_RGB = 34176;
  119. GL_SOURCE1_RGB = 34177;
  120. GL_SOURCE2_RGB = 34178;
  121. GL_OPERAND0_RGB = 34192;
  122. GL_OPERAND1_RGB = 34193;
  123. GL_OPERAND2_RGB = 34194;
  124. GL_COMBINE_ALPHA = 34162;
  125. GL_SOURCE0_ALPHA = 34184;
  126. GL_SOURCE1_ALPHA = 34185;
  127. GL_SOURCE2_ALPHA = 34186;
  128. GL_OPERAND0_ALPHA = 34200;
  129. GL_OPERAND1_ALPHA = 34201;
  130. GL_OPERAND2_ALPHA = 34202;
  131. }
  132. extBlendFuncSeparate = var0.GL_EXT_blend_func_separate && !var0.OpenGL14;
  133. openGL14 = var0.OpenGL14 || var0.GL_EXT_blend_func_separate;
  134. framebufferSupported = openGL14 && (var0.GL_ARB_framebuffer_object || var0.GL_EXT_framebuffer_object || var0.OpenGL30);
  135. if (framebufferSupported) {
  136. logText = logText + "Using framebuffer objects because ";
  137. if (var0.OpenGL30) {
  138. logText = logText + "OpenGL 3.0 is supported and separate blending is supported.\n";
  139. framebufferType = 0;
  140. GL_FRAMEBUFFER = 36160;
  141. GL_RENDERBUFFER = 36161;
  142. GL_COLOR_ATTACHMENT0 = 36064;
  143. GL_DEPTH_ATTACHMENT = 36096;
  144. GL_FRAMEBUFFER_COMPLETE = 36053;
  145. GL_FB_INCOMPLETE_ATTACHMENT = 36054;
  146. GL_FB_INCOMPLETE_MISS_ATTACH = 36055;
  147. GL_FB_INCOMPLETE_DRAW_BUFFER = 36059;
  148. GL_FB_INCOMPLETE_READ_BUFFER = 36060;
  149. } else if (var0.GL_ARB_framebuffer_object) {
  150. logText = logText + "ARB_framebuffer_object is supported and separate blending is supported.\n";
  151. framebufferType = 1;
  152. GL_FRAMEBUFFER = 36160;
  153. GL_RENDERBUFFER = 36161;
  154. GL_COLOR_ATTACHMENT0 = 36064;
  155. GL_DEPTH_ATTACHMENT = 36096;
  156. GL_FRAMEBUFFER_COMPLETE = 36053;
  157. GL_FB_INCOMPLETE_MISS_ATTACH = 36055;
  158. GL_FB_INCOMPLETE_ATTACHMENT = 36054;
  159. GL_FB_INCOMPLETE_DRAW_BUFFER = 36059;
  160. GL_FB_INCOMPLETE_READ_BUFFER = 36060;
  161. } else if (var0.GL_EXT_framebuffer_object) {
  162. logText = logText + "EXT_framebuffer_object is supported.\n";
  163. framebufferType = 2;
  164. GL_FRAMEBUFFER = 36160;
  165. GL_RENDERBUFFER = 36161;
  166. GL_COLOR_ATTACHMENT0 = 36064;
  167. GL_DEPTH_ATTACHMENT = 36096;
  168. GL_FRAMEBUFFER_COMPLETE = 36053;
  169. GL_FB_INCOMPLETE_MISS_ATTACH = 36055;
  170. GL_FB_INCOMPLETE_ATTACHMENT = 36054;
  171. GL_FB_INCOMPLETE_DRAW_BUFFER = 36059;
  172. GL_FB_INCOMPLETE_READ_BUFFER = 36060;
  173. }
  174. } else {
  175. logText = logText + "Not using framebuffer objects because ";
  176. logText = logText + "OpenGL 1.4 is " + (var0.OpenGL14 ? "" : "not ") + "supported, ";
  177. logText = logText + "EXT_blend_func_separate is " + (var0.GL_EXT_blend_func_separate ? "" : "not ") + "supported, ";
  178. logText = logText + "OpenGL 3.0 is " + (var0.OpenGL30 ? "" : "not ") + "supported, ";
  179. logText = logText + "ARB_framebuffer_object is " + (var0.GL_ARB_framebuffer_object ? "" : "not ") + "supported, and ";
  180. logText = logText + "EXT_framebuffer_object is " + (var0.GL_EXT_framebuffer_object ? "" : "not ") + "supported.\n";
  181. }
  182. openGL21 = var0.OpenGL21;
  183. shadersAvailable = openGL21 || var0.GL_ARB_vertex_shader && var0.GL_ARB_fragment_shader && var0.GL_ARB_shader_objects;
  184. logText = logText + "Shaders are " + (shadersAvailable ? "" : "not ") + "available because ";
  185. if (shadersAvailable) {
  186. if (var0.OpenGL21) {
  187. logText = logText + "OpenGL 2.1 is supported.\n";
  188. arbShaders = false;
  189. GL_LINK_STATUS = 35714;
  190. GL_COMPILE_STATUS = 35713;
  191. GL_VERTEX_SHADER = 35633;
  192. GL_FRAGMENT_SHADER = 35632;
  193. } else {
  194. logText = logText + "ARB_shader_objects, ARB_vertex_shader, and ARB_fragment_shader are supported.\n";
  195. arbShaders = true;
  196. GL_LINK_STATUS = 35714;
  197. GL_COMPILE_STATUS = 35713;
  198. GL_VERTEX_SHADER = 35633;
  199. GL_FRAGMENT_SHADER = 35632;
  200. }
  201. } else {
  202. logText = logText + "OpenGL 2.1 is " + (var0.OpenGL21 ? "" : "not ") + "supported, ";
  203. logText = logText + "ARB_shader_objects is " + (var0.GL_ARB_shader_objects ? "" : "not ") + "supported, ";
  204. logText = logText + "ARB_vertex_shader is " + (var0.GL_ARB_vertex_shader ? "" : "not ") + "supported, and ";
  205. logText = logText + "ARB_fragment_shader is " + (var0.GL_ARB_fragment_shader ? "" : "not ") + "supported.\n";
  206. }
  207. shadersSupported = framebufferSupported && shadersAvailable;
  208. nvidia = GL11.glGetString(GL11.GL_VENDOR).toLowerCase().contains("nvidia");
  209. arbVbo = !var0.OpenGL15 && var0.GL_ARB_vertex_buffer_object;
  210. vboSupported = var0.OpenGL15 || arbVbo;
  211. logText = logText + "VBOs are " + (vboSupported ? "" : "not ") + "available because ";
  212. if (vboSupported) {
  213. if (arbVbo) {
  214. logText = logText + "ARB_vertex_buffer_object is supported.\n";
  215. GL_STATIC_DRAW = 35044;
  216. GL_ARRAY_BUFFER = 34962;
  217. } else {
  218. logText = logText + "OpenGL 1.5 is supported.\n";
  219. GL_STATIC_DRAW = 35044;
  220. GL_ARRAY_BUFFER = 34962;
  221. }
  222. }
  223. }
  224. public static boolean areShadersSupported() {
  225. return shadersSupported;
  226. }
  227. public static String getLogText() {
  228. return logText;
  229. }
  230. public static int glGetProgrami(int program, int pname) {
  231. return arbShaders ? ARBShaderObjects.glGetObjectParameteriARB(program, pname) : GL20.glGetProgrami(program, pname);
  232. }
  233. public static void glAttachShader(int program, int shaderIn) {
  234. if (arbShaders) {
  235. ARBShaderObjects.glAttachObjectARB(program, shaderIn);
  236. } else {
  237. GL20.glAttachShader(program, shaderIn);
  238. }
  239. }
  240. public static void glDeleteShader(int p_153180_0_) {
  241. if (arbShaders) {
  242. ARBShaderObjects.glDeleteObjectARB(p_153180_0_);
  243. } else {
  244. GL20.glDeleteShader(p_153180_0_);
  245. }
  246. }
  247. /**
  248. * creates a shader with the given mode and returns the GL id. params: mode
  249. */
  250. public static int glCreateShader(int type) {
  251. return arbShaders ? ARBShaderObjects.glCreateShaderObjectARB(type) : GL20.glCreateShader(type);
  252. }
  253. public static void glShaderSource(int shaderIn, ByteBuffer string) {
  254. if (arbShaders) {
  255. ARBShaderObjects.glShaderSourceARB(shaderIn, string);
  256. } else {
  257. GL20.glShaderSource(shaderIn, string);
  258. }
  259. }
  260. public static void glCompileShader(int shaderIn) {
  261. if (arbShaders) {
  262. ARBShaderObjects.glCompileShaderARB(shaderIn);
  263. } else {
  264. GL20.glCompileShader(shaderIn);
  265. }
  266. }
  267. public static int glGetShaderi(int shaderIn, int pname) {
  268. return arbShaders ? ARBShaderObjects.glGetObjectParameteriARB(shaderIn, pname) : GL20.glGetShaderi(shaderIn, pname);
  269. }
  270. public static String glGetShaderInfoLog(int shaderIn, int maxLength) {
  271. return arbShaders ? ARBShaderObjects.glGetInfoLogARB(shaderIn, maxLength) : GL20.glGetShaderInfoLog(shaderIn, maxLength);
  272. }
  273. public static String glGetProgramInfoLog(int program, int maxLength) {
  274. return arbShaders ? ARBShaderObjects.glGetInfoLogARB(program, maxLength) : GL20.glGetProgramInfoLog(program, maxLength);
  275. }
  276. public static void glUseProgram(int program) {
  277. if (arbShaders) {
  278. ARBShaderObjects.glUseProgramObjectARB(program);
  279. } else {
  280. GL20.glUseProgram(program);
  281. }
  282. }
  283. public static int glCreateProgram() {
  284. return arbShaders ? ARBShaderObjects.glCreateProgramObjectARB() : GL20.glCreateProgram();
  285. }
  286. public static void glDeleteProgram(int program) {
  287. if (arbShaders) {
  288. ARBShaderObjects.glDeleteObjectARB(program);
  289. } else {
  290. GL20.glDeleteProgram(program);
  291. }
  292. }
  293. public static void glLinkProgram(int program) {
  294. if (arbShaders) {
  295. ARBShaderObjects.glLinkProgramARB(program);
  296. } else {
  297. GL20.glLinkProgram(program);
  298. }
  299. }
  300. public static int glGetUniformLocation(int programObj, CharSequence name) {
  301. return arbShaders ? ARBShaderObjects.glGetUniformLocationARB(programObj, name) : GL20.glGetUniformLocation(programObj, name);
  302. }
  303. public static void glUniform1(int location, IntBuffer values) {
  304. if (arbShaders) {
  305. ARBShaderObjects.glUniform1ARB(location, values);
  306. } else {
  307. GL20.glUniform1(location, values);
  308. }
  309. }
  310. public static void glUniform1i(int location, int v0) {
  311. if (arbShaders) {
  312. ARBShaderObjects.glUniform1iARB(location, v0);
  313. } else {
  314. GL20.glUniform1i(location, v0);
  315. }
  316. }
  317. public static void glUniform1(int location, FloatBuffer values) {
  318. if (arbShaders) {
  319. ARBShaderObjects.glUniform1ARB(location, values);
  320. } else {
  321. GL20.glUniform1(location, values);
  322. }
  323. }
  324. public static void glUniform2(int location, IntBuffer values) {
  325. if (arbShaders) {
  326. ARBShaderObjects.glUniform2ARB(location, values);
  327. } else {
  328. GL20.glUniform2(location, values);
  329. }
  330. }
  331. public static void glUniform2(int location, FloatBuffer values) {
  332. if (arbShaders) {
  333. ARBShaderObjects.glUniform2ARB(location, values);
  334. } else {
  335. GL20.glUniform2(location, values);
  336. }
  337. }
  338. public static void glUniform3(int location, IntBuffer values) {
  339. if (arbShaders) {
  340. ARBShaderObjects.glUniform3ARB(location, values);
  341. } else {
  342. GL20.glUniform3(location, values);
  343. }
  344. }
  345. public static void glUniform3(int location, FloatBuffer values) {
  346. if (arbShaders) {
  347. ARBShaderObjects.glUniform3ARB(location, values);
  348. } else {
  349. GL20.glUniform3(location, values);
  350. }
  351. }
  352. public static void glUniform4(int location, IntBuffer values) {
  353. if (arbShaders) {
  354. ARBShaderObjects.glUniform4ARB(location, values);
  355. } else {
  356. GL20.glUniform4(location, values);
  357. }
  358. }
  359. public static void glUniform4(int location, FloatBuffer values) {
  360. if (arbShaders) {
  361. ARBShaderObjects.glUniform4ARB(location, values);
  362. } else {
  363. GL20.glUniform4(location, values);
  364. }
  365. }
  366. public static void glUniformMatrix2(int location, boolean transpose, FloatBuffer matrices) {
  367. if (arbShaders) {
  368. ARBShaderObjects.glUniformMatrix2ARB(location, transpose, matrices);
  369. } else {
  370. GL20.glUniformMatrix2(location, transpose, matrices);
  371. }
  372. }
  373. public static void glUniformMatrix3(int location, boolean transpose, FloatBuffer matrices) {
  374. if (arbShaders) {
  375. ARBShaderObjects.glUniformMatrix3ARB(location, transpose, matrices);
  376. } else {
  377. GL20.glUniformMatrix3(location, transpose, matrices);
  378. }
  379. }
  380. public static void glUniformMatrix4(int location, boolean transpose, FloatBuffer matrices) {
  381. if (arbShaders) {
  382. ARBShaderObjects.glUniformMatrix4ARB(location, transpose, matrices);
  383. } else {
  384. GL20.glUniformMatrix4(location, transpose, matrices);
  385. }
  386. }
  387. public static int glGetAttribLocation(int p_153164_0_, CharSequence p_153164_1_) {
  388. return arbShaders ? ARBVertexShader.glGetAttribLocationARB(p_153164_0_, p_153164_1_) : GL20.glGetAttribLocation(p_153164_0_, p_153164_1_);
  389. }
  390. public static int glGenBuffers() {
  391. return arbVbo ? ARBVertexBufferObject.glGenBuffersARB() : GL15.glGenBuffers();
  392. }
  393. public static void glBindBuffer(int target, int buffer) {
  394. if (arbVbo) {
  395. ARBVertexBufferObject.glBindBufferARB(target, buffer);
  396. } else {
  397. GL15.glBindBuffer(target, buffer);
  398. }
  399. }
  400. public static void glBufferData(int target, ByteBuffer data, int usage) {
  401. if (arbVbo) {
  402. ARBVertexBufferObject.glBufferDataARB(target, data, usage);
  403. } else {
  404. GL15.glBufferData(target, data, usage);
  405. }
  406. }
  407. public static void glDeleteBuffers(int buffer) {
  408. if (arbVbo) {
  409. ARBVertexBufferObject.glDeleteBuffersARB(buffer);
  410. } else {
  411. GL15.glDeleteBuffers(buffer);
  412. }
  413. }
  414. public static boolean useVbo() {
  415. return !Config.isMultiTexture() && (vboSupported && Minecraft.getMinecraft().gameSettings.useVbo);
  416. }
  417. public static void glBindFramebuffer(int target, int framebufferIn) {
  418. if (framebufferSupported) {
  419. switch (framebufferType) {
  420. case 0:
  421. GL30.glBindFramebuffer(target, framebufferIn);
  422. break;
  423. case 1:
  424. ARBFramebufferObject.glBindFramebuffer(target, framebufferIn);
  425. break;
  426. case 2:
  427. EXTFramebufferObject.glBindFramebufferEXT(target, framebufferIn);
  428. }
  429. }
  430. }
  431. public static void glBindRenderbuffer(int target, int renderbuffer) {
  432. if (framebufferSupported) {
  433. switch (framebufferType) {
  434. case 0:
  435. GL30.glBindRenderbuffer(target, renderbuffer);
  436. break;
  437. case 1:
  438. ARBFramebufferObject.glBindRenderbuffer(target, renderbuffer);
  439. break;
  440. case 2:
  441. EXTFramebufferObject.glBindRenderbufferEXT(target, renderbuffer);
  442. }
  443. }
  444. }
  445. public static void glDeleteRenderbuffers(int renderbuffer) {
  446. if (framebufferSupported) {
  447. switch (framebufferType) {
  448. case 0:
  449. GL30.glDeleteRenderbuffers(renderbuffer);
  450. break;
  451. case 1:
  452. ARBFramebufferObject.glDeleteRenderbuffers(renderbuffer);
  453. break;
  454. case 2:
  455. EXTFramebufferObject.glDeleteRenderbuffersEXT(renderbuffer);
  456. }
  457. }
  458. }
  459. public static void glDeleteFramebuffers(int framebufferIn) {
  460. if (framebufferSupported) {
  461. switch (framebufferType) {
  462. case 0:
  463. GL30.glDeleteFramebuffers(framebufferIn);
  464. break;
  465. case 1:
  466. ARBFramebufferObject.glDeleteFramebuffers(framebufferIn);
  467. break;
  468. case 2:
  469. EXTFramebufferObject.glDeleteFramebuffersEXT(framebufferIn);
  470. }
  471. }
  472. }
  473. /**
  474. * Calls the appropriate glGenFramebuffers method and returns the newly created fbo, or returns -1 if not supported.
  475. */
  476. public static int glGenFramebuffers() {
  477. if (!framebufferSupported) {
  478. return -1;
  479. } else {
  480. switch (framebufferType) {
  481. case 0:
  482. return GL30.glGenFramebuffers();
  483. case 1:
  484. return ARBFramebufferObject.glGenFramebuffers();
  485. case 2:
  486. return EXTFramebufferObject.glGenFramebuffersEXT();
  487. default:
  488. return -1;
  489. }
  490. }
  491. }
  492. public static int glGenRenderbuffers() {
  493. if (!framebufferSupported) {
  494. return -1;
  495. } else {
  496. switch (framebufferType) {
  497. case 0:
  498. return GL30.glGenRenderbuffers();
  499. case 1:
  500. return ARBFramebufferObject.glGenRenderbuffers();
  501. case 2:
  502. return EXTFramebufferObject.glGenRenderbuffersEXT();
  503. default:
  504. return -1;
  505. }
  506. }
  507. }
  508. public static void glRenderbufferStorage(int target, int internalFormat, int width, int height) {
  509. if (framebufferSupported) {
  510. switch (framebufferType) {
  511. case 0:
  512. GL30.glRenderbufferStorage(target, internalFormat, width, height);
  513. break;
  514. case 1:
  515. ARBFramebufferObject.glRenderbufferStorage(target, internalFormat, width, height);
  516. break;
  517. case 2:
  518. EXTFramebufferObject.glRenderbufferStorageEXT(target, internalFormat, width, height);
  519. }
  520. }
  521. }
  522. public static void glFramebufferRenderbuffer(int target, int attachment, int renderBufferTarget, int renderBuffer) {
  523. if (framebufferSupported) {
  524. switch (framebufferType) {
  525. case 0:
  526. GL30.glFramebufferRenderbuffer(target, attachment, renderBufferTarget, renderBuffer);
  527. break;
  528. case 1:
  529. ARBFramebufferObject.glFramebufferRenderbuffer(target, attachment, renderBufferTarget, renderBuffer);
  530. break;
  531. case 2:
  532. EXTFramebufferObject.glFramebufferRenderbufferEXT(target, attachment, renderBufferTarget, renderBuffer);
  533. }
  534. }
  535. }
  536. public static int glCheckFramebufferStatus(int target) {
  537. if (!framebufferSupported) {
  538. return -1;
  539. } else {
  540. switch (framebufferType) {
  541. case 0:
  542. return GL30.glCheckFramebufferStatus(target);
  543. case 1:
  544. return ARBFramebufferObject.glCheckFramebufferStatus(target);
  545. case 2:
  546. return EXTFramebufferObject.glCheckFramebufferStatusEXT(target);
  547. default:
  548. return -1;
  549. }
  550. }
  551. }
  552. public static void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level) {
  553. if (framebufferSupported) {
  554. switch (framebufferType) {
  555. case 0:
  556. GL30.glFramebufferTexture2D(target, attachment, textarget, texture, level);
  557. break;
  558. case 1:
  559. ARBFramebufferObject.glFramebufferTexture2D(target, attachment, textarget, texture, level);
  560. break;
  561. case 2:
  562. EXTFramebufferObject.glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
  563. }
  564. }
  565. }
  566. /**
  567. * Sets the current lightmap texture to the specified OpenGL constant
  568. */
  569. public static void setActiveTexture(int texture) {
  570. if (arbMultitexture) {
  571. ARBMultitexture.glActiveTextureARB(texture);
  572. } else {
  573. GL13.glActiveTexture(texture);
  574. }
  575. }
  576. /**
  577. * Sets the current lightmap texture to the specified OpenGL constant
  578. */
  579. public static void setClientActiveTexture(int texture) {
  580. if (arbMultitexture) {
  581. ARBMultitexture.glClientActiveTextureARB(texture);
  582. } else {
  583. GL13.glClientActiveTexture(texture);
  584. }
  585. }
  586. /**
  587. * Sets the current coordinates of the given lightmap texture
  588. */
  589. public static void setLightmapTextureCoords(int target, float p_77475_1_, float p_77475_2_) {
  590. if (arbMultitexture) {
  591. ARBMultitexture.glMultiTexCoord2fARB(target, p_77475_1_, p_77475_2_);
  592. } else {
  593. GL13.glMultiTexCoord2f(target, p_77475_1_, p_77475_2_);
  594. }
  595. if (target == lightmapTexUnit) {
  596. lastBrightnessX = p_77475_1_;
  597. lastBrightnessY = p_77475_2_;
  598. }
  599. }
  600. public static void glBlendFunc(int sFactorRGB, int dFactorRGB, int sfactorAlpha, int dfactorAlpha) {
  601. if (openGL14) {
  602. if (extBlendFuncSeparate) {
  603. EXTBlendFuncSeparate.glBlendFuncSeparateEXT(sFactorRGB, dFactorRGB, sfactorAlpha, dfactorAlpha);
  604. } else {
  605. GL14.glBlendFuncSeparate(sFactorRGB, dFactorRGB, sfactorAlpha, dfactorAlpha);
  606. }
  607. } else {
  608. GL11.glBlendFunc(sFactorRGB, dFactorRGB);
  609. }
  610. }
  611. public static boolean isFramebufferEnabled() {
  612. return !Config.isFastRender() && (!Config.isAntialiasing() && (framebufferSupported && Minecraft.getMinecraft().gameSettings.fboEnable));
  613. }
  614. }