-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/com/fusionflux/portalcubed/client/render/portal/FramebufferRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.fusionflux.portalcubed.client.render.portal; | ||
|
||
import com.fusionflux.portalcubed.entity.ExperimentalPortal; | ||
import com.fusionflux.portalcubed.mixin.client.MinecraftAccessor; | ||
import com.mojang.blaze3d.pipeline.RenderTarget; | ||
import com.mojang.blaze3d.pipeline.TextureTarget; | ||
import com.mojang.blaze3d.platform.GlStateManager; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import net.minecraft.client.Minecraft; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Queue; | ||
|
||
import static com.mojang.blaze3d.platform.GlConst.GL_COLOR_BUFFER_BIT; | ||
import static com.mojang.blaze3d.platform.GlConst.GL_DEPTH_BUFFER_BIT; | ||
|
||
public class FramebufferRenderer extends PortalRenderer { | ||
// Nice setup, fastutil (IntArrayFIFOQueue isn't a priority queue) | ||
private static final Queue<RenderTarget> FREE_TARGETS = new ArrayDeque<>(); | ||
|
||
private int portalLayer = 0; | ||
|
||
private static RenderTarget getRenderTarget(int width, int height) { | ||
final RenderTarget target = FREE_TARGETS.poll(); | ||
if (target == null) { | ||
return new TextureTarget(width, height, true, Minecraft.ON_OSX); | ||
} | ||
if (target.width != width || target.height != height) { | ||
target.resize(width, height, Minecraft.ON_OSX); | ||
} | ||
return target; | ||
} | ||
|
||
private static void freeRenderTarget(RenderTarget target) { | ||
if (!FREE_TARGETS.offer(target)) { | ||
target.destroyBuffers(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean enabled(ExperimentalPortal portal) { | ||
return portalLayer < MAX_PORTAL_LAYER && portal.getActive(); | ||
} | ||
|
||
@Override | ||
public void preRender(ExperimentalPortal portal, float tickDelta, PoseStack poseStack) { | ||
} | ||
|
||
@Override | ||
public void postRender(ExperimentalPortal portal, float tickDelta, PoseStack poseStack) { | ||
final Minecraft minecraft = Minecraft.getInstance(); | ||
final RenderTarget oldTarget = minecraft.getMainRenderTarget(); | ||
final RenderTarget newTarget = getRenderTarget(oldTarget.width, oldTarget.height); | ||
|
||
((MinecraftAccessor)minecraft).setMainRenderTarget(newTarget); | ||
newTarget.bindWrite(true); | ||
|
||
GlStateManager._clearColor(1, 0, 1, 1); | ||
GlStateManager._clearDepth(1); | ||
GlStateManager._clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); | ||
|
||
portalLayer++; | ||
renderWorld(portal, tickDelta, poseStack); | ||
portalLayer--; | ||
|
||
((MinecraftAccessor)minecraft).setMainRenderTarget(oldTarget); | ||
oldTarget.bindWrite(true); | ||
|
||
freeRenderTarget(newTarget); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/fusionflux/portalcubed/mixin/client/MinecraftAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.fusionflux.portalcubed.mixin.client; | ||
|
||
import com.mojang.blaze3d.pipeline.RenderTarget; | ||
import net.minecraft.client.Minecraft; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(Minecraft.class) | ||
public interface MinecraftAccessor { | ||
@Mutable | ||
@Accessor("mainRenderTarget") | ||
void setMainRenderTarget(RenderTarget target); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters