Skip to content

Commit

Permalink
Merge branch '1.16.x/next' of https://github.com/jellysquid3/sodium-f…
Browse files Browse the repository at this point in the history
…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
qouteall committed Mar 20, 2021
2 parents ab518e5 + 8efced1 commit 5ee08c1
Show file tree
Hide file tree
Showing 76 changed files with 1,411 additions and 697 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 14
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 14
- name: Grant execute permission for gradlew
run: chmod +x gradlew
java-version: 8
- name: Build with Gradle
run: ./gradlew build
- name: Upload build artifacts
uses: actions/upload-artifact@v1
with:
name: build-artifacts
path: build/libs
path: build/libs
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Upload assets to CurseForge
run: ./gradlew build
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GlShader(ShaderType type, Identifier name, String src, ShaderConstants co
src = processShader(src, constants);

int handle = GL20.glCreateShader(type.id);
GL20.glShaderSource(handle, src);
ShaderWorkarounds.safeShaderSource(handle, src);
GL20.glCompileShader(handle);

String log = GL20.glGetShaderInfoLog(handle);
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ protected long compute(int x, int y, int z) {
// solve lighting issues underwater.
boolean op = state.getFluidState() != EMPTY_FLUID_STATE || state.getOpacity(world, pos) == 0;
boolean fo = state.isOpaqueFullCube(world, pos);
boolean em = state.hasEmissiveLighting(world, pos);

// OPTIMIZE: Do not calculate lightmap data if the block is full and opaque
int lm = fo ? 0 : WorldRenderer.getLightmapCoordinates(world, state, pos);
// OPTIMIZE: Do not calculate lightmap data if the block is full and opaque.
// FIX: Calculate lightmap data for emissive blocks (currently only magma), even though they are full and opaque.
int lm = (fo && !em) ? 0 : WorldRenderer.getLightmapCoordinates(world, state, pos);

return packAO(ao) | packLM(lm) | packOP(op) | packFO(fo) | (1L << 60);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public FlatLightPipeline(LightDataAccess lightCache) {
@Override
public void calculate(ModelQuadView quad, BlockPos pos, QuadLightData out, Direction face, boolean shade) {
// If the face is aligned, use the light data above it
if ((quad.getFlags() & ModelQuadFlags.IS_ALIGNED) != 0) {
if ((quad.getFlags() & ModelQuadFlags.IS_ALIGNED) != 0 && !this.lightCache.getWorld().getBlockState(pos).hasEmissiveLighting(this.lightCache.getWorld(), pos)) {
Arrays.fill(out.lm, unpackLM(this.lightCache.get(pos, face)));
} else {
Arrays.fill(out.lm, unpackLM(this.lightCache.get(pos)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import me.jellysquid.mods.sodium.client.model.vertex.formats.particle.ParticleVertexType;
import me.jellysquid.mods.sodium.client.model.vertex.formats.quad.QuadVertexSink;
import me.jellysquid.mods.sodium.client.model.vertex.formats.quad.QuadVertexType;
import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.BasicScreenQuadVertexSink;
import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.BasicScreenQuadVertexType;
import me.jellysquid.mods.sodium.client.model.vertex.type.VanillaVertexType;

public class VanillaVertexTypes {
public static final VanillaVertexType<QuadVertexSink> QUADS = new QuadVertexType();
public static final VanillaVertexType<LineVertexSink> LINES = new LineVertexType();
public static final VanillaVertexType<GlyphVertexSink> GLYPHS = new GlyphVertexType();
public static final VanillaVertexType<ParticleVertexSink> PARTICLES = new ParticleVertexType();
public static final VanillaVertexType<BasicScreenQuadVertexSink> BASIC_SCREEN_QUADS = new BasicScreenQuadVertexType();
}
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);
}
}
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;
}
}
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();
}
}
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();
}
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@
import me.jellysquid.mods.sodium.client.render.chunk.format.ChunkMeshAttribute;
import me.jellysquid.mods.sodium.client.render.chunk.format.ModelVertexSink;

