Skip to content

Commit 722c594

Browse files
committed
Merge remote-tracking branch 'origin/1.19.3' into 1.19
# Conflicts: # fabric/project.gradle # fabric/src/main/resources/mixins.canvas.client.json
2 parents 6dec9a4 + 8caf3e6 commit 722c594

19 files changed

+356
-176
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ This list is updated infrequently.
4747
More releases can be found in [`#canvas-3rd-party-releases` channel](https://discord.com/channels/614624415631671316/752632870257950790) on the [discord server](https://discord.gg/7NaqR2e).
4848

4949
# Developing With Canvas
50-
Before using Canvas, you should first understand RenderMaterials, Meshes, RenderContexts and other features defined by the Fabric Rendering API. For that information, consult the [rendering article on the Fabric Wiki](https://fabricmc.net/wiki/rendering). Note: Fabric wiki is still WIP as of this writing but should be more complete "soon."
50+
Before using Canvas, you should first understand RenderMaterials, Meshes, RenderContexts and other features defined by the Fabric Rendering API. For that information, consult the [rendering article on the Fabric Wiki](https://fabricmc.net/wiki/documentation:rendering). Note: Fabric wiki is still WIP as of this writing but should be more complete "soon."
5151

5252
You can also see [RenderBender](https://github.com/grondag/renderbender) for some (not very good) examples of usage. Avoid duplicating those examples directly - they aren't especially performant or suitable for use at scale. As soon as someone releases a model loader / library for Fabric Rendering API / FREX, that will almost certainly be a better approach.
5353

@@ -126,10 +126,10 @@ And add Canvas to your dependencies
126126

127127
```gradle
128128
dependencies {
129-
modCompileOnly "io.vram:canvas-fabric-mc118:1.0.+"
129+
modCompileOnly "io.vram:canvas-fabric:19.3.+"
130130
131131
// optional for testing in dev environment
132-
modRuntimeOnly "io.vram:canvas-fabric-mc118:1.0.+"
132+
modRuntimeOnly "io.vram:canvas-fabric:19.3.+"
133133
}
134134
```
135135

fabric/src/main/resources/mixins.canvas.client.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"package": "grondag.canvas.mixin",
55
"compatibilityLevel": "JAVA_16",
66
"mixins": [
7+
"MixinAccessibilityOptionsScreen",
78
"MixinAnimatedTexture",
89
"MixinAnimationMetadataSection",
910
"MixinBakedGlyph",
11+
"MixinBlockEntityRenderDispatcher",
1012
"MixinBlockRenderDispatcher",
1113
"MixinBufferBuilder",
1214
"MixinBufferUploader",

src/main/java/grondag/canvas/apiimpl/rendercontext/CanvasItemRenderContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ protected void renderCustomModel(BlockEntityWithoutLevelRenderer builtInRenderer
9191
mode = GuiMode.NORMAL;
9292
}
9393

94-
context.pushItemState(stack);
94+
context.push(stack);
9595
context.guiMode(mode);
9696
}
9797

9898
builtInRenderer.renderByItem(stack, inputContext.mode(), inputContext.matrixStack().toVanilla(), vertexConsumers, inputContext.lightmap(), inputContext.overlay());
9999

100100
if (context != null) {
101-
context.popItemState();
101+
context.pop();
102102
context.guiMode(GuiMode.NORMAL);
103103
}
104104
}

src/main/java/grondag/canvas/material/property/TargetRenderState.java

+59-75
Original file line numberDiff line numberDiff line change
@@ -30,95 +30,79 @@
3030
import grondag.canvas.pipeline.Pipeline;
3131

3232
@SuppressWarnings("resource")
33-
public class TargetRenderState implements Predicate<RenderState> {
34-
public static final TargetRenderState SOLID = new TargetRenderState(
33+
public enum TargetRenderState implements Predicate<RenderState> {
34+
SOLID(
3535
MaterialConstants.TARGET_SOLID,
3636
"solid",
37-
() -> {
38-
Pipeline.solidTerrainFbo.bind();
39-
},
40-
() -> {
41-
Pipeline.defaultFbo.bind();
42-
}
43-
);
44-
45-
public static final TargetRenderState OUTLINE = new TargetRenderState(
37+
() -> {
38+
Pipeline.solidTerrainFbo.bind();
39+
},
40+
() -> {
41+
Pipeline.defaultFbo.bind();
42+
}
43+
),
44+
OUTLINE(
4645
MaterialConstants.TARGET_OUTLINE,
4746
"outline",
48-
() -> {
49-
Minecraft.getInstance().levelRenderer.entityTarget().bindWrite(false);
50-
},
51-
() -> {
52-
Pipeline.defaultFbo.bind();
53-
}
54-
);
55-
56-
public static final TargetRenderState TRANSLUCENT = new TargetRenderState(
47+
() -> {
48+
Minecraft.getInstance().levelRenderer.entityTarget().bindWrite(false);
49+
},
50+
() -> {
51+
Pipeline.defaultFbo.bind();
52+
}
53+
),
54+
TRANSLUCENT(
5755
MaterialConstants.TARGET_TRANSLUCENT,
5856
"translucent",
59-
() -> {
60-
Pipeline.translucentTerrainFbo.bind();
61-
},
62-
() -> {
63-
Pipeline.defaultFbo.bind();
64-
}
65-
);
66-
67-
public static final TargetRenderState PARTICLES = new TargetRenderState(
57+
() -> {
58+
Pipeline.translucentTerrainFbo.bind();
59+
},
60+
() -> {
61+
Pipeline.defaultFbo.bind();
62+
}
63+
),
64+
PARTICLES(
6865
MaterialConstants.TARGET_PARTICLES,
6966
"particles",
70-
() -> {
71-
Pipeline.translucentParticlesFbo.bind();
72-
},
73-
() -> {
74-
Pipeline.defaultFbo.bind();
75-
}
76-
);
77-
78-
public static final TargetRenderState WEATHER = new TargetRenderState(
67+
() -> {
68+
Pipeline.translucentParticlesFbo.bind();
69+
},
70+
() -> {
71+
Pipeline.defaultFbo.bind();
72+
}
73+
),
74+
WEATHER(
7975
MaterialConstants.TARGET_WEATHER,
8076
"weather",
81-
() -> {
82-
Pipeline.weatherFbo.bind();
83-
},
84-
() -> {
85-
Pipeline.defaultFbo.bind();
86-
}
87-
);
88-
89-
public static final TargetRenderState CLOUDS = new TargetRenderState(
77+
() -> {
78+
Pipeline.weatherFbo.bind();
79+
},
80+
() -> {
81+
Pipeline.defaultFbo.bind();
82+
}
83+
),
84+
CLOUDS(
9085
MaterialConstants.TARGET_CLOUDS,
91-
"clouds",
92-
() -> {
93-
Pipeline.cloudsFbo.bind();
94-
},
95-
() -> {
96-
Pipeline.defaultFbo.bind();
97-
}
98-
);
99-
100-
public static final TargetRenderState ENTITIES = new TargetRenderState(
86+
"clouds",
87+
() -> {
88+
Pipeline.cloudsFbo.bind();
89+
},
90+
() -> {
91+
Pipeline.defaultFbo.bind();
92+
}
93+
),
94+
ENTITIES(
10195
MaterialConstants.TARGET_ENTITIES,
10296
"entities",
103-
() -> {
104-
Pipeline.translucentEntityFbo.bind();
105-
},
106-
() -> {
107-
Pipeline.defaultFbo.bind();
108-
}
97+
() -> {
98+
Pipeline.translucentEntityFbo.bind();
99+
},
100+
() -> {
101+
Pipeline.defaultFbo.bind();
102+
}
109103
);
110104

111-
private static final TargetRenderState[] VALUES = new TargetRenderState[MaterialConstants.TARGET_COUNT];
112-
113-
static {
114-
VALUES[MaterialConstants.TARGET_SOLID] = SOLID;
115-
VALUES[MaterialConstants.TARGET_OUTLINE] = OUTLINE;
116-
VALUES[MaterialConstants.TARGET_TRANSLUCENT] = TRANSLUCENT;
117-
VALUES[MaterialConstants.TARGET_PARTICLES] = PARTICLES;
118-
VALUES[MaterialConstants.TARGET_WEATHER] = WEATHER;
119-
VALUES[MaterialConstants.TARGET_CLOUDS] = CLOUDS;
120-
VALUES[MaterialConstants.TARGET_ENTITIES] = ENTITIES;
121-
}
105+
private static final TargetRenderState[] VALUES = values();
122106

123107
public static TargetRenderState fromIndex(int index) {
124108
return VALUES[index];
@@ -129,7 +113,7 @@ public static TargetRenderState fromIndex(int index) {
129113
private final Runnable startAction;
130114
private final Runnable endAction;
131115

132-
private TargetRenderState(int index, String name, Runnable startAction, Runnable endAction) {
116+
TargetRenderState(int index, String name, Runnable startAction, Runnable endAction) {
133117
this.index = index;
134118
this.name = name;
135119
this.startAction = startAction;

src/main/java/grondag/canvas/material/state/RenderContextState.java

+34-43
Original file line numberDiff line numberDiff line change
@@ -20,67 +20,56 @@
2020

2121
package grondag.canvas.material.state;
2222

23-
import org.jetbrains.annotations.Nullable;
23+
import java.util.Stack;
24+
25+
import javax.annotation.Nonnull;
2426

2527
import net.minecraft.world.entity.Entity;
2628
import net.minecraft.world.item.ItemStack;
27-
import net.minecraft.world.level.block.Blocks;
2829
import net.minecraft.world.level.block.entity.BlockEntity;
29-
import net.minecraft.world.level.block.state.BlockState;
3030

3131
import io.vram.frex.api.material.MaterialFinder;
3232
import io.vram.frex.api.material.MaterialMap;
3333

3434
public class RenderContextState {
35-
@SuppressWarnings("rawtypes")
36-
private MaterialMap activeMap = MaterialMap.IDENTITY;
37-
@SuppressWarnings("rawtypes")
38-
private MaterialMap swapMap = null;
39-
private Object activeGameObject = null;
4035
private final MaterialFinder finder = MaterialFinder.newInstance();
41-
42-
private MaterialMap<Entity> entityMap = MaterialMap.identity();
43-
private MaterialMap<BlockState> blockEntityMap = MaterialMap.identity();
44-
private MaterialMap<ItemStack> itemMap = MaterialMap.identity();
4536
private GuiMode guiMode = GuiMode.NORMAL;
46-
private boolean renderingItem = false;
4737

48-
public void setCurrentEntity(@Nullable Entity entity) {
49-
entityMap = entity == null ? MaterialMap.identity() : MaterialMap.get(entity.getType());
50-
activeGameObject = entity;
51-
activeMap = entityMap;
38+
// PERF: use int states and bitwise operation
39+
private record State (MaterialMap map, Object searchObj) { }
40+
41+
// PERF: use array with failsafe
42+
private final Stack<State> states = new Stack<>();
43+
44+
public RenderContextState() {
5245
}
5346

54-
public void setCurrentBlockEntity(@Nullable BlockEntity blockEntity) {
55-
if (blockEntity == null) {
56-
activeGameObject = Blocks.AIR.defaultBlockState();
57-
blockEntityMap = MaterialMap.identity();
58-
} else {
59-
activeGameObject = blockEntity.getBlockState();
60-
blockEntityMap = MaterialMap.get(blockEntity.getType());
61-
}
47+
public void push(@Nonnull Entity entity) {
48+
states.push(new State(MaterialMap.get(entity.getType()), entity));
49+
}
6250

63-
activeMap = blockEntityMap;
51+
public void push(@Nonnull BlockEntity blockEntity) {
52+
states.push(new State(MaterialMap.get(blockEntity.getType()), blockEntity.getBlockState()));
6453
}
6554

6655
/**
6756
* For items with custom renderer.
6857
*
6958
* @param itemStack the item stack
7059
*/
71-
public void pushItemState(ItemStack itemStack) {
72-
assert swapMap == null;
73-
itemMap = MaterialMap.get(itemStack);
74-
swapMap = activeMap; // preserve active function
75-
activeMap = itemMap;
76-
renderingItem = true;
60+
public void push(@Nonnull ItemStack itemStack) {
61+
states.push(new State(MaterialMap.get(itemStack), null));
62+
}
63+
64+
public void pop() {
65+
states.pop();
7766
}
7867

79-
public void popItemState() {
80-
itemMap = MaterialMap.identity();
81-
activeMap = swapMap;
82-
swapMap = null;
83-
renderingItem = false;
68+
/**
69+
* Prevent unwanted state/overflow due to conflicting hooks, etc.
70+
*/
71+
public void clear() {
72+
states.clear();
8473
}
8574

8675
public void guiMode(GuiMode guiMode) {
@@ -89,16 +78,18 @@ public void guiMode(GuiMode guiMode) {
8978

9079
@SuppressWarnings("unchecked")
9180
public CanvasRenderMaterial mapMaterial(CanvasRenderMaterial mat) {
92-
if (activeMap.isIdentity() && guiMode == GuiMode.NORMAL) {
81+
if (states.empty() && guiMode == GuiMode.NORMAL) {
9382
return mat;
9483
} else {
9584
finder.copyFrom(mat);
9685

97-
if (renderingItem) {
98-
activeMap.map(finder, null);
99-
finder.textureIndex(mat.textureIndex()); // custom item wants to retain custom texture
100-
} else {
101-
activeMap.map(finder, activeGameObject);
86+
if (!states.empty()) {
87+
final State state = states.peek();
88+
state.map.map(finder, state.searchObj);
89+
90+
if (state.searchObj == null) {
91+
finder.textureIndex(mat.textureIndex());
92+
}
10293
}
10394

10495
guiMode.apply(finder);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* This file is part of Canvas Renderer and is licensed to the project under
3+
* terms that are compatible with the GNU Lesser General Public License.
4+
* See the NOTICE file distributed with this work for additional information
5+
* regarding copyright ownership and licensing.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package grondag.canvas.mixin;
22+
23+
import org.spongepowered.asm.mixin.Mixin;
24+
import org.spongepowered.asm.mixin.injection.At;
25+
import org.spongepowered.asm.mixin.injection.Inject;
26+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
27+
28+
import net.minecraft.client.Minecraft;
29+
import net.minecraft.client.OptionInstance;
30+
import net.minecraft.client.Options;
31+
import net.minecraft.client.gui.screens.AccessibilityOptionsScreen;
32+
import net.minecraft.client.gui.screens.Screen;
33+
import net.minecraft.client.gui.screens.SimpleOptionsSubScreen;
34+
import net.minecraft.network.chat.Component;
35+
36+
import grondag.canvas.apiimpl.CanvasState;
37+
import grondag.canvas.shader.data.AccessibilityData;
38+
39+
@Mixin(AccessibilityOptionsScreen.class)
40+
public class MixinAccessibilityOptionsScreen extends SimpleOptionsSubScreen {
41+
public MixinAccessibilityOptionsScreen(Screen screen, Options options, Component component, OptionInstance<?>[] optionInstances) {
42+
super(screen, options, component, optionInstances);
43+
}
44+
45+
@Inject(at = @At("HEAD"), method = "method_31384")
46+
void onClosing(CallbackInfo ci) {
47+
canvas_onClose();
48+
}
49+
50+
@Override
51+
public void onClose() {
52+
canvas_onClose();
53+
super.onClose();
54+
}
55+
56+
private static void canvas_onClose() {
57+
if (AccessibilityData.checkChanged() && Minecraft.getInstance().level != null) {
58+
CanvasState.recompileIfNeeded(true);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)