Skip to content

Commit

Permalink
Merge branch '1.20.x' into BaseInstanceGPUArgs3
Browse files Browse the repository at this point in the history
  • Loading branch information
thr3343 committed Dec 18, 2023
2 parents 714834b + a36d269 commit 0934a4e
Show file tree
Hide file tree
Showing 98 changed files with 3,117 additions and 1,272 deletions.
4 changes: 1 addition & 3 deletions src/main/java/net/vulkanmod/config/widget/OptionWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.sounds.SoundManager;
Expand All @@ -21,7 +20,6 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
import net.vulkanmod.vulkan.util.ColorUtil;
import net.vulkanmod.vulkan.util.VUtil;

import java.util.Objects;
import java.util.function.Consumer;
Expand Down Expand Up @@ -76,7 +74,7 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();

int color = this.controlHovered ? ColorUtil.packColorInt(0.0f, 0.0f, 0.0f, 0.45f) : ColorUtil.packColorInt(0.0f, 0.0f, 0.0f, 0.3f);
int color = this.controlHovered ? ColorUtil.packColorIntRGBA(0.0f, 0.0f, 0.0f, 0.45f) : ColorUtil.packColorIntRGBA(0.0f, 0.0f, 0.0f, 0.3f);

if(this.hovered)
guiGraphics.fill(this.x - 2, this.y - 2, this.x + this.width + 2, this.y + this.height + 2, 0x28000000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package net.vulkanmod.config.widget;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.vulkanmod.config.RangeOption;
import net.vulkanmod.vulkan.util.ColorUtil;
import net.vulkanmod.vulkan.util.VUtil;
import org.lwjgl.glfw.GLFW;

public class RangeOptionWidget extends OptionWidget {
Expand Down Expand Up @@ -40,7 +38,7 @@ protected void renderBackground(GuiGraphics guiGraphics, Minecraft client, int m
// this.drawTexture(matrices, this.controlX + (int)(this.value * (this.controlWidth - 8)), this.y, 0, 46 + i, 4, 20);
// this.drawTexture(matrices, this.controlX + (int)(this.value * (this.controlWidth - 8)) + 4, this.y, 196, 46 + i, 4, 20);

int color = this.controlHovered ? ColorUtil.packColorInt(1.0f, 1.0f, 1.0f, 1.0f) : ColorUtil.packColorInt(1.0f, 1.0f, 1.0f, 0.8f);
int color = this.controlHovered ? ColorUtil.packColorIntRGBA(1.0f, 1.0f, 1.0f, 1.0f) : ColorUtil.packColorIntRGBA(1.0f, 1.0f, 1.0f, 0.8f);

guiGraphics.fill(this.controlX + (int)(this.value * (this.controlWidth - 8)), this.y + 20, this.controlX + (int)(this.value * (this.controlWidth - 8)) + 8, this.y, color);
}
Expand Down
204 changes: 152 additions & 52 deletions src/main/java/net/vulkanmod/gl/GlFramebuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import it.unimi.dsi.fastutil.ints.Int2ReferenceOpenHashMap;
import net.vulkanmod.vulkan.Renderer;
import net.vulkanmod.vulkan.framebuffer.Framebuffer;
import org.apache.commons.lang3.Validate;
import net.vulkanmod.vulkan.framebuffer.RenderPass;
import net.vulkanmod.vulkan.texture.VulkanImage;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GL30C;

public class GlFramebuffer {
import static org.lwjgl.vulkan.VK11.*;

private static int ID_COUNT = 0;
public class GlFramebuffer {
private static int ID_COUNTER = 1;
private static final Int2ReferenceOpenHashMap<GlFramebuffer> map = new Int2ReferenceOpenHashMap<>();
private static int boundId = 0;
private static GlFramebuffer boundFramebuffer;
private static GlFramebuffer boundRenderbuffer;

public static int genFramebufferId() {
int id = ID_COUNT;
int id = ID_COUNTER;
map.put(id, new GlFramebuffer(id));
ID_COUNT++;
ID_COUNTER++;
return id;
}

Expand All @@ -28,21 +28,52 @@ public static void bindFramebuffer(int target, int id) {
// 36160 GL_FRAMEBUFFER
// 36161 GL_RENDERBUFFER

if(target != GL30C.GL_FRAMEBUFFER) {
throw new IllegalArgumentException("target is not GL_FRAMEBUFFER");
// if(target != GL30.GL_FRAMEBUFFER) {
// throw new IllegalArgumentException("target is not GL_FRAMEBUFFER");
// }

if(boundId == id)
return;

if(id == 0) {
Renderer.getInstance().endRenderPass();

// RenderTarget renderTarget = Minecraft.getInstance().getMainRenderTarget();
// if(renderTarget != null)
// renderTarget.bindWrite(true);
boundFramebuffer = null;
boundId = 0;
return;
}

boundId = id;
boundFramebuffer = map.get(id);

if(boundFramebuffer == null)
throw new NullPointerException("bound framebuffer is null");

if(boundFramebuffer.framebuffer != null)
boundFramebuffer.beginRendering();
if(boundFramebuffer.framebuffer != null) {
if(boundFramebuffer.beginRendering())
boundId = id;
else
boundId = -1;
}
}

public static void deleteFramebuffer(int id) {
if(id == 0) {
return;
}

boundFramebuffer = map.remove(id);

if(boundFramebuffer == null)
throw new NullPointerException("bound framebuffer is null");

boundFramebuffer.cleanUp();
boundFramebuffer = null;
}

public static void glFramebufferTexture2D(int target, int attachment, int texTarget, int texture, int level) {
public static void framebufferTexture2D(int target, int attachment, int texTarget, int texture, int level) {
// GL30C.glFramebufferTexture2D(target, attachment, texTarget, texture, level);

// attachment
Expand All @@ -52,7 +83,7 @@ public static void glFramebufferTexture2D(int target, int attachment, int texTar
// texTarget
// 3553 texture2D

if(attachment != GL30C.GL_COLOR_ATTACHMENT0 && attachment != GL30C.GL_DEPTH_ATTACHMENT) {
if(attachment != GL30.GL_COLOR_ATTACHMENT0 && attachment != GL30.GL_DEPTH_ATTACHMENT) {
throw new UnsupportedOperationException();
}
if(texTarget != GL11.GL_TEXTURE_2D) {
Expand All @@ -65,83 +96,152 @@ public static void glFramebufferTexture2D(int target, int attachment, int texTar
boundFramebuffer.setAttachmentTexture(attachment, texture);
}

public static void glFramebufferRenderbuffer(int target, int attachment, int renderbuffertarget, int renderbuffer) {
public static void framebufferRenderbuffer(int target, int attachment, int renderbuffertarget, int renderbuffer) {
// GL30C.glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);

if(target != GL30C.GL_FRAMEBUFFER) {
throw new IllegalArgumentException("target is not GL_FRAMEBUFFER");
}
if(renderbuffertarget != GL30C.GL_RENDERBUFFER) {
throw new UnsupportedOperationException();
}
// if(target != GL30.GL_FRAMEBUFFER) {
// throw new IllegalArgumentException("target is not GL_FRAMEBUFFER");
// }
// if(renderbuffertarget != GL30.GL_RENDERBUFFER) {
// throw new UnsupportedOperationException();
// }

// boundFramebuffer.setAttachmentTexture(attachment, texture);
boundFramebuffer.setAttachmentRenderbuffer(attachment, renderbuffer);
//TODO
}

public static void bindRenderbuffer(int target, int id) {
// target
// 36160 GL_FRAMEBUFFER
// 36161 GL_RENDERBUFFER

if(target != GL30C.GL_RENDERBUFFER) {
throw new IllegalArgumentException("target is not GL_RENDERBUFFER");
}

boundRenderbuffer = map.get(id);

if(boundRenderbuffer == null)
throw new NullPointerException("bound renderbuffer is null");
public static int glCheckFramebufferStatus(int target) {
//TODO
return GL30.GL_FRAMEBUFFER_COMPLETE;
}

public static void glRenderbufferStorage(int target, int internalformat, int width, int height) {
//TODO
// GL30C.glRenderbufferStorage(target, internalformat, width, height);
public static GlFramebuffer getBoundFramebuffer() {
return boundFramebuffer;
}

public static int glCheckFramebufferStatus(int target) {
//TODO
return GL30.GL_FRAMEBUFFER_COMPLETE;
public static GlFramebuffer getFramebuffer(int id) {
return map.get(id);
}

private final int id;
Framebuffer framebuffer;
GlTexture colorAttachment;
GlTexture depthAttachment;
RenderPass renderPass;

VulkanImage colorAttachment;
VulkanImage depthAttachment;

GlFramebuffer(int i) {
this.id = i;
}

void beginRendering() {
Renderer.getInstance().beginRendering(this.framebuffer);
boolean beginRendering() {
return Renderer.getInstance().beginRendering(this.renderPass, this.framebuffer);
}

void setAttachmentTexture(int attachment, int texture) {
GlTexture glTexture = GlTexture.getTexture(texture);
Validate.notNull(glTexture);

if(glTexture == null)
throw new NullPointerException(String.format("Texture %d is null", texture));

if(glTexture.vulkanImage == null)
return;

switch (attachment) {
case(GL30C.GL_COLOR_ATTACHMENT0) ->
case(GL30.GL_COLOR_ATTACHMENT0) ->
this.setColorAttachment(glTexture);

case(GL30C.GL_DEPTH_ATTACHMENT) ->
this.depthAttachment = glTexture;
case(GL30.GL_DEPTH_ATTACHMENT) ->
this.setDepthAttachment(glTexture);

default -> throw new IllegalStateException("Unexpected value: " + attachment);
}
}

void setAttachmentRenderbuffer(int attachment, int texture) {
GlRenderbuffer renderbuffer = GlRenderbuffer.getRenderbuffer(texture);

if(renderbuffer == null)
throw new NullPointerException(String.format("Texture %d is null", texture));

if(renderbuffer.vulkanImage == null)
return;

switch (attachment) {
case(GL30.GL_COLOR_ATTACHMENT0) ->
this.setColorAttachment(renderbuffer);

case(GL30.GL_DEPTH_ATTACHMENT) ->
this.setDepthAttachment(renderbuffer);

default -> throw new IllegalStateException("Unexpected value: " + attachment);
}
}

void setColorAttachment(GlTexture texture) {
this.colorAttachment = texture;
this.colorAttachment = texture.vulkanImage;
createAndBind();
}

void setDepthAttachment(GlTexture texture) {
//TODO check if texture is in depth format
this.depthAttachment = texture.vulkanImage;
createAndBind();
}

void setColorAttachment(GlRenderbuffer texture) {
this.colorAttachment = texture.vulkanImage;
createAndBind();
}

void setDepthAttachment(GlRenderbuffer texture) {
//TODO check if texture is in depth format
this.depthAttachment = texture.vulkanImage;
createAndBind();
}

void createAndBind() {
//Cannot create without color attachment
if(this.colorAttachment == null)
return;

if(this.framebuffer == null) {
this.framebuffer = new Framebuffer(this.colorAttachment.vulkanImage);
if(this.framebuffer != null) {
this.cleanUp();
}

boolean hasDepthImage = this.depthAttachment != null;
VulkanImage depthImage = this.depthAttachment;
// hasDepthImage = false;
// VulkanImage depthImage = null;

this.framebuffer = Framebuffer.builder(this.colorAttachment, depthImage).build();
RenderPass.Builder builder = RenderPass.builder(this.framebuffer);

builder.getColorAttachmentInfo()
.setLoadOp(VK_ATTACHMENT_LOAD_OP_LOAD)
.setFinalLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

if(hasDepthImage)
builder.getDepthAttachmentInfo().setOps(VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_LOAD_OP_LOAD);

this.renderPass = builder.build();

this.beginRendering();
}

public Framebuffer getFramebuffer() {
return framebuffer;
}

public RenderPass getRenderPass() {
return renderPass;
}

void cleanUp() {
this.framebuffer.cleanUp(false);
this.renderPass.cleanUp();

this.framebuffer = null;
this.renderPass = null;
}
}
Loading

0 comments on commit 0934a4e

Please sign in to comment.