Skip to content

Commit

Permalink
Revert "Revert "Apply BufferBuilder optimizations via delegate (Caffe…
Browse files Browse the repository at this point in the history
…ineMC#2241)""

This reverts commit 3621222.
  • Loading branch information
The Judge committed Mar 31, 2024
1 parent 29c680f commit bb412fc
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public interface VertexFormatDescription {
* start at the byte offset (index * stride).
*/
int stride();

/**
* Returns whether or not the format is "simple" (has no duplicate elements).
*/
boolean isSimpleFormat();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute;
import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.NoSuchElementException;

public class VertexFormatDescriptionImpl implements VertexFormatDescription {
Expand All @@ -14,11 +16,29 @@ public class VertexFormatDescriptionImpl implements VertexFormatDescription {

private final int[] offsets;

private final boolean isSimple;

public VertexFormatDescriptionImpl(VertexFormat format, int id) {
this.id = id;
this.stride = format.getVertexSizeByte();

this.offsets = getOffsets(format);
this.isSimple = checkSimple(format);
}

private static boolean checkSimple(VertexFormat format) {
EnumSet<CommonVertexAttribute> attributeSet = EnumSet.noneOf(CommonVertexAttribute.class);
var elementList = format.getElements();

for (int elementIndex = 0; elementIndex < elementList.size(); elementIndex++) {
var element = elementList.get(elementIndex);
var commonType = CommonVertexAttribute.getCommonType(element);
if (element != VertexFormats.PADDING_ELEMENT && (commonType == null || !attributeSet.add(commonType))) {
return false;
}
}

return true;
}

public static int[] getOffsets(VertexFormat format) {
Expand Down Expand Up @@ -66,4 +86,9 @@ public int id() {
public int stride() {
return this.stride;
}

@Override
public boolean isSimpleFormat() {
return this.isSimple;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.jellysquid.mods.sodium.client.render.vertex.buffer;

import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter;
import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription;

import java.nio.ByteBuffer;

public interface ExtendedBufferBuilder extends VertexBufferWriter {
ByteBuffer sodium$getBuffer();
int sodium$getElementOffset();
void sodium$moveToNextVertex();
VertexFormatDescription sodium$getFormatDescription();
boolean sodium$usingFixedColor();
SodiumBufferBuilder sodium$getDelegate();
}
Loading

0 comments on commit bb412fc

Please sign in to comment.