mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-14 06:24:12 +01:00
It bytes back
- Fix time/constant ambient light flags being written to the wrong offsets. - Align uniform buffer size to 16 instead of the offset alignment.
This commit is contained in:
parent
a33a2d2940
commit
b3ade312eb
@ -11,7 +11,7 @@ import net.minecraft.core.Vec3i;
|
|||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
public class FrameUniforms implements UniformProvider {
|
public class FrameUniforms implements UniformProvider {
|
||||||
public static final int SIZE = 228;
|
public static final int SIZE = 220;
|
||||||
|
|
||||||
private RenderContext context;
|
private RenderContext context;
|
||||||
|
|
||||||
@ -52,9 +52,9 @@ public class FrameUniforms implements UniformProvider {
|
|||||||
|
|
||||||
writeVec2(ptr + 192, camera.getXRot(), camera.getYRot());
|
writeVec2(ptr + 192, camera.getXRot(), camera.getYRot());
|
||||||
|
|
||||||
MemoryUtil.memPutInt(ptr + 208, getConstantAmbientLightFlag(context));
|
MemoryUtil.memPutInt(ptr + 200, getConstantAmbientLightFlag(context));
|
||||||
|
|
||||||
writeTime(ptr + 212);
|
writeTime(ptr + 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeTime(long ptr) {
|
private void writeTime(long ptr) {
|
||||||
|
@ -4,14 +4,10 @@ import org.lwjgl.opengl.GL32;
|
|||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferUsage;
|
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferUsage;
|
||||||
|
import com.jozufozu.flywheel.lib.math.MoreMath;
|
||||||
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
||||||
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
|
|
||||||
public class UniformBuffer<T extends UniformProvider> {
|
public class UniformBuffer<T extends UniformProvider> {
|
||||||
private static final int OFFSET_ALIGNMENT = GL32.glGetInteger(GL32.GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT);
|
|
||||||
private static final boolean PO2_ALIGNMENT = Mth.isPowerOfTwo(OFFSET_ALIGNMENT);
|
|
||||||
|
|
||||||
private final int index;
|
private final int index;
|
||||||
private final GlBuffer buffer;
|
private final GlBuffer buffer;
|
||||||
public final T provider;
|
public final T provider;
|
||||||
@ -22,8 +18,9 @@ public class UniformBuffer<T extends UniformProvider> {
|
|||||||
this.buffer = new GlBuffer(GlBufferUsage.DYNAMIC_DRAW);
|
this.buffer = new GlBuffer(GlBufferUsage.DYNAMIC_DRAW);
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
|
|
||||||
// renderdoc complains if the size of the buffer does not have the offset alignment
|
// renderdoc complains if the size of the buffer is not 16-byte aligned,
|
||||||
var actualBytes = align(provider.byteSize());
|
// though things work fine on my machine if we're short a few bytes
|
||||||
|
var actualBytes = MoreMath.align16(provider.byteSize());
|
||||||
this.data = MemoryBlock.mallocTracked(actualBytes);
|
this.data = MemoryBlock.mallocTracked(actualBytes);
|
||||||
this.data.clear();
|
this.data.clear();
|
||||||
}
|
}
|
||||||
@ -41,13 +38,4 @@ public class UniformBuffer<T extends UniformProvider> {
|
|||||||
data.free();
|
data.free();
|
||||||
buffer.delete();
|
buffer.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/3407012/rounding-up-to-the-nearest-multiple-of-a-number
|
|
||||||
private static int align(int numToRound) {
|
|
||||||
if (PO2_ALIGNMENT) {
|
|
||||||
return (numToRound + OFFSET_ALIGNMENT - 1) & -OFFSET_ALIGNMENT;
|
|
||||||
} else {
|
|
||||||
return ((numToRound + OFFSET_ALIGNMENT - 1) / OFFSET_ALIGNMENT) * OFFSET_ALIGNMENT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user