mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 20:45:59 +01:00
TextureBinder for dealing with vanilla RenderTypes
This commit is contained in:
parent
ecb3fd1540
commit
3919aaeead
@ -39,9 +39,10 @@ public enum GlError {
|
||||
}
|
||||
|
||||
public static void pollAndThrow(Supplier<String> context) {
|
||||
// TODO: build flag? to enable or disable this function
|
||||
GlError poll = GlError.poll();
|
||||
if (poll != null) {
|
||||
throw new GlException(poll, context.get());
|
||||
//throw new GlException(poll, context.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,11 +9,10 @@ import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
||||
import com.jozufozu.flywheel.util.ChunkIter;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.jozufozu.flywheel.util.TextureBinder;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
@ -103,9 +102,7 @@ public class InstanceWorld {
|
||||
public void renderLayer(RenderLayerEvent event) {
|
||||
event.type.setupRenderState();
|
||||
|
||||
ShaderInstance shader = RenderSystem.getShader();
|
||||
if (shader != null)
|
||||
shader.apply();
|
||||
TextureBinder.bindActiveTextures();
|
||||
|
||||
materialManager.render(event.layer, event.viewProjection, event.camX, event.camY, event.camZ);
|
||||
|
||||
|
@ -0,0 +1,59 @@
|
||||
package com.jozufozu.flywheel.mixin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.jozufozu.flywheel.util.TextureBinder;
|
||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
|
||||
@Mixin(ShaderInstance.class)
|
||||
public class ShaderInstanceMixin implements TextureBinder {
|
||||
@Shadow
|
||||
@Final
|
||||
private List<Integer> samplerLocations;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private List<String> samplerNames;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Map<String, Object> samplerMap;
|
||||
|
||||
@Override
|
||||
public void bind() {
|
||||
int i = GlStateManager._getActiveTexture();
|
||||
|
||||
for(int j = 0; j < samplerLocations.size(); ++j) {
|
||||
String s = samplerNames.get(j);
|
||||
if (samplerMap.get(s) != null) {
|
||||
RenderSystem.activeTexture('\u84c0' + j);
|
||||
RenderSystem.enableTexture();
|
||||
Object object = this.samplerMap.get(s);
|
||||
int l = -1;
|
||||
if (object instanceof RenderTarget) {
|
||||
l = ((RenderTarget)object).getColorTextureId();
|
||||
} else if (object instanceof AbstractTexture) {
|
||||
l = ((AbstractTexture)object).getId();
|
||||
} else if (object instanceof Integer) {
|
||||
l = (Integer)object;
|
||||
}
|
||||
|
||||
if (l != -1) {
|
||||
RenderSystem.bindTexture(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager._activeTexture(i);
|
||||
}
|
||||
}
|
30
src/main/java/com/jozufozu/flywheel/util/TextureBinder.java
Normal file
30
src/main/java/com/jozufozu/flywheel/util/TextureBinder.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.jozufozu.flywheel.util;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
|
||||
/**
|
||||
* This is a silly hack that's needed because flywheel does things too different from vanilla.
|
||||
*
|
||||
* <p>
|
||||
* When a {@link RenderType} is setup, the associated textures are passed to the active ShaderInstance, and properly
|
||||
* bound later on when {@link ShaderInstance#apply()} is called.
|
||||
* This interface (and {@link com.jozufozu.flywheel.mixin.ShaderInstanceMixin mixin} binds textures to opengl
|
||||
* without binding the shader.
|
||||
* </p>
|
||||
*/
|
||||
public interface TextureBinder {
|
||||
|
||||
/**
|
||||
* Call this after calling {@link RenderType#setupRenderState()}.
|
||||
*/
|
||||
static void bindActiveTextures() {
|
||||
TextureBinder shader = (TextureBinder) RenderSystem.getShader();
|
||||
if (shader != null)
|
||||
shader.bind();
|
||||
}
|
||||
|
||||
void bind();
|
||||
}
|
@ -18,7 +18,8 @@
|
||||
"InstanceAddMixin",
|
||||
"InstanceRemoveMixin",
|
||||
"LeakChunkStorageArrayMixin",
|
||||
"PausedPartialTickAccessor"
|
||||
"PausedPartialTickAccessor",
|
||||
"ShaderInstanceMixin"
|
||||
],
|
||||
"mixins": [
|
||||
"matrix.Matrix3fMixin",
|
||||
|
Loading…
Reference in New Issue
Block a user