IT RENDERS RAHHHHHHHHHH COLOURS CAN BE SHOWN, AAAAND UPDATED LIVE OH YEAHHH THIS IS CAUSE FOR CELEBRATION
This commit is contained in:
parent
4e606e094a
commit
7428616d5c
8 changed files with 65 additions and 17 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Display;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
|
|
@ -15,7 +16,6 @@ import org.lwjgl.vulkan.VkCommandBufferSubmitInfo;
|
|||
import org.lwjgl.vulkan.VkSemaphoreSubmitInfo;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.lwjgl.vulkan.VK13.VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT;
|
||||
|
|
@ -36,7 +36,7 @@ public class Render {
|
|||
|
||||
public Render(EngineInstance engineInstance) {
|
||||
RendererContext = new VulkanContext(engineInstance.window());
|
||||
|
||||
CurrentFrame = 0;
|
||||
GraphicsQueue = new Queue.GraphicsQueue(RendererContext, 0);
|
||||
PresentQueue = new Queue.PresentQueue(RendererContext, 0);
|
||||
CommandPools= new CommandPool[VulkanUtils.MAX_IN_FLIGHT];
|
||||
|
|
@ -68,19 +68,25 @@ public class Render {
|
|||
|
||||
public void cleanup() {
|
||||
RendererContext.GetDevice().waitIdle();
|
||||
Logger.debug("Waiting Vulkan Context");
|
||||
sceneRender.cleanup();
|
||||
Logger.debug("Dynamic Renderer Cleaned up");
|
||||
Arrays.asList(RenderCompleteSemaphores).forEach(i->i.cleanup(RendererContext));
|
||||
Logger.debug("Render Semaphores cleaned up");
|
||||
Arrays.asList(PresentCompleteSemaphores).forEach(i->i.cleanup(RendererContext));
|
||||
Logger.debug("Present Semaphores cleaned up");
|
||||
Arrays.asList(Fences).forEach(i->i.cleanup(RendererContext));
|
||||
Logger.debug("Fences cleaned up");
|
||||
for(int i = 0; i < CommandPools.length; i++){
|
||||
CommandBuffers[i].cleanup(RendererContext, CommandPools[i]);
|
||||
CommandPools[i].cleanup(RendererContext);
|
||||
}
|
||||
Logger.debug("Command pools cleaned up");
|
||||
RendererContext.cleanup();
|
||||
}
|
||||
public void render(EngineInstance engineInstance){
|
||||
SwapChain swapChain = RendererContext.GetSwapChain();
|
||||
WaitForFence(CurrentFrame);
|
||||
WaitForFence(CurrentFrame); //problem child found
|
||||
var CommandPool = CommandPools[CurrentFrame];
|
||||
var CommandBuffer = CommandBuffers[CurrentFrame];
|
||||
RecordingStart(CommandPool, CommandBuffer);
|
||||
|
|
@ -94,7 +100,10 @@ public class Render {
|
|||
swapChain.PresentImage(PresentQueue, RenderCompleteSemaphores[ImageIndex],ImageIndex);
|
||||
CurrentFrame = (CurrentFrame + 1) % VulkanUtils.MAX_IN_FLIGHT;
|
||||
}
|
||||
|
||||
private void ResetFence(int currentFrame){
|
||||
var fence = Fences[currentFrame];
|
||||
fence.Reset(RendererContext);
|
||||
}
|
||||
private void WaitForFence(int currentFrame){
|
||||
var fence = Fences[currentFrame];
|
||||
fence.FenceWait(RendererContext);
|
||||
|
|
@ -114,8 +123,8 @@ public class Render {
|
|||
VkSemaphoreSubmitInfo.Buffer SemaphoreSignals = VkSemaphoreSubmitInfo.calloc(1, MemStack)
|
||||
.sType$Default()
|
||||
.stageMask(VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT)
|
||||
.semaphore(RenderCompleteSemaphores[currentFrame].GetSemaphore());
|
||||
GraphicsQueue.Sumbit(Commands, SemaphoreWait, SemaphoreSignals, fence);
|
||||
.semaphore(RenderCompleteSemaphores[ImageIndex].GetSemaphore());
|
||||
GraphicsQueue.Submit(Commands, SemaphoreWait, SemaphoreSignals, fence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public class RenderThread implements Runnable {
|
|||
}
|
||||
@Override
|
||||
public void run() {
|
||||
int TotalFrames = 0;
|
||||
PrimaryRuntime.ThreadsOpen++;
|
||||
long InitialTime = System.nanoTime();
|
||||
double FrameDiff =0;
|
||||
|
|
@ -55,11 +56,12 @@ public class RenderThread implements Runnable {
|
|||
Frames++;
|
||||
if (SecondCounter >= 1000000000L){
|
||||
SecondCounter = 0;
|
||||
EngineConfig.FrameRate_RENDERTHREAD = Frames;
|
||||
//EngineConfig.FrameRate_RENDERTHREAD = Frames;
|
||||
Logger.info("Render FPS: " + Frames);
|
||||
Frames = 0;
|
||||
}
|
||||
render.render(PrimaryRuntime.GetEngineInstance());
|
||||
TotalFrames++;
|
||||
FrameDiff = 0;
|
||||
}
|
||||
InitialTime = now;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class CommandBuffer {
|
|||
var Commands = VkCommandBufferSubmitInfo.calloc(1, MemStack)
|
||||
.sType$Default()
|
||||
.commandBuffer(VulkanCommandBuffer);
|
||||
queue.Sumbit(Commands, null, null, fence);
|
||||
queue.Submit(Commands, null, null, fence);
|
||||
}
|
||||
fence.FenceWait(vulkanContext);
|
||||
fence.cleanup(vulkanContext);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ public class Fence {
|
|||
}
|
||||
|
||||
public void cleanup(VulkanContext vulkanContext){
|
||||
Logger.debug("Destroying Vulkan Fence");
|
||||
vkDestroyFence(vulkanContext.GetDevice().FetchVulkanDevice(), VulkanFence, null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class Queue {
|
|||
vkQueueWaitIdle(VulkanQueue);
|
||||
}
|
||||
|
||||
public void Sumbit(VkCommandBufferSubmitInfo.Buffer CommandBuffers, VkSemaphoreSubmitInfo.Buffer WaitSemaphores, VkSemaphoreSubmitInfo.Buffer SignalSemaphores, Fence fence){
|
||||
public void Submit(VkCommandBufferSubmitInfo.Buffer CommandBuffers, VkSemaphoreSubmitInfo.Buffer WaitSemaphores, VkSemaphoreSubmitInfo.Buffer SignalSemaphores, Fence fence){
|
||||
try(var MemStack = MemoryStack.stackPush()){
|
||||
var SubmitInfo = VkSubmitInfo2.calloc(1, MemStack)
|
||||
.sType$Default()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen;
|
||||
|
||||
import net.halbear.Terrain4J.EngineCore.Display.Render;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.VulkanContext;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.CommandBuffer;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.vulkan.*;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
|
@ -16,16 +18,50 @@ import static org.lwjgl.vulkan.VK10.*;
|
|||
import static org.lwjgl.vulkan.VK13.*;
|
||||
|
||||
public class SceneRender { //dynamic rendering;
|
||||
private final VkClearValue ClearValueColour;
|
||||
private VkClearValue ClearValueColour;
|
||||
private VkRenderingAttachmentInfo.Buffer[] AttachmentInfoColour;
|
||||
private VkRenderingInfo[] RenderInfo;
|
||||
private float R = 0f;
|
||||
private float G = 0.5f;
|
||||
private float B = 0.7f;
|
||||
private boolean Rb = false;
|
||||
private boolean Gb = true;
|
||||
private boolean Bb = false;
|
||||
public SceneRender(VulkanContext vulkanContext){
|
||||
ClearValueColour = VkClearValue.calloc().color(c->c.float32(0,0.5f).float32(1,0.7f).float32(2,0.9f).float32(3,1.0f));
|
||||
ClearValueColour = VkClearValue.calloc().color(c->c.float32(0,R).float32(1,G).float32(2,B).float32(3,1.0f));
|
||||
AttachmentInfoColour = CreateColourAttachmentsInfo(vulkanContext,ClearValueColour);
|
||||
RenderInfo = CreateRenderInfo(vulkanContext, AttachmentInfoColour);
|
||||
}
|
||||
|
||||
public void UpdateColours(VulkanContext vulkanContext){
|
||||
if (Gb){
|
||||
if (G < 1.0f && Math.random() <0.5) G+=0.0005f;
|
||||
else if (G >= 1.0f) Gb = false;
|
||||
} else{
|
||||
if (G >0.0f&& Math.random() <0.5) G-=0.0005f;
|
||||
else if (G <= 0.0f) Gb = true;
|
||||
}
|
||||
if (Rb){
|
||||
if (R < 1.0f&& Math.random() <0.3) R+=0.0005f;
|
||||
else if (R >= 1.0f) Rb = false;
|
||||
} else{
|
||||
if (R >0.0f&& Math.random() <0.3) R-=0.0005f;
|
||||
else if (R <= 0.0f) Rb = true;
|
||||
}
|
||||
if (Bb){
|
||||
if (B < 1.0f&& Math.random() <0.7) B+=0.0005f;
|
||||
else if (B >= 1.0f) Bb = false;
|
||||
} else{
|
||||
if (B >0.0f&& Math.random() <0.7) B-=0.0005f;
|
||||
else if (B <= 0.0f) Bb = true;
|
||||
}
|
||||
ClearValueColour = VkClearValue.calloc().color(c->c.float32(0,R).float32(1,G).float32(2,B).float32(3,1.0f));
|
||||
AttachmentInfoColour = CreateColourAttachmentsInfo(vulkanContext,ClearValueColour);
|
||||
RenderInfo = CreateRenderInfo(vulkanContext, AttachmentInfoColour);
|
||||
}
|
||||
|
||||
public void Render(VulkanContext vulkanContext, CommandBuffer commandBuffer, int ImageIndex){
|
||||
EngineConfig.FrameRate_RENDERTHREAD++;
|
||||
try(var MemStack = MemoryStack.stackPush()){
|
||||
SwapChain swapChain = vulkanContext.GetSwapChain();
|
||||
long SwapChainImage = swapChain.GetVulkanImageView(ImageIndex).GetVulkanImage();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ public class SwapChain {
|
|||
return Math.min(RequestedImages, MaxImages);
|
||||
}
|
||||
ReturnValue = Math.max(ReturnValue, MinImages);
|
||||
Logger.debug("Requested Image Count: [{}]\nReceived [{}] Images\nSurfaceCapabilities-> MaxImgs:[{}] MinImgs:[{}] ",RequestedImages,ReturnValue,MaxImages,MinImages);
|
||||
return ReturnValue;
|
||||
}
|
||||
public static VkExtent2D CalculateSwapChainExtent(Window window, VkSurfaceCapabilitiesKHR SurfaceCapabilities){
|
||||
|
|
@ -109,7 +108,7 @@ public class SwapChain {
|
|||
return -1;
|
||||
}
|
||||
else if (Error == KHRSwapchain.VK_SUBOPTIMAL_KHR){
|
||||
Logger.warn("Suboptimal surface properties match, not fatal");
|
||||
//Logger.warn("Suboptimal surface properties match, not fatal");
|
||||
} else if (Error != VK_SUCCESS){
|
||||
throw new RuntimeException("Failed to fetch next image in the swapchain: " + Error);
|
||||
}
|
||||
|
|
@ -129,9 +128,12 @@ public class SwapChain {
|
|||
int Error = KHRSwapchain.vkQueuePresentKHR(queue.GetVulkanQueue(), Present);
|
||||
if (Error == KHRSwapchain.VK_ERROR_OUT_OF_DATE_KHR){
|
||||
resize = true;
|
||||
//Logger.debug("Detected Resize");
|
||||
//vkQueueWaitIdle(queue.GetVulkanQueue());
|
||||
} else if (Error == KHRSwapchain.VK_SUBOPTIMAL_KHR){
|
||||
Logger.warn("Suboptimal surface properties match, not fatal");
|
||||
//Logger.warn("Suboptimal surface properties match, not fatal");
|
||||
} else if (Error != VK_SUCCESS){
|
||||
Logger.debug("Failure in Present Image");
|
||||
throw new RuntimeException("failed to present KHR: " + Error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ cap_main_to_tickrate=false
|
|||
#Vulkan Debugging toggle
|
||||
vkValidated=true
|
||||
|
||||
vsync=true
|
||||
vsync=false
|
||||
RequestedImages=3
|
||||
#This is the name of the GPU you want the engine to use
|
||||
PhysicalDeviceName=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue