Fix uniform bindings

This commit is contained in:
Kneelawk 2024-03-04 14:28:02 -08:00
parent 7bb04daa82
commit aae98c06f4
Failed to generate hash of commit
3 changed files with 18 additions and 8 deletions

View file

@ -11,6 +11,7 @@ import com.jozufozu.flywheel.api.instance.InstanceType;
import com.jozufozu.flywheel.backend.compile.component.IndirectComponent;
import com.jozufozu.flywheel.backend.compile.core.CompilationHarness;
import com.jozufozu.flywheel.backend.compile.core.Compile;
import com.jozufozu.flywheel.backend.engine.uniform.Uniforms;
import com.jozufozu.flywheel.backend.gl.GlCompat;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
@ -81,7 +82,7 @@ public class IndirectPrograms extends AtomicReferenceCounted {
.withComponent(IndirectComponent::create)
.withResource(InstanceType::cullShader)
.withResource(CULL_SHADER_MAIN))
.postLink((key, program) -> program.setUniformBlockBinding("_FlwFrameUniforms", 0))
.postLink((key, program) -> program.setUniformBlockBinding("_FlwFrameUniforms", Uniforms.FRAME_INDEX))
.harness("culling", sources);
}

View file

@ -6,6 +6,7 @@ import com.jozufozu.flywheel.backend.InternalVertex;
import com.jozufozu.flywheel.backend.Samplers;
import com.jozufozu.flywheel.backend.compile.core.CompilationHarness;
import com.jozufozu.flywheel.backend.compile.core.Compile;
import com.jozufozu.flywheel.backend.engine.uniform.Uniforms;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.glsl.ShaderSources;
@ -60,8 +61,11 @@ public class PipelineCompiler {
program.bindAttribLocation("_flw_a_normal", 5);
})
.postLink((key, program) -> {
program.setUniformBlockBinding("_FlwFrameUniforms", 0);
program.setUniformBlockBinding("_FlwFogUniforms", 1);
program.setUniformBlockBinding("_FlwFrameUniforms", Uniforms.FRAME_INDEX);
program.setUniformBlockBinding("_FlwFogUniforms", Uniforms.FOG_INDEX);
program.setUniformBlockBinding("_FlwOptionsUniforms", Uniforms.OPTIONS_INDEX);
program.setUniformBlockBinding("_FlwPlayerUniforms", Uniforms.PLAYER_INDEX);
program.setUniformBlockBinding("_FlwLevelUniforms", Uniforms.LEVEL_INDEX);
program.bind();

View file

@ -17,6 +17,11 @@ import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.Vec3;
public class Uniforms {
public static final int FRAME_INDEX = 0;
public static final int FOG_INDEX = 1;
public static final int OPTIONS_INDEX = 2;
public static final int PLAYER_INDEX = 3;
public static final int LEVEL_INDEX = 4;
public static boolean frustumPaused = false;
public static boolean frustumCapture = false;
private static @Nullable UniformBuffer<FrameUniforms> frame;
@ -27,35 +32,35 @@ public class Uniforms {
public static UniformBuffer<FrameUniforms> frame() {
if (frame == null) {
frame = new UniformBuffer<>(0, new FrameUniforms());
frame = new UniformBuffer<>(FRAME_INDEX, new FrameUniforms());
}
return frame;
}
public static UniformBuffer<FogUniforms> fog() {
if (fog == null) {
fog = new UniformBuffer<>(1, new FogUniforms());
fog = new UniformBuffer<>(FOG_INDEX, new FogUniforms());
}
return fog;
}
public static UniformBuffer<OptionsUniforms> options() {
if (options == null) {
options = new UniformBuffer<>(2, new OptionsUniforms());
options = new UniformBuffer<>(OPTIONS_INDEX, new OptionsUniforms());
}
return options;
}
public static UniformBuffer<PlayerUniforms> player() {
if (player == null) {
player = new UniformBuffer<>(3, new PlayerUniforms());
player = new UniformBuffer<>(PLAYER_INDEX, new PlayerUniforms());
}
return player;
}
public static UniformBuffer<LevelUniforms> level() {
if (level == null) {
level = new UniformBuffer<>(4, new LevelUniforms());
level = new UniformBuffer<>(LEVEL_INDEX, new LevelUniforms());
}
return level;
}