public interface ChunkVertexType extends BlittableVertexType<ModelVertexSink>, CustomVertexType<ModelVertexSink, ChunkMeshAttribute> { }
public interface ChunkVertexType extends BlittableVertexType<ModelVertexSink>, CustomVertexType<ModelVertexSink, ChunkMeshAttribute> {
/**
* @return The scale to be applied to vertex coordinates
*/
float getModelScale();

/**
* @return The scale to be applied to texture coordinates
*/
float getTextureScale();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class SodiumWorldRenderer implements ChunkStatusListener {
private final Set<BlockEntity> globalBlockEntities = new ObjectOpenHashSet<>();

private Frustum frustum;
private ChunkRenderManager<?> chunkRenderManager;
private ChunkRenderManager chunkRenderManager;
private BlockRenderPassManager renderPassManager;
private ChunkRenderBackend<?> chunkRenderBackend;
private ChunkRenderBackend chunkRenderBackend;

/**
* @throws IllegalStateException If the renderer has not yet been created
Expand Down Expand Up @@ -199,7 +199,7 @@ public void updateChunks(Camera camera, Frustum frustum, boolean hasForcedFrustu

profiler.pop();

Entity.setRenderDistanceMultiplier(MathHelper.clamp((double) this.client.options.viewDistance / 8.0D, 1.0D, 2.5D));
Entity.setRenderDistanceMultiplier(MathHelper.clamp((double) this.client.options.viewDistance / 8.0D, 1.0D, 2.5D) * (double) this.client.options.entityDistanceScaling);
}

/**
Expand Down Expand Up @@ -252,12 +252,12 @@ private void initRenderer() {
this.chunkRenderBackend = createChunkRenderBackend(opts.advanced.chunkRendererBackend, vertexFormat);
this.chunkRenderBackend.createShaders();

this.chunkRenderManager = new ChunkRenderManager<>(this, this.chunkRenderBackend, this.renderPassManager, this.world, this.renderDistance);
this.chunkRenderManager = new ChunkRenderManager(this, this.chunkRenderBackend, this.renderPassManager, this.world, this.renderDistance);
this.chunkRenderManager.restoreChunks(this.loadedChunkPositions);
}

private static ChunkRenderBackend<?> createChunkRenderBackend(SodiumGameOptions.ChunkRendererBackendOption opt,
ChunkVertexType vertexFormat) {
private static ChunkRenderBackend createChunkRenderBackend(SodiumGameOptions.ChunkRendererBackendOption opt,
ChunkVertexType vertexFormat) {
boolean disableBlacklist = SodiumClientMod.options().advanced.disableDriverBlacklist;

switch (opt) {
Expand Down Expand Up @@ -419,7 +419,7 @@ public void scheduleRebuildForChunk(int x, int y, int z, boolean important) {
this.chunkRenderManager.scheduleRebuild(x, y, z, important);
}

public ChunkRenderBackend<?> getChunkRenderer() {
public ChunkRenderBackend getChunkRenderer() {
return this.chunkRenderBackend;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package me.jellysquid.mods.sodium.client.render.chunk;

public abstract class ChunkGraphicsState {
import me.jellysquid.mods.sodium.common.util.collections.TrackedArrayItem;

public abstract class ChunkGraphicsState implements TrackedArrayItem {
private final int id;
private final int x, y, z;

protected ChunkGraphicsState(ChunkRenderContainer<?> container) {
protected ChunkGraphicsState(ChunkRenderContainer container, int id) {
this.x = container.getRenderX();
this.y = container.getRenderY();
this.z = container.getRenderZ();
this.id = id;
}

public abstract void delete();
Expand All @@ -22,4 +26,9 @@ public int getY() {
public int getZ() {
return this.z;
}

@Override
public int getId() {
return this.id;
}
}
Loading

0 comments on commit 5ee08c1

Please sign in to comment.