Search in sources :

Example 1 with GlStateManager

use of com.mojang.blaze3d.platform.GlStateManager in project meteor-client by MeteorDevelopment.

the class GL method getTracker.

private static ICapabilityTracker getTracker(String fieldName) {
    try {
        Class<?> glStateManager = GlStateManager.class;
        Field field = glStateManager.getDeclaredField(fieldName);
        field.setAccessible(true);
        Object state = field.get(null);
        String trackerName = FabricLoader.getInstance().getMappingResolver().mapClassName("intermediary", "com.mojang.blaze3d.platform.GlStateManager$class_1018");
        Field capStateField = null;
        for (Field f : state.getClass().getDeclaredFields()) {
            if (f.getType().getName().equals(trackerName)) {
                capStateField = f;
                break;
            }
        }
        capStateField.setAccessible(true);
        return (ICapabilityTracker) capStateField.get(state);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : GlStateManager(com.mojang.blaze3d.platform.GlStateManager) Field(java.lang.reflect.Field) ICapabilityTracker(meteordevelopment.meteorclient.mixininterface.ICapabilityTracker)

Example 2 with GlStateManager

use of com.mojang.blaze3d.platform.GlStateManager in project Iris by IrisShaders.

the class ClearPassCreator method createClearPasses.

public static ImmutableList<ClearPass> createClearPasses(RenderTargets renderTargets, boolean fullClear, PackRenderTargetDirectives renderTargetDirectives) {
    final int maxDrawBuffers = GlStateManager._getInteger(GL21C.GL_MAX_DRAW_BUFFERS);
    // Sort buffers by their clear color so we can group up glClear calls.
    Map<Vector4f, IntList> clearByColor = new HashMap<>();
    renderTargetDirectives.getRenderTargetSettings().forEach((bufferI, settings) -> {
        // unboxed
        final int buffer = bufferI;
        if (fullClear || settings.shouldClear()) {
            Vector4f defaultClearColor;
            if (buffer == 0) {
                // colortex0 is cleared to the fog color (with 1.0 alpha) by default.
                defaultClearColor = null;
            } else if (buffer == 1) {
                // colortex1 is cleared to solid white (with 1.0 alpha) by default.
                defaultClearColor = new Vector4f(1.0f, 1.0f, 1.0f, 1.0f);
            } else {
                // all other buffers are cleared to solid black (with 0.0 alpha) by default.
                defaultClearColor = new Vector4f(0.0f, 0.0f, 0.0f, 0.0f);
            }
            Vector4f clearColor = settings.getClearColor().orElse(defaultClearColor);
            clearByColor.computeIfAbsent(clearColor, color -> new IntArrayList()).add(buffer);
        }
    });
    List<ClearPass> clearPasses = new ArrayList<>();
    clearByColor.forEach((clearColor, buffers) -> {
        int startIndex = 0;
        while (startIndex < buffers.size()) {
            // clear up to the maximum number of draw buffers per each clear pass.
            // This allows us to handle having more than 8 buffers with the same clear color on systems with
            // a max draw buffers of 8 (ie, most systems).
            int[] clearBuffers = new int[Math.min(buffers.size() - startIndex, maxDrawBuffers)];
            for (int i = 0; i < clearBuffers.length; i++) {
                clearBuffers[i] = buffers.getInt(startIndex);
                startIndex++;
            }
            // only clear depth if this is the first clear pass
            clearPasses.add(new ClearPass(clearColor, renderTargets.createFramebufferWritingToAlt(clearBuffers), clearPasses.isEmpty()));
            clearPasses.add(new ClearPass(clearColor, renderTargets.createFramebufferWritingToMain(clearBuffers), false));
        }
    });
    return ImmutableList.copyOf(clearPasses);
}
Also used : GlStateManager(com.mojang.blaze3d.platform.GlStateManager) PackRenderTargetDirectives(net.coderbot.iris.shaderpack.PackRenderTargetDirectives) List(java.util.List) IntList(it.unimi.dsi.fastutil.ints.IntList) ImmutableList(com.google.common.collect.ImmutableList) Vector4f(net.coderbot.iris.vendored.joml.Vector4f) Map(java.util.Map) HashMap(java.util.HashMap) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) GL21C(org.lwjgl.opengl.GL21C) RenderTargets(net.coderbot.iris.rendertarget.RenderTargets) ArrayList(java.util.ArrayList) Vector4f(net.coderbot.iris.vendored.joml.Vector4f) HashMap(java.util.HashMap) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) ArrayList(java.util.ArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) IntList(it.unimi.dsi.fastutil.ints.IntList)

Example 3 with GlStateManager

use of com.mojang.blaze3d.platform.GlStateManager in project Hypnotic-Client by Hypnotic-Development.

the class GL method getTracker.

private static ICapabilityTracker getTracker(String fieldName) {
    try {
        Class<?> glStateManager = GlStateManager.class;
        Field field = glStateManager.getDeclaredField(fieldName);
        field.setAccessible(true);
        Object state = field.get(null);
        String trackerName = FabricLoader.getInstance().getMappingResolver().mapClassName("intermediary", "com.mojang.blaze3d.platform.GlStateManager$class_1018");
        Field capStateField = null;
        for (Field f : state.getClass().getDeclaredFields()) {
            if (f.getType().getName().equals(trackerName)) {
                capStateField = f;
                break;
            }
        }
        capStateField.setAccessible(true);
        return (ICapabilityTracker) capStateField.get(state);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : GlStateManager(com.mojang.blaze3d.platform.GlStateManager) Field(java.lang.reflect.Field)

Example 4 with GlStateManager

use of com.mojang.blaze3d.platform.GlStateManager in project Client by MatHax.

the class GL method getTracker.

private static ICapabilityTracker getTracker(String fieldName) {
    try {
        Class<?> glStateManager = GlStateManager.class;
        Field field = glStateManager.getDeclaredField(fieldName);
        field.setAccessible(true);
        Object state = field.get(null);
        String trackerName = FabricLoader.getInstance().getMappingResolver().mapClassName("intermediary", "com.mojang.blaze3d.platform.GlStateManager$class_1018");
        Field capStateField = null;
        for (Field f : state.getClass().getDeclaredFields()) {
            if (f.getType().getName().equals(trackerName)) {
                capStateField = f;
                break;
            }
        }
        capStateField.setAccessible(true);
        return (ICapabilityTracker) capStateField.get(state);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : GlStateManager(com.mojang.blaze3d.platform.GlStateManager) Field(java.lang.reflect.Field) ICapabilityTracker(mathax.client.mixininterface.ICapabilityTracker)

Aggregations

GlStateManager (com.mojang.blaze3d.platform.GlStateManager)4 Field (java.lang.reflect.Field)3 ImmutableList (com.google.common.collect.ImmutableList)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ICapabilityTracker (mathax.client.mixininterface.ICapabilityTracker)1 ICapabilityTracker (meteordevelopment.meteorclient.mixininterface.ICapabilityTracker)1 RenderTargets (net.coderbot.iris.rendertarget.RenderTargets)1 PackRenderTargetDirectives (net.coderbot.iris.shaderpack.PackRenderTargetDirectives)1 Vector4f (net.coderbot.iris.vendored.joml.Vector4f)1 GL21C (org.lwjgl.opengl.GL21C)1