Skip to content

Commit

Permalink
Remove another direct buffer creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-OOG-ah committed Nov 25, 2024
1 parent 87637c6 commit f9bacde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package me.jellysquid.mods.sodium.client.render;

import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack;
import com.gtnewhorizons.angelica.compat.toremove.MatrixStack;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.rendering.RenderingState;
import java.nio.FloatBuffer;
import net.coderbot.iris.shadows.ShadowRenderingState;
import org.joml.Matrix4f;
import org.lwjgl.BufferUtils;

import java.nio.FloatBuffer;

public class GameRendererContext {
/**
Expand All @@ -17,8 +16,8 @@ public class GameRendererContext {
* @return A float-buffer on the stack containing the model-view-projection matrix in a format suitable for
* uploading as uniform state
*/
public static FloatBuffer getModelViewProjectionMatrix(MatrixStack.Entry matrices) {
final FloatBuffer bufModelViewProjection = BufferUtils.createFloatBuffer(16);
public static FloatBuffer getModelViewProjectionMatrix(MatrixStack.Entry matrices, MemoryStack stack) {
final FloatBuffer bufModelViewProjection = stack.mallocFloat(16);
final Matrix4f projectionMatrix = (AngelicaConfig.enableIris && ShadowRenderingState.areShadowsCurrentlyBeingRendered()) ? ShadowRenderingState.getShadowOrthoMatrix() : RenderingState.INSTANCE.getProjectionMatrix();
final Matrix4f matrix = new Matrix4f(projectionMatrix);
matrix.mul(matrices.getModel());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jellysquid.mods.sodium.client.render.chunk.shader;

import com.gtnewhorizons.angelica.compat.lwjgl.MemoryStack;
import com.gtnewhorizons.angelica.compat.toremove.MatrixStack;
import me.jellysquid.mods.sodium.client.gl.device.RenderDevice;
import me.jellysquid.mods.sodium.client.gl.shader.GlProgram;
Expand Down Expand Up @@ -47,6 +48,12 @@ public void setup(MatrixStack matrixStack, float modelScale, float textureScale)

this.fogShader.setup();

if(this.uModelViewProjectionMatrix != -1) GL20.glUniformMatrix4(this.uModelViewProjectionMatrix, false, GameRendererContext.getModelViewProjectionMatrix(matrixStack.peek()));
if (this.uModelViewProjectionMatrix == -1) return;
try (MemoryStack stack = MemoryStack.stackPush()) {
GL20.glUniformMatrix4(
this.uModelViewProjectionMatrix,
false,
GameRendererContext.getModelViewProjectionMatrix(matrixStack.peek(), stack));
}
}
}

0 comments on commit f9bacde

Please sign in to comment.