vulkan test
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "d3dclass.h"
|
||||
#include "vulkan.h"
|
||||
#include "cameraclass.h"
|
||||
#include "object.h"
|
||||
#include "lightclass.h"
|
||||
@@ -71,7 +72,7 @@ public:
|
||||
RenderTextureClass* GetReflectionTexture() const { return m_ReflectionTexture; };
|
||||
|
||||
|
||||
bool Initialize(int, int, HWND);
|
||||
bool Initialize(int, int, HWND, bool IsVulkan);
|
||||
void Shutdown();
|
||||
bool Frame(InputClass*);
|
||||
void PhysicsThreadFunction();
|
||||
@@ -182,6 +183,7 @@ private :
|
||||
// ------------------------------------- //
|
||||
|
||||
D3DClass* m_Direct3D;
|
||||
VulkanClass* m_Vulkan;
|
||||
IDXGISwapChain* m_swapChain;
|
||||
ModelClass* m_Model,* m_GroundModel, * m_WallModel, * m_BathModel, * m_WaterModel;
|
||||
ModelListClass* m_ModelList;
|
||||
|
@@ -1,8 +1,49 @@
|
||||
#pragma once
|
||||
#include "Vulkan/Include/vulkan/vulkan.h"
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
#include <stdexcept>
|
||||
#include "Logger.h"
|
||||
|
||||
class vulkan
|
||||
{
|
||||
|
||||
class VulkanClass {
|
||||
public:
|
||||
|
||||
};
|
||||
void Initialize(HWND hwnd, int width, int height);
|
||||
void Shutdown();
|
||||
void Render();
|
||||
|
||||
private:
|
||||
void CreateInstance();
|
||||
void CreateSurface(HWND hwnd);
|
||||
void PickPhysicalDevice();
|
||||
void CreateLogicalDevice();
|
||||
void CreateSwapChain(int width, int height);
|
||||
void CreateImageViews();
|
||||
void CreateRenderPass();
|
||||
void CreateGraphicsPipeline();
|
||||
void CreateFramebuffers();
|
||||
void CreateCommandPool();
|
||||
void CreateCommandBuffers();
|
||||
void CreateSyncObjects();
|
||||
|
||||
VkInstance instance;
|
||||
VkSurfaceKHR surface;
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice device;
|
||||
VkQueue graphicsQueue;
|
||||
VkQueue presentQueue;
|
||||
VkSwapchainKHR swapChain;
|
||||
std::vector<VkImage> swapChainImages;
|
||||
VkFormat swapChainImageFormat;
|
||||
VkExtent2D swapChainExtent;
|
||||
std::vector<VkImageView> swapChainImageViews;
|
||||
VkRenderPass renderPass;
|
||||
VkPipelineLayout pipelineLayout;
|
||||
VkPipeline graphicsPipeline;
|
||||
std::vector<VkFramebuffer> swapChainFramebuffers;
|
||||
VkCommandPool commandPool;
|
||||
std::vector<VkCommandBuffer> commandBuffers;
|
||||
std::vector<VkSemaphore> imageAvailableSemaphores;
|
||||
std::vector<VkSemaphore> renderFinishedSemaphores;
|
||||
std::vector<VkFence> inFlightFences;
|
||||
};
|
@@ -47,7 +47,7 @@ bool SystemClass::Initialize()
|
||||
// Create and initialize the application class object. This object will handle rendering all the graphics for this application.
|
||||
m_Application = new ApplicationClass;
|
||||
|
||||
result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd);
|
||||
result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd, false);
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
|
@@ -63,11 +63,19 @@ ApplicationClass::~ApplicationClass()
|
||||
}
|
||||
|
||||
|
||||
bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
||||
bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd, bool IsVulkan)
|
||||
{
|
||||
|
||||
Logger::Get().Log("Initializing application class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
if (IsVulkan)
|
||||
{
|
||||
m_Vulkan = new VulkanClass();
|
||||
m_Vulkan->Initialize(hwnd, screenWidth, screenHeight);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
char mouseString1[32], mouseString2[32], mouseString3[32];
|
||||
@@ -473,6 +481,13 @@ void ApplicationClass::Shutdown()
|
||||
{
|
||||
Logger::Get().Log("Shutting down application class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
|
||||
if (m_Vulkan)
|
||||
{
|
||||
m_Vulkan->Shutdown();
|
||||
delete m_Vulkan;
|
||||
m_Vulkan = nullptr;
|
||||
}
|
||||
|
||||
// Release the shader manager object.
|
||||
if (m_ShaderManager)
|
||||
{
|
||||
@@ -697,6 +712,9 @@ void ApplicationClass::Shutdown()
|
||||
|
||||
bool ApplicationClass::Frame(InputClass* Input)
|
||||
{
|
||||
|
||||
m_Vulkan->Render();
|
||||
|
||||
int mouseX, mouseY, currentMouseX, currentMouseY;
|
||||
bool result, leftMouseDown, rightMouseDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE, scrollUp, scrollDown;
|
||||
float rotationY, rotationX, positionX, positionY, positionZ;
|
||||
|
@@ -1 +1,98 @@
|
||||
#include "vulkan.h"
|
||||
|
||||
void VulkanClass::Initialize(HWND hwnd, int width, int height) {
|
||||
CreateInstance();
|
||||
CreateSurface(hwnd);
|
||||
PickPhysicalDevice();
|
||||
CreateLogicalDevice();
|
||||
CreateSwapChain(width, height);
|
||||
CreateImageViews();
|
||||
CreateRenderPass();
|
||||
CreateGraphicsPipeline();
|
||||
CreateFramebuffers();
|
||||
CreateCommandPool();
|
||||
CreateCommandBuffers();
|
||||
CreateSyncObjects();
|
||||
}
|
||||
|
||||
void VulkanClass::Shutdown() {
|
||||
for (size_t i = 0; i < swapChainFramebuffers.size(); i++) {
|
||||
vkDestroyFramebuffer(device, swapChainFramebuffers[i], nullptr);
|
||||
}
|
||||
vkDestroyPipeline(device, graphicsPipeline, nullptr);
|
||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||
vkDestroyRenderPass(device, renderPass, nullptr);
|
||||
for (size_t i = 0; i < swapChainImageViews.size(); i++) {
|
||||
vkDestroyImageView(device, swapChainImageViews[i], nullptr);
|
||||
}
|
||||
vkDestroySwapchainKHR(device, swapChain, nullptr);
|
||||
vkDestroyDevice(device, nullptr);
|
||||
vkDestroySurfaceKHR(instance, surface, nullptr);
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
}
|
||||
|
||||
void VulkanClass::Render() {
|
||||
// Rendering code will go here
|
||||
}
|
||||
|
||||
void VulkanClass::CreateInstance() {
|
||||
VkApplicationInfo appInfo{};
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pApplicationName = "Vulkan App";
|
||||
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.pEngineName = "No Engine";
|
||||
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.apiVersion = VK_API_VERSION_1_0;
|
||||
|
||||
VkInstanceCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
createInfo.pApplicationInfo = &appInfo;
|
||||
|
||||
if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create instance!");
|
||||
}
|
||||
}
|
||||
|
||||
void VulkanClass::CreateSurface(HWND hwnd) {
|
||||
// Platform-specific surface creation code
|
||||
}
|
||||
|
||||
void VulkanClass::PickPhysicalDevice() {
|
||||
// Code to pick a suitable physical device
|
||||
}
|
||||
|
||||
void VulkanClass::CreateLogicalDevice() {
|
||||
// Code to create a logical device
|
||||
}
|
||||
|
||||
void VulkanClass::CreateSwapChain(int width, int height) {
|
||||
// Code to create a swap chain
|
||||
}
|
||||
|
||||
void VulkanClass::CreateImageViews() {
|
||||
// Code to create image views
|
||||
}
|
||||
|
||||
void VulkanClass::CreateRenderPass() {
|
||||
// Code to create a render pass
|
||||
}
|
||||
|
||||
void VulkanClass::CreateGraphicsPipeline() {
|
||||
// Code to create a graphics pipeline
|
||||
}
|
||||
|
||||
void VulkanClass::CreateFramebuffers() {
|
||||
// Code to create framebuffers
|
||||
}
|
||||
|
||||
void VulkanClass::CreateCommandPool() {
|
||||
// Code to create a command pool
|
||||
}
|
||||
|
||||
void VulkanClass::CreateCommandBuffers() {
|
||||
// Code to create command buffers
|
||||
}
|
||||
|
||||
void VulkanClass::CreateSyncObjects() {
|
||||
// Code to create synchronization objects
|
||||
}
|
Reference in New Issue
Block a user