Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack253-png committed Sep 21, 2024
1 parent c055263 commit 4fe33dd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package com.primogemstudio.advancedfmk.flutter;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Unique;

import java.lang.ref.Cleaner;

public class FlutterInstance implements AutoCloseable {
Expand Down Expand Up @@ -32,6 +41,34 @@ public int getTexture() {
return FlutterNative.getTexture(handle);
}

public void renderToScreen() {
var x = rect.left;
var y = Minecraft.getInstance().getWindow().getHeight() - rect.bottom;
var width = rect.right - rect.left;
var height = rect.bottom - rect.top;
var w = Minecraft.getInstance().getWindow().getWidth();
var h = Minecraft.getInstance().getWindow().getHeight();
GlStateManager._colorMask(true, true, true, false);
GlStateManager._disableDepthTest();
GlStateManager._depthMask(false);
GlStateManager._viewport(x, y, width, height);
GlStateManager._enableBlend();
var shader = Shaders.BLIT_NO_FLIP;
shader.getUniform("PositionOffset").set((float) (x / w), (float) (y / h));
shader.setSampler("DiffuseSampler", getTexture());
shader.apply();
BufferBuilder buff = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLIT_SCREEN);
buff.addVertex(0.0F, 0.0F, 0.0F);
buff.addVertex(1.0F, 0.0F, 0.0F);
buff.addVertex(1.0F, 1.0F, 0.0F);
buff.addVertex(0.0F, 1.0F, 0.0F);
BufferUploader.draw(buff.buildOrThrow());
shader.clear();
GlStateManager._disableBlend();
GlStateManager._depthMask(true);
GlStateManager._colorMask(true, true, true, true);
}

@Override
public void close() {
Events.unregister(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,6 @@ private static void flipFrame(long l, CallbackInfo ci) {
instance = new FlutterInstance("/home/coder2/flutter/flutter_demo/build/linux/x64/release/bundle/data/flutter_assets", new Rect(0, window.getHeight() - 600 - 100, 800, window.getHeight() - 100), 800, 600);
}
instance.pollEvents();
var rect = instance.rect;
blit(rect.left, window.getHeight() - rect.bottom, rect.right - rect.left, rect.bottom - rect.top);
}

@Unique
private static void blit(int x, int y, int width, int height) {
var w = Minecraft.getInstance().getWindow().getWidth();
var h = Minecraft.getInstance().getWindow().getHeight();
GlStateManager._colorMask(true, true, true, false);
GlStateManager._disableDepthTest();
GlStateManager._depthMask(false);
GlStateManager._viewport(x, y, width, height);
GlStateManager._enableBlend();
var shader = Shaders.BLIT_NO_FLIP;
shader.getUniform("PositionOffset").set((float) (x / w), (float) (y / h));
shader.setSampler("DiffuseSampler", instance.getTexture());
shader.apply();
BufferBuilder buff = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLIT_SCREEN);
buff.addVertex(0.0F, 0.0F, 0.0F);
buff.addVertex(1.0F, 0.0F, 0.0F);
buff.addVertex(1.0F, 1.0F, 0.0F);
buff.addVertex(0.0F, 1.0F, 0.0F);
BufferUploader.draw(buff.buildOrThrow());
shader.clear();
GlStateManager._disableBlend();
GlStateManager._depthMask(true);
GlStateManager._colorMask(true, true, true, true);
instance.renderToScreen();
}
}

0 comments on commit 4fe33dd

Please sign in to comment.