minecraftvulkan/engine/xe_engine.cpp

60 lines
1.9 KiB
C++
Raw Normal View History

2022-09-19 11:08:42 +00:00
#include "xe_engine.hpp"
2022-09-21 02:02:58 +00:00
#include "xe_image.hpp"
2022-09-22 17:21:30 +00:00
2022-09-20 01:28:41 +00:00
#include <chrono>
2022-09-22 22:29:34 +00:00
#include <iostream>
#include <AL/alc.h>
2022-09-22 17:21:30 +00:00
#include <AL/alut.h>
2022-09-19 11:08:42 +00:00
namespace xe {
2022-09-20 01:28:41 +00:00
XeEngine::XeEngine(int width, int height, std::string name) : xeWindow{width, height, name},
xeDevice{xeWindow},
xeRenderer{xeWindow, xeDevice},
xeCamera{} {
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-22 17:21:30 +00:00
};
XeEngine::~XeEngine() {
alutExit();
2022-09-20 01:28:41 +00:00
};
2022-09-19 11:08:42 +00:00
2022-09-21 02:02:58 +00:00
void XeEngine::loadDescriptorPool() {
2022-09-19 11:08:42 +00:00
xeDescriptorPool = XeDescriptorPool::Builder(xeDevice)
.setMaxSets(XeSwapChain::MAX_FRAMES_IN_FLIGHT)
.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, XeSwapChain::MAX_FRAMES_IN_FLIGHT)
.addPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, XeSwapChain::MAX_FRAMES_IN_FLIGHT)
2022-09-21 02:02:58 +00:00
.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, XeSwapChain::MAX_FRAMES_IN_FLIGHT)
2022-09-19 16:54:23 +00:00
.build();
}
2022-09-20 01:28:41 +00:00
std::shared_ptr<XeModel> XeEngine::loadModelFromFile(const std::string &filename) {
2022-09-19 20:35:45 +00:00
return XeModel::createModelFromFile(xeDevice, filename);
}
2022-09-20 01:28:41 +00:00
std::shared_ptr<XeModel> XeEngine::loadModelFromData(std::vector<XeModel::Vertex> vertices, std::vector<uint32_t> indices) {
XeModel::Builder builder{};
builder.vertices = vertices;
2022-09-21 20:49:43 +00:00
if(indices.size() > 0) {
2022-09-20 01:28:41 +00:00
builder.indices = indices;
}
return std::make_shared<XeModel>(xeDevice, builder);
}
2022-09-19 20:35:45 +00:00
2022-09-21 02:02:58 +00:00
std::shared_ptr<XeImage> XeEngine::loadImage(const std::string &filename) {
return std::make_shared<XeImage>(xeDevice, filename);
}
2022-09-20 01:28:41 +00:00
bool XeEngine::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();
2022-09-19 20:35:45 +00:00
}
2022-09-19 11:08:42 +00:00
}