Files
NeoForge/patches/com/mojang/renderpearl/backend/opengl/GlCommandEncoder.java.patch
T
2026-10-10 23:34:12 +02:00

54 lines
2.9 KiB
Diff

--- a/com/mojang/renderpearl/backend/opengl/GlCommandEncoder.java
+++ b/com/mojang/renderpearl/backend/opengl/GlCommandEncoder.java
@@ -274,6 +_,24 @@
}
@Override
+ public void clearStencilTexture(GpuTexture texture, int value) {
+ GL33C.glClearStencil(value);
+ GlStateManager._stencilMask(-1);
+ GlStateManager._depthMask(true);
+ GlStateManager._disableScissorTest();
+
+ for (int i = 0; i < texture.getMipLevels(); i++) {
+ this.device.directStateAccess().bindFrameBufferTextures(this.drawFbo, 0, 0, 0, GlConst.GL_FRAMEBUFFER, ((GlTexture)texture).id, i);
+ GL33C.glDrawBuffer(GlConst.GL_NONE);
+ GlStateManager._clear(GL33C.GL_STENCIL_BUFFER_BIT);
+ }
+
+ GL33C.glDrawBuffer(GlConst.GL_COLOR_ATTACHMENT0);
+ GlStateManager._glFramebufferTexture2D(GlConst.GL_FRAMEBUFFER, GL33C.GL_STENCIL_ATTACHMENT, GlConst.GL_TEXTURE_2D, 0, 0);
+ GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, 0);
+ }
+
+ @Override
public void writeToBuffer(GpuBufferSlice slice, ByteBuffer data) {
GlBuffer buffer = (GlBuffer)slice.buffer();
buffer.checkCanBeUsed();
@@ -396,11 +_,22 @@
boolean isDepth = source.getFormat().hasDepthAspect();
int sourceId = ((GlTexture)source).glId();
int destId = ((GlTexture)destination).glId();
- this.device.directStateAccess().bindFrameBufferTextures(this.readFbo, isDepth ? 0 : sourceId, isDepth ? sourceId : 0, mipLevel, 0);
- this.device.directStateAccess().bindFrameBufferTextures(this.drawFbo, isDepth ? 0 : destId, isDepth ? destId : 0, mipLevel, 0);
+ boolean hasStencil = source.getFormat().hasStencilAspect();
+ this.device.directStateAccess().bindFrameBufferTextures(this.readFbo, (isDepth || hasStencil) ? 0 : sourceId, isDepth ? sourceId : 0, 0, 0, hasStencil ? sourceId : 0, 0);
+ this.device.directStateAccess().bindFrameBufferTextures(this.drawFbo, (isDepth || hasStencil) ? 0 : destId, isDepth ? destId : 0, 0, 0, hasStencil ? destId : 0, 0);
+ int bufferMask = 0;
+ if (source.getFormat().hasColorAspect()) {
+ bufferMask |= GlConst.GL_COLOR_BUFFER_BIT;
+ }
+ if (source.getFormat().hasDepthAspect()) {
+ bufferMask |= GlConst.GL_DEPTH_BUFFER_BIT;
+ }
+ if (source.getFormat().hasStencilAspect()) {
+ bufferMask |= GL33C.GL_STENCIL_BUFFER_BIT;
+ }
this.device
.directStateAccess()
- .blitFrameBuffers(this.readFbo, this.drawFbo, sourceX, sourceY, width, height, destX, destY, width, height, isDepth ? 256 : 16384, 9728);
+ .blitFrameBuffers(this.readFbo, this.drawFbo, sourceX, sourceY, width, height, destX, destY, width, height, bufferMask, 9728);
int error = GlStateManager._getError();
if (error != 0) {
throw new IllegalStateException(