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-25 01:16:13 +00:00
|
|
|
Engine::Engine(int width, int height, std::string name) : xeWindow{width, height, name},
|
2022-09-20 01:28:41 +00:00
|
|
|
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-25 01:16:13 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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-25 01:16:13 +00:00
|
|
|
std::shared_ptr<Model> Engine::loadModelFromFile(const std::string &filename) {
|
|
|
|
return Model::createModelFromFile(xeDevice, filename);
|
2022-09-19 20:35:45 +00:00
|
|
|
}
|
|
|
|
|
2022-09-25 16:07:49 +00:00
|
|
|
std::shared_ptr<Model> Engine::loadModelFromData(std::vector<float> vertexData, uint32_t vertexSize, std::vector<uint32_t> indices) {
|
2022-09-25 01:16:13 +00:00
|
|
|
Model::Builder builder{};
|
2022-09-25 16:07:49 +00:00
|
|
|
builder.vertexData = vertexData;
|
|
|
|
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-25 01:16:13 +00:00
|
|
|
return std::make_shared<Model>(xeDevice, builder);
|
2022-09-20 01:28:41 +00:00
|
|
|
}
|
2022-09-19 20:35:45 +00:00
|
|
|
|
2022-09-25 16:07:49 +00:00
|
|
|
std::shared_ptr<Image> Engine::loadImageFromFile(const std::string &filename) {
|
2022-09-25 01:16:13 +00:00
|
|
|
return std::make_shared<Image>(xeDevice, filename);
|
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();
|
|
|
|
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
|
|
|
}
|