minecraftvulkan/engine/xe_engine.cpp

63 lines
1.9 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-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)
.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, SwapChain::MAX_FRAMES_IN_FLIGHT)
.addPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, SwapChain::MAX_FRAMES_IN_FLIGHT)
.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, SwapChain::MAX_FRAMES_IN_FLIGHT)
2022-09-19 16:54:23 +00:00
.build();
}
2022-09-27 17:35:49 +00:00
Model* Engine::loadModelFromFile(const std::string &filename) {
2022-09-25 01:16:13 +00:00
return Model::createModelFromFile(xeDevice, filename);
2022-09-19 20:35:45 +00:00
}
2022-09-27 17:35:49 +00:00
Model* Engine::loadModelFromData(std::vector<unsigned char> vertexData, uint32_t vertexSize, std::vector<uint32_t> indices) {
2022-09-25 01:16:13 +00:00
Model::Builder builder{};
builder.vertexData.data = vertexData;
2022-09-25 16:07:49 +00:00
builder.vertexSize = vertexSize;
2022-09-21 20:49:43 +00:00
if(indices.size() > 0) {
2022-09-20 01:28:41 +00:00
builder.indices = indices;
}
2022-09-27 17:35:49 +00:00
return new Model(xeDevice, builder);
2022-09-20 01:28:41 +00:00
}
2022-09-19 20:35:45 +00:00
Image* Engine::loadImageFromFile(const std::string &filename, bool anisotropic) {
return new Image(xeDevice, filename, anisotropic);
2022-09-21 02:02:58 +00:00
}
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
}