Skip to content

Commit

Permalink
Merge branch '1.20' of https://github.com/FoundryMC/Veil into 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocelot5836 committed Nov 17, 2024
2 parents 975f275 + 478e9f2 commit da32e2b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,26 @@ public static void drawIndirect(VertexBuffer vbo, long indirect, int drawCount,
((VertexBufferExtension) vbo).veil$drawIndirect(indirect, drawCount, stride);
}

/**
* Consumes all OpenGL errors and prints them to console.
*
* @param glCall The name of the OpenGL call made for extra logging or <code>null</code> to not include
*/
public static void printGlErrors(@Nullable String glCall) {
while (true) {
int error = GlStateManager._getError();
if (error == GL_NO_ERROR) {
break;
}

if (glCall != null) {
Veil.LOGGER.error("[OpenGL Error] '{}' 0x{}", glCall, Integer.toHexString(error).toUpperCase(Locale.ROOT));
} else {
Veil.LOGGER.error("[OpenGL Error] 0x{}", Integer.toHexString(error).toUpperCase(Locale.ROOT));
}
}
}

/**
* Retrieves the number of indices in the specified vertex buffer.
*
Expand Down Expand Up @@ -471,7 +491,8 @@ public static int maxTargetBindings(int target) {
case GL_UNIFORM_BUFFER -> maxUniformBuffersBindings();
case GL_ATOMIC_COUNTER_BUFFER -> maxAtomicCounterBufferBindings();
case GL_SHADER_STORAGE_BUFFER -> maxShaderStorageBufferBindings();
default -> throw new IllegalArgumentException("Invalid Target: 0x" + Integer.toHexString(target).toUpperCase(Locale.ROOT));
default ->
throw new IllegalArgumentException("Invalid Target: 0x" + Integer.toHexString(target).toUpperCase(Locale.ROOT));
};
}

Expand All @@ -489,7 +510,8 @@ public static VeilShaderLimits shaderLimits(int shader) {
case GL_GEOMETRY_SHADER -> GL_GEOMETRY_SHADER_LIMITS.get();
case GL_FRAGMENT_SHADER -> GL_FRAGMENT_SHADER_LIMITS.get();
case GL_COMPUTE_SHADER -> GL_COMPUTE_SHADER_LIMITS.get();
default -> throw new IllegalArgumentException("Invalid Shader Type: 0x" + Integer.toHexString(shader).toUpperCase(Locale.ROOT));
default ->
throw new IllegalArgumentException("Invalid Shader Type: 0x" + Integer.toHexString(shader).toUpperCase(Locale.ROOT));
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package foundry.veil.api.client.render.framebuffer;

import com.mojang.blaze3d.platform.GlStateManager;
import foundry.veil.Veil;
import foundry.veil.api.client.render.VeilRenderSystem;
import foundry.veil.api.client.render.deferred.VeilDeferredRenderer;
import net.minecraft.client.Minecraft;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.ApiStatus;

Expand All @@ -24,6 +28,10 @@ public AdvancedFboMutableTextureAttachment(int attachmentType, int textureId, in
public void attach(int attachment) {
int attachmentType = this.getAttachmentType();
Validate.isTrue(attachmentType < GL_DEPTH_ATTACHMENT || attachment == 0, "Only one depth buffer attachment is supported.");

if (Minecraft.ON_OSX) {
VeilRenderSystem.printGlErrors(null);
}
if (this.layer == -1) {
GlStateManager._glFramebufferTexture2D(
GL_FRAMEBUFFER,
Expand All @@ -32,6 +40,9 @@ public void attach(int attachment) {
this.textureId,
0
);
if (Minecraft.ON_OSX) {
VeilRenderSystem.printGlErrors("glFramebufferTexture2D");
}
} else {
glFramebufferTextureLayer(
GL_FRAMEBUFFER,
Expand All @@ -40,6 +51,9 @@ public void attach(int attachment) {
0,
this.layer
);
if (Minecraft.ON_OSX) {
VeilRenderSystem.printGlErrors("glFramebufferTextureLayer");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static org.lwjgl.opengl.GL11C.glDrawArrays;
import static org.lwjgl.opengl.GL11C.glGetInteger;
import static org.lwjgl.opengl.GL15C.GL_ELEMENT_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15C.glBindBuffer;
import static org.lwjgl.opengl.GL20C.GL_CURRENT_PROGRAM;
import static org.lwjgl.opengl.GL31C.glDrawArraysInstanced;
import static org.lwjgl.opengl.GL31C.glDrawElementsInstanced;
import static org.lwjgl.opengl.GL40C.GL_PATCHES;
Expand Down Expand Up @@ -75,7 +77,7 @@ public void drawPatches(CallbackInfo ci) {
}

ShaderProgram shader = VeilRenderSystem.getShader();
if (shader != null && shader.hasTesselation()) {
if (shader != null && shader.hasTesselation() && shader.getProgram() == glGetInteger(GL_CURRENT_PROGRAM)) {
// Quads are internally switched to triangles with indices in vanilla mc, so just use draw arrays
// This will be wrong if custom indices are used! (transparent objects)
glDrawArrays(GL_PATCHES, 0, this.indexCount * 4 / 6);
Expand All @@ -91,7 +93,7 @@ public int modifyDrawMode(int glMode) {
@Unique
private int veil$getDrawMode(int defaultMode) {
ShaderProgram shader = VeilRenderSystem.getShader();
if (shader != null && shader.hasTesselation()) {
if (shader != null && shader.hasTesselation() && shader.getProgram() == glGetInteger(GL_CURRENT_PROGRAM)) {
return GL_PATCHES;
}
return defaultMode;
Expand All @@ -101,7 +103,7 @@ public int modifyDrawMode(int glMode) {
private void _veil$drawInstanced(int instances) {
if (this.mode == VertexFormat.Mode.QUADS) {
ShaderProgram shader = VeilRenderSystem.getShader();
if (shader != null && shader.hasTesselation()) {
if (shader != null && shader.hasTesselation() && shader.getProgram() == glGetInteger(GL_CURRENT_PROGRAM)) {
// Quads are internally switched to triangles with indices in vanilla mc, so just use draw arrays
// This will be wrong if custom indices are used! (transparent objects)
glDrawArraysInstanced(GL_PATCHES, 0, this.indexCount * 4 / 6, instances);
Expand Down

0 comments on commit da32e2b

Please sign in to comment.