mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-08 21:14:41 -04:00
Remove CoreShaderRegistrationCallback as its no longer required. (#4063)
This commit is contained in:
parent
42a8e21cd7
commit
2ade441e60
3 changed files with 22 additions and 87 deletions
fabric-rendering-v1/src
client/java/net/fabricmc/fabric/api/client/rendering/v1
testmodClient
java/net/fabricmc/fabric/test/rendering/client
resources/assets/fabric-rendering-v1-testmod/shaders/core
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.api.client.rendering.v1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.minecraft.client.gl.ShaderProgram;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
|
||||
/**
|
||||
* Called when core shaders ({@linkplain ShaderProgram shader programs} loaded from {@code assets/<namespace>/shaders/core})
|
||||
* are loaded to register custom modded shaders.
|
||||
*
|
||||
* <p>Fabric API also modifies the {@code #moj_import} feature in core shaders to accept
|
||||
* arbitrary namespaces for shaders loaded using the {@code <filename.glsl>} syntax.
|
||||
* For example, {@code #moj_import <my_mod:test.glsl>} would import the shader from
|
||||
* {@code assets/my_mod/shaders/include/test.glsl}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CoreShaderRegistrationCallback {
|
||||
Event<CoreShaderRegistrationCallback> EVENT = EventFactory.createArrayBacked(CoreShaderRegistrationCallback.class, callbacks -> context -> {
|
||||
for (CoreShaderRegistrationCallback callback : callbacks) {
|
||||
callback.registerShaders(context);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Registers core shaders using the registration context.
|
||||
*
|
||||
* @param context the registration context
|
||||
*/
|
||||
void registerShaders(RegistrationContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* A context object used to create and register core shader programs.
|
||||
*
|
||||
* <p>This is not meant for implementation by users of the API.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
interface RegistrationContext {
|
||||
/**
|
||||
* Creates and registers a core shader program.
|
||||
*
|
||||
* <p>The program is loaded from {@code assets/<namespace>/shaders/core/<path>.json}.
|
||||
*
|
||||
* @param id the program ID
|
||||
* @param vertexFormat the vertex format used by the shader
|
||||
* @param loadCallback a callback that is called when the shader program has been successfully loaded
|
||||
*/
|
||||
void register(Identifier id, VertexFormat vertexFormat, Consumer<ShaderProgram> loadCallback) throws IOException;
|
||||
}
|
||||
}
|
|
@ -16,35 +16,43 @@
|
|||
|
||||
package net.fabricmc.fabric.test.rendering.client;
|
||||
|
||||
import net.minecraft.client.gl.ShaderProgram;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gl.Defines;
|
||||
import net.minecraft.client.gl.ShaderProgramKey;
|
||||
import net.minecraft.client.gl.ShaderProgramKeys;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.BufferRenderer;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.CoreShaderRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
|
||||
/**
|
||||
* Tests {@link HudRenderCallback} and {@link CoreShaderRegistrationCallback} by drawing a green rectangle
|
||||
* Tests {@link HudRenderCallback} and custom shaders by drawing a green rectangle
|
||||
* in the lower-right corner of the screen.
|
||||
*/
|
||||
public class HudAndShaderTest implements ClientModInitializer {
|
||||
private static ShaderProgram testShader;
|
||||
private static final ShaderProgramKey TEST_SHADER = new ShaderProgramKey(
|
||||
Identifier.of("fabric-rendering-v1-testmod", "core/test"),
|
||||
VertexFormats.POSITION, Defines.EMPTY);
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
CoreShaderRegistrationCallback.EVENT.register(context -> {
|
||||
// Register a custom shader taking POSITION vertices.
|
||||
Identifier id = Identifier.of("fabric-rendering-v1-testmod", "test");
|
||||
context.register(id, VertexFormats.POSITION, program -> testShader = program);
|
||||
});
|
||||
ShaderProgramKeys.getAll().add(TEST_SHADER);
|
||||
|
||||
/*HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
|
||||
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
Window window = client.getWindow();
|
||||
int x = window.getScaledWidth() - 15;
|
||||
int y = window.getScaledHeight() - 15;
|
||||
RenderSystem.setShader(testShader);
|
||||
RenderSystem.setShader(TEST_SHADER);
|
||||
RenderSystem.setShaderColor(0f, 1f, 0f, 1f);
|
||||
Matrix4f positionMatrix = drawContext.getMatrices().peek().getPositionMatrix();
|
||||
BufferBuilder buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
|
||||
|
@ -55,6 +63,6 @@ public class HudAndShaderTest implements ClientModInitializer {
|
|||
BufferRenderer.drawWithGlobalProgram(buffer.end());
|
||||
// Reset shader color
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
|
||||
});*/
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
"srcrgb": "srcalpha",
|
||||
"dstrgb": "1-srcalpha"
|
||||
},
|
||||
"vertex": "fabric-rendering-v1-testmod:test",
|
||||
"fragment": "fabric-rendering-v1-testmod:test",
|
||||
"vertex": "fabric-rendering-v1-testmod:core/test",
|
||||
"fragment": "fabric-rendering-v1-testmod:core/test",
|
||||
"attributes": [
|
||||
],
|
||||
"samplers": [
|
||||
|
|
Loading…
Add table
Reference in a new issue