summaryrefslogtreecommitdiff
path: root/engine/xe_engine.cpp
blob: 0ba7df5dc6b7f476506be89fef38c6c24553773e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "xe_engine.hpp"

namespace xe {

XeEngine::XeEngine(int width, int height, std::string name) 
: xeWindow{width, height, name}, 
  xeDevice{xeWindow}, 
  xeRenderer{xeWindow, xeDevice},
  xeCamera{},
  xeInput{xeWindow} {
  loadDescriptorPool();
  alutInit(0, NULL);
  std::cout << "Audio device: " << alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER) << "\n";
};

XeEngine::~XeEngine() {
  alutExit();
};

void XeEngine::loadDescriptorPool() {
  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)
    .addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, XeSwapChain::MAX_FRAMES_IN_FLIGHT)
    .build();
}

std::shared_ptr<XeModel> XeEngine::loadModelFromFile(const std::string &filename) {
  return XeModel::createModelFromFile(xeDevice, filename);
}

std::shared_ptr<XeModel> XeEngine::loadModelFromData(std::vector<XeModel::Vertex> vertices, std::vector<uint32_t> indices) {
  XeModel::Builder builder{};
  builder.vertices = vertices;
  if(indices.size() > 0) { 
    builder.indices = indices;
  }
  return std::make_shared<XeModel>(xeDevice, builder);
}

std::shared_ptr<XeImage> XeEngine::loadImage(const std::string &filename) {
  return std::make_shared<XeImage>(xeDevice, filename);
}

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();
}

}