mirror of
https://gitea.windcorp.ru/Wind-Corporation/Progressia.git
synced 2025-07-01 13:53:35 +03:00
Added logging, refactored versioning; STB is now included
- Added logging - Rewrote versioning code - Refactored dependency management - STB (stb_image.h) is now included - All other dependencies now use find_package - Cross-compilation from Linux to Windows is now possible
This commit is contained in:
@ -4,8 +4,12 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "../../main/logging.h"
|
||||
#include "../../main/meta.h"
|
||||
#include "vulkan_mgmt.h"
|
||||
using namespace progressia::main::logging;
|
||||
|
||||
namespace progressia {
|
||||
namespace desktop {
|
||||
@ -16,12 +20,12 @@ static void onGlfwError(int errorCode, const char *description);
|
||||
static void onWindowGeometryChange(GLFWwindow *window, int width, int height);
|
||||
|
||||
void initializeGlfw() {
|
||||
std::cout << "Beginning GLFW init" << std::endl;
|
||||
debug("Beginning GLFW init");
|
||||
|
||||
glfwSetErrorCallback(onGlfwError);
|
||||
|
||||
if (!glfwInit()) {
|
||||
std::cout << "glfwInit() failed" << std::endl;
|
||||
fatal("glfwInit() failed");
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
@ -29,16 +33,26 @@ void initializeGlfw() {
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
|
||||
window = glfwCreateWindow(800, 800, "Progressia", nullptr, nullptr);
|
||||
std::string title;
|
||||
|
||||
{
|
||||
std::stringstream accumulator;
|
||||
accumulator << progressia::main::meta::NAME << " "
|
||||
<< progressia::main::meta::VERSION << " build "
|
||||
<< progressia::main::meta::BUILD_ID;
|
||||
title = accumulator.str();
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(800, 800, title.c_str(), nullptr, nullptr);
|
||||
|
||||
glfwSetWindowSizeCallback(window, onWindowGeometryChange);
|
||||
|
||||
std::cout << "GLFW init complete" << std::endl;
|
||||
debug("GLFW init complete");
|
||||
}
|
||||
|
||||
void showWindow() {
|
||||
glfwShowWindow(window);
|
||||
std::cout << "Window now visible" << std::endl;
|
||||
debug("Window now visible");
|
||||
}
|
||||
|
||||
bool shouldRun() { return !glfwWindowShouldClose(window); }
|
||||
@ -48,8 +62,7 @@ void doGlfwRoutine() { glfwPollEvents(); }
|
||||
void shutdownGlfw() { glfwTerminate(); }
|
||||
|
||||
void onGlfwError(int errorCode, const char *description) {
|
||||
std::cout << "[GLFW] " << description << " (" << errorCode << ")"
|
||||
<< std::endl;
|
||||
fatal() << "[GLFW] " << description << " (" << errorCode << ")";
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
|
||||
#include "../../main/logging.h"
|
||||
#include "../../main/rendering.h"
|
||||
#include "vulkan_buffer.h"
|
||||
#include "vulkan_frame.h"
|
||||
@ -53,7 +54,8 @@ std::vector<char> tmp_readFile(const std::string &path) {
|
||||
|
||||
if (resource.data == nullptr) {
|
||||
// REPORT_ERROR
|
||||
std::cerr << "Could not find resource \"" << path << "\"" << std::endl;
|
||||
progressia::main::logging::fatal()
|
||||
<< "Could not find resource \"" << path << "\"";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "vulkan_common.h"
|
||||
|
||||
#include "../config.h"
|
||||
#include "vulkan_adapter.h"
|
||||
#include "vulkan_frame.h"
|
||||
#include "vulkan_pick_device.h"
|
||||
@ -8,9 +9,12 @@
|
||||
#include "vulkan_swap_chain.h"
|
||||
#include "vulkan_texture_descriptors.h"
|
||||
|
||||
#include "../../main/logging.h"
|
||||
#include "../../main/meta.h"
|
||||
#include "glfw_mgmt_details.h"
|
||||
|
||||
using namespace progressia::main::logging;
|
||||
|
||||
namespace progressia {
|
||||
namespace desktop {
|
||||
|
||||
@ -46,7 +50,7 @@ Vulkan::Vulkan(std::vector<const char *> instanceExtensions,
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pApplicationName = NAME;
|
||||
appInfo.applicationVersion =
|
||||
VK_MAKE_VERSION(VERSION.major, VERSION.minor, VERSION.patch);
|
||||
VK_MAKE_VERSION(VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
||||
appInfo.pEngineName = nullptr;
|
||||
appInfo.engineVersion = 0;
|
||||
appInfo.apiVersion = VK_API_VERSION_1_0;
|
||||
@ -69,12 +73,11 @@ Vulkan::Vulkan(std::vector<const char *> instanceExtensions,
|
||||
}
|
||||
|
||||
if (!toFind.empty()) {
|
||||
std::cout << "Could not locate following requested Vulkan "
|
||||
"extensions:";
|
||||
auto m = fatal(
|
||||
"Could not locate following requested Vulkan extensions:");
|
||||
for (const auto &extension : toFind) {
|
||||
std::cout << "\n\t- " << extension;
|
||||
m << "\n\t- " << extension;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
@ -99,12 +102,11 @@ Vulkan::Vulkan(std::vector<const char *> instanceExtensions,
|
||||
}
|
||||
|
||||
if (!toFind.empty()) {
|
||||
std::cout << "Could not locate following requested Vulkan "
|
||||
"validation layers:";
|
||||
auto m = fatal("Could not locate following requested Vulkan "
|
||||
"validation layers:");
|
||||
for (const auto &layer : toFind) {
|
||||
std::cout << "\n\t- " << layer;
|
||||
m << "\n\t- " << layer;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
@ -143,7 +145,7 @@ Vulkan::Vulkan(std::vector<const char *> instanceExtensions,
|
||||
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
|
||||
|
||||
if (deviceCount == 0) {
|
||||
std::cout << "No GPUs with Vulkan support found" << std::endl;
|
||||
fatal("No GPUs with Vulkan support found");
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
@ -342,7 +344,7 @@ VkFormat Vulkan::findSupportedFormat(const std::vector<VkFormat> &candidates,
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Could not find a suitable format" << std::endl;
|
||||
fatal("Could not find a suitable format");
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
@ -364,7 +366,7 @@ uint32_t Vulkan::findMemoryType(uint32_t allowedByDevice,
|
||||
return i;
|
||||
}
|
||||
|
||||
std::cout << "Could not find suitable memory type" << std::endl;
|
||||
fatal("Could not find suitable memory type");
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
return -1;
|
||||
@ -467,8 +469,8 @@ debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "[Vulkan] [" << typeStr << " / " << severityStr << "]\t"
|
||||
<< pCallbackData->pMessage << std::endl;
|
||||
error() << "[Vulkan] [" << typeStr << " / " << severityStr << "]\t"
|
||||
<< pCallbackData->pMessage;
|
||||
// REPORT_ERROR
|
||||
return VK_FALSE;
|
||||
}
|
||||
@ -519,7 +521,7 @@ VulkanErrorHandler::attachDebugProbe(VkInstanceCreateInfo &createInfo) {
|
||||
|
||||
void VulkanErrorHandler::onInstanceReady() {
|
||||
#ifdef VULKAN_ERROR_CHECKING
|
||||
std::cout << "Registering debug callback" << std::endl;
|
||||
debug("Registering debug callback");
|
||||
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo{};
|
||||
populateDebugMessengerCreateInfo(createInfo, vulkan);
|
||||
@ -537,8 +539,7 @@ void VulkanErrorHandler::handleVkResult(const char *errorMessage,
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "Vulkan error (" << result << "): " << errorMessage
|
||||
<< std::endl;
|
||||
fatal() << "Vulkan error (" << result << "): " << errorMessage;
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include <boost/core/noncopyable.hpp>
|
||||
|
||||
#include "../../main/logging.h"
|
||||
#include "../../main/rendering/graphics_interface.h"
|
||||
|
||||
namespace progressia {
|
||||
@ -154,9 +155,10 @@ class Vulkan : public VkObjectWrapper {
|
||||
if (func != nullptr) {
|
||||
return func(instance, std::forward<Args>(args)...);
|
||||
} else {
|
||||
std::cout << "[Vulkan] [dynVkCall / VkResult]\tFunction not found "
|
||||
"for name \""
|
||||
<< functionName << "\"" << std::endl;
|
||||
progressia::main::logging::error()
|
||||
<< "[Vulkan] [dynVkCall / VkResult]\tFunction not found for "
|
||||
"name \""
|
||||
<< functionName << "\"";
|
||||
// REPORT_ERROR
|
||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||
}
|
||||
@ -173,9 +175,9 @@ class Vulkan : public VkObjectWrapper {
|
||||
func(instance, std::forward<Args>(args)...);
|
||||
return VK_SUCCESS;
|
||||
} else {
|
||||
std::cout
|
||||
progressia::main::logging::error()
|
||||
<< "[Vulkan] [dynVkCall / void]\tFunction not found for name \""
|
||||
<< functionName << "\"" << std::endl;
|
||||
<< functionName << "\"";
|
||||
// REPORT_ERROR
|
||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||
}
|
||||
|
@ -1,15 +1,19 @@
|
||||
#include "vulkan_mgmt.h"
|
||||
|
||||
#include "../config.h"
|
||||
#include "vulkan_common.h"
|
||||
#include "vulkan_swap_chain.h"
|
||||
|
||||
#include "../../main/logging.h"
|
||||
using namespace progressia::main::logging;
|
||||
|
||||
namespace progressia {
|
||||
namespace desktop {
|
||||
|
||||
Vulkan *vulkan;
|
||||
|
||||
void initializeVulkan() {
|
||||
std::cout << "Vulkan initializing" << std::endl;
|
||||
debug("Vulkan initializing");
|
||||
|
||||
// Instance extensions
|
||||
|
||||
@ -42,7 +46,7 @@ void initializeVulkan() {
|
||||
|
||||
vulkan = new Vulkan(instanceExtensions, deviceExtensions, validationLayers);
|
||||
|
||||
std::cout << "Vulkan initialized" << std::endl;
|
||||
debug("Vulkan initialized");
|
||||
}
|
||||
|
||||
Vulkan *getVulkan() { return vulkan; }
|
||||
@ -54,14 +58,14 @@ void endRender() { return vulkan->endRender(); }
|
||||
void resizeVulkanSurface() { vulkan->getSwapChain().recreate(); }
|
||||
|
||||
void shutdownVulkan() {
|
||||
std::cout << "Vulkan terminating" << std::endl;
|
||||
debug("Vulkan terminating");
|
||||
|
||||
if (vulkan != nullptr) {
|
||||
delete vulkan;
|
||||
vulkan = nullptr;
|
||||
}
|
||||
|
||||
std::cout << "Vulkan terminated" << std::endl;
|
||||
debug("Vulkan terminated");
|
||||
}
|
||||
|
||||
} // namespace desktop
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "vulkan_pick_device.h"
|
||||
|
||||
#include "../../main/logging.h"
|
||||
#include "vulkan_swap_chain.h"
|
||||
using namespace progressia::main::logging;
|
||||
|
||||
namespace progressia {
|
||||
namespace desktop {
|
||||
@ -60,14 +62,15 @@ pickPhysicalDevice(std::vector<PhysicalDeviceData> &choices, Vulkan &vulkan,
|
||||
choices.erase(it, choices.end());
|
||||
|
||||
if (choices.empty()) {
|
||||
std::cout << "No suitable GPUs found" << std::endl;
|
||||
fatal("No suitable GPUs found");
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const auto *pick = &choices.front();
|
||||
|
||||
std::cout << "Suitable devices:";
|
||||
auto m = info("\n");
|
||||
m << "Suitable devices:";
|
||||
for (const auto &option : choices) {
|
||||
|
||||
struct {
|
||||
@ -80,17 +83,17 @@ pickPhysicalDevice(std::vector<PhysicalDeviceData> &choices, Vulkan &vulkan,
|
||||
{"CPU", -1}};
|
||||
|
||||
auto type = option.properties.deviceType;
|
||||
std::cout << "\n\t- " << opinions[type].description << " "
|
||||
<< option.properties.deviceName;
|
||||
m << "\n\t- " << opinions[type].description << " "
|
||||
<< option.properties.deviceName;
|
||||
|
||||
if (opinions[pick->properties.deviceType].value <
|
||||
opinions[type].value) {
|
||||
pick = &option;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
m << "\n";
|
||||
|
||||
std::cout << "Picked device " << pick->properties.deviceName << std::endl;
|
||||
m << "Picked device " << pick->properties.deviceName;
|
||||
return *pick;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,9 @@
|
||||
#include "vulkan_common.h"
|
||||
#include "vulkan_render_pass.h"
|
||||
|
||||
#include "../../main/logging.h"
|
||||
using namespace progressia::main::logging;
|
||||
|
||||
namespace progressia {
|
||||
namespace desktop {
|
||||
|
||||
@ -136,10 +139,9 @@ void SwapChain::create() {
|
||||
for (auto &attachment : vulkan.getAdapter().getAttachments()) {
|
||||
if (attachment.format == VK_FORMAT_UNDEFINED) {
|
||||
if (!attachment.image) {
|
||||
std::cout << "Attachment " << attachment.name
|
||||
<< " format is VK_FORMAT_UNDEFINED but it does not "
|
||||
"have an image"
|
||||
<< std::endl;
|
||||
fatal() << "Attachment " << attachment.name
|
||||
<< " format is VK_FORMAT_UNDEFINED but it does not "
|
||||
"have an image";
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
@ -162,9 +164,8 @@ void SwapChain::create() {
|
||||
} else if (attachment.image) {
|
||||
attachmentViews.push_back(attachment.image->view);
|
||||
} else {
|
||||
std::cout << "Attachment " << attachment.name
|
||||
<< " is not colorBuffer but it does not have an image"
|
||||
<< std::endl;
|
||||
fatal() << "Attachment " << attachment.name
|
||||
<< " is not colorBuffer but it does not have an image";
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
@ -196,7 +197,7 @@ VkSurfaceFormatKHR SwapChain::chooseSurfaceFormat(
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "No suitable formats available" << std::endl;
|
||||
fatal("No suitable formats available");
|
||||
// REPORT_ERROR
|
||||
exit(1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user