Skip to content
Open
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
12 changes: 6 additions & 6 deletions common/src/main/java/com/cinemamod/mcef/MCEFBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package com.cinemamod.mcef;

import com.cinemamod.mcef.listeners.MCEFCursorChangeListener;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.opengl.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import org.cef.browser.CefBrowser;
Expand Down Expand Up @@ -157,8 +157,8 @@ public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, B
renderer.onPaint(buffer, width, height);
} else {
if (renderer.getTextureID() == 0) return;
RenderSystem.bindTexture(renderer.getTextureID());
RenderSystem.pixelStore(GL_UNPACK_ROW_LENGTH, width);
GlStateManager._bindTexture(renderer.getTextureID());
GlStateManager._pixelStore(GL_UNPACK_ROW_LENGTH, width);
for (Rectangle dirtyRect : dirtyRects) {
GlStateManager._pixelStore(GL_UNPACK_SKIP_PIXELS, dirtyRect.x);
GlStateManager._pixelStore(GL_UNPACK_SKIP_ROWS, dirtyRect.y);
Expand All @@ -176,7 +176,7 @@ public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, B
} else if (popupDrawn) {
// else, a use copy of the popup graphics, as it needs to remain visible
// and for some reason that I do not for the life of me understand, chromium does not seem to keep this data in memory outside of the paint loop, meaning it has to be copied around, which wastes performance
RenderSystem.pixelStore(GL_UNPACK_ROW_LENGTH, popupSize.width);
GlStateManager._pixelStore(GL_UNPACK_ROW_LENGTH, popupSize.width);
GlStateManager._pixelStore(GL_UNPACK_SKIP_PIXELS, 0);
GlStateManager._pixelStore(GL_UNPACK_SKIP_ROWS, 0);
renderer.onPaint(popupGraphics, popupSize.x, popupSize.y, popupSize.width, popupSize.height);
Expand All @@ -185,11 +185,11 @@ public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, B
}
} else {
if (renderer.getTextureID() == 0) return;
RenderSystem.bindTexture(renderer.getTextureID());
GlStateManager._bindTexture(renderer.getTextureID());
int start = buffer.capacity();
int end = 0;
for (Rectangle dirtyRect : dirtyRects) {
RenderSystem.pixelStore(GL_UNPACK_ROW_LENGTH, popupSize.width);
GlStateManager._pixelStore(GL_UNPACK_ROW_LENGTH, popupSize.width);
GlStateManager._pixelStore(GL_UNPACK_SKIP_PIXELS, dirtyRect.x);
GlStateManager._pixelStore(GL_UNPACK_SKIP_ROWS, dirtyRect.y);
renderer.onPaint(buffer, popupSize.x + dirtyRect.x, popupSize.y + dirtyRect.y, dirtyRect.width, dirtyRect.height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void downloadJavaCefBuild() throws IOException {
/**
* @return true if the jcef build checksum file matches the remote checksum file (for the {@link MCEFDownloader#javaCefCommitHash}),
* false if the jcef build checksum file did not exist or did not match; this means we should redownload JCEF
* @throws IOException
*/
public boolean downloadJavaCefChecksum() throws IOException {
File mcefLibrariesPath = new File(System.getProperty("mcef.libraries.path"));
Expand Down
19 changes: 10 additions & 9 deletions common/src/main/java/com/cinemamod/mcef/MCEFRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.cinemamod.mcef;

import com.mojang.blaze3d.opengl.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;

import java.nio.ByteBuffer;
Expand All @@ -36,10 +37,10 @@ protected MCEFRenderer(boolean transparent) {

public void initialize() {
textureID[0] = glGenTextures();
RenderSystem.bindTexture(textureID[0]);
RenderSystem.texParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
RenderSystem.texParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
RenderSystem.bindTexture(0);
GlStateManager._bindTexture(textureID[0]);
GlStateManager._texParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GlStateManager._texParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GlStateManager._bindTexture(0);
}

public int getTextureID() {
Expand All @@ -59,11 +60,11 @@ protected void cleanup() {

protected void onPaint(ByteBuffer buffer, int width, int height) {
if (textureID[0] == 0) return;
if (transparent) RenderSystem.enableBlend();
RenderSystem.bindTexture(textureID[0]);
RenderSystem.pixelStore(GL_UNPACK_ROW_LENGTH, width);
RenderSystem.pixelStore(GL_UNPACK_SKIP_PIXELS, 0);
RenderSystem.pixelStore(GL_UNPACK_SKIP_ROWS, 0);
if (transparent) GlStateManager._enableBlend();
GlStateManager._bindTexture(textureID[0]);
GlStateManager._pixelStore(GL_UNPACK_ROW_LENGTH, width);
GlStateManager._pixelStore(GL_UNPACK_SKIP_PIXELS, 0);
GlStateManager._pixelStore(GL_UNPACK_SKIP_ROWS, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buffer);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.cinemamod.mcef.example;

import com.cinemamod.mcef.mixins.ExampleTextureMixin;
import com.mojang.blaze3d.opengl.GlTexture;
import com.mojang.blaze3d.textures.TextureFormat;

public class ExampleGlTexture extends GlTexture {

protected int width;
protected int height;
public ExampleGlTexture(int usage, String label, TextureFormat texFormat, int width, int height, int depthOrLayers, int mipLevels, int glId) {
super(usage, label, texFormat, width, height, depthOrLayers, mipLevels, glId);
this.width = width;
this.height = height;
}

@Override
public int getWidth(int i) {
return this.width >> i;
}

public void setWidth(int width) {
this.width = width;
}

@Override
public int getHeight(int i) {
return this.height >> i;
}

public void setHeight(int height) {
this.height = height;
}

@Override
public int glId() {
return this.id;
}

public void setGlId(int id) {
((ExampleTextureMixin) this).setId(id);
}

}
54 changes: 31 additions & 23 deletions common/src/main/java/com/cinemamod/mcef/example/ExampleScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,41 @@

import com.cinemamod.mcef.MCEF;
import com.cinemamod.mcef.MCEFBrowser;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.textures.GpuTexture;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.MeshData;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

import java.awt.*;
import java.util.UUID;

public class ExampleScreen extends Screen {
private static final int BROWSER_DRAW_OFFSET = 20;

private MCEFBrowser browser;
protected ResourceLocation exampleLocation;
protected ExampleTexture exampleTexture;

protected ExampleScreen(Component component) {
public ExampleScreen(Component component) {
super(component);
}

@Override
protected void init() {
super.init();
if (browser == null) {
exampleLocation = ResourceLocation.fromNamespaceAndPath("example", "frame_" + UUID.randomUUID().toString().replace("-", ""));

exampleTexture = new ExampleTexture(-1, this.exampleLocation.toString());
String url = "https://www.google.com";
boolean transparent = true;
boolean transparent = false;
browser = MCEF.createBrowser(url, transparent);
resizeBrowser();

Minecraft.getInstance().getTextureManager().register(this.exampleLocation, this.exampleTexture);

}
}

Expand All @@ -76,6 +82,12 @@ private void resizeBrowser() {
}
}

private void updateFrame() {
this.exampleTexture.setId(this.browser.getRenderer().getTextureID());
this.exampleTexture.setWidth(this.width);
this.exampleTexture.setHeight(this.height);
}

@Override
public void resize(Minecraft minecraft, int i, int j) {
super.resize(minecraft, i, j);
Expand All @@ -91,20 +103,16 @@ public void onClose() {
@Override
public void render(GuiGraphics guiGraphics, int i, int j, float f) {
super.render(guiGraphics, i, j, f);
// RenderSystem.disableDepthTest();
// RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR);
GpuTexture texture = RenderSystem.getShaderTexture(browser.getRenderer().getTextureID());
RenderSystem.setShaderTexture(0, texture);
Tesselator t = Tesselator.getInstance();
BufferBuilder buffer = t.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
buffer.addVertex(BROWSER_DRAW_OFFSET, height - BROWSER_DRAW_OFFSET, 0).setUv(0.0f, 1.0f).setColor(255, 255, 255, 255);
buffer.addVertex(width - BROWSER_DRAW_OFFSET, height - BROWSER_DRAW_OFFSET, 0).setUv(1.0f, 1.0f).setColor(255, 255, 255, 255);
buffer.addVertex(width - BROWSER_DRAW_OFFSET, BROWSER_DRAW_OFFSET, 0).setUv(1.0f, 0.0f).setColor(255, 255, 255, 255);
buffer.addVertex(BROWSER_DRAW_OFFSET, BROWSER_DRAW_OFFSET, 0).setUv(0.0f, 0.0f).setColor(255, 255, 255, 255);
MeshData data = buffer.build();
// BufferUploader.drawWithShader(buffer.build());
RenderSystem.setShaderTexture(0, texture);
// RenderSystem.enableDepthTest();
this.updateFrame();
guiGraphics.blit(
RenderPipelines.GUI_TEXTURED,
this.exampleLocation,
BROWSER_DRAW_OFFSET, BROWSER_DRAW_OFFSET,
0, 0,
width - BROWSER_DRAW_OFFSET * 2, height - BROWSER_DRAW_OFFSET * 2,
width - BROWSER_DRAW_OFFSET * 2, height - BROWSER_DRAW_OFFSET * 2,
Color.white.getRGB()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.cinemamod.mcef.example;

import com.mojang.blaze3d.systems.GpuDevice;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.textures.FilterMode;
import com.mojang.blaze3d.textures.TextureFormat;
import net.minecraft.client.renderer.texture.AbstractTexture;
import org.jetbrains.annotations.NotNull;

public class ExampleTexture extends AbstractTexture {
protected final ExampleGlTexture glTexture;

public ExampleTexture(int id, @NotNull String label) {
this.glTexture = new ExampleGlTexture(5, label, TextureFormat.RGBA8, 100, 100, 1, 1, id);
this.glTexture.setTextureFilter(FilterMode.NEAREST, false);
this.texture = this.glTexture;
GpuDevice device = RenderSystem.getDevice();
this.textureView = device.createTextureView(this.texture);
}

public void setId(int id) {
this.glTexture.setGlId(id);
}

public void setWidth(int width) {
this.glTexture.setWidth(width);
}

public void setHeight(int height) {
this.glTexture.setHeight(height);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.Component;
import org.joml.Matrix3x2fStack;

public class MCEFDownloaderMenu extends Screen {
private final Screen menu;
Expand All @@ -38,19 +39,19 @@ public MCEFDownloaderMenu(Screen menu) {

@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
renderBackground(graphics, mouseX, mouseY, partialTick);
double cx = width / 2d;
double cy = height / 2d;
//renderBackground(graphics, mouseX, mouseY, partialTick);
float cx = width / 2f;
float cy = height / 2f;

double progressBarHeight = 14;
double progressBarWidth = width / 3d; // TODO: base off screen with (1/3 of screen)
float progressBarHeight = 14;
float progressBarWidth = width / 3f; // TODO: base off screen with (1/3 of screen)

PoseStack poseStack = graphics.pose();
Matrix3x2fStack poseStack = graphics.pose();

/* Draw Progress Bar */
poseStack.pushPose();
poseStack.translate(cx, cy, 0);
poseStack.translate(-progressBarWidth / 2d, -progressBarHeight / 2d, 0);
poseStack.pushMatrix();
poseStack.translate(cx, cy);
poseStack.translate(-progressBarWidth / 2f, -progressBarHeight / 2f);
graphics.fill( // bar border
0, 0,
(int) progressBarWidth,
Expand All @@ -69,7 +70,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
(int) progressBarHeight - 4,
-1
);
poseStack.popPose();
poseStack.popMatrix();

// putting this here incase I want to re-add a third line later on
// allows me to generalize the code to not care about line count
Expand All @@ -81,11 +82,10 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
/* Draw Text */
// calculate offset for the top line
int oSet = ((font.lineHeight / 2) + ((font.lineHeight + 2) * (text.length + 2))) + 4;
poseStack.pushPose();
poseStack.pushMatrix();
poseStack.translate(
(int) (cx),
(int) (cy - oSet),
0
(int) (cy - oSet)
);
// draw menu name
graphics.drawString(
Expand All @@ -98,10 +98,10 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
int index = 0;
for (String s : text) {
if (index == 1) {
poseStack.translate(0, font.lineHeight + 2, 0);
poseStack.translate(0, font.lineHeight + 2);
}

poseStack.translate(0, font.lineHeight + 2, 0);
poseStack.translate(0, font.lineHeight + 2);
graphics.drawString(
font,
s,
Expand All @@ -110,7 +110,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
);
index++;
}
poseStack.popPose();
poseStack.pushMatrix();

// TODO: if listener.isFailed(), draw some "Failed to initialize MCEF" text with an "OK" button to proceed
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cinemamod.mcef.mixins;

import com.mojang.blaze3d.opengl.GlTexture;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(GlTexture.class)
public interface ExampleTextureMixin {
@Accessor("id")
@Mutable
void setId(int id);
}
3 changes: 2 additions & 1 deletion common/src/main/resources/mcef.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"CefDownloadMixin",
"CefInitMixin",
"CefRenderUpdateMixin",
"CefWindowsShutdownMixin"
"CefWindowsShutdownMixin",
"ExampleTextureMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
8 changes: 4 additions & 4 deletions fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
org.gradle.jvmargs=-Xmx4G
org.gradle.daemon=false

minecraft_dependency=1.21.4
curseforge_minecraft_version=1.21.4
minecraft_dependency=1.21.7
curseforge_minecraft_version=1.21.7

fabric_version=0.119.5+1.21.5
min_fabric_version=0.119.5+1.21.5
fabric_version=0.128.2+1.21.7
min_fabric_version=0.128.2+1.21.7

maven_group=com.cinemamod
archives_base_name=mcef-fabric
Expand Down
Loading