minecraftvulkan/engine/xe_engine.cpp

47 lines
1.4 KiB
C++
Raw Normal View History

2022-09-19 11:08:42 +00:00
#include "xe_engine.hpp"
namespace xe {
2022-09-25 23:05:56 +00:00
static Engine* _instance;
Engine* Engine::getInstance() {
return _instance;
}
2022-09-27 01:24:28 +00:00
Engine::Engine(int width, int height, std::string name, const char *icon) : xeWindow{width, height, name, icon},
2022-09-20 01:28:41 +00:00
xeDevice{xeWindow},
xeRenderer{xeWindow, xeDevice},
xeCamera{},
xeInput{xeWindow} {
2022-09-21 02:02:58 +00:00
loadDescriptorPool();
2022-09-22 17:21:30 +00:00
alutInit(0, NULL);
2022-09-22 22:29:34 +00:00
std::cout << "Audio device: " << alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER) << "\n";
2022-09-25 23:05:56 +00:00
_instance = this;
2022-09-22 17:21:30 +00:00
};
2022-09-25 01:16:13 +00:00
Engine::~Engine() {
2022-09-28 13:38:25 +00:00
Model::submitDeleteQueue(true);
Image::submitDeleteQueue(true);
2022-09-22 17:21:30 +00:00
alutExit();
2022-09-20 01:28:41 +00:00
};
2022-09-19 11:08:42 +00:00
2022-09-25 01:16:13 +00:00
void Engine::loadDescriptorPool() {
xeDescriptorPool = DescriptorPool::Builder(xeDevice)
.setMaxSets(SwapChain::MAX_FRAMES_IN_FLIGHT)
2022-09-29 19:20:36 +00:00
.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, SwapChain::MAX_FRAMES_IN_FLIGHT * 4)
.addPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, SwapChain::MAX_FRAMES_IN_FLIGHT * 4)
.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, SwapChain::MAX_FRAMES_IN_FLIGHT * 4)
2022-09-19 16:54:23 +00:00
.build();
}
2022-09-25 01:16:13 +00:00
bool Engine::poll() {
2022-09-20 01:28:41 +00:00
glfwPollEvents();
auto newTime = std::chrono::high_resolution_clock::now();
frameTime = std::chrono::duration<float, std::chrono::seconds::period>(newTime - currentTime).count();
currentTime = newTime;
float aspect = xeRenderer.getAspectRatio();
2022-09-26 15:03:27 +00:00
xeCamera.setPerspectiveProjection(glm::radians(FOV), aspect, 0.1f, 1000.f);
2022-09-20 01:28:41 +00:00
return !xeWindow.shouldClose();
2022-09-19 20:35:45 +00:00
}
2022-09-19 11:08:42 +00:00
}