Skip to content

Commit

Permalink
Test offset window
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack253-png committed Sep 21, 2024
1 parent 681a343 commit c055263
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public final class FlutterNative {
static {
System.load("D:/engine/src/out/host_release/flutter_minecraft.dll");
System.load("/home/coder2/flutter/engine_build/test/src/out/host_release/libflutter_minecraft.so");
}

static Cleaner cleaner = Cleaner.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public Rect(int left, int top, int right, int bottom) {

public Rect() {
}

@Override
public String toString() {
return left + " " + top + " " + right + " " + bottom;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
public class ViewEvent {
public static void resize(int width, int height) {
instances.forEach(i -> {
i.rect.top = height - i.height;
i.rect.bottom = height;
i.rect.top = height - i.height - 100;
i.rect.bottom = height - 100;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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 com.mojang.blaze3d.vertex.*;
import com.primogemstudio.advancedfmk.flutter.FlutterInstance;
import com.primogemstudio.advancedfmk.flutter.Rect;
import com.primogemstudio.advancedfmk.flutter.Shaders;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -23,21 +23,26 @@ public abstract class RenderSystemMixin {

@Inject(method = "flipFrame", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwSwapBuffers(J)V"), remap = false)
private static void flipFrame(long l, CallbackInfo ci) {
var window = Minecraft.getInstance().getWindow();
if (instance == null) {
var window = Minecraft.getInstance().getWindow();
instance = new FlutterInstance("F:/Else Language/Dart/flutter-starrail/build/app", new Rect(0, window.getHeight() - 600, 800, window.getHeight()), 800, 600);
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();
blit(800, 600);
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 width, int height) {
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(0, 0, width, height);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
}
],
"uniforms": [
{ "name": "PositionOffset", "type": "float", "count": 2, "values": [ 0.0, 0.0 ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ in vec3 Position;

out vec2 texCoord;

uniform vec2 PositionOffset;

void main() {
vec2 screenPos = Position.xy * 2.0 - 1.0;
vec2 screenPos = Position.xy * 2.0 - 1.0 + PositionOffset;
gl_Position = vec4(screenPos.x, screenPos.y, 1.0, 1.0);
texCoord = vec2(Position.x, 1 - Position.y);
}

0 comments on commit c055263

Please sign in to comment.