minecraftvulkan/engine/xe_engine.cpp
2022-09-24 21:16:13 -04:00

61 lines
No EOL
1.8 KiB
C++

#include "xe_engine.hpp"
#include "xe_image.hpp"
#include <chrono>
#include <iostream>
#include <AL/alc.h>
#include <AL/alut.h>
namespace xe {
Engine::Engine(int width, int height, std::string name) : xeWindow{width, height, name},
xeDevice{xeWindow},
xeRenderer{xeWindow, xeDevice},
xeCamera{} {
loadDescriptorPool();
alutInit(0, NULL);
std::cout << "Audio device: " << alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER) << "\n";
};
Engine::~Engine() {
alutExit();
};
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)
.build();
}
std::shared_ptr<Model> Engine::loadModelFromFile(const std::string &filename) {
return Model::createModelFromFile(xeDevice, filename);
}
std::shared_ptr<Model> Engine::loadModelFromData(std::vector<Model::Vertex> vertices, std::vector<uint32_t> indices) {
Model::Builder builder{};
builder.vertices = vertices;
if(indices.size() > 0) {
builder.indices = indices;
}
return std::make_shared<Model>(xeDevice, builder);
}
std::shared_ptr<Image> Engine::loadImage(const std::string &filename) {
return std::make_shared<Image>(xeDevice, filename);
}
bool Engine::poll() {
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();
xeCamera.setPerspectiveProjection(glm::radians(FOV), aspect, 0.1f, 100.f);
return !xeWindow.shouldClose();
}
}