Spaces:
Build error
Build error
File size: 28,118 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
package com.mojang.blaze3d.systems;
import com.google.common.collect.Queues;
import com.mojang.blaze3d.DontObfuscate;
import com.mojang.blaze3d.ProjectionType;
import com.mojang.blaze3d.TracyFrameCapture;
import com.mojang.blaze3d.buffers.BufferType;
import com.mojang.blaze3d.buffers.BufferUsage;
import com.mojang.blaze3d.buffers.GpuBuffer;
import com.mojang.blaze3d.pipeline.RenderCall;
import com.mojang.blaze3d.platform.GLX;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.logging.LogUtils;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.Locale;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import javax.annotation.Nullable;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.CompiledShaderProgram;
import net.minecraft.client.renderer.FogParameters;
import net.minecraft.client.renderer.ShaderProgram;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.util.TimeSource;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.joml.Matrix4f;
import org.joml.Matrix4fStack;
import org.joml.Vector3f;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import org.lwjgl.system.MemoryUtil;
import org.slf4j.Logger;
@OnlyIn(Dist.CLIENT)
@DontObfuscate
public class RenderSystem {
static final Logger LOGGER = LogUtils.getLogger();
private static final ConcurrentLinkedQueue<RenderCall> recordingQueue = Queues.newConcurrentLinkedQueue();
private static final Tesselator RENDER_THREAD_TESSELATOR = new Tesselator(1536);
private static final int MINIMUM_ATLAS_TEXTURE_SIZE = 1024;
@Nullable
private static Thread renderThread;
private static int MAX_SUPPORTED_TEXTURE_SIZE = -1;
private static boolean isInInit;
private static double lastDrawTime = Double.MIN_VALUE;
private static final RenderSystem.AutoStorageIndexBuffer sharedSequential = new RenderSystem.AutoStorageIndexBuffer(1, 1, IntConsumer::accept);
private static final RenderSystem.AutoStorageIndexBuffer sharedSequentialQuad = new RenderSystem.AutoStorageIndexBuffer(4, 6, (p_157398_, p_157399_) -> {
p_157398_.accept(p_157399_ + 0);
p_157398_.accept(p_157399_ + 1);
p_157398_.accept(p_157399_ + 2);
p_157398_.accept(p_157399_ + 2);
p_157398_.accept(p_157399_ + 3);
p_157398_.accept(p_157399_ + 0);
});
private static final RenderSystem.AutoStorageIndexBuffer sharedSequentialLines = new RenderSystem.AutoStorageIndexBuffer(4, 6, (p_157401_, p_157402_) -> {
p_157401_.accept(p_157402_ + 0);
p_157401_.accept(p_157402_ + 1);
p_157401_.accept(p_157402_ + 2);
p_157401_.accept(p_157402_ + 3);
p_157401_.accept(p_157402_ + 2);
p_157401_.accept(p_157402_ + 1);
});
private static Matrix4f projectionMatrix = new Matrix4f();
private static Matrix4f savedProjectionMatrix = new Matrix4f();
private static ProjectionType projectionType = ProjectionType.PERSPECTIVE;
private static ProjectionType savedProjectionType = ProjectionType.PERSPECTIVE;
private static final Matrix4fStack modelViewStack = new Matrix4fStack(16);
private static Matrix4f textureMatrix = new Matrix4f();
private static final int[] shaderTextures = new int[12];
private static final float[] shaderColor = new float[]{1.0F, 1.0F, 1.0F, 1.0F};
private static float shaderGlintAlpha = 1.0F;
private static FogParameters shaderFog = FogParameters.NO_FOG;
private static final Vector3f[] shaderLightDirections = new Vector3f[2];
private static float shaderGameTime;
private static float shaderLineWidth = 1.0F;
private static String apiDescription = "Unknown";
@Nullable
private static CompiledShaderProgram shader;
private static final AtomicLong pollEventsWaitStart = new AtomicLong();
private static final AtomicBoolean pollingEvents = new AtomicBoolean(false);
public static void initRenderThread() {
if (renderThread != null) {
throw new IllegalStateException("Could not initialize render thread");
} else {
renderThread = Thread.currentThread();
}
}
public static boolean isOnRenderThread() {
return Thread.currentThread() == renderThread;
}
public static boolean isOnRenderThreadOrInit() {
return isInInit || isOnRenderThread();
}
public static void assertOnRenderThreadOrInit() {
if (!isInInit && !isOnRenderThread()) {
throw constructThreadException();
}
}
public static void assertOnRenderThread() {
if (!isOnRenderThread()) {
throw constructThreadException();
}
}
private static IllegalStateException constructThreadException() {
return new IllegalStateException("Rendersystem called from wrong thread");
}
public static void recordRenderCall(RenderCall p_69880_) {
recordingQueue.add(p_69880_);
}
private static void pollEvents() {
pollEventsWaitStart.set(Util.getMillis());
pollingEvents.set(true);
GLFW.glfwPollEvents();
pollingEvents.set(false);
}
public static boolean isFrozenAtPollEvents() {
return pollingEvents.get() && Util.getMillis() - pollEventsWaitStart.get() > 200L;
}
public static void flipFrame(long p_69496_, @Nullable TracyFrameCapture p_365037_) {
pollEvents();
replayQueue();
Tesselator.getInstance().clear();
GLFW.glfwSwapBuffers(p_69496_);
if (p_365037_ != null) {
p_365037_.endFrame();
}
pollEvents();
}
public static void replayQueue() {
while (!recordingQueue.isEmpty()) {
RenderCall rendercall = recordingQueue.poll();
rendercall.execute();
}
}
public static void limitDisplayFPS(int p_69831_) {
double d0 = lastDrawTime + 1.0 / (double)p_69831_;
double d1;
for (d1 = GLFW.glfwGetTime(); d1 < d0; d1 = GLFW.glfwGetTime()) {
GLFW.glfwWaitEventsTimeout(d0 - d1);
}
lastDrawTime = d1;
}
public static void disableDepthTest() {
assertOnRenderThread();
GlStateManager._disableDepthTest();
}
public static void enableDepthTest() {
GlStateManager._enableDepthTest();
}
public static void enableScissor(int p_69489_, int p_69490_, int p_69491_, int p_69492_) {
GlStateManager._enableScissorTest();
GlStateManager._scissorBox(p_69489_, p_69490_, p_69491_, p_69492_);
}
public static void disableScissor() {
GlStateManager._disableScissorTest();
}
public static void depthFunc(int p_69457_) {
assertOnRenderThread();
GlStateManager._depthFunc(p_69457_);
}
public static void depthMask(boolean p_69459_) {
assertOnRenderThread();
GlStateManager._depthMask(p_69459_);
}
public static void enableBlend() {
assertOnRenderThread();
GlStateManager._enableBlend();
}
public static void disableBlend() {
assertOnRenderThread();
GlStateManager._disableBlend();
}
public static void blendFunc(GlStateManager.SourceFactor p_69409_, GlStateManager.DestFactor p_69410_) {
assertOnRenderThread();
GlStateManager._blendFunc(p_69409_.value, p_69410_.value);
}
public static void blendFunc(int p_69406_, int p_69407_) {
assertOnRenderThread();
GlStateManager._blendFunc(p_69406_, p_69407_);
}
public static void blendFuncSeparate(
GlStateManager.SourceFactor p_69417_, GlStateManager.DestFactor p_69418_, GlStateManager.SourceFactor p_69419_, GlStateManager.DestFactor p_69420_
) {
assertOnRenderThread();
GlStateManager._blendFuncSeparate(p_69417_.value, p_69418_.value, p_69419_.value, p_69420_.value);
}
public static void blendFuncSeparate(int p_69412_, int p_69413_, int p_69414_, int p_69415_) {
assertOnRenderThread();
GlStateManager._blendFuncSeparate(p_69412_, p_69413_, p_69414_, p_69415_);
}
public static void blendEquation(int p_69404_) {
assertOnRenderThread();
GlStateManager._blendEquation(p_69404_);
}
public static void enableCull() {
assertOnRenderThread();
GlStateManager._enableCull();
}
public static void disableCull() {
assertOnRenderThread();
GlStateManager._disableCull();
}
public static void polygonMode(int p_69861_, int p_69862_) {
assertOnRenderThread();
GlStateManager._polygonMode(p_69861_, p_69862_);
}
public static void enablePolygonOffset() {
assertOnRenderThread();
GlStateManager._enablePolygonOffset();
}
public static void disablePolygonOffset() {
assertOnRenderThread();
GlStateManager._disablePolygonOffset();
}
public static void polygonOffset(float p_69864_, float p_69865_) {
assertOnRenderThread();
GlStateManager._polygonOffset(p_69864_, p_69865_);
}
public static void enableColorLogicOp() {
assertOnRenderThread();
GlStateManager._enableColorLogicOp();
}
public static void disableColorLogicOp() {
assertOnRenderThread();
GlStateManager._disableColorLogicOp();
}
public static void logicOp(GlStateManager.LogicOp p_69836_) {
assertOnRenderThread();
GlStateManager._logicOp(p_69836_.value);
}
public static void activeTexture(int p_69389_) {
assertOnRenderThread();
GlStateManager._activeTexture(p_69389_);
}
public static void texParameter(int p_69938_, int p_69939_, int p_69940_) {
GlStateManager._texParameter(p_69938_, p_69939_, p_69940_);
}
public static void deleteTexture(int p_69455_) {
GlStateManager._deleteTexture(p_69455_);
}
public static void bindTextureForSetup(int p_157185_) {
bindTexture(p_157185_);
}
public static void bindTexture(int p_69397_) {
GlStateManager._bindTexture(p_69397_);
}
public static void viewport(int p_69950_, int p_69951_, int p_69952_, int p_69953_) {
GlStateManager._viewport(p_69950_, p_69951_, p_69952_, p_69953_);
}
public static void colorMask(boolean p_69445_, boolean p_69446_, boolean p_69447_, boolean p_69448_) {
assertOnRenderThread();
GlStateManager._colorMask(p_69445_, p_69446_, p_69447_, p_69448_);
}
public static void stencilFunc(int p_69926_, int p_69927_, int p_69928_) {
assertOnRenderThread();
GlStateManager._stencilFunc(p_69926_, p_69927_, p_69928_);
}
public static void stencilMask(int p_69930_) {
assertOnRenderThread();
GlStateManager._stencilMask(p_69930_);
}
public static void stencilOp(int p_69932_, int p_69933_, int p_69934_) {
assertOnRenderThread();
GlStateManager._stencilOp(p_69932_, p_69933_, p_69934_);
}
public static void clearDepth(double p_69431_) {
GlStateManager._clearDepth(p_69431_);
}
public static void clearColor(float p_69425_, float p_69426_, float p_69427_, float p_69428_) {
GlStateManager._clearColor(p_69425_, p_69426_, p_69427_, p_69428_);
}
public static void clearStencil(int p_69433_) {
assertOnRenderThread();
GlStateManager._clearStencil(p_69433_);
}
public static void clear(int p_69422_) {
GlStateManager._clear(p_69422_);
}
public static void setShaderFog(FogParameters p_366203_) {
assertOnRenderThread();
shaderFog = p_366203_;
}
public static FogParameters getShaderFog() {
assertOnRenderThread();
return shaderFog;
}
public static void setShaderGlintAlpha(double p_268332_) {
setShaderGlintAlpha((float)p_268332_);
}
public static void setShaderGlintAlpha(float p_268329_) {
assertOnRenderThread();
shaderGlintAlpha = p_268329_;
}
public static float getShaderGlintAlpha() {
assertOnRenderThread();
return shaderGlintAlpha;
}
public static void setShaderLights(Vector3f p_254155_, Vector3f p_254006_) {
assertOnRenderThread();
shaderLightDirections[0] = p_254155_;
shaderLightDirections[1] = p_254006_;
}
public static void setupShaderLights(CompiledShaderProgram p_362948_) {
assertOnRenderThread();
if (p_362948_.LIGHT0_DIRECTION != null) {
p_362948_.LIGHT0_DIRECTION.set(shaderLightDirections[0]);
}
if (p_362948_.LIGHT1_DIRECTION != null) {
p_362948_.LIGHT1_DIRECTION.set(shaderLightDirections[1]);
}
}
public static void setShaderColor(float p_157430_, float p_157431_, float p_157432_, float p_157433_) {
assertOnRenderThread();
shaderColor[0] = p_157430_;
shaderColor[1] = p_157431_;
shaderColor[2] = p_157432_;
shaderColor[3] = p_157433_;
}
public static float[] getShaderColor() {
assertOnRenderThread();
return shaderColor;
}
public static void drawElements(int p_157187_, int p_157188_, int p_157189_) {
assertOnRenderThread();
GlStateManager._drawElements(p_157187_, p_157188_, p_157189_, 0L);
}
public static void lineWidth(float p_69833_) {
assertOnRenderThread();
shaderLineWidth = p_69833_;
}
public static float getShaderLineWidth() {
assertOnRenderThread();
return shaderLineWidth;
}
public static void pixelStore(int p_69855_, int p_69856_) {
GlStateManager._pixelStore(p_69855_, p_69856_);
}
public static void readPixels(int p_69872_, int p_69873_, int p_69874_, int p_69875_, int p_69876_, int p_69877_, ByteBuffer p_69878_) {
assertOnRenderThread();
GlStateManager._readPixels(p_69872_, p_69873_, p_69874_, p_69875_, p_69876_, p_69877_, p_69878_);
}
public static void getString(int p_69520_, Consumer<String> p_69521_) {
assertOnRenderThread();
p_69521_.accept(GlStateManager._getString(p_69520_));
}
public static String getBackendDescription() {
return String.format(Locale.ROOT, "LWJGL version %s", GLX._getLWJGLVersion());
}
public static String getApiDescription() {
return apiDescription;
}
public static TimeSource.NanoTimeSource initBackendSystem() {
return GLX._initGlfw()::getAsLong;
}
public static void initRenderer(int p_69581_, boolean p_69582_) {
GLX._init(p_69581_, p_69582_);
apiDescription = GLX.getOpenGLVersionString();
}
public static void setErrorCallback(GLFWErrorCallbackI p_69901_) {
GLX._setGlfwErrorCallback(p_69901_);
}
public static void renderCrosshair(int p_69882_) {
assertOnRenderThread();
GLX._renderCrosshair(p_69882_, true, true, true);
}
public static String getCapsString() {
assertOnRenderThread();
return "Using framebuffer using OpenGL 3.2";
}
public static void setupDefaultState(int p_69903_, int p_69904_, int p_69905_, int p_69906_) {
GlStateManager._clearDepth(1.0);
GlStateManager._enableDepthTest();
GlStateManager._depthFunc(515);
projectionMatrix.identity();
savedProjectionMatrix.identity();
modelViewStack.clear();
textureMatrix.identity();
GlStateManager._viewport(p_69903_, p_69904_, p_69905_, p_69906_);
}
public static int maxSupportedTextureSize() {
if (MAX_SUPPORTED_TEXTURE_SIZE == -1) {
assertOnRenderThreadOrInit();
int i = GlStateManager._getInteger(3379);
for (int j = Math.max(32768, i); j >= 1024; j >>= 1) {
GlStateManager._texImage2D(32868, 0, 6408, j, j, 0, 6408, 5121, null);
int k = GlStateManager._getTexLevelParameter(32868, 0, 4096);
if (k != 0) {
MAX_SUPPORTED_TEXTURE_SIZE = j;
return j;
}
}
MAX_SUPPORTED_TEXTURE_SIZE = Math.max(i, 1024);
LOGGER.info("Failed to determine maximum texture size by probing, trying GL_MAX_TEXTURE_SIZE = {}", MAX_SUPPORTED_TEXTURE_SIZE);
}
return MAX_SUPPORTED_TEXTURE_SIZE;
}
public static void glBindBuffer(int p_157209_, int p_344603_) {
GlStateManager._glBindBuffer(p_157209_, p_344603_);
}
public static void glBindVertexArray(int p_344671_) {
GlStateManager._glBindVertexArray(p_344671_);
}
public static void glBufferData(int p_69526_, ByteBuffer p_69527_, int p_69528_) {
assertOnRenderThreadOrInit();
GlStateManager._glBufferData(p_69526_, p_69527_, p_69528_);
}
public static void glDeleteBuffers(int p_69530_) {
assertOnRenderThread();
GlStateManager._glDeleteBuffers(p_69530_);
}
public static void glDeleteVertexArrays(int p_157214_) {
assertOnRenderThread();
GlStateManager._glDeleteVertexArrays(p_157214_);
}
public static void glUniform1i(int p_69544_, int p_69545_) {
assertOnRenderThread();
GlStateManager._glUniform1i(p_69544_, p_69545_);
}
public static void glUniform1(int p_69541_, IntBuffer p_69542_) {
assertOnRenderThread();
GlStateManager._glUniform1(p_69541_, p_69542_);
}
public static void glUniform2(int p_69550_, IntBuffer p_69551_) {
assertOnRenderThread();
GlStateManager._glUniform2(p_69550_, p_69551_);
}
public static void glUniform3(int p_69556_, IntBuffer p_69557_) {
assertOnRenderThread();
GlStateManager._glUniform3(p_69556_, p_69557_);
}
public static void glUniform4(int p_69562_, IntBuffer p_69563_) {
assertOnRenderThread();
GlStateManager._glUniform4(p_69562_, p_69563_);
}
public static void glUniform1(int p_69538_, FloatBuffer p_69539_) {
assertOnRenderThread();
GlStateManager._glUniform1(p_69538_, p_69539_);
}
public static void glUniform2(int p_69547_, FloatBuffer p_69548_) {
assertOnRenderThread();
GlStateManager._glUniform2(p_69547_, p_69548_);
}
public static void glUniform3(int p_69553_, FloatBuffer p_69554_) {
assertOnRenderThread();
GlStateManager._glUniform3(p_69553_, p_69554_);
}
public static void glUniform4(int p_69559_, FloatBuffer p_69560_) {
assertOnRenderThread();
GlStateManager._glUniform4(p_69559_, p_69560_);
}
public static void glUniformMatrix2(int p_69565_, boolean p_69566_, FloatBuffer p_69567_) {
assertOnRenderThread();
GlStateManager._glUniformMatrix2(p_69565_, p_69566_, p_69567_);
}
public static void glUniformMatrix3(int p_69569_, boolean p_69570_, FloatBuffer p_69571_) {
assertOnRenderThread();
GlStateManager._glUniformMatrix3(p_69569_, p_69570_, p_69571_);
}
public static void glUniformMatrix4(int p_69573_, boolean p_69574_, FloatBuffer p_69575_) {
assertOnRenderThread();
GlStateManager._glUniformMatrix4(p_69573_, p_69574_, p_69575_);
}
public static void setupOverlayColor(int p_69922_, int p_342657_) {
assertOnRenderThread();
setShaderTexture(1, p_69922_);
}
public static void teardownOverlayColor() {
assertOnRenderThread();
setShaderTexture(1, 0);
}
public static void setupLevelDiffuseLighting(Vector3f p_254489_, Vector3f p_254541_) {
assertOnRenderThread();
setShaderLights(p_254489_, p_254541_);
}
public static void setupGuiFlatDiffuseLighting(Vector3f p_254419_, Vector3f p_254483_) {
assertOnRenderThread();
GlStateManager.setupGuiFlatDiffuseLighting(p_254419_, p_254483_);
}
public static void setupGui3DDiffuseLighting(Vector3f p_253859_, Vector3f p_253890_) {
assertOnRenderThread();
GlStateManager.setupGui3DDiffuseLighting(p_253859_, p_253890_);
}
public static void beginInitialization() {
isInInit = true;
}
public static void finishInitialization() {
isInInit = false;
if (!recordingQueue.isEmpty()) {
replayQueue();
}
if (!recordingQueue.isEmpty()) {
throw new IllegalStateException("Recorded to render queue during initialization");
}
}
public static Tesselator renderThreadTesselator() {
assertOnRenderThread();
return RENDER_THREAD_TESSELATOR;
}
public static void defaultBlendFunc() {
blendFuncSeparate(
GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
GlStateManager.SourceFactor.ONE,
GlStateManager.DestFactor.ZERO
);
}
@Nullable
public static CompiledShaderProgram setShader(ShaderProgram p_364012_) {
assertOnRenderThread();
CompiledShaderProgram compiledshaderprogram = Minecraft.getInstance().getShaderManager().getProgram(p_364012_);
shader = compiledshaderprogram;
return compiledshaderprogram;
}
public static void setShader(CompiledShaderProgram p_362982_) {
assertOnRenderThread();
shader = p_362982_;
}
public static void clearShader() {
assertOnRenderThread();
shader = null;
}
@Nullable
public static CompiledShaderProgram getShader() {
assertOnRenderThread();
return shader;
}
public static void setShaderTexture(int p_157457_, ResourceLocation p_157458_) {
assertOnRenderThread();
if (p_157457_ >= 0 && p_157457_ < shaderTextures.length) {
TextureManager texturemanager = Minecraft.getInstance().getTextureManager();
AbstractTexture abstracttexture = texturemanager.getTexture(p_157458_);
shaderTextures[p_157457_] = abstracttexture.getId();
}
}
public static void setShaderTexture(int p_157454_, int p_157455_) {
assertOnRenderThread();
if (p_157454_ >= 0 && p_157454_ < shaderTextures.length) {
shaderTextures[p_157454_] = p_157455_;
}
}
public static int getShaderTexture(int p_157204_) {
assertOnRenderThread();
return p_157204_ >= 0 && p_157204_ < shaderTextures.length ? shaderTextures[p_157204_] : 0;
}
public static void setProjectionMatrix(Matrix4f p_277884_, ProjectionType p_362578_) {
assertOnRenderThread();
projectionMatrix = new Matrix4f(p_277884_);
projectionType = p_362578_;
}
public static void setTextureMatrix(Matrix4f p_254081_) {
assertOnRenderThread();
textureMatrix = new Matrix4f(p_254081_);
}
public static void resetTextureMatrix() {
assertOnRenderThread();
textureMatrix.identity();
}
public static void backupProjectionMatrix() {
assertOnRenderThread();
savedProjectionMatrix = projectionMatrix;
savedProjectionType = projectionType;
}
public static void restoreProjectionMatrix() {
assertOnRenderThread();
projectionMatrix = savedProjectionMatrix;
projectionType = savedProjectionType;
}
public static Matrix4f getProjectionMatrix() {
assertOnRenderThread();
return projectionMatrix;
}
public static Matrix4f getModelViewMatrix() {
assertOnRenderThread();
return modelViewStack;
}
public static Matrix4fStack getModelViewStack() {
assertOnRenderThread();
return modelViewStack;
}
public static Matrix4f getTextureMatrix() {
assertOnRenderThread();
return textureMatrix;
}
public static RenderSystem.AutoStorageIndexBuffer getSequentialBuffer(VertexFormat.Mode p_221942_) {
assertOnRenderThread();
return switch (p_221942_) {
case QUADS -> sharedSequentialQuad;
case LINES -> sharedSequentialLines;
default -> sharedSequential;
};
}
public static void setShaderGameTime(long p_157448_, float p_157449_) {
assertOnRenderThread();
shaderGameTime = ((float)(p_157448_ % 24000L) + p_157449_) / 24000.0F;
}
public static float getShaderGameTime() {
assertOnRenderThread();
return shaderGameTime;
}
public static ProjectionType getProjectionType() {
assertOnRenderThread();
return projectionType;
}
@OnlyIn(Dist.CLIENT)
public static final class AutoStorageIndexBuffer {
private final int vertexStride;
private final int indexStride;
private final RenderSystem.AutoStorageIndexBuffer.IndexGenerator generator;
@Nullable
private GpuBuffer buffer;
private VertexFormat.IndexType type = VertexFormat.IndexType.SHORT;
private int indexCount;
AutoStorageIndexBuffer(int p_157472_, int p_157473_, RenderSystem.AutoStorageIndexBuffer.IndexGenerator p_157474_) {
this.vertexStride = p_157472_;
this.indexStride = p_157473_;
this.generator = p_157474_;
}
public boolean hasStorage(int p_221945_) {
return p_221945_ <= this.indexCount;
}
public void bind(int p_221947_) {
if (this.buffer == null) {
this.buffer = new GpuBuffer(BufferType.INDICES, BufferUsage.DYNAMIC_WRITE, 0);
}
this.buffer.bind();
this.ensureStorage(p_221947_);
}
private void ensureStorage(int p_157477_) {
if (!this.hasStorage(p_157477_)) {
p_157477_ = Mth.roundToward(p_157477_ * 2, this.indexStride);
RenderSystem.LOGGER.debug("Growing IndexBuffer: Old limit {}, new limit {}.", this.indexCount, p_157477_);
int i = p_157477_ / this.indexStride;
int j = i * this.vertexStride;
VertexFormat.IndexType vertexformat$indextype = VertexFormat.IndexType.least(j);
int k = Mth.roundToward(p_157477_ * vertexformat$indextype.bytes, 4);
ByteBuffer bytebuffer = MemoryUtil.memAlloc(k);
try {
this.type = vertexformat$indextype;
it.unimi.dsi.fastutil.ints.IntConsumer intconsumer = this.intConsumer(bytebuffer);
for (int l = 0; l < p_157477_; l += this.indexStride) {
this.generator.accept(intconsumer, l * this.vertexStride / this.indexStride);
}
bytebuffer.flip();
this.buffer.resize(k);
this.buffer.write(bytebuffer, 0);
} finally {
MemoryUtil.memFree(bytebuffer);
}
this.indexCount = p_157477_;
}
}
private it.unimi.dsi.fastutil.ints.IntConsumer intConsumer(ByteBuffer p_157479_) {
switch (this.type) {
case SHORT:
return p_157482_ -> p_157479_.putShort((short)p_157482_);
case INT:
default:
return p_157479_::putInt;
}
}
public VertexFormat.IndexType type() {
return this.type;
}
@OnlyIn(Dist.CLIENT)
interface IndexGenerator {
void accept(it.unimi.dsi.fastutil.ints.IntConsumer p_157488_, int p_157489_);
}
}
} |