diff --git a/base/CommandLineParser.hpp b/base/CommandLineParser.hpp deleted file mode 100644 index c958fcf..0000000 --- a/base/CommandLineParser.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Simple command line parse - * - * Copyright (C) 2016-2022 by Sascha Willems - www.saschawillems.de - * - * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - */ - -#pragma once - -#include -#include -#include - -class CommandLineParser -{ -public: - struct CommandLineOption { - std::vector commands; - std::string value; - bool hasValue = false; - std::string help; - bool set = false; - }; - std::unordered_map options; - - void add(std::string name, std::vector commands, bool hasValue, std::string help) - { - options[name].commands = commands; - options[name].help = help; - options[name].set = false; - options[name].hasValue = hasValue; - options[name].value = ""; - } - - void printHelp() - { - std::cout << "Available command line options:\n"; - for (auto option : options) { - std::cout << " "; - for (size_t i = 0; i < option.second.commands.size(); i++) { - std::cout << option.second.commands[i]; - if (i < option.second.commands.size() - 1) { - std::cout << ", "; - } - } - std::cout << ": " << option.second.help << "\n"; - } - std::cout << "Press any key to close..."; - } - - void parse(std::vector arguments) - { - bool printHelp = false; - // Known arguments - for (auto& option : options) { - for (auto& command : option.second.commands) { - for (size_t i = 0; i < arguments.size(); i++) { - if (strcmp(arguments[i], command.c_str()) == 0) { - option.second.set = true; - // Get value - if (option.second.hasValue) { - if (arguments.size() > i + 1) { - option.second.value = arguments[i + 1]; - } - if (option.second.value == "") { - printHelp = true; - break; - } - } - } - } - } - } - // Print help for unknown arguments or missing argument values - if (printHelp) { - options["help"].set = true; - } - } - - void parse(int argc, char* argv[]) - { - std::vector args; - for (int i = 0; i < argc; i++) { - args.push_back(argv[i]); - }; - parse(args); - } - - bool isSet(std::string name) - { - return ((options.find(name) != options.end()) && options[name].set); - } - - std::string getValueAsString(std::string name, std::string defaultValue) - { - assert(options.find(name) != options.end()); - std::string value = options[name].value; - return (value != "") ? value : defaultValue; - } - - int32_t getValueAsInt(std::string name, int32_t defaultValue) - { - assert(options.find(name) != options.end()); - std::string value = options[name].value; - if (value != "") { - char* numConvPtr; - int32_t intVal = strtol(value.c_str(), &numConvPtr, 10); - return (intVal > 0) ? intVal : defaultValue; - } - else { - return defaultValue; - } - return int32_t(); - } - -}; \ No newline at end of file diff --git a/base/VulkanTools.cpp b/base/VulkanTools.cpp index 6cb1a5e..dc3e8bf 100644 --- a/base/VulkanTools.cpp +++ b/base/VulkanTools.cpp @@ -1,10 +1,3 @@ -/* -* Assorted commonly used Vulkan helper functions -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ #include "VulkanTools.h" diff --git a/base/VulkanTools.h b/base/VulkanTools.h index 40d8b0e..b7f55bc 100644 --- a/base/VulkanTools.h +++ b/base/VulkanTools.h @@ -1,10 +1,3 @@ -/* -* Assorted Vulkan helper functions -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ #pragma once diff --git a/base/benchmark.hpp b/base/benchmark.hpp deleted file mode 100644 index bae91a6..0000000 --- a/base/benchmark.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/* -* Benchmark class -* -* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -#include -#include -#include -#include -#include -#include -#include - -namespace vks -{ - class Benchmark { - private: - FILE *stream; - VkPhysicalDeviceProperties deviceProps; - public: - bool active = false; - bool outputFrameTimes = false; - int outputFrames = -1; // -1 means no frames limit - uint32_t warmup = 1; - uint32_t duration = 10; - std::vector frameTimes; - std::string filename = ""; - - double runtime = 0.0; - uint32_t frameCount = 0; - - void run(std::function renderFunc, VkPhysicalDeviceProperties deviceProps) { - active = true; - this->deviceProps = deviceProps; -#if defined(_WIN32) - AttachConsole(ATTACH_PARENT_PROCESS); - freopen_s(&stream, "CONOUT$", "w+", stdout); - freopen_s(&stream, "CONOUT$", "w+", stderr); -#endif - std::cout << std::fixed << std::setprecision(3); - - // Warm up phase to get more stable frame rates - { - double tMeasured = 0.0; - while (tMeasured < (warmup * 1000)) { - auto tStart = std::chrono::high_resolution_clock::now(); - renderFunc(); - auto tDiff = std::chrono::duration(std::chrono::high_resolution_clock::now() - tStart).count(); - tMeasured += tDiff; - }; - } - - // Benchmark phase - { - while (runtime < (duration * 1000.0)) { - auto tStart = std::chrono::high_resolution_clock::now(); - renderFunc(); - auto tDiff = std::chrono::duration(std::chrono::high_resolution_clock::now() - tStart).count(); - runtime += tDiff; - frameTimes.push_back(tDiff); - frameCount++; - if (outputFrames != -1 && outputFrames == frameCount) break; - }; - std::cout << "Benchmark finished" << "\n"; - std::cout << "device : " << deviceProps.deviceName << " (driver version: " << deviceProps.driverVersion << ")" << "\n"; - std::cout << "runtime: " << (runtime / 1000.0) << "\n"; - std::cout << "frames : " << frameCount << "\n"; - std::cout << "fps : " << frameCount / (runtime / 1000.0) << "\n"; - } - } - - void saveResults() { - std::ofstream result(filename, std::ios::out); - if (result.is_open()) { - result << std::fixed << std::setprecision(4); - - result << "device,driverversion,duration (ms),frames,fps" << "\n"; - result << deviceProps.deviceName << "," << deviceProps.driverVersion << "," << runtime << "," << frameCount << "," << frameCount / (runtime / 1000.0) << "\n"; - - if (outputFrameTimes) { - result << "\n" << "frame,ms" << "\n"; - for (size_t i = 0; i < frameTimes.size(); i++) { - result << i << "," << frameTimes[i] << "\n"; - } - double tMin = *std::min_element(frameTimes.begin(), frameTimes.end()); - double tMax = *std::max_element(frameTimes.begin(), frameTimes.end()); - double tAvg = std::accumulate(frameTimes.begin(), frameTimes.end(), 0.0) / (double)frameTimes.size(); - std::cout << "best : " << (1000.0 / tMin) << " fps (" << tMin << " ms)" << "\n"; - std::cout << "worst : " << (1000.0 / tMax) << " fps (" << tMax << " ms)" << "\n"; - std::cout << "avg : " << (1000.0 / tAvg) << " fps (" << tAvg << " ms)" << "\n"; - std::cout << "\n"; - } - - result.flush(); -#if defined(_WIN32) - FreeConsole(); -#endif - } - } - }; -} \ No newline at end of file diff --git a/base/threadpool.hpp b/base/threadpool.hpp deleted file mode 100644 index d14ecf7..0000000 --- a/base/threadpool.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/* -* Basic C++11 based thread pool with per-thread job queues -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -#include -#include -#include -#include -#include -#include - -// make_unique is not available in C++11 -// Taken from Herb Sutter's blog (https://herbsutter.com/gotw/_102/) -template -std::unique_ptr make_unique(Args&& ...args) -{ - return std::unique_ptr(new T(std::forward(args)...)); -} - -namespace vks -{ - class Thread - { - private: - bool destroying = false; - std::thread worker; - std::queue> jobQueue; - std::mutex queueMutex; - std::condition_variable condition; - - // Loop through all remaining jobs - void queueLoop() - { - while (true) - { - std::function job; - { - std::unique_lock lock(queueMutex); - condition.wait(lock, [this] { return !jobQueue.empty() || destroying; }); - if (destroying) - { - break; - } - job = jobQueue.front(); - } - - job(); - - { - std::lock_guard lock(queueMutex); - jobQueue.pop(); - condition.notify_one(); - } - } - } - - public: - Thread() - { - worker = std::thread(&Thread::queueLoop, this); - } - - ~Thread() - { - if (worker.joinable()) - { - wait(); - queueMutex.lock(); - destroying = true; - condition.notify_one(); - queueMutex.unlock(); - worker.join(); - } - } - - // Add a new job to the thread's queue - void addJob(std::function function) - { - std::lock_guard lock(queueMutex); - jobQueue.push(std::move(function)); - condition.notify_one(); - } - - // Wait until all work items have been finished - void wait() - { - std::unique_lock lock(queueMutex); - condition.wait(lock, [this]() { return jobQueue.empty(); }); - } - }; - - class ThreadPool - { - public: - std::vector> threads; - - // Sets the number of threads to be allocated in this pool - void setThreadCount(uint32_t count) - { - threads.clear(); - for (auto i = 0; i < count; i++) - { - threads.push_back(make_unique()); - } - } - - // Wait until all threads have finished their work items - void wait() - { - for (auto &thread : threads) - { - thread->wait(); - } - } - }; - -} diff --git a/src/render/glTFModel.cpp b/src/render/glTFModel.cpp index ca51294..671fc70 100644 --- a/src/render/glTFModel.cpp +++ b/src/render/glTFModel.cpp @@ -29,6 +29,7 @@ glTFModel::BoundingBox::BoundingBox(glm::vec3 min, glm::vec3 max) : min(min), max(max) { }; + //Axis-Aligned Bounding Box),¼ò³Æ AABB glTFModel::BoundingBox glTFModel::BoundingBox::getAABB(glm::mat4 m) { glm::vec3 min = glm::vec3(m[3]); glm::vec3 max = min; @@ -53,7 +54,7 @@ max += glm::max(v0, v1); return BoundingBox(min, max); - } + } // Texture void glTFModel::Texture::updateDescriptor() diff --git a/src/render/render.h b/src/render/render.h index 004807b..c471561 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -93,7 +93,7 @@ public: struct FilePath { //model path - std::string glTFModelFilePath = getAssetPath() + "DamagedHelmet/DamagedHelmet.gltf"; + std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf"; std::string modelVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.vert.spv"; std::string modelFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.frag.spv"; @@ -296,7 +296,7 @@ public: void setupNodeDescriptorSet(glTFModel::Node* node); void setupDescriptors(); void preparePipelines(); - //void CreateToneMappingPipeline(); + // void tonemappingPipelin(); void generateCubemaps(); void generateBRDFLUT(); void prepareUniformBuffers(); @@ -305,7 +305,6 @@ public: void windowResized(); void prepare(); virtual void render(); - //virtual void viewChanged(); virtual void updateUIOverlay(); virtual void fileDropped(std::string filename); }; \ No newline at end of file