forked from nullified33/sodium-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1.16.x/next' of https://github.com/jellysquid3/sodium-f…
…abric into compat_next_1_16_4 � Conflicts: � src/main/java/me/jellysquid/mods/sodium/client/render/chunk/ChunkRenderContainer.java � src/main/java/me/jellysquid/mods/sodium/client/render/chunk/ChunkRenderManager.java � src/main/java/me/jellysquid/mods/sodium/client/render/chunk/cull/graph/ChunkGraphNode.java � src/main/java/me/jellysquid/mods/sodium/client/render/chunk/shader/ChunkProgram.java
- Loading branch information
Showing
76 changed files
with
1,411 additions
and
697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/me/jellysquid/mods/sodium/client/gl/shader/ShaderWorkarounds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2020 Grondag | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package me.jellysquid.mods.sodium.client.gl.shader; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import org.lwjgl.PointerBuffer; | ||
import org.lwjgl.opengl.GL20C; | ||
import org.lwjgl.system.MemoryStack; | ||
import org.lwjgl.system.MemoryUtil; | ||
|
||
/** | ||
* Contains a workaround for a crash in nglShaderSource on some AMD drivers. Copied from the following Canvas commit: | ||
* https://github.com/grondag/canvas/commit/820bf754092ccaf8d0c169620c2ff575722d7d96 | ||
*/ | ||
class ShaderWorkarounds { | ||
/** | ||
* Identical in function to {@link GL20C#glShaderSource(int, CharSequence)} but | ||
* passes a null pointer for string length to force the driver to rely on the null | ||
* terminator for string length. This is a workaround for an apparent flaw with some | ||
* AMD drivers that don't receive or interpret the length correctly, resulting in | ||
* an access violation when the driver tries to read past the string memory. | ||
* | ||
* <p>Hat tip to fewizz for the find and the fix. | ||
*/ | ||
static void safeShaderSource(int glId, CharSequence source) { | ||
final MemoryStack stack = MemoryStack.stackGet(); | ||
final int stackPointer = stack.getPointer(); | ||
|
||
try { | ||
final ByteBuffer sourceBuffer = MemoryUtil.memUTF8(source, true); | ||
final PointerBuffer pointers = stack.mallocPointer(1); | ||
pointers.put(sourceBuffer); | ||
|
||
GL20C.nglShaderSource(glId, 1, pointers.address0(), 0); | ||
org.lwjgl.system.APIUtil.apiArrayFree(pointers.address0(), 1); | ||
} finally { | ||
stack.setPointer(stackPointer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexSink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad; | ||
|
||
import me.jellysquid.mods.sodium.client.model.vertex.VertexSink; | ||
import me.jellysquid.mods.sodium.client.util.math.Matrix4fExtended; | ||
import me.jellysquid.mods.sodium.client.util.math.MatrixUtil; | ||
import net.minecraft.client.render.VertexFormat; | ||
import net.minecraft.client.render.VertexFormats; | ||
import net.minecraft.util.math.Matrix4f; | ||
|
||
public interface BasicScreenQuadVertexSink extends VertexSink { | ||
VertexFormat VERTEX_FORMAT = VertexFormats.POSITION_COLOR; | ||
|
||
/** | ||
* Writes a quad vertex to this sink. | ||
* | ||
* @param x The x-position of the vertex | ||
* @param y The y-position of the vertex | ||
* @param z The z-position of the vertex | ||
* @param color The ABGR-packed color of the vertex | ||
*/ | ||
void writeQuad(float x, float y, float z, int color); | ||
|
||
/** | ||
* Writes a quad vertex to the sink, transformed by the given matrix. | ||
* | ||
* @param matrix The matrix to transform the vertex's position by | ||
*/ | ||
default void writeQuad(Matrix4f matrix, float x, float y, float z, int color) { | ||
Matrix4fExtended modelMatrix = MatrixUtil.getExtendedMatrix(matrix); | ||
|
||
float x2 = modelMatrix.transformVecX(x, y, z); | ||
float y2 = modelMatrix.transformVecY(x, y, z); | ||
float z2 = modelMatrix.transformVecZ(x, y, z); | ||
|
||
this.writeQuad(x2, y2, z2, color); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad; | ||
|
||
import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; | ||
import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer.BasicScreenQuadVertexBufferWriterNio; | ||
import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer.BasicScreenQuadVertexBufferWriterUnsafe; | ||
import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer.BasicScreenQuadVertexWriterFallback; | ||
import me.jellysquid.mods.sodium.client.model.vertex.type.BlittableVertexType; | ||
import me.jellysquid.mods.sodium.client.model.vertex.type.VanillaVertexType; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.minecraft.client.render.VertexFormat; | ||
|
||
public class BasicScreenQuadVertexType implements VanillaVertexType<BasicScreenQuadVertexSink>, BlittableVertexType<BasicScreenQuadVertexSink> { | ||
@Override | ||
public BasicScreenQuadVertexSink createFallbackWriter(VertexConsumer consumer) { | ||
return new BasicScreenQuadVertexWriterFallback(consumer); | ||
} | ||
|
||
@Override | ||
public BasicScreenQuadVertexSink createBufferWriter(VertexBufferView buffer, boolean direct) { | ||
return direct ? new BasicScreenQuadVertexBufferWriterUnsafe(buffer) : new BasicScreenQuadVertexBufferWriterNio(buffer); | ||
} | ||
|
||
@Override | ||
public VertexFormat getVertexFormat() { | ||
return BasicScreenQuadVertexSink.VERTEX_FORMAT; | ||
} | ||
|
||
@Override | ||
public BlittableVertexType<BasicScreenQuadVertexSink> asBlittable() { | ||
return this; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.../client/model/vertex/formats/screen_quad/writer/BasicScreenQuadVertexBufferWriterNio.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer; | ||
|
||
import me.jellysquid.mods.sodium.client.model.vertex.VanillaVertexTypes; | ||
import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; | ||
import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterNio; | ||
import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.BasicScreenQuadVertexSink; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class BasicScreenQuadVertexBufferWriterNio extends VertexBufferWriterNio implements BasicScreenQuadVertexSink { | ||
public BasicScreenQuadVertexBufferWriterNio(VertexBufferView backingBuffer) { | ||
super(backingBuffer, VanillaVertexTypes.BASIC_SCREEN_QUADS); | ||
} | ||
|
||
@Override | ||
public void writeQuad(float x, float y, float z, int color) { | ||
int i = this.writeOffset; | ||
|
||
ByteBuffer buf = this.byteBuffer; | ||
buf.putFloat(i, x); | ||
buf.putFloat(i + 4, y); | ||
buf.putFloat(i + 8, z); | ||
buf.putInt(i + 12, color); | ||
|
||
this.advance(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ient/model/vertex/formats/screen_quad/writer/BasicScreenQuadVertexBufferWriterUnsafe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer; | ||
|
||
import me.jellysquid.mods.sodium.client.model.vertex.VanillaVertexTypes; | ||
import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; | ||
import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; | ||
import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.BasicScreenQuadVertexSink; | ||
|
||
public class BasicScreenQuadVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe implements BasicScreenQuadVertexSink { | ||
public BasicScreenQuadVertexBufferWriterUnsafe(VertexBufferView backingBuffer) { | ||
super(backingBuffer, VanillaVertexTypes.BASIC_SCREEN_QUADS); | ||
} | ||
|
||
@SuppressWarnings("SuspiciousNameCombination") | ||
@Override | ||
public void writeQuad(float x, float y, float z, int color) { | ||
long i = this.writePointer; | ||
|
||
UNSAFE.putFloat(i, x); | ||
UNSAFE.putFloat(i + 4, y); | ||
UNSAFE.putFloat(i + 8, z); | ||
UNSAFE.putInt(i + 12, color); | ||
|
||
this.advance(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...m/client/model/vertex/formats/screen_quad/writer/BasicScreenQuadVertexWriterFallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer; | ||
|
||
import me.jellysquid.mods.sodium.client.model.vertex.fallback.VertexWriterFallback; | ||
import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.BasicScreenQuadVertexSink; | ||
import me.jellysquid.mods.sodium.client.util.color.ColorABGR; | ||
import net.minecraft.client.render.VertexConsumer; | ||
|
||
public class BasicScreenQuadVertexWriterFallback extends VertexWriterFallback implements BasicScreenQuadVertexSink { | ||
public BasicScreenQuadVertexWriterFallback(VertexConsumer consumer) { | ||
super(consumer); | ||
} | ||
|
||
@Override | ||
public void writeQuad(float x, float y, float z, int color) { | ||
VertexConsumer consumer = this.consumer; | ||
consumer.vertex(x, y, z); | ||
consumer.color(ColorABGR.unpackRed(color), ColorABGR.unpackGreen(color), ColorABGR.unpackBlue(color), ColorABGR.unpackAlpha(color)); | ||
consumer.next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.