starting swap chain and image views

This commit is contained in:
Harrison Corlett 2026-01-20 15:38:46 +00:00
parent 015c5aaa84
commit 3bf2ebd06f
7 changed files with 88 additions and 9 deletions

View file

@ -8,7 +8,7 @@ public class Init {
public static void main(String[] args){
Logger.info("Launching Software");
var GameEngine = new PrimaryRuntime("Terrain4J", new GameCore());
GameEngine.run();
Logger.info("Launched Engine");
GameEngine.run();
}
}

View file

@ -33,15 +33,19 @@ public class EngineConfig {
private EngineConfig() {
var EngineConfig = new Properties();
Path path = Paths.get("");
InputStream stream = EngineConfig.class.getResourceAsStream(path.toAbsolutePath().toString() + "/" + FILENAME);
InputStream stream = EngineConfig.class.getResourceAsStream("/" + FILENAME);
boolean SuccessfulLoad = false;
if (stream != null) {
try {
EngineConfig.load(stream);
SuccessfulLoad = true;
Logger.debug("File [{}] read", FILENAME);
} catch (IOException excp) {
Logger.error("File [{}] not read", FILENAME, excp);
}
} else{
Logger.debug("FileStream for file [{}] is null, Filepath [{}] not found", FILENAME,path.toAbsolutePath().toString() + "/" + FILENAME);
}
if (SuccessfulLoad){
PhysicalDeviceName = EngineConfig.getOrDefault("PhysicalDeviceName", DEFAULT_ACCURACY).toString();
@ -58,8 +62,9 @@ public class EngineConfig {
}
} else{
try {
EngineConfig.setProperty("vkValidated", "true");
EngineConfig.setProperty("frame_accuracy", "0");
EngineConfig.setProperty("main_tick_rate", "60");
EngineConfig.setProperty("main_tick_rate", "120");
EngineConfig.setProperty("display_width", "640");
EngineConfig.setProperty("display_height", "480");
EngineConfig.setProperty("vsync", "false");

View file

@ -55,7 +55,7 @@ public class PrimaryRuntime {
}
if (SecondCounter >= 1000000000){
SecondCounter = 0;
System.out.println("FPS: " + Frames + " Ticks: " + TickFrames);
//System.out.println("FPS: " + Frames + " Ticks: " + TickFrames);
EngineConfig.FrameRate_PRIMARYTHREAD = Frames;
EngineConfig.FrameRate_RENDER = EngineConfig.RENDERFRAMES;
EngineConfig.TPS = TickFrames;

View file

@ -0,0 +1,4 @@
package net.halbear.Terrain4J.EngineCore.Vulkan.Structure;
public class ImageView {
}

View file

@ -21,9 +21,7 @@ public class Surface {
private final SurfaceFormat SurfaceFormatVar;
private final long VulkanSurface;
public record SurfaceFormat(int ImageFormat, int ColourSpace){
}
public record SurfaceFormat(int ImageFormat, int ColourSpace){}
public Surface(VulkanInstance VkInstance, PhysicalDevice PhysDevice, Window window){
Logger.debug("Creating Vulkan Surface");

View file

@ -0,0 +1,72 @@
package net.halbear.Terrain4J.EngineCore.Vulkan.Structure;
import net.halbear.Terrain4J.EngineCore.Display.Window;
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.*;
import org.tinylog.Logger;
import java.nio.LongBuffer;
import static net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils.vkCheck;
import static org.lwjgl.vulkan.VK10.VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
public class SwapChain {
private final ImageView[] ImageViewArray;
private final int ImageCount;
private final VkExtent2D SwapChainExtent;
private final long VulkanSwapChain;
public SwapChain(Window window, Device device, Surface surface, int RequestedImages, boolean VSYNC){
Logger.debug("Creating Vulkan SwapChain");
try(var MemStack = MemoryStack.stackPush()){
VkSurfaceCapabilitiesKHR SurfaceCapabilities = surface.GetSurfaceCapabilities();
int requestedImages = CalculateImageCount(SurfaceCapabilities, RequestedImages);
SwapChainExtent = CalculateSwapChainExtent(window, SurfaceCapabilities);
Surface.SurfaceFormat surfaceFormat = surface.GetSurfaceFormat();
var VulkanSwapChainCreateInfo = VkSwapchainCreateInfoKHR.calloc(MemStack)
.sType$Default()
.surface(surface.GetVkSurface())
.minImageCount(requestedImages)
.imageFormat(surfaceFormat.ImageFormat())
.imageColorSpace(surfaceFormat.ColourSpace())
.imageExtent(SwapChainExtent)
.imageArrayLayers(1)
.imageUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
.preTransform(SurfaceCapabilities.currentTransform())
.compositeAlpha(KHRSurface.VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR)
.clipped(true);
if (VSYNC){
VulkanSwapChainCreateInfo.presentMode(KHRSurface.VK_PRESENT_MODE_FIFO_KHR);
} else{
VulkanSwapChainCreateInfo.presentMode(KHRSurface.VK_PRESENT_MODE_IMMEDIATE_KHR);
}
LongBuffer LongPointer = MemStack.mallocLong(1);
vkCheck(KHRSwapchain.vkCreateSwapchainKHR(device.FetchVulkanDevice(),VulkanSwapChainCreateInfo, null, LongPointer), "Failed to create vulkan Swap Chain");
VulkanSwapChain = LongPointer.get(0);
ImageViewArray = CreateImageViews(MemStack, device, VulkanSwapChain, surfaceFormat.ImageFormat());
ImageCount = ImageViewArray.length;
}
}
public static int CalculateImageCount(VkSurfaceCapabilitiesKHR SurfaceCapabilities, int RequestedImages){
int MaxImages = SurfaceCapabilities.maxImageCount();
int MinImages = SurfaceCapabilities.minImageCount();
int result = MinImages;
if(MaxImages != 0){
return Math.min(RequestedImages, MaxImages);
}
result = Math.max(result, MinImages);
Logger.debug("Requested Image Count: [{}]\nReceived [{}] Images\nSurfaceCapabilities-> MaxImgs:[{}] MinImgs:[{}] ",RequestedImages,result,MaxImages,MinImages);
return result;
}
public static VkExtent2D CalculateSwapChainExtent(Window window, VkSurfaceCapabilitiesKHR SurfaceCapabilities){
return null; //finish later
}
public static ImageView[] CreateImageViews(MemoryStack MemStack, Device device, long SwapChain, int Format){
return null; //finish later
}
}