Small bits
This commit is contained in:
parent
d323668ab4
commit
d5118cda5b
|
@ -13,12 +13,9 @@ Client::Client(config::client::options& options): options(options) { }
|
||||||
Client::~Client() { }
|
Client::~Client() { }
|
||||||
|
|
||||||
void Client::run(server_handle* const localHandle) {
|
void Client::run(server_handle* const localHandle) {
|
||||||
if (!render::Load(window, options.preferVulkan, options.renderer, options.window.getSamples()))
|
if (!render::Load(window, options.preferVulkan, options.renderer, options.window))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
window.setTargetFPS(options.window.targetFPS);
|
|
||||||
window.setFullscreen(options.window.fullscreen);
|
|
||||||
|
|
||||||
InputMap inputs(window.getPtr());
|
InputMap inputs(window.getPtr());
|
||||||
Controllable player(window.getPtr(), inputs, options.control);
|
Controllable player(window.getPtr(), inputs, options.control);
|
||||||
Camera camera(&player, options.camera);
|
Camera camera(&player, options.camera);
|
||||||
|
@ -91,6 +88,7 @@ void Client::run(server_handle* const localHandle) {
|
||||||
const auto actions = render::UI::Get()->draw(options, state, reports);
|
const auto actions = render::UI::Get()->draw(options, state, reports);
|
||||||
if (actions && render::UI::Actions::FPS) {
|
if (actions && render::UI::Actions::FPS) {
|
||||||
window.setTargetFPS(options.window.targetFPS);
|
window.setTargetFPS(options.window.targetFPS);
|
||||||
|
pipeline->setVSync(options.window.targetFPS < Window::MIN_FPS);
|
||||||
}
|
}
|
||||||
if (actions && render::UI::Actions::FullScreen) {
|
if (actions && render::UI::Actions::FullScreen) {
|
||||||
window.setFullscreen(options.window.fullscreen);
|
window.setFullscreen(options.window.fullscreen);
|
||||||
|
|
|
@ -81,6 +81,9 @@ bool Window::create(const CreateInfo &opt) {
|
||||||
glfwSetWindowTitle(ptr, APP_NAME);
|
glfwSetWindowTitle(ptr, APP_NAME);
|
||||||
glfwSetWindowAttrib(ptr, GLFW_RESIZABLE, true);
|
glfwSetWindowAttrib(ptr, GLFW_RESIZABLE, true);
|
||||||
|
|
||||||
|
setTargetFPS(opt.fps);
|
||||||
|
setFullscreen(opt.fullscreen);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +91,6 @@ bool Window::isReady() const { return ptr != nullptr; }
|
||||||
|
|
||||||
void Window::setTargetFPS(int val) {
|
void Window::setTargetFPS(int val) {
|
||||||
targetFPS = val;
|
targetFPS = val;
|
||||||
glfwSwapInterval(static_cast<int>(val < MIN_FPS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double Window::getTime() const {
|
double Window::getTime() const {
|
||||||
|
|
|
@ -6,6 +6,13 @@
|
||||||
typedef struct GLFWwindow GLFWwindow;
|
typedef struct GLFWwindow GLFWwindow;
|
||||||
typedef void (*GLFWframebuffersizefun)(GLFWwindow*, int, int);
|
typedef void (*GLFWframebuffersizefun)(GLFWwindow*, int, int);
|
||||||
|
|
||||||
|
struct windowOptions {
|
||||||
|
int targetFPS = 60;
|
||||||
|
int sampling = -1;
|
||||||
|
bool fullscreen = false;
|
||||||
|
|
||||||
|
constexpr int getSamples() const { return sampling > 0 ? (1 << (sampling - 1)) : sampling; }
|
||||||
|
};
|
||||||
|
|
||||||
/// GLFW context and window
|
/// GLFW context and window
|
||||||
class Window {
|
class Window {
|
||||||
|
@ -29,6 +36,8 @@ public:
|
||||||
int minor;
|
int minor;
|
||||||
} client;
|
} client;
|
||||||
int samples;
|
int samples;
|
||||||
|
int fps;
|
||||||
|
bool fullscreen;
|
||||||
};
|
};
|
||||||
bool create(const CreateInfo &opt);
|
bool create(const CreateInfo &opt);
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "render/Renderer.hpp"
|
#include "render/Renderer.hpp"
|
||||||
#include "contouring/Abstract.hpp"
|
#include "contouring/Abstract.hpp"
|
||||||
#include "control/Camera.hpp"
|
#include "control/Camera.hpp"
|
||||||
|
#include "Window.hpp"
|
||||||
|
|
||||||
namespace config::client {
|
namespace config::client {
|
||||||
|
|
||||||
|
@ -179,13 +180,7 @@ public:
|
||||||
bool controls = false;
|
bool controls = false;
|
||||||
} debugMenu;
|
} debugMenu;
|
||||||
|
|
||||||
struct {
|
windowOptions window;
|
||||||
int targetFPS = 60;
|
|
||||||
int sampling = -1;
|
|
||||||
bool fullscreen = false;
|
|
||||||
|
|
||||||
constexpr int getSamples() const { return sampling > 0 ? (1 << (sampling - 1)) : sampling; }
|
|
||||||
} window;
|
|
||||||
|
|
||||||
bool preferVulkan = true;
|
bool preferVulkan = true;
|
||||||
render::renderOptions renderer;
|
render::renderOptions renderer;
|
||||||
|
|
|
@ -87,6 +87,7 @@ public:
|
||||||
virtual void reloadShaders(const passOptions &) = 0;
|
virtual void reloadShaders(const passOptions &) = 0;
|
||||||
virtual void reloadTextures(const std::string &, float mipMapLOD, float anisotropy) = 0;
|
virtual void reloadTextures(const std::string &, float mipMapLOD, float anisotropy) = 0;
|
||||||
virtual void setFillMode(bool wireframe) = 0;
|
virtual void setFillMode(bool wireframe) = 0;
|
||||||
|
virtual void setVSync(bool vSync) = 0;
|
||||||
|
|
||||||
virtual void loadUI(Window&) = 0;
|
virtual void loadUI(Window&) = 0;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../state.hpp"
|
#include "../state.hpp"
|
||||||
#include "../Window.hpp"
|
#include "../Window.hpp"
|
||||||
#include "../../core/world/materials.hpp"
|
#include "../../core/world/materials.hpp"
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
using namespace render;
|
using namespace render;
|
||||||
|
|
||||||
|
@ -16,6 +17,11 @@ UI::UI() {
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
|
for(auto file: std::filesystem::directory_iterator("content/textures/")) {
|
||||||
|
if(file.is_directory() && file.path().filename() != "ui")
|
||||||
|
texturePacks.push_back(file.path().filename());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UI::~UI() {
|
UI::~UI() {
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
@ -115,7 +121,18 @@ UI::Actions UI::draw(config::client::options &options, state::state &state, cons
|
||||||
if (ImGui::Checkbox("Wireframe", &options.renderer.wireframe)) {
|
if (ImGui::Checkbox("Wireframe", &options.renderer.wireframe)) {
|
||||||
actions |= Actions::FillMode;
|
actions |= Actions::FillMode;
|
||||||
}
|
}
|
||||||
ImGui::Text("Textures '%s'", options.renderer.textures.c_str()); // MAYBE: select
|
if (ImGui::BeginCombo("Textures", options.renderer.textures.c_str())) {
|
||||||
|
for (auto& pack: texturePacks) {
|
||||||
|
const bool is_selected = (pack == options.renderer.textures);
|
||||||
|
if (ImGui::Selectable(pack.c_str(), is_selected)) {
|
||||||
|
options.renderer.textures = pack;
|
||||||
|
actions |= Actions::RendererTextures;
|
||||||
|
}
|
||||||
|
if (is_selected)
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
}
|
||||||
|
ImGui::EndCombo();
|
||||||
|
}
|
||||||
std::string anisotropy = std::to_string(options.renderer.getAnisotropy()) + "x";
|
std::string anisotropy = std::to_string(options.renderer.getAnisotropy()) + "x";
|
||||||
if (ImGui::SliderInt("Quality", &options.renderer.textureQuality, 0, 200, "%d%%") |
|
if (ImGui::SliderInt("Quality", &options.renderer.textureQuality, 0, 200, "%d%%") |
|
||||||
ImGui::SliderInt("Sharpness", &options.renderer.textureSharpness, 0, 8, anisotropy.c_str())) {
|
ImGui::SliderInt("Sharpness", &options.renderer.textureSharpness, 0, 8, anisotropy.c_str())) {
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
#include "../../core/flags.hpp"
|
#include "../../core/flags.hpp"
|
||||||
|
|
||||||
namespace config::client { struct options; }
|
namespace config::client { struct options; }
|
||||||
|
@ -17,6 +19,8 @@ namespace render {
|
||||||
class UI {
|
class UI {
|
||||||
protected:
|
protected:
|
||||||
UI();
|
UI();
|
||||||
|
|
||||||
|
std::vector<std::string> texturePacks;
|
||||||
public:
|
public:
|
||||||
virtual ~UI();
|
virtual ~UI();
|
||||||
|
|
||||||
|
@ -56,7 +60,7 @@ public:
|
||||||
static void Unload();
|
static void Unload();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static Actions draw(config::client::options&, state::state &, const state::reports &, intptr_t aim);
|
Actions draw(config::client::options&, state::state &, const state::reports &, intptr_t aim);
|
||||||
|
|
||||||
static UI* sInstance;
|
static UI* sInstance;
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,11 +42,14 @@ void framebuffer_size_callback(GLFWwindow *, int width, int height) {
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderer::Load(Window& window, const renderOptions& opt, int samples) {
|
bool Renderer::Load(Window& window, const renderOptions& opt, const windowOptions& windOpt) {
|
||||||
Window::CreateInfo windowInfo;
|
Window::CreateInfo windowInfo;
|
||||||
windowInfo.pfnResize = framebuffer_size_callback;
|
windowInfo.pfnResize = framebuffer_size_callback;
|
||||||
windowInfo.client = {Window::CreateInfo::Client::Type::GL, GL_MAJOR, GL_MINOR};
|
windowInfo.client = {Window::CreateInfo::Client::Type::GL, GL_MAJOR, GL_MINOR};
|
||||||
windowInfo.samples = samples;
|
windowInfo.samples = windOpt.getSamples();
|
||||||
|
windowInfo.fps = windOpt.targetFPS;
|
||||||
|
windowInfo.fullscreen = windOpt.fullscreen;
|
||||||
|
|
||||||
if (!window.create(windowInfo))
|
if (!window.create(windowInfo))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -80,6 +83,7 @@ bool Renderer::Load(Window& window, const renderOptions& opt, int samples) {
|
||||||
TracyGpuContext;
|
TracyGpuContext;
|
||||||
|
|
||||||
sInstance = new Renderer(opt);
|
sInstance = new Renderer(opt);
|
||||||
|
sInstance->setVSync(windOpt.targetFPS < Window::MIN_FPS);
|
||||||
LodModel::MakeDefault();
|
LodModel::MakeDefault();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -178,3 +182,7 @@ void Renderer::setClearColor(glm::vec4 c) {
|
||||||
void Renderer::setFillMode(bool wireframe) {
|
void Renderer::setFillMode(bool wireframe) {
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::setVSync(bool vSync) {
|
||||||
|
glfwSwapInterval(static_cast<int>(vSync));
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
#include "api/Models.hpp"
|
#include "api/Models.hpp"
|
||||||
#include "api/Images.hpp"
|
#include "api/Images.hpp"
|
||||||
|
|
||||||
|
struct windowOptions;
|
||||||
namespace render::gl {
|
namespace render::gl {
|
||||||
|
|
||||||
/// OpenGL rendering
|
/// OpenGL rendering
|
||||||
|
@ -16,7 +17,7 @@ class Renderer final: public render::Renderer {
|
||||||
public:
|
public:
|
||||||
virtual ~Renderer();
|
virtual ~Renderer();
|
||||||
|
|
||||||
static bool Load(Window& window, const renderOptions& options, int samples);
|
static bool Load(Window& window, const renderOptions& options, const windowOptions& windOpt);
|
||||||
|
|
||||||
glm::vec3 FogColor;
|
glm::vec3 FogColor;
|
||||||
GLfloat FogDepth;
|
GLfloat FogDepth;
|
||||||
|
@ -56,6 +57,7 @@ public:
|
||||||
void reloadShaders(const pass::VoxelProgram::options &) override;
|
void reloadShaders(const pass::VoxelProgram::options &) override;
|
||||||
void reloadTextures(const std::string &, float mipMapLOD, float anisotropy) override;
|
void reloadTextures(const std::string &, float mipMapLOD, float anisotropy) override;
|
||||||
void setFillMode(bool wireframe) override;
|
void setFillMode(bool wireframe) override;
|
||||||
|
void setVSync(bool vSync) override;
|
||||||
|
|
||||||
void loadUI(Window &) override;
|
void loadUI(Window &) override;
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
bool Load(Window& window, bool preferVulkan, const renderOptions& options, int samples) {
|
bool Load(Window& window, bool preferVulkan, const renderOptions& options, const windowOptions& windOpt) {
|
||||||
if(!preferVulkan) {
|
if(!preferVulkan) {
|
||||||
LOG_T("Trying OpenGL");
|
LOG_T("Trying OpenGL");
|
||||||
if(gl::Renderer::Load(window, options, samples))
|
if(gl::Renderer::Load(window, options, windOpt))
|
||||||
return true;
|
return true;
|
||||||
window.destroy();
|
window.destroy();
|
||||||
}
|
}
|
||||||
LOG_T("Trying Vulkan");
|
LOG_T("Trying Vulkan");
|
||||||
if(vk::Renderer::Load(window, options, samples))
|
if(vk::Renderer::Load(window, options, windOpt))
|
||||||
return true;
|
return true;
|
||||||
window.destroy();
|
window.destroy();
|
||||||
if(preferVulkan) {
|
if(preferVulkan) {
|
||||||
LOG_I("Fallback to OpenGL");
|
LOG_I("Fallback to OpenGL");
|
||||||
if(gl::Renderer::Load(window, options, samples))
|
if(gl::Renderer::Load(window, options, windOpt))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
LOG_E("No available graphics library");
|
LOG_E("No available graphics library");
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class Window;
|
class Window;
|
||||||
|
struct windowOptions;
|
||||||
namespace render {
|
namespace render {
|
||||||
struct renderOptions;
|
struct renderOptions;
|
||||||
|
|
||||||
bool Load(Window& window, bool preferVulkan, const renderOptions& options, int samples);
|
bool Load(Window& window, bool preferVulkan, const renderOptions& options, const windowOptions& windOpt);
|
||||||
}
|
}
|
|
@ -141,30 +141,18 @@ void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeli
|
||||||
{ // Descriptor pools
|
{ // Descriptor pools
|
||||||
std::array<VkDescriptorPoolSize, 2> poolSizes{};
|
std::array<VkDescriptorPoolSize, 2> poolSizes{};
|
||||||
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||||
poolSizes[0].descriptorCount = framebuffers.size();
|
poolSizes[0].descriptorCount = framebuffers.size() * 3;
|
||||||
poolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
poolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
poolSizes[1].descriptorCount = framebuffers.size() * 3;
|
poolSizes[1].descriptorCount = framebuffers.size() * 4;
|
||||||
|
|
||||||
VkDescriptorPoolCreateInfo poolInfo{};
|
VkDescriptorPoolCreateInfo poolInfo{};
|
||||||
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
poolInfo.poolSizeCount = poolSizes.size();
|
poolInfo.poolSizeCount = poolSizes.size();
|
||||||
poolInfo.pPoolSizes = poolSizes.data();
|
poolInfo.pPoolSizes = poolSizes.data();
|
||||||
poolInfo.maxSets = framebuffers.size();
|
poolInfo.maxSets = framebuffers.size() * 3;
|
||||||
poolInfo.flags = 0; //VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
|
poolInfo.flags = 0; //VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
|
||||||
|
|
||||||
if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &voxelDescriptorPool) != VK_SUCCESS) {
|
if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &descriptorPool) != VK_SUCCESS) {
|
||||||
FATAL("Failed to create descriptor pool!");
|
|
||||||
}
|
|
||||||
|
|
||||||
poolSizes[1].descriptorCount = framebuffers.size();
|
|
||||||
|
|
||||||
if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &skyDescriptorPool) != VK_SUCCESS) {
|
|
||||||
FATAL("Failed to create descriptor pool!");
|
|
||||||
}
|
|
||||||
|
|
||||||
poolInfo.poolSizeCount = 1;
|
|
||||||
|
|
||||||
if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &indicDescriptorPool) != VK_SUCCESS) {
|
|
||||||
FATAL("Failed to create descriptor pool!");
|
FATAL("Failed to create descriptor pool!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,10 +160,10 @@ void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeli
|
||||||
VkDescriptorSetAllocateInfo allocInfo{};
|
VkDescriptorSetAllocateInfo allocInfo{};
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
allocInfo.descriptorSetCount = framebuffers.size();
|
allocInfo.descriptorSetCount = framebuffers.size();
|
||||||
|
|
||||||
auto allocSets = [&](VkDescriptorPool pool, VkDescriptorSetLayout layout, std::vector<VkDescriptorSet>& out) {
|
auto allocSets = [&](VkDescriptorSetLayout layout, std::vector<VkDescriptorSet>& out) {
|
||||||
std::vector<VkDescriptorSetLayout> layouts(framebuffers.size(), layout);
|
std::vector<VkDescriptorSetLayout> layouts(framebuffers.size(), layout);
|
||||||
allocInfo.descriptorPool = pool;
|
allocInfo.descriptorPool = descriptorPool;
|
||||||
allocInfo.pSetLayouts = layouts.data();
|
allocInfo.pSetLayouts = layouts.data();
|
||||||
|
|
||||||
out.resize(framebuffers.size());
|
out.resize(framebuffers.size());
|
||||||
|
@ -183,9 +171,9 @@ void CommandCenter::allocate(const std::vector<VkImageView>& views, const Pipeli
|
||||||
FATAL("Failed to allocate descriptor sets!");
|
FATAL("Failed to allocate descriptor sets!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
allocSets(voxelDescriptorPool, pipe.getVoxelDescriptorSet(), voxelDescriptorSets);
|
allocSets(pipe.getVoxelDescriptorSet(), voxelDescriptorSets);
|
||||||
allocSets(indicDescriptorPool, pipe.getIndicDescriptorSet(), indicDescriptorSets);
|
allocSets(pipe.getIndicDescriptorSet(), indicDescriptorSets);
|
||||||
allocSets(skyDescriptorPool, pipe.getSkyDescriptorSet(), skyDescriptorSets);
|
allocSets(pipe.getSkyDescriptorSet(), skyDescriptorSets);
|
||||||
|
|
||||||
for (size_t i = 0; i < voxelDescriptorSets.size(); i++) {
|
for (size_t i = 0; i < voxelDescriptorSets.size(); i++) {
|
||||||
VkDescriptorBufferInfo bufferInfo{};
|
VkDescriptorBufferInfo bufferInfo{};
|
||||||
|
@ -260,9 +248,7 @@ void CommandCenter::free() {
|
||||||
TracyVkDestroy(tracyCtx);
|
TracyVkDestroy(tracyCtx);
|
||||||
vkFreeCommandBuffers(device, graphicsPool, static_cast<uint32_t>(graphicsBuffers.size()), graphicsBuffers.data());
|
vkFreeCommandBuffers(device, graphicsPool, static_cast<uint32_t>(graphicsBuffers.size()), graphicsBuffers.data());
|
||||||
|
|
||||||
vkDestroyDescriptorPool(device, voxelDescriptorPool, ALLOC);
|
vkDestroyDescriptorPool(device, descriptorPool, ALLOC);
|
||||||
vkDestroyDescriptorPool(device, indicDescriptorPool, ALLOC);
|
|
||||||
vkDestroyDescriptorPool(device, skyDescriptorPool, ALLOC);
|
|
||||||
|
|
||||||
colorbuffer.reset();
|
colorbuffer.reset();
|
||||||
depthbuffer.reset();
|
depthbuffer.reset();
|
||||||
|
|
|
@ -57,17 +57,16 @@ private:
|
||||||
|
|
||||||
BufferGroup uniformBuffers;
|
BufferGroup uniformBuffers;
|
||||||
|
|
||||||
VkDescriptorPool voxelDescriptorPool;
|
VkDescriptorPool descriptorPool;
|
||||||
|
|
||||||
std::vector<VkDescriptorSet> voxelDescriptorSets;
|
std::vector<VkDescriptorSet> voxelDescriptorSets;
|
||||||
std::unique_ptr<TextureArray> voxelTextureAtlas;
|
std::unique_ptr<TextureArray> voxelTextureAtlas;
|
||||||
std::unique_ptr<TextureArray> voxelNormalAtlas;
|
std::unique_ptr<TextureArray> voxelNormalAtlas;
|
||||||
std::unique_ptr<TextureArray> voxelHOSAtlas;
|
std::unique_ptr<TextureArray> voxelHOSAtlas;
|
||||||
|
|
||||||
VkDescriptorPool indicDescriptorPool;
|
|
||||||
std::vector<VkDescriptorSet> indicDescriptorSets;
|
std::vector<VkDescriptorSet> indicDescriptorSets;
|
||||||
std::unique_ptr<Indicator> indicCubeBuffer;
|
std::unique_ptr<Indicator> indicCubeBuffer;
|
||||||
|
|
||||||
VkDescriptorPool skyDescriptorPool;
|
|
||||||
std::vector<VkDescriptorSet> skyDescriptorSets;
|
std::vector<VkDescriptorSet> skyDescriptorSets;
|
||||||
std::unique_ptr<TextureCube> skyboxTexture;
|
std::unique_ptr<TextureCube> skyboxTexture;
|
||||||
std::unique_ptr<Shape> skyCubeBuffer;
|
std::unique_ptr<Shape> skyCubeBuffer;
|
||||||
|
|
|
@ -81,7 +81,7 @@ std::optional<VkFormat> PhysicalDeviceInfo::findSupportedFormat(const std::vecto
|
||||||
}
|
}
|
||||||
VkFormat PhysicalDeviceInfo::findDepthFormat() const {
|
VkFormat PhysicalDeviceInfo::findDepthFormat() const {
|
||||||
if (auto res = findSupportedFormat(
|
if (auto res = findSupportedFormat(
|
||||||
{VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT},
|
{VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT},
|
||||||
VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
|
VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
|
||||||
return res.value();
|
return res.value();
|
||||||
|
|
||||||
|
|
|
@ -24,20 +24,21 @@ struct QueueFamilyIndices {
|
||||||
};
|
};
|
||||||
struct PhysicalDeviceInfo {
|
struct PhysicalDeviceInfo {
|
||||||
PhysicalDeviceInfo() {}
|
PhysicalDeviceInfo() {}
|
||||||
PhysicalDeviceInfo(GLFWwindow *window, VkPhysicalDevice device, VkSurfaceKHR surface, int targetSamples):
|
PhysicalDeviceInfo(GLFWwindow *window, VkPhysicalDevice device, VkSurfaceKHR surface, int targetSamples, bool vSync):
|
||||||
window(window), device(device), surface(surface),
|
window(window), device(device), surface(surface),
|
||||||
swapDetails(SwapChainSupportDetails::Query(device, surface)), queueIndices(QueueFamilyIndices::Query(device, surface))
|
swapDetails(SwapChainSupportDetails::Query(device, surface)), queueIndices(QueueFamilyIndices::Query(device, surface)),
|
||||||
|
vSync(vSync)
|
||||||
{
|
{
|
||||||
vkGetPhysicalDeviceProperties(device, &properties);
|
vkGetPhysicalDeviceProperties(device, &properties);
|
||||||
vkGetPhysicalDeviceFeatures(device, &features);
|
vkGetPhysicalDeviceFeatures(device, &features);
|
||||||
|
|
||||||
samples = [&] {
|
samples = [&] {
|
||||||
if (targetSamples < 0)
|
|
||||||
targetSamples = 4;
|
|
||||||
VkSampleCountFlags counts = properties.limits.framebufferColorSampleCounts & properties.limits.framebufferDepthSampleCounts;
|
VkSampleCountFlags counts = properties.limits.framebufferColorSampleCounts & properties.limits.framebufferDepthSampleCounts;
|
||||||
//MAYBE: properties.limits.framebufferStencilSampleCounts
|
//MAYBE: properties.limits.framebufferStencilSampleCounts
|
||||||
|
if (targetSamples < 0)
|
||||||
|
targetSamples = counts / 4;
|
||||||
for (auto sample: {VK_SAMPLE_COUNT_64_BIT, VK_SAMPLE_COUNT_32_BIT, VK_SAMPLE_COUNT_16_BIT,
|
for (auto sample: {VK_SAMPLE_COUNT_64_BIT, VK_SAMPLE_COUNT_32_BIT, VK_SAMPLE_COUNT_16_BIT,
|
||||||
VK_SAMPLE_COUNT_8_BIT, VK_SAMPLE_COUNT_4_BIT, VK_SAMPLE_COUNT_2_BIT
|
VK_SAMPLE_COUNT_8_BIT, VK_SAMPLE_COUNT_4_BIT, VK_SAMPLE_COUNT_2_BIT
|
||||||
}) {
|
}) {
|
||||||
if (targetSamples >= sample && (counts & sample))
|
if (targetSamples >= sample && (counts & sample))
|
||||||
return sample;
|
return sample;
|
||||||
|
@ -64,5 +65,7 @@ struct PhysicalDeviceInfo {
|
||||||
VkPhysicalDeviceProperties properties;
|
VkPhysicalDeviceProperties properties;
|
||||||
VkPhysicalDeviceFeatures features;
|
VkPhysicalDeviceFeatures features;
|
||||||
std::vector<const char *> optionalExtensions;
|
std::vector<const char *> optionalExtensions;
|
||||||
|
bool vSync;
|
||||||
|
bool tripleBuffering = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@
|
||||||
#define CONTENT_DIR "content/"
|
#define CONTENT_DIR "content/"
|
||||||
#define SHADER_DIR CONTENT_DIR "shaders/"
|
#define SHADER_DIR CONTENT_DIR "shaders/"
|
||||||
|
|
||||||
constexpr auto BLENDING = true;
|
constexpr auto BLENDING = false;
|
||||||
|
|
||||||
using namespace render::vk;
|
using namespace render::vk;
|
||||||
|
|
||||||
|
|
|
@ -163,11 +163,14 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugValidationCallback(VkDebugUtilsMessageSeveri
|
||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderer::Load(Window& window, const renderOptions& opt, int samples) {
|
bool Renderer::Load(Window& window, const renderOptions& opt, const windowOptions& windOpt) {
|
||||||
Window::CreateInfo windowInfo;
|
Window::CreateInfo windowInfo;
|
||||||
windowInfo.pfnResize = on_resize_callback;
|
windowInfo.pfnResize = on_resize_callback;
|
||||||
windowInfo.client = {Window::CreateInfo::Client::Type::VK, 0, 0};
|
windowInfo.client = {Window::CreateInfo::Client::Type::VK, 0, 0};
|
||||||
windowInfo.samples = -1;
|
windowInfo.samples = -1;
|
||||||
|
windowInfo.fps = windOpt.targetFPS;
|
||||||
|
windowInfo.fullscreen = windOpt.fullscreen;
|
||||||
|
|
||||||
if (!window.create(windowInfo))
|
if (!window.create(windowInfo))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -297,7 +300,7 @@ bool Renderer::Load(Window& window, const renderOptions& opt, int samples) {
|
||||||
uint bestScore = 0;
|
uint bestScore = 0;
|
||||||
for(const auto& device: devices) {
|
for(const auto& device: devices) {
|
||||||
uint score = 1;
|
uint score = 1;
|
||||||
auto infos = PhysicalDeviceInfo(window.getPtr(), device, surface, samples);
|
auto infos = PhysicalDeviceInfo(window.getPtr(), device, surface, windOpt.getSamples(), windOpt.targetFPS < Window::MIN_FPS);
|
||||||
|
|
||||||
{
|
{
|
||||||
uint32_t availableExtensionsCount;
|
uint32_t availableExtensionsCount;
|
||||||
|
@ -521,6 +524,12 @@ void Renderer::setFillMode(bool wireframe) {
|
||||||
options.wireframe = wireframe;
|
options.wireframe = wireframe;
|
||||||
recreateSwapChain();
|
recreateSwapChain();
|
||||||
}
|
}
|
||||||
|
void Renderer::setVSync(bool vSync) {
|
||||||
|
if (vSync != getInfos().vSync) {
|
||||||
|
physicalInfo->vSync = vSync;
|
||||||
|
recreateSwapChain();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::lookFrom(const Camera& camera) {
|
void Renderer::lookFrom(const Camera& camera) {
|
||||||
ProjectionMatrix = camera.getProjectionMatrix();
|
ProjectionMatrix = camera.getProjectionMatrix();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "../Renderer.hpp"
|
#include "../Renderer.hpp"
|
||||||
#include "forward.hpp"
|
#include "forward.hpp"
|
||||||
|
|
||||||
|
struct windowOptions;
|
||||||
namespace render::vk {
|
namespace render::vk {
|
||||||
class Allocator;
|
class Allocator;
|
||||||
class SwapChain;
|
class SwapChain;
|
||||||
|
@ -13,7 +14,7 @@ class Renderer final: public render::Renderer {
|
||||||
public:
|
public:
|
||||||
virtual ~Renderer();
|
virtual ~Renderer();
|
||||||
|
|
||||||
static bool Load(Window& window, const renderOptions& options, int samples);
|
static bool Load(Window& window, const renderOptions& options, const windowOptions& windOpt);
|
||||||
|
|
||||||
void loadUI(Window &) override;
|
void loadUI(Window &) override;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ public:
|
||||||
void reloadShaders(const passOptions &) override;
|
void reloadShaders(const passOptions &) override;
|
||||||
void reloadTextures(const std::string &, float mipMapLOD, float anisotropy) override;
|
void reloadTextures(const std::string &, float mipMapLOD, float anisotropy) override;
|
||||||
void setFillMode(bool wireframe) override;
|
void setFillMode(bool wireframe) override;
|
||||||
|
void setVSync(bool vSync) override;
|
||||||
|
|
||||||
Allocator* getAllocator() const { return allocator.get(); }
|
Allocator* getAllocator() const { return allocator.get(); }
|
||||||
struct UICtx {
|
struct UICtx {
|
||||||
|
|
|
@ -8,13 +8,20 @@ SwapChain::SwapChain(VkDevice device, const PhysicalDeviceInfo& info): device(de
|
||||||
vkGetDeviceQueue(device, info.queueIndices.presentFamily.value(), 0, &presentQueue);
|
vkGetDeviceQueue(device, info.queueIndices.presentFamily.value(), 0, &presentQueue);
|
||||||
{ // Swapchain
|
{ // Swapchain
|
||||||
VkPresentModeKHR presentMode = [&]() {
|
VkPresentModeKHR presentMode = [&]() {
|
||||||
// MAYBE: add prefer no triple buffering options
|
std::vector<VkPresentModeKHR> preferredModes;
|
||||||
for (const auto& availablePresentMode: info.swapDetails.presentModes) {
|
if (info.vSync) {
|
||||||
if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {
|
preferredModes.push_back(VK_PRESENT_MODE_FIFO_RELAXED_KHR);
|
||||||
return availablePresentMode;
|
} else {
|
||||||
|
if (info.tripleBuffering)
|
||||||
|
preferredModes.push_back(VK_PRESENT_MODE_MAILBOX_KHR);
|
||||||
|
preferredModes.push_back(VK_PRESENT_MODE_IMMEDIATE_KHR);
|
||||||
|
}
|
||||||
|
for(auto mode: preferredModes) {
|
||||||
|
for (const auto& availablePresentMode: info.swapDetails.presentModes) {
|
||||||
|
if (availablePresentMode == mode)
|
||||||
|
return availablePresentMode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return VK_PRESENT_MODE_FIFO_KHR;
|
return VK_PRESENT_MODE_FIFO_KHR;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ SharedUniverse::SharedUniverse(const options &o, server_handle *const localHandl
|
||||||
const auto id = entities.at(PLAYER_ENTITY_ID).instances.emplace(Entity::Instance{});
|
const auto id = entities.at(PLAYER_ENTITY_ID).instances.emplace(Entity::Instance{});
|
||||||
assert(id == PLAYER_ENTITY_ID);
|
assert(id == PLAYER_ENTITY_ID);
|
||||||
|
|
||||||
localHandle->areas = (world::client::area_map*)(&areas); //FIXME: templated area
|
localHandle->areas = (world::client::area_map*)(&areas); //WONT FIX: templated area
|
||||||
localHandle->emit = std::function([&](const world::action::packet &packet) {
|
localHandle->emit = std::function([&](const world::action::packet &packet) {
|
||||||
if(const auto fill = std::get_if<world::action::Fill>(&packet)) {
|
if(const auto fill = std::get_if<world::action::Fill>(&packet)) {
|
||||||
this->set(fill->pos, fill->val);
|
this->set(fill->pos, fill->val);
|
||||||
|
|
|
@ -9,9 +9,6 @@ namespace world::server {
|
||||||
/// Server with data for LocalClientUniverse binding
|
/// Server with data for LocalClientUniverse binding
|
||||||
class SharedUniverse final: public Universe {
|
class SharedUniverse final: public Universe {
|
||||||
public:
|
public:
|
||||||
//TODO: override area type
|
|
||||||
//TODO: update edits
|
|
||||||
|
|
||||||
SharedUniverse(const options &, server_handle *const);
|
SharedUniverse(const options &, server_handle *const);
|
||||||
virtual ~SharedUniverse();
|
virtual ~SharedUniverse();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue