Skip to content

Commit

Permalink
Add color attachment clear skip
Browse files Browse the repository at this point in the history
  • Loading branch information
thr3343 committed Jul 18, 2024
1 parent babc862 commit fb74639
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 19 additions & 5 deletions src/main/java/net/vulkanmod/vulkan/VRenderSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.lwjgl.system.MemoryUtil;

import static org.lwjgl.vulkan.VK10.*;
import static org.lwjgl.opengl.GL11C.GL_DEPTH_BUFFER_BIT;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
Expand All @@ -34,13 +35,13 @@ public abstract class VRenderSystem {
public static int colorMask = PipelineState.ColorMask.getColorMask(true, true, true, true);

public static boolean cull = true;

private static boolean canApplyClear = false;
public static boolean logicOp = false;
public static int logicOpFun = 0;

public static float clearDepthValue = DEFAULT_DEPTH_VALUE;
public static FloatBuffer clearColor = MemoryUtil.memCallocFloat(4);

private static final float[] checkedClearColor = new float[4];
public static MappedBuffer modelViewMatrix = new MappedBuffer(16 * 4);
public static MappedBuffer projectionMatrix = new MappedBuffer(16 * 4);
public static MappedBuffer TextureMatrix = new MappedBuffer(16 * 4);
Expand Down Expand Up @@ -154,12 +155,25 @@ public static MappedBuffer getShaderFogColor() {
return shaderFogColor;
}

public static void setClearColor(float f1, float f2, float f3, float f4) {
ColorUtil.setRGBA_Buffer(clearColor, f1, f2, f3, f4);
public static void setClearColor(float f0, float f1, float f2, float f3) {
//set to true if different color
if(!(canApplyClear = checkClearColor(f0, f1, f2, f3))) return;
ColorUtil.setRGBA_Buffer(clearColor, f0, f1, f2, f3);
checkedClearColor[0]=f0;
checkedClearColor[1]=f1;
checkedClearColor[2]=f2;
checkedClearColor[3]=f3;
}

private static boolean checkClearColor(float f0, float f1, float f2, float f3) {
return checkedClearColor[0] !=f0 | checkedClearColor[1] !=f1 | checkedClearColor[2] !=f2 | checkedClearColor[3] != f3;
}

public static void clear(int mask) {
Renderer.clearAttachments(mask);
//Skip reapplying the same color over and over per clear
//Depth clears are much faster than color clears
Renderer.clearAttachments(canApplyClear ? mask : GL_DEPTH_BUFFER_BIT); //Depth Only Clears needed to fix Chat + Command Elements
canApplyClear=false;
}

public static void clearDepth(double depth) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/vulkanmod/vulkan/pass/DefaultMainPass.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static DefaultMainPass create() {
private void createRenderPasses() {
RenderPass.Builder builder = RenderPass.builder(this.mainFramebuffer);
builder.getColorAttachmentInfo().setFinalLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
builder.getColorAttachmentInfo().setOps(VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE);
builder.getDepthAttachmentInfo().setOps(VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE);
builder.getColorAttachmentInfo().setOps(VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE);
builder.getDepthAttachmentInfo().setOps(VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE);

this.mainRenderPass = builder.build();

Expand Down

0 comments on commit fb74639

Please sign in to comment.