Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ jobs:
cache-read-only: ${{ !endsWith(github.ref_name, '/dev') }}

- name: Build
# Doesn't actually publish, as no secrets are passed in, just makes sure that publishing works
run: ./gradlew publish --no-daemon
run: ./gradlew build -x test --no-daemon

- name: Capture Build Artifacts
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: |
common/build/libs/
fabric/build/libs/
neoforge/build/libs/
vanillin/common/build/libs/
vanillin/fabric/build/libs/
vanillin/neoforge/build/libs/
common/build/libs/*.jar
neoforge/build/libs/*.jar
vanillin/common/build/libs/*.jar
vanillin/neoforge/build/libs/*.jar
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ docs/*.local
.DS_Store
mcmodsrepo
**/src/**/generatedPackageInfos/

# Generated build output and local tooling
.vscode/
*.log
replay_pid*.log
hs_err_pid*.log
2 changes: 1 addition & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend")
val main = sourceSets.getByName("main")

loom.accessWidenerPath = project(projects.flywheelFabric.path).file("src/main/resources/flywheel.accesswidener")
loom.accessWidenerPath = rootProject.file("fabric/src/main/resources/flywheel.accesswidener")

transitiveSourceSets {
compileClasspath = main.compileClasspath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package dev.engine_room.flywheel.api.visualization;

import java.util.SortedSet;

import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.Nullable;

import dev.engine_room.flywheel.api.backend.RenderContext;
import dev.engine_room.flywheel.api.internal.FlwApiLink;
import dev.engine_room.flywheel.api.visual.Effect;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.minecraft.core.Vec3i;
import net.minecraft.server.level.BlockDestructionProgress;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand Down Expand Up @@ -70,8 +66,7 @@ interface RenderDispatcher {
* Render crumbling block entities.
*
* <p>Guaranteed to be called after {@link #onStartLevelRender} and {@link #afterSubmitEntities}
* @param destructionProgress The destruction progress map from {@link net.minecraft.client.renderer.LevelRenderer LevelRenderer}.
*/
void beforeSubmitCrumbling(RenderContext ctx, Long2ObjectMap<SortedSet<BlockDestructionProgress>> destructionProgress);
void beforeSubmitCrumbling(RenderContext ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,31 @@ private static void array(List<VertexAttribute> out, ArrayElementType array) {
}
}

private static VertexFormatElement.Type toGlType(IntegerRepr repr) {
private static VertexAttribute.Type toGlType(IntegerRepr repr) {
return switch (repr) {
case BYTE -> VertexFormatElement.Type.BYTE;
case SHORT -> VertexFormatElement.Type.SHORT;
case INT -> VertexFormatElement.Type.INT;
case BYTE -> VertexAttribute.Type.BYTE;
case SHORT -> VertexAttribute.Type.SHORT;
case INT -> VertexAttribute.Type.INT;
};
}

private static VertexFormatElement.Type toGlType(UnsignedIntegerRepr repr) {
private static VertexAttribute.Type toGlType(UnsignedIntegerRepr repr) {
return switch (repr) {
case UNSIGNED_BYTE -> VertexFormatElement.Type.UBYTE;
case UNSIGNED_SHORT -> VertexFormatElement.Type.USHORT;
case UNSIGNED_INT -> VertexFormatElement.Type.UINT;
case UNSIGNED_BYTE -> VertexAttribute.Type.UBYTE;
case UNSIGNED_SHORT -> VertexAttribute.Type.USHORT;
case UNSIGNED_INT -> VertexAttribute.Type.UINT;
};
}

private static VertexFormatElement.Type toGlType(FloatRepr repr) {
private static VertexAttribute.Type toGlType(FloatRepr repr) {
return switch (repr) {
case BYTE, NORMALIZED_BYTE -> VertexFormatElement.Type.BYTE;
case UNSIGNED_BYTE, NORMALIZED_UNSIGNED_BYTE -> VertexFormatElement.Type.UBYTE;
case SHORT, NORMALIZED_SHORT -> VertexFormatElement.Type.SHORT;
case UNSIGNED_SHORT, NORMALIZED_UNSIGNED_SHORT -> VertexFormatElement.Type.USHORT;
case INT, NORMALIZED_INT -> VertexFormatElement.Type.INT;
case UNSIGNED_INT, NORMALIZED_UNSIGNED_INT -> VertexFormatElement.Type.UINT;
case FLOAT -> VertexFormatElement.Type.FLOAT;
case BYTE, NORMALIZED_BYTE -> VertexAttribute.Type.BYTE;
case UNSIGNED_BYTE, NORMALIZED_UNSIGNED_BYTE -> VertexAttribute.Type.UBYTE;
case SHORT, NORMALIZED_SHORT -> VertexAttribute.Type.SHORT;
case UNSIGNED_SHORT, NORMALIZED_UNSIGNED_SHORT -> VertexAttribute.Type.USHORT;
case INT, NORMALIZED_INT -> VertexAttribute.Type.INT;
case UNSIGNED_INT, NORMALIZED_UNSIGNED_INT -> VertexAttribute.Type.UINT;
case FLOAT -> VertexAttribute.Type.FLOAT;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@

import org.jetbrains.annotations.UnknownNullability;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mojang.blaze3d.opengl.GlConst;
import com.mojang.blaze3d.opengl.GlStateManager;
import com.mojang.blaze3d.opengl.GlTexture;
import com.mojang.blaze3d.platform.NativeImage;

import dev.engine_room.flywheel.api.Flywheel;
import dev.engine_room.flywheel.backend.gl.GlTextureUnit;
import dev.engine_room.flywheel.lib.util.IdentifierUtil;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.resources.ResourceManager;

public class NoiseTextures {
private static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/backend/noise");
public static final Identifier NOISE_TEXTURE = IdentifierUtil.id("textures/flywheel/noise/blue.png");

@UnknownNullability
Expand All @@ -34,7 +39,7 @@ public static void reload(ResourceManager manager) {

try (var is = optional.get()
.open()) {
var image = NativeImage.read(NativeImage.Format.LUMINANCE, is);
var image = NativeImage.read(NativeImage.Format.RGBA, is);

// TODO 1.21.11: maybe we should not use DynamicTexture here and do gen/upload manually
BLUE_NOISE = new DynamicTexture(() -> "Flywheel Blue Noise", image);
Expand All @@ -48,8 +53,8 @@ public static void reload(ResourceManager manager) {
GlStateManager._texParameter(GlConst.GL_TEXTURE_2D, GlConst.GL_TEXTURE_WRAP_T, GlConst.GL_REPEAT);

GlStateManager._bindTexture(0);
} catch (IOException e) {

} catch (Throwable t) {
LOGGER.error("Failed to load blue noise texture", t);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,26 @@ private static void setupDepthTest(DepthTest depthTest) {
private static void setupTransparency(Transparency transparency) {
switch (transparency) {
case OPAQUE -> {
GlStateManager._disableBlend();
GlStateManager._disableBlend(0);
}
case ADDITIVE -> {
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);
GlStateManager._blendFuncSeparate(GlConst.GL_ONE, GlConst.GL_ONE, GlConst.GL_ONE, GlConst.GL_ONE);
}
case LIGHTNING -> {
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);
GlStateManager._blendFuncSeparate(GlConst.GL_SRC_ALPHA, GlConst.GL_ONE, GlConst.GL_SRC_ALPHA, GlConst.GL_ONE);
}
case GLINT -> {
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);
GlStateManager._blendFuncSeparate(GlConst.GL_SRC_COLOR, GlConst.GL_ONE, GlConst.GL_ZERO, GlConst.GL_ONE);
}
case CRUMBLING -> {
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);
GlStateManager._blendFuncSeparate(GlConst.GL_DST_COLOR, GlConst.GL_SRC_COLOR, GlConst.GL_ONE, GlConst.GL_ZERO);
}
case TRANSLUCENT -> {
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);
GlStateManager._blendFuncSeparate(GlConst.GL_SRC_ALPHA, GlConst.GL_ONE_MINUS_SRC_ALPHA, GlConst.GL_ONE, GlConst.GL_ONE_MINUS_SRC_ALPHA);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.lwjgl.opengl.GL32;

import com.mojang.blaze3d.opengl.GlConst;
import com.mojang.blaze3d.vertex.VertexFormat;

import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.backend.InternalVertex;
Expand Down Expand Up @@ -183,9 +182,9 @@ public boolean isInvalid() {

public void draw(int instanceCount) {
if (instanceCount > 1) {
GL32.glDrawElementsInstancedBaseVertex(GlConst.toGl(VertexFormat.Mode.TRIANGLES), mesh.indexCount(), GlConst.GL_UNSIGNED_INT, firstIndexByteOffset(), instanceCount, baseVertex);
GL32.glDrawElementsInstancedBaseVertex(GlConst.GL_TRIANGLES, mesh.indexCount(), GlConst.GL_UNSIGNED_INT, firstIndexByteOffset(), instanceCount, baseVertex);
} else {
GL32.glDrawElementsBaseVertex(GlConst.toGl(VertexFormat.Mode.TRIANGLES), mesh.indexCount(), GlConst.GL_UNSIGNED_INT, firstIndexByteOffset(), baseVertex);
GL32.glDrawElementsBaseVertex(GlConst.GL_TRIANGLES, mesh.indexCount(), GlConst.GL_UNSIGNED_INT, firstIndexByteOffset(), baseVertex);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.engine_room.flywheel.backend.engine;

import java.util.Collections;
import java.util.List;

import org.jspecify.annotations.Nullable;
import org.lwjgl.opengl.GL33C;

import com.mojang.blaze3d.opengl.FrameBufferAttachment;
import com.mojang.blaze3d.opengl.GlConst;
import com.mojang.blaze3d.opengl.GlDevice;
import com.mojang.blaze3d.opengl.GlSampler;
Expand Down Expand Up @@ -61,9 +63,10 @@ public static void bindLightAndOverlay() {

public static void bindRenderTarget(RenderTarget target) {
GlTexture colorTexture = (GlTexture) target.getColorTexture();
int i = colorTexture.getFbo(
int i = GlUtil.getGlDevice().frameBufferCache().getFbo(
GlUtil.getGlDevice().directStateAccess(),
target.getDepthTexture()
List.of((FrameBufferAttachment) target.getColorTexture()),
(FrameBufferAttachment) target.getDepthTexture()
);
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DepthPyramid(IndirectPrograms programs) {

public void generate() {
var mainRenderTarget = Minecraft.getInstance()
.getMainRenderTarget();
.gameRenderer.mainRenderTarget();

int width = mip0Size(mainRenderTarget.width);
int height = mip0Size(mainRenderTarget.height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void render(LightStorage lightStorage, EnvironmentStorage environmentStor
lightBuffers.bind();
matrixBuffer.bind();
Uniforms.bindAll();
TextureBinder.bindRenderTarget(Minecraft.getInstance().getMainRenderTarget());
TextureBinder.bindRenderTarget(Minecraft.getInstance().gameRenderer.mainRenderTarget());

for (var group : cullingGroups.values()) {
group.submitSolid();
Expand Down Expand Up @@ -245,7 +245,7 @@ public void renderCrumbling(List<Engine.CrumblingBlock> crumblingBlocks) {
// Set up the crumbling program buffers. Nothing changes here between draws.
GlBufferType.DRAW_INDIRECT_BUFFER.bind(crumblingDrawBuffer.handle());
GL30.glBindBufferRange(GL43.GL_SHADER_STORAGE_BUFFER, BufferBindings.DRAW, crumblingDrawBuffer.handle(), 0, IndirectBuffers.DRAW_COMMAND_STRIDE);
TextureBinder.bindRenderTarget(Minecraft.getInstance().getMainRenderTarget());
TextureBinder.bindRenderTarget(Minecraft.getInstance().gameRenderer.mainRenderTarget());

for (var groupEntry : byType.entrySet()) {
var byProgress = groupEntry.getValue();
Expand Down Expand Up @@ -292,7 +292,7 @@ public void renderCrumbling(List<Engine.CrumblingBlock> crumblingBlocks) {
@Override
public void triggerFallback() {
IndirectPrograms.kill();
Minecraft.getInstance().levelRenderer.allChanged();
Minecraft.getInstance().levelRenderer.resetLevelRenderData();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package dev.engine_room.flywheel.backend.engine.indirect;

import java.util.List;

import org.lwjgl.opengl.GL32;
import org.lwjgl.opengl.GL46;

import com.mojang.blaze3d.opengl.FrameBufferAttachment;
import com.mojang.blaze3d.opengl.GlConst;
import com.mojang.blaze3d.opengl.GlStateManager;
import com.mojang.blaze3d.opengl.GlTexture;
Expand Down Expand Up @@ -50,14 +53,14 @@ public OitFramebuffer(OitPrograms programs) {
public void prepare() {
RenderTarget renderTarget;

if (Minecraft.useShaderTransparency()) {
renderTarget = Minecraft.getInstance().levelRenderer.getItemEntityTarget();
if (Minecraft.getInstance().options.improvedTransparency().get()) {
renderTarget = Minecraft.getInstance().levelRenderer.itemEntityTarget();

renderTarget.copyDepthFrom(Minecraft.getInstance()
.getMainRenderTarget());
.gameRenderer.mainRenderTarget());
} else {
renderTarget = Minecraft.getInstance()
.getMainRenderTarget();
.gameRenderer.mainRenderTarget();
}

maybeResizeFBO(renderTarget.width, renderTarget.height);
Expand Down Expand Up @@ -85,11 +88,11 @@ public void depthRange() {
// No depth writes, but we'll still use the depth test.
GlStateManager._depthMask(false);
GlStateManager._colorMask(ColorTargetState.WRITE_ALL);
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);
GlStateManager._blendFuncSeparate(GlConst.GL_ONE, GlConst.GL_ONE, GlConst.GL_ONE, GlConst.GL_ONE);
GL32.glBlendEquation(GlConst.GL_MAX);

float far = Minecraft.getInstance().gameRenderer.getGameRenderState().levelRenderState.cameraRenderState.depthFar;
float far = Minecraft.getInstance().gameRenderer.gameRenderState().levelRenderState.cameraRenderState.depthFar;

if (GlCompat.SUPPORTS_DSA) {
GL46.glNamedFramebufferDrawBuffers(fbo, DEPTH_RANGE_DRAW_BUFFERS);
Expand All @@ -108,7 +111,7 @@ public void renderTransmittance() {
// No depth writes, but we'll still use the depth test
GlStateManager._depthMask(false);
GlStateManager._colorMask(ColorTargetState.WRITE_ALL);
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);
GlStateManager._blendFuncSeparate(GlConst.GL_ONE, GlConst.GL_ONE, GlConst.GL_ONE, GlConst.GL_ONE);
GL32.glBlendEquation(GlConst.GL_FUNC_ADD);

Expand All @@ -134,7 +137,7 @@ public void renderDepthFromTransmittance() {
// Only write to depth, not color.
GlStateManager._depthMask(true);
GlStateManager._colorMask(ColorTargetState.WRITE_NONE);
GlStateManager._disableBlend();
GlStateManager._disableBlend(0);
GlStateManager._depthFunc(GlConst.GL_ALWAYS);

if (GlCompat.SUPPORTS_DSA) {
Expand All @@ -156,7 +159,7 @@ public void accumulate() {
// No depth writes, but we'll still use the depth test
GlStateManager._depthMask(false);
GlStateManager._colorMask(ColorTargetState.WRITE_ALL);
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);
GlStateManager._blendFuncSeparate(GlConst.GL_ONE, GlConst.GL_ONE, GlConst.GL_ONE, GlConst.GL_ONE);
GL32.glBlendEquation(GlConst.GL_FUNC_ADD);

Expand All @@ -175,10 +178,10 @@ public void accumulate() {
* Composite the accumulated luminance onto the main framebuffer.
*/
public void composite() {
if (Minecraft.useShaderTransparency()) {
bindRenderTarget(Minecraft.getInstance().levelRenderer.getItemEntityTarget());
if (Minecraft.getInstance().options.improvedTransparency().get()) {
bindRenderTarget(Minecraft.getInstance().levelRenderer.itemEntityTarget());
} else {
bindRenderTarget(Minecraft.getInstance().getMainRenderTarget());
bindRenderTarget(Minecraft.getInstance().gameRenderer.mainRenderTarget());
}

// The composite shader writes out the closest depth to gl_FragDepth.
Expand All @@ -187,7 +190,7 @@ public void composite() {
// If Neo gets wavelet OIT we can use their hooks to be correct with everything.
GlStateManager._depthMask(true);
GlStateManager._colorMask(ColorTargetState.WRITE_ALL);
GlStateManager._enableBlend();
GlStateManager._enableBlend(0);

// We rely on the blend func to achieve:
// final color = (1 - transmittance_total) * sum(color_f * alpha_f * transmittance_f) / sum(alpha_f * transmittance_f)
Expand All @@ -207,14 +210,15 @@ public void composite() {

drawFullscreenQuad();

bindRenderTarget(Minecraft.getInstance().getMainRenderTarget());
bindRenderTarget(Minecraft.getInstance().gameRenderer.mainRenderTarget());
}

private static void bindRenderTarget(RenderTarget target) {
GlTexture colorTexture = (GlTexture) target.getColorTexture();
int i = colorTexture.getFbo(
int i = GlUtil.getGlDevice().frameBufferCache().getFbo(
GlUtil.getGlDevice().directStateAccess(),
target.getDepthTexture()
List.of((FrameBufferAttachment) target.getColorTexture()),
(FrameBufferAttachment) target.getDepthTexture()
);
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, i);
GlStateManager._viewport(0, 0, colorTexture.getWidth(0), colorTexture.getHeight(0));
Expand Down
Loading