further vulkan stuff
This commit is contained in:
parent
df4ebe6078
commit
f93891f1fd
97
main.cpp
97
main.cpp
@ -1,8 +1,25 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
int main() {
|
||||
VkInstance instance;
|
||||
VkDevice device;
|
||||
VkSurfaceKHR surface;
|
||||
GLFWwindow *window;
|
||||
|
||||
void startGlfw() {
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, false);
|
||||
|
||||
window = glfwCreateWindow(400, 300, "Vulkan Test", nullptr, nullptr);
|
||||
}
|
||||
|
||||
void startVulkan() {
|
||||
VkApplicationInfo appinfo; // general app info
|
||||
appinfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appinfo.pNext = nullptr;
|
||||
@ -29,6 +46,9 @@ int main() {
|
||||
"VK_LAYER_NV_optimus"
|
||||
};
|
||||
|
||||
uint32_t amountOfGlfwExtensins = 0;
|
||||
auto glfWExtensions = glfwGetRequiredInstanceExtensions(&amountOfGlfwExtensins);
|
||||
|
||||
VkInstanceCreateInfo instanceInfo;
|
||||
instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
instanceInfo.pNext = nullptr;
|
||||
@ -36,15 +56,19 @@ int main() {
|
||||
instanceInfo.pApplicationInfo = &appinfo;
|
||||
instanceInfo.enabledLayerCount = validationLayers.size();
|
||||
instanceInfo.ppEnabledLayerNames = validationLayers.data();
|
||||
instanceInfo.enabledExtensionCount = 0;
|
||||
instanceInfo.ppEnabledExtensionNames = nullptr;
|
||||
instanceInfo.enabledExtensionCount = amountOfGlfwExtensins;
|
||||
instanceInfo.ppEnabledExtensionNames = glfWExtensions;
|
||||
|
||||
VkInstance instance;
|
||||
// create vulkan instance
|
||||
if (vkCreateInstance(&instanceInfo, nullptr, &instance) != VK_SUCCESS) {
|
||||
std::cout << "error on creating vkinstance" << std::endl;
|
||||
}
|
||||
|
||||
if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {
|
||||
std::cout << "error on creating surface" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
std::cout << "detecting gpus." << std::endl;
|
||||
|
||||
uint32_t physicaldevicesnumber = 0;
|
||||
@ -75,10 +99,36 @@ int main() {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
VkSurfaceCapabilitiesKHR surfaceCapabilities;
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevices.at(0), surface, &surfaceCapabilities);
|
||||
std::cout << "\tminImageCount: " << surfaceCapabilities.minImageCount << std::endl;
|
||||
std::cout << "\tmaxImageCount: " << surfaceCapabilities.maxImageCount << std::endl;
|
||||
std::cout << "\tcurrentExtent: " << surfaceCapabilities.currentExtent.height << "/"
|
||||
<< surfaceCapabilities.currentExtent.width << std::endl;
|
||||
std::cout << "\tminImageExtent: " << surfaceCapabilities.minImageExtent.height << "/"
|
||||
<< surfaceCapabilities.minImageExtent.width << std::endl;
|
||||
std::cout << "\tmaxImageExtent: " << surfaceCapabilities.maxImageExtent.height << "/"
|
||||
<< surfaceCapabilities.maxImageExtent.width << std::endl;
|
||||
std::cout << "\tmaxImageArrayLayers: " << surfaceCapabilities.maxImageArrayLayers << std::endl;
|
||||
std::cout << "\tsupportedTransforms: " << surfaceCapabilities.supportedTransforms << std::endl;
|
||||
std::cout << "\tcurrentTransform: " << surfaceCapabilities.currentTransform << std::endl;
|
||||
std::cout << "\tsupportedCompositeAlpha: " << surfaceCapabilities.supportedCompositeAlpha << std::endl;
|
||||
std::cout << "\tsupportedUsageFlags: " << surfaceCapabilities.supportedUsageFlags << std::endl;
|
||||
|
||||
uint32_t amountOfFormats = 0;
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevices.at(0), surface, &amountOfFormats, nullptr);
|
||||
auto *surfaceFormats = new VkSurfaceFormatKHR[amountOfFormats];
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevices.at(0), surface, &amountOfFormats, surfaceFormats);
|
||||
|
||||
for(int i = 0; i < amountOfFormats; i++){
|
||||
std::cout << "format supported: " << surfaceFormats[i].format << std::endl;
|
||||
}
|
||||
|
||||
|
||||
uint32_t amountOfExtensions = 0;
|
||||
vkEnumerateInstanceExtensionProperties(NULL, &amountOfExtensions, NULL);
|
||||
VkExtensionProperties *extensions = new VkExtensionProperties[amountOfExtensions];
|
||||
vkEnumerateInstanceExtensionProperties(NULL, &amountOfExtensions, extensions);
|
||||
vkEnumerateInstanceExtensionProperties(nullptr, &amountOfExtensions, nullptr);
|
||||
auto *extensions = new VkExtensionProperties[amountOfExtensions];
|
||||
vkEnumerateInstanceExtensionProperties(nullptr, &amountOfExtensions, extensions);
|
||||
std::cout << "found " << amountOfExtensions << " extensions" << std::endl;
|
||||
|
||||
for (int i = 0; i < amountOfExtensions; i++) {
|
||||
@ -110,19 +160,40 @@ int main() {
|
||||
deviceCreateInfo.pEnabledFeatures = &usedFeatures;
|
||||
|
||||
std::cout << "creating logical device" << std::endl;
|
||||
VkDevice device;
|
||||
|
||||
if (vkCreateDevice(physicalDevices.at(0), &deviceCreateInfo, NULL, &device) !=
|
||||
VK_SUCCESS) { // todo select right physicaldevice
|
||||
std::cout << "create logical device failed." << std::endl;
|
||||
}
|
||||
|
||||
// stop jobs
|
||||
vkDeviceWaitIdle(device); // waits until any work has finished
|
||||
vkDestroyDevice(device, nullptr);
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
|
||||
delete[] layers;
|
||||
delete[] extensions;
|
||||
}
|
||||
|
||||
void gameLoop() {
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void shutdownVulkan() {
|
||||
vkDeviceWaitIdle(device); // waits until any work has finished
|
||||
vkDestroyDevice(device, nullptr);
|
||||
vkDestroySurfaceKHR(instance, surface, nullptr);
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
}
|
||||
|
||||
void shutdownGlfw() {
|
||||
glfwDestroyWindow(window);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
startGlfw();
|
||||
startVulkan();
|
||||
gameLoop();
|
||||
shutdownVulkan();
|
||||
shutdownGlfw();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user