Refactor MatrixStack and RenderScope #59

This commit is contained in:
2026-03-25 17:58:08 +01:00
parent 6873f76c43
commit 3d315fa2cc
6 changed files with 8 additions and 31 deletions
@@ -1,23 +1,11 @@
package org.saturnclient.common.ref.render; package org.saturnclient.common.ref.render;
public interface MatrixStackRef { public interface MatrixStackRef {
public void translate(double x, double y, double z); public void translate(float x, float y);
public void translate(float x, float y, float z); public void scale(float x, float y);
public void scale(float x, float y, float z);
public void multiply(QuaternionfRef quaternion);
public void multiply(QuaternionfRef quaternion, float originX, float originY, float originZ);
public void push(); public void push();
public void pop(); public void pop();
public Object peek();
public boolean isEmpty();
public void loadIdentity();
} }
@@ -20,8 +20,8 @@ public class ElementRenderer {
renderScope.getMatrixStack().push(); renderScope.getMatrixStack().push();
renderScope.setOpacity(element.opacity); renderScope.setOpacity(element.opacity);
renderScope.getMatrixStack().translate(element.x, element.y, 0); renderScope.getMatrixStack().translate(element.x, element.y);
renderScope.getMatrixStack().scale(element.scale, element.scale, 1.0f); renderScope.getMatrixStack().scale(element.scale, element.scale);
element.render(renderScope, new ElementContext(elapsed, mouseX, mouseY, element)); element.render(renderScope, new ElementContext(elapsed, mouseX, mouseY, element));
renderScope.getMatrixStack().pop(); renderScope.getMatrixStack().pop();
} }
@@ -24,7 +24,6 @@ public interface RenderScope {
public int getScaledWindowHeight(); public int getScaledWindowHeight();
/* Saturn common sprites */
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height, public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
int color); int color);
@@ -44,25 +43,15 @@ public interface RenderScope {
public boolean scissorContains(int x, int y); public boolean scissorContains(int x, int y);
public void draw();
public void drawItem(ItemStackRef item, int x, int y); public void drawItem(ItemStackRef item, int x, int y);
public void drawItem(ItemStackRef stack, int x, int y, int seed);
public void drawItem(ItemStackRef stack, int x, int y, int seed, int z);
public void drawItemWithoutEntity(ItemStackRef stack, int x, int y); public void drawItemWithoutEntity(ItemStackRef stack, int x, int y);
public void drawItemWithoutEntity(ItemStackRef stack, int x, int y, int seed);
public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height); public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height);
public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height, int color); public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height, int color);
public void fill(int x1, int y1, int x2, int y2, int color); public void fill(int x1, int y1, int x2, int y2, int color);
public void fill(int x1, int y1, int x2, int y2, int z, int color);
public void drawBorder(int x, int y, int width, int height, int color); public void drawBorder(int x, int y, int width, int height, int color);
} }
@@ -51,7 +51,7 @@ public abstract class SaturnScreen {
public void render(RenderScope renderScope, int mouseX, int mouseY, float delta, long elapsed) { public void render(RenderScope renderScope, int mouseX, int mouseY, float delta, long elapsed) {
renderScope.getMatrixStack().push(); renderScope.getMatrixStack().push();
renderScope.getMatrixStack().scale(0.5f, 0.5f, 0.5f); renderScope.getMatrixStack().scale(0.5f, 0.5f);
ElementRenderer.render(new ArrayList<>(elements), elapsed, renderScope, mouseX, mouseY); ElementRenderer.render(new ArrayList<>(elements), elapsed, renderScope, mouseX, mouseY);
@@ -39,7 +39,7 @@ public class Scroll extends Element {
renderScope.enableScissor(padding, padding, width - padding, height - padding); renderScope.enableScissor(padding, padding, width - padding, height - padding);
renderScope.getMatrixStack().push(); renderScope.getMatrixStack().push();
renderScope.getMatrixStack().translate(padding, -scroll + padding, 0); renderScope.getMatrixStack().translate(padding, -scroll + padding);
ElementRenderer.render(children, ctx.elapsed, renderScope, ElementRenderer.render(children, ctx.elapsed, renderScope,
ctx.mouseX - padding, ctx.mouseX - padding,
@@ -95,8 +95,8 @@ public class HudEditor extends SaturnScreen {
MatrixStackRef matrices = renderScope.getMatrixStack(); MatrixStackRef matrices = renderScope.getMatrixStack();
matrices.push(); matrices.push();
matrices.translate(dim.x.value, dim.y.value, 0); matrices.translate(dim.x.value, dim.y.value);
matrices.scale(dim.scale.value, dim.scale.value, 1.0f); matrices.scale(dim.scale.value, dim.scale.value);
// Render the mod // Render the mod
mod.renderDummy(renderScope); mod.renderDummy(renderScope);