| 1 | package com.mojang.renderpearl.backend.opengl;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.systems.RenderSystem;
|
| 4 | import com.mojang.jtracy.Plot;
|
| 5 | import com.mojang.jtracy.TracyClient;
|
| 6 | import com.mojang.renderpearl.api.pipeline.ColorTargetState;
|
| 7 | import java.nio.ByteBuffer;
|
| 8 | import java.nio.charset.StandardCharsets;
|
| 9 | import java.util.Arrays;
|
| 10 | import java.util.stream.IntStream;
|
| 11 | import net.fabricmc.api.EnvType;
|
| 12 | import net.fabricmc.api.Environment;
|
| 13 | import net.minecraft.util.Util;
|
| 14 | import net.minecraft.util.Util.OS;
|
| 15 | import org.joml.Vector4fc;
|
| 16 | import org.jspecify.annotations.Nullable;
|
| 17 | import org.lwjgl.PointerBuffer;
|
| 18 | import org.lwjgl.opengl.GL33C;
|
| 19 | import org.lwjgl.system.MemoryStack;
|
| 20 | import org.lwjgl.system.MemoryUtil;
|
| 21 |
|
| 22 | @Environment(EnvType.CLIENT)
|
| 23 | public class GlStateManager {
|
| 24 | private static final Plot PLOT_TEXTURES = TracyClient.createPlot("GPU Textures");
|
| 25 | private static int numTextures = 0;
|
| 26 | private static final Plot PLOT_BUFFERS = TracyClient.createPlot("GPU Buffers");
|
| 27 | private static int numBuffers = 0;
|
| 28 | private static final boolean IS_MACOS = Util.getPlatform() == OS.OSX;
|
| 29 | private static final GlStateManager.BlendState BLEND = new GlStateManager.BlendState();
|
| 30 | private static final boolean[] BLEND_ENABLE = new boolean[8];
|
| 31 | private static final GlStateManager.DepthState DEPTH = new GlStateManager.DepthState();
|
| 32 | private static final GlStateManager.CullState CULL = new GlStateManager.CullState();
|
| 33 | private static final GlStateManager.PolygonOffsetState POLY_OFFSET = new GlStateManager.PolygonOffsetState();
|
| 34 | private static final GlStateManager.ColorLogicState COLOR_LOGIC = new GlStateManager.ColorLogicState();
|
| 35 | private static final GlStateManager.ScissorState SCISSOR = new GlStateManager.ScissorState();
|
| 36 | private static int activeTexture;
|
| 37 | private static final int TEXTURE_COUNT = 12;
|
| 38 | private static final GlStateManager.TextureState[] TEXTURES = IntStream.range(0, 12)
|
| 39 | .mapToObj(i -> new GlStateManager.TextureState())
|
| 40 | .toArray(GlStateManager.TextureState[]::new);
|
| 41 | private static final @ColorTargetState.WriteMask int[] COLOR_MASK = new int[8];
|
| 42 | private static int readFbo;
|
| 43 | private static int writeFbo;
|
| 44 |
|
| 45 | public static void _disableScissorTest() {
|
| 46 | RenderSystem.assertOnRenderThread();
|
| 47 | SCISSOR.mode.disable();
|
| 48 | }
|
| 49 |
|
| 50 | public static void _enableScissorTest() {
|
| 51 | RenderSystem.assertOnRenderThread();
|
| 52 | SCISSOR.mode.enable();
|
| 53 | }
|
| 54 |
|
| 55 | public static void _scissorBox(final int x, final int y, final int width, final int height) {
|
| 56 | RenderSystem.assertOnRenderThread();
|
| 57 | GL33C.glScissor(x, y, width, height);
|
| 58 | }
|
| 59 |
|
| 60 | public static void _disableDepthTest() {
|
| 61 | RenderSystem.assertOnRenderThread();
|
| 62 | DEPTH.mode.disable();
|
| 63 | }
|
| 64 |
|
| 65 | public static void _enableDepthTest() {
|
| 66 | RenderSystem.assertOnRenderThread();
|
| 67 | DEPTH.mode.enable();
|
| 68 | }
|
| 69 |
|
| 70 | public static void _depthFunc(final int func) {
|
| 71 | RenderSystem.assertOnRenderThread();
|
| 72 | if (func != DEPTH.func) {
|
| 73 | DEPTH.func = func;
|
| 74 | GL33C.glDepthFunc(func);
|
| 75 | }
|
| 76 | }
|
| 77 |
|
| 78 | public static void _depthMask(final boolean mask) {
|
| 79 | RenderSystem.assertOnRenderThread();
|
| 80 | if (mask != DEPTH.mask) {
|
| 81 | DEPTH.mask = mask;
|
| 82 | GL33C.glDepthMask(mask);
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | public static void _disableBlend(final int index) {
|
| 87 | RenderSystem.assertOnRenderThread();
|
| 88 | if (BLEND_ENABLE[index]) {
|
| 89 | BLEND_ENABLE[index] = false;
|
| 90 | GL33C.glDisablei(3042, index);
|
| 91 | }
|
| 92 | }
|
| 93 |
|
| 94 | public static void _enableBlend(final int index) {
|
| 95 | RenderSystem.assertOnRenderThread();
|
| 96 | if (!BLEND_ENABLE[index]) {
|
| 97 | BLEND_ENABLE[index] = true;
|
| 98 | GL33C.glEnablei(3042, index);
|
| 99 | }
|
| 100 | }
|
| 101 |
|
| 102 | public static void _blendFuncSeparate(final int srcRgb, final int dstRgb, final int srcAlpha, final int dstAlpha) {
|
| 103 | RenderSystem.assertOnRenderThread();
|
| 104 | if (srcRgb != BLEND.srcRgb || dstRgb != BLEND.dstRgb || srcAlpha != BLEND.srcAlpha || dstAlpha != BLEND.dstAlpha) {
|
| 105 | BLEND.srcRgb = srcRgb;
|
| 106 | BLEND.dstRgb = dstRgb;
|
| 107 | BLEND.srcAlpha = srcAlpha;
|
| 108 | BLEND.dstAlpha = dstAlpha;
|
| 109 | glBlendFuncSeparate(srcRgb, dstRgb, srcAlpha, dstAlpha);
|
| 110 | }
|
| 111 | }
|
| 112 |
|
| 113 | public static void _blendEquationSeparate(final int modeRgb, final int modeAlpha) {
|
| 114 | RenderSystem.assertOnRenderThread();
|
| 115 | if (modeRgb != BLEND.modeRgb || modeAlpha != BLEND.modeAlpha) {
|
| 116 | BLEND.modeRgb = modeRgb;
|
| 117 | BLEND.modeAlpha = modeAlpha;
|
| 118 | glBlendEquationSeparate(modeRgb, modeAlpha);
|
| 119 | }
|
| 120 | }
|
| 121 |
|
| 122 | public static int glGetProgrami(final int program, final int pname) {
|
| 123 | RenderSystem.assertOnRenderThread();
|
| 124 | return GL33C.glGetProgrami(program, pname);
|
| 125 | }
|
| 126 |
|
| 127 | public static void glAttachShader(final int program, final int shader) {
|
| 128 | RenderSystem.assertOnRenderThread();
|
| 129 | GL33C.glAttachShader(program, shader);
|
| 130 | }
|
| 131 |
|
| 132 | public static void glDeleteShader(final int shader) {
|
| 133 | RenderSystem.assertOnRenderThread();
|
| 134 | GL33C.glDeleteShader(shader);
|
| 135 | }
|
| 136 |
|
| 137 | public static int glCreateShader(final int type) {
|
| 138 | RenderSystem.assertOnRenderThread();
|
| 139 | return GL33C.glCreateShader(type);
|
| 140 | }
|
| 141 |
|
| 142 | public static void glShaderSource(final int shader, final String source) {
|
| 143 | RenderSystem.assertOnRenderThread();
|
| 144 | byte[] encoded = source.getBytes(StandardCharsets.UTF_8);
|
| 145 | ByteBuffer buffer = MemoryUtil.memAlloc(encoded.length + 1);
|
| 146 | buffer.put(encoded);
|
| 147 | buffer.put((byte)0);
|
| 148 | buffer.flip();
|
| 149 |
|
| 150 | try (MemoryStack stack = MemoryStack.stackPush()) {
|
| 151 | PointerBuffer pointers = stack.mallocPointer(1);
|
| 152 | pointers.put(buffer);
|
| 153 | GL33C.nglShaderSource(shader, 1, pointers.address0(), 0L);
|
| 154 | } finally {
|
| 155 | MemoryUtil.memFree(buffer);
|
| 156 | }
|
| 157 | }
|
| 158 |
|
| 159 | public static void glCompileShader(final int shader) {
|
| 160 | RenderSystem.assertOnRenderThread();
|
| 161 | GL33C.glCompileShader(shader);
|
| 162 | }
|
| 163 |
|
| 164 | public static int glGetShaderi(final int shader, final int pname) {
|
| 165 | RenderSystem.assertOnRenderThread();
|
| 166 | return GL33C.glGetShaderi(shader, pname);
|
| 167 | }
|
| 168 |
|
| 169 | public static void _glUseProgram(final int program) {
|
| 170 | RenderSystem.assertOnRenderThread();
|
| 171 | GL33C.glUseProgram(program);
|
| 172 | }
|
| 173 |
|
| 174 | public static int glCreateProgram() {
|
| 175 | RenderSystem.assertOnRenderThread();
|
| 176 | return GL33C.glCreateProgram();
|
| 177 | }
|
| 178 |
|
| 179 | public static void glDeleteProgram(final int program) {
|
| 180 | RenderSystem.assertOnRenderThread();
|
| 181 | GL33C.glDeleteProgram(program);
|
| 182 | }
|
| 183 |
|
| 184 | public static void glLinkProgram(final int program) {
|
| 185 | RenderSystem.assertOnRenderThread();
|
| 186 | GL33C.glLinkProgram(program);
|
| 187 | }
|
| 188 |
|
| 189 | public static int _glGetUniformLocation(final int program, final CharSequence name) {
|
| 190 | RenderSystem.assertOnRenderThread();
|
| 191 | return GL33C.glGetUniformLocation(program, name);
|
| 192 | }
|
| 193 |
|
| 194 | public static void _glUniform1i(final int location, final int v0) {
|
| 195 | RenderSystem.assertOnRenderThread();
|
| 196 | GL33C.glUniform1i(location, v0);
|
| 197 | }
|
| 198 |
|
| 199 | public static void _glBindAttribLocation(final int program, final int location, final CharSequence name) {
|
| 200 | RenderSystem.assertOnRenderThread();
|
| 201 | GL33C.glBindAttribLocation(program, location, name);
|
| 202 | }
|
| 203 |
|
| 204 | static void incrementTrackedBuffers() {
|
| 205 | numBuffers++;
|
| 206 | PLOT_BUFFERS.setValue(numBuffers);
|
| 207 | }
|
| 208 |
|
| 209 | public static int _glGenBuffers() {
|
| 210 | RenderSystem.assertOnRenderThread();
|
| 211 | incrementTrackedBuffers();
|
| 212 | return GL33C.glGenBuffers();
|
| 213 | }
|
| 214 |
|
| 215 | public static int _glGenVertexArrays() {
|
| 216 | RenderSystem.assertOnRenderThread();
|
| 217 | return GL33C.glGenVertexArrays();
|
| 218 | }
|
| 219 |
|
| 220 | public static void _glBindBuffer(final int target, final int buffer) {
|
| 221 | RenderSystem.assertOnRenderThread();
|
| 222 | GL33C.glBindBuffer(target, buffer);
|
| 223 | }
|
| 224 |
|
| 225 | public static void _glBindVertexArray(final int arrayId) {
|
| 226 | RenderSystem.assertOnRenderThread();
|
| 227 | GL33C.glBindVertexArray(arrayId);
|
| 228 | }
|
| 229 |
|
| 230 | public static void _glBufferData(final int target, final ByteBuffer data, final int usage) {
|
| 231 | RenderSystem.assertOnRenderThread();
|
| 232 | GL33C.glBufferData(target, data, usage);
|
| 233 | }
|
| 234 |
|
| 235 | public static void _glBufferSubData(final int target, final long offset, final ByteBuffer data) {
|
| 236 | RenderSystem.assertOnRenderThread();
|
| 237 | GL33C.glBufferSubData(target, offset, data);
|
| 238 | }
|
| 239 |
|
| 240 | public static void _glBufferData(final int target, final long size, final int usage) {
|
| 241 | RenderSystem.assertOnRenderThread();
|
| 242 | GL33C.glBufferData(target, size, usage);
|
| 243 | }
|
| 244 |
|
| 245 | public static @Nullable ByteBuffer _glMapBufferRange(final int target, final long offset, final long length, final int access) {
|
| 246 | RenderSystem.assertOnRenderThread();
|
| 247 | return GL33C.glMapBufferRange(target, offset, length, access);
|
| 248 | }
|
| 249 |
|
| 250 | public static void _glUnmapBuffer(final int target) {
|
| 251 | RenderSystem.assertOnRenderThread();
|
| 252 | GL33C.glUnmapBuffer(target);
|
| 253 | }
|
| 254 |
|
| 255 | public static void _glDeleteBuffers(final int buffer) {
|
| 256 | RenderSystem.assertOnRenderThread();
|
| 257 | numBuffers--;
|
| 258 | PLOT_BUFFERS.setValue(numBuffers);
|
| 259 | GL33C.glDeleteBuffers(buffer);
|
| 260 | }
|
| 261 |
|
| 262 | public static void _glBindFramebuffer(final int target, final int framebuffer) {
|
| 263 | if ((target == 36008 || target == 36160) && readFbo != framebuffer) {
|
| 264 | GL33C.glBindFramebuffer(36008, framebuffer);
|
| 265 | readFbo = framebuffer;
|
| 266 | }
|
| 267 |
|
| 268 | if ((target == 36009 || target == 36160) && writeFbo != framebuffer) {
|
| 269 | GL33C.glBindFramebuffer(36009, framebuffer);
|
| 270 | writeFbo = framebuffer;
|
| 271 | }
|
| 272 | }
|
| 273 |
|
| 274 | public static int getFrameBuffer(final int target) {
|
| 275 | if (target == 36008) {
|
| 276 | return readFbo;
|
| 277 | } else {
|
| 278 | return target == 36009 ? writeFbo : 0;
|
| 279 | }
|
| 280 | }
|
| 281 |
|
| 282 | public static void _glBlitFrameBuffer(
|
| 283 | final int srcX0,
|
| 284 | final int srcY0,
|
| 285 | final int srcX1,
|
| 286 | final int srcY1,
|
| 287 | final int dstX0,
|
| 288 | final int dstY0,
|
| 289 | final int dstX1,
|
| 290 | final int dstY1,
|
| 291 | final int mask,
|
| 292 | final int filter
|
| 293 | ) {
|
| 294 | RenderSystem.assertOnRenderThread();
|
| 295 | GL33C.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
|
| 296 | }
|
| 297 |
|
| 298 | public static void _glDeleteFramebuffers(final int framebuffer) {
|
| 299 | RenderSystem.assertOnRenderThread();
|
| 300 | GL33C.glDeleteFramebuffers(framebuffer);
|
| 301 | if (readFbo == framebuffer) {
|
| 302 | readFbo = 0;
|
| 303 | }
|
| 304 |
|
| 305 | if (writeFbo == framebuffer) {
|
| 306 | writeFbo = 0;
|
| 307 | }
|
| 308 | }
|
| 309 |
|
| 310 | public static int glGenFramebuffers() {
|
| 311 | RenderSystem.assertOnRenderThread();
|
| 312 | return GL33C.glGenFramebuffers();
|
| 313 | }
|
| 314 |
|
| 315 | public static void _glFramebufferTexture2D(final int target, final int attachment, final int textarget, final int texture, final int level) {
|
| 316 | RenderSystem.assertOnRenderThread();
|
| 317 | GL33C.glFramebufferTexture2D(target, attachment, textarget, texture, level);
|
| 318 | }
|
| 319 |
|
| 320 | public static void _glReadBuffer(final int mode) {
|
| 321 | RenderSystem.assertOnRenderThread();
|
| 322 | GL33C.glReadBuffer(mode);
|
| 323 | }
|
| 324 |
|
| 325 | public static void glBlendFuncSeparate(final int srcColor, final int dstColor, final int srcAlpha, final int dstAlpha) {
|
| 326 | RenderSystem.assertOnRenderThread();
|
| 327 | GL33C.glBlendFuncSeparate(srcColor, dstColor, srcAlpha, dstAlpha);
|
| 328 | }
|
| 329 |
|
| 330 | public static void glBlendEquationSeparate(final int modeRgb, final int modeAlpha) {
|
| 331 | RenderSystem.assertOnRenderThread();
|
| 332 | GL33C.glBlendEquationSeparate(modeRgb, modeAlpha);
|
| 333 | }
|
| 334 |
|
| 335 | public static String glGetShaderInfoLog(final int shader, final int maxLength) {
|
| 336 | RenderSystem.assertOnRenderThread();
|
| 337 | return GL33C.glGetShaderInfoLog(shader, maxLength);
|
| 338 | }
|
| 339 |
|
| 340 | public static String glGetProgramInfoLog(final int program, final int maxLength) {
|
| 341 | RenderSystem.assertOnRenderThread();
|
| 342 | return GL33C.glGetProgramInfoLog(program, maxLength);
|
| 343 | }
|
| 344 |
|
| 345 | public static void _enableCull() {
|
| 346 | RenderSystem.assertOnRenderThread();
|
| 347 | CULL.enable.enable();
|
| 348 | }
|
| 349 |
|
| 350 | public static void _disableCull() {
|
| 351 | RenderSystem.assertOnRenderThread();
|
| 352 | CULL.enable.disable();
|
| 353 | }
|
| 354 |
|
| 355 | public static void _polygonMode(final int face, final int mode) {
|
| 356 | RenderSystem.assertOnRenderThread();
|
| 357 | GL33C.glPolygonMode(face, mode);
|
| 358 | }
|
| 359 |
|
| 360 | public static void _enablePolygonOffset() {
|
| 361 | RenderSystem.assertOnRenderThread();
|
| 362 | POLY_OFFSET.fill.enable();
|
| 363 | }
|
| 364 |
|
| 365 | public static void _disablePolygonOffset() {
|
| 366 | RenderSystem.assertOnRenderThread();
|
| 367 | POLY_OFFSET.fill.disable();
|
| 368 | }
|
| 369 |
|
| 370 | public static void _polygonOffset(final float factor, final float units) {
|
| 371 | RenderSystem.assertOnRenderThread();
|
| 372 | if (factor != POLY_OFFSET.factor || units != POLY_OFFSET.units) {
|
| 373 | POLY_OFFSET.factor = factor;
|
| 374 | POLY_OFFSET.units = units;
|
| 375 | GL33C.glPolygonOffset(factor, units);
|
| 376 | }
|
| 377 | }
|
| 378 |
|
| 379 | public static void _enableColorLogicOp() {
|
| 380 | RenderSystem.assertOnRenderThread();
|
| 381 | COLOR_LOGIC.enable.enable();
|
| 382 | }
|
| 383 |
|
| 384 | public static void _disableColorLogicOp() {
|
| 385 | RenderSystem.assertOnRenderThread();
|
| 386 | COLOR_LOGIC.enable.disable();
|
| 387 | }
|
| 388 |
|
| 389 | public static void _logicOp(final int op) {
|
| 390 | RenderSystem.assertOnRenderThread();
|
| 391 | if (op != COLOR_LOGIC.op) {
|
| 392 | COLOR_LOGIC.op = op;
|
| 393 | GL33C.glLogicOp(op);
|
| 394 | }
|
| 395 | }
|
| 396 |
|
| 397 | public static void _activeTexture(final int texture) {
|
| 398 | RenderSystem.assertOnRenderThread();
|
| 399 | if (activeTexture != texture - 33984) {
|
| 400 | activeTexture = texture - 33984;
|
| 401 | GL33C.glActiveTexture(texture);
|
| 402 | }
|
| 403 | }
|
| 404 |
|
| 405 | public static void _texParameter(final int target, final int name, final int value) {
|
| 406 | RenderSystem.assertOnRenderThread();
|
| 407 | GL33C.glTexParameteri(target, name, value);
|
| 408 | }
|
| 409 |
|
| 410 | public static int _getTexLevelParameter(final int target, final int level, final int name) {
|
| 411 | return GL33C.glGetTexLevelParameteri(target, level, name);
|
| 412 | }
|
| 413 |
|
| 414 | public static int _genTexture() {
|
| 415 | RenderSystem.assertOnRenderThread();
|
| 416 | numTextures++;
|
| 417 | PLOT_TEXTURES.setValue(numTextures);
|
| 418 | return GL33C.glGenTextures();
|
| 419 | }
|
| 420 |
|
| 421 | public static void _deleteTexture(final int id) {
|
| 422 | RenderSystem.assertOnRenderThread();
|
| 423 | GL33C.glDeleteTextures(id);
|
| 424 |
|
| 425 | for (GlStateManager.TextureState state : TEXTURES) {
|
| 426 | if (state.binding == id) {
|
| 427 | state.binding = -1;
|
| 428 | }
|
| 429 | }
|
| 430 |
|
| 431 | numTextures--;
|
| 432 | PLOT_TEXTURES.setValue(numTextures);
|
| 433 | }
|
| 434 |
|
| 435 | public static void _bindTexture(final int id) {
|
| 436 | RenderSystem.assertOnRenderThread();
|
| 437 | if (id != TEXTURES[activeTexture].binding) {
|
| 438 | TEXTURES[activeTexture].binding = id;
|
| 439 | GL33C.glBindTexture(3553, id);
|
| 440 | }
|
| 441 | }
|
| 442 |
|
| 443 | public static void _texImage2D(
|
| 444 | final int target,
|
| 445 | final int level,
|
| 446 | final int internalformat,
|
| 447 | final int width,
|
| 448 | final int height,
|
| 449 | final int border,
|
| 450 | final int format,
|
| 451 | final int type,
|
| 452 | final @Nullable ByteBuffer pixels
|
| 453 | ) {
|
| 454 | RenderSystem.assertOnRenderThread();
|
| 455 | GL33C.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
| 456 | }
|
| 457 |
|
| 458 | public static void _texSubImage2D(
|
| 459 | final int target,
|
| 460 | final int level,
|
| 461 | final int xoffset,
|
| 462 | final int yoffset,
|
| 463 | final int width,
|
| 464 | final int height,
|
| 465 | final int format,
|
| 466 | final int type,
|
| 467 | final long pixels
|
| 468 | ) {
|
| 469 | RenderSystem.assertOnRenderThread();
|
| 470 | GL33C.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
|
| 471 | }
|
| 472 |
|
| 473 | public static void _texSubImage2D(
|
| 474 | final int target,
|
| 475 | final int level,
|
| 476 | final int xoffset,
|
| 477 | final int yoffset,
|
| 478 | final int width,
|
| 479 | final int height,
|
| 480 | final int format,
|
| 481 | final int type,
|
| 482 | final ByteBuffer pixels
|
| 483 | ) {
|
| 484 | RenderSystem.assertOnRenderThread();
|
| 485 | GL33C.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
|
| 486 | }
|
| 487 |
|
| 488 | public static void _viewport(final int x, final int y, final int width, final int height) {
|
| 489 | GL33C.glViewport(x, y, width, height);
|
| 490 | }
|
| 491 |
|
| 492 | public static void _colorMask(final @ColorTargetState.WriteMask int writeMask) {
|
| 493 | RenderSystem.assertOnRenderThread();
|
| 494 |
|
| 495 | for (int i = 0; i < COLOR_MASK.length; i++) {
|
| 496 | if (writeMask != COLOR_MASK[i]) {
|
| 497 | COLOR_MASK[i] = writeMask;
|
| 498 | GL33C.glColorMaski(i, (writeMask & 1) != 0, (writeMask & 2) != 0, (writeMask & 4) != 0, (writeMask & 8) != 0);
|
| 499 | }
|
| 500 | }
|
| 501 | }
|
| 502 |
|
| 503 | public static void _colorMask(final int index, final @ColorTargetState.WriteMask int writeMask) {
|
| 504 | RenderSystem.assertOnRenderThread();
|
| 505 | if (writeMask != COLOR_MASK[index]) {
|
| 506 | COLOR_MASK[index] = writeMask;
|
| 507 | GL33C.glColorMaski(index, (writeMask & 1) != 0, (writeMask & 2) != 0, (writeMask & 4) != 0, (writeMask & 8) != 0);
|
| 508 | }
|
| 509 | }
|
| 510 |
|
| 511 | public static void _clear(final int mask) {
|
| 512 | RenderSystem.assertOnRenderThread();
|
| 513 | GL33C.glClear(mask);
|
| 514 | if (IS_MACOS) {
|
| 515 | _getError();
|
| 516 | }
|
| 517 | }
|
| 518 |
|
| 519 | public static void _clearBuffer(final int index, final Vector4fc clearColor) {
|
| 520 | RenderSystem.assertOnRenderThread();
|
| 521 | GL33C.glClearBufferfv(6144, index, new float[]{clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w()});
|
| 522 | if (IS_MACOS) {
|
| 523 | _getError();
|
| 524 | }
|
| 525 | }
|
| 526 |
|
| 527 | public static void _clearBuffer(final double clearDepth) {
|
| 528 | RenderSystem.assertOnRenderThread();
|
| 529 | GL33C.glClearBufferfv(6145, 0, new float[]{(float)clearDepth});
|
| 530 | if (IS_MACOS) {
|
| 531 | _getError();
|
| 532 | }
|
| 533 | }
|
| 534 |
|
| 535 | public static void _vertexAttribPointer(final int index, final int size, final int type, final boolean normalized, final int stride, final long value) {
|
| 536 | RenderSystem.assertOnRenderThread();
|
| 537 | GL33C.glVertexAttribPointer(index, size, type, normalized, stride, value);
|
| 538 | }
|
| 539 |
|
| 540 | public static void _vertexAttribIPointer(final int index, final int size, final int type, final int stride, final long value) {
|
| 541 | RenderSystem.assertOnRenderThread();
|
| 542 | GL33C.glVertexAttribIPointer(index, size, type, stride, value);
|
| 543 | }
|
| 544 |
|
| 545 | public static void _enableVertexAttribArray(final int index) {
|
| 546 | RenderSystem.assertOnRenderThread();
|
| 547 | GL33C.glEnableVertexAttribArray(index);
|
| 548 | }
|
| 549 |
|
| 550 | public static void _drawElements(final int mode, final int count, final int type, final long indices) {
|
| 551 | RenderSystem.assertOnRenderThread();
|
| 552 | GL33C.glDrawElements(mode, count, type, indices);
|
| 553 | }
|
| 554 |
|
| 555 | public static void _drawArrays(final int mode, final int first, final int count) {
|
| 556 | RenderSystem.assertOnRenderThread();
|
| 557 | GL33C.glDrawArrays(mode, first, count);
|
| 558 | }
|
| 559 |
|
| 560 | public static void _pixelStore(final int name, final int value) {
|
| 561 | RenderSystem.assertOnRenderThread();
|
| 562 | GL33C.glPixelStorei(name, value);
|
| 563 | }
|
| 564 |
|
| 565 | public static void _readPixels(final int x, final int y, final int width, final int height, final int format, final int type, final long pixels) {
|
| 566 | RenderSystem.assertOnRenderThread();
|
| 567 | GL33C.glReadPixels(x, y, width, height, format, type, pixels);
|
| 568 | }
|
| 569 |
|
| 570 | public static int _getError() {
|
| 571 | RenderSystem.assertOnRenderThread();
|
| 572 | return GL33C.glGetError();
|
| 573 | }
|
| 574 |
|
| 575 | public static void clearGlErrors() {
|
| 576 | RenderSystem.assertOnRenderThread();
|
| 577 |
|
| 578 | while (GL33C.glGetError() != 0) {
|
| 579 | }
|
| 580 | }
|
| 581 |
|
| 582 | public static String _getString(final int id) {
|
| 583 | RenderSystem.assertOnRenderThread();
|
| 584 | return GL33C.glGetString(id);
|
| 585 | }
|
| 586 |
|
| 587 | public static int _getInteger(final int name) {
|
| 588 | RenderSystem.assertOnRenderThread();
|
| 589 | return GL33C.glGetInteger(name);
|
| 590 | }
|
| 591 |
|
| 592 | public static long _glFenceSync(final int condition, final int flags) {
|
| 593 | RenderSystem.assertOnRenderThread();
|
| 594 | return GL33C.glFenceSync(condition, flags);
|
| 595 | }
|
| 596 |
|
| 597 | public static int _glClientWaitSync(final long sync, final int flags, final long timeout) {
|
| 598 | RenderSystem.assertOnRenderThread();
|
| 599 | return GL33C.glClientWaitSync(sync, flags, timeout);
|
| 600 | }
|
| 601 |
|
| 602 | public static void _glDeleteSync(final long sync) {
|
| 603 | RenderSystem.assertOnRenderThread();
|
| 604 | GL33C.glDeleteSync(sync);
|
| 605 | }
|
| 606 |
|
| 607 | static {
|
| 608 | Arrays.setAll(COLOR_MASK, var0 -> 15);
|
| 609 | Arrays.fill(BLEND_ENABLE, false);
|
| 610 | }
|
| 611 |
|
| 612 | @Environment(EnvType.CLIENT)
|
| 613 | private static class BlendState {
|
| 614 | public int srcRgb = 1;
|
| 615 | public int dstRgb = 0;
|
| 616 | public int modeRgb = 32774;
|
| 617 | public int srcAlpha = 1;
|
| 618 | public int dstAlpha = 0;
|
| 619 | public int modeAlpha = 32774;
|
| 620 | }
|
| 621 |
|
| 622 | @Environment(EnvType.CLIENT)
|
| 623 | private static class BooleanState {
|
| 624 | private final int state;
|
| 625 | private boolean enabled;
|
| 626 |
|
| 627 | public BooleanState(final int state) {
|
| 628 | this.state = state;
|
| 629 | }
|
| 630 |
|
| 631 | public void disable() {
|
| 632 | this.setEnabled(false);
|
| 633 | }
|
| 634 |
|
| 635 | public void enable() {
|
| 636 | this.setEnabled(true);
|
| 637 | }
|
| 638 |
|
| 639 | public void setEnabled(final boolean enabled) {
|
| 640 | RenderSystem.assertOnRenderThread();
|
| 641 | if (enabled != this.enabled) {
|
| 642 | this.enabled = enabled;
|
| 643 | if (enabled) {
|
| 644 | GL33C.glEnable(this.state);
|
| 645 | } else {
|
| 646 | GL33C.glDisable(this.state);
|
| 647 | }
|
| 648 | }
|
| 649 | }
|
| 650 | }
|
| 651 |
|
| 652 | @Environment(EnvType.CLIENT)
|
| 653 | private static class ColorLogicState {
|
| 654 | public final GlStateManager.BooleanState enable = new GlStateManager.BooleanState(3058);
|
| 655 | public int op = 5379;
|
| 656 | }
|
| 657 |
|
| 658 | @Environment(EnvType.CLIENT)
|
| 659 | private static class CullState {
|
| 660 | public final GlStateManager.BooleanState enable = new GlStateManager.BooleanState(2884);
|
| 661 | }
|
| 662 |
|
| 663 | @Environment(EnvType.CLIENT)
|
| 664 | private static class DepthState {
|
| 665 | public final GlStateManager.BooleanState mode = new GlStateManager.BooleanState(2929);
|
| 666 | public boolean mask = true;
|
| 667 | public int func = 513;
|
| 668 | }
|
| 669 |
|
| 670 | @Environment(EnvType.CLIENT)
|
| 671 | private static class PolygonOffsetState {
|
| 672 | public final GlStateManager.BooleanState fill = new GlStateManager.BooleanState(32823);
|
| 673 | public float factor;
|
| 674 | public float units;
|
| 675 | }
|
| 676 |
|
| 677 | @Environment(EnvType.CLIENT)
|
| 678 | private static class ScissorState {
|
| 679 | public final GlStateManager.BooleanState mode = new GlStateManager.BooleanState(3089);
|
| 680 | }
|
| 681 |
|
| 682 | @Environment(EnvType.CLIENT)
|
| 683 | private static class TextureState {
|
| 684 | public int binding;
|
| 685 | }
|
| 686 | }
|
| 687 |
|