minecraftvulkan/engine/xe_engine.cpp

68 lines
1.9 KiB
C++
Raw Normal View History

2022-09-19 11:08:42 +00:00
#include "xe_engine.hpp"
#include "xe_descriptors.hpp"
2022-09-19 20:35:45 +00:00
#include <string>
2022-09-19 11:08:42 +00:00
namespace xe {
XeEngine::XeEngine(int width, int height, std::string name)
2022-09-19 20:35:45 +00:00
: xeWindow{width, height, name},
xeDevice{xeWindow},
xeRenderer{xeWindow, xeDevice},
xeCamera{} {
2022-09-19 16:54:23 +00:00
loadDescriptors();
};
2022-09-19 11:08:42 +00:00
2022-09-19 16:54:23 +00:00
void XeEngine::loadDescriptors() {
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)
.build();
2022-09-19 16:54:23 +00:00
xeDescriptorSetLayout = XeDescriptorSetLayout::Builder(xeDevice)
.addBinding(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT)
.build();
}
2022-09-19 20:35:45 +00:00
std::unique_ptr<XeRenderSystem> XeEngine::createRenderSystem(const std::string &vert, const std::string &frag, uint32_t pushCunstantDataSize, uint32_t uniformBufferDataSize) {
2022-09-19 16:54:23 +00:00
return std::make_unique<XeRenderSystem>(
xeDevice,
xeRenderer,
2022-09-19 20:35:45 +00:00
*xeDescriptorPool,
*xeDescriptorSetLayout,
2022-09-19 16:54:23 +00:00
vert,
frag,
pushCunstantDataSize,
uniformBufferDataSize
);
2022-09-19 11:08:42 +00:00
}
2022-09-19 20:35:45 +00:00
std::shared_ptr<XeModel> XeEngine::createModel(const std::string &filename) {
return XeModel::createModelFromFile(xeDevice, filename);
}
void XeEngine::render(
XeRenderSystem& xeRenderSystem,
std::vector<XeGameObject>& gameObjects,
void* pushConstantData,
uint32_t pushConstantSize,
void* uniformBufferData,
uint32_t uniformBufferSize) {
auto commandBuffer = xeRenderer.getCurrentCommandBuffer();
xeRenderer.beginSwapChainRenderPass(commandBuffer);
xeRenderSystem.renderGameObjects(
xeRenderer.getFrameIndex(),
commandBuffer,
gameObjects,
pushConstantData,
pushConstantSize,
uniformBufferData,
uniformBufferSize
);
xeRenderer.endSwapChainRenderPass(commandBuffer);
}
2022-09-19 11:08:42 +00:00
}