minecraftvulkan/engine/xe_render_system.hpp

119 lines
3.2 KiB
C++
Raw Normal View History

2022-09-19 16:54:23 +00:00
#pragma once
#include "xe_device.hpp"
#include "xe_pipeline.hpp"
#include "xe_game_object.hpp"
#include "xe_swap_chain.hpp"
2022-09-19 20:35:45 +00:00
#include "xe_renderer.hpp"
#include "xe_descriptors.hpp"
2022-09-20 01:28:41 +00:00
#include "xe_engine.hpp"
2022-09-19 16:54:23 +00:00
#include <vulkan/vulkan.h>
2022-09-19 16:54:23 +00:00
#include <memory>
#include <stdexcept>
#include <iostream>
2022-09-21 16:36:12 +00:00
#include <map>
2022-09-19 16:54:23 +00:00
namespace xe {
class XeRenderSystem {
public:
2022-09-20 01:28:41 +00:00
2022-09-21 16:36:12 +00:00
class Builder {
public:
Builder(XeEngine &xeEngine, std::string vert, std::string frag) : xeEngine{xeEngine}, vert{vert}, frag{frag} {}
Builder& addPushConstant(uint32_t size) {
pushCunstantDataSize = size;
return *this;
}
Builder& addUniformBinding(uint32_t binding, uint32_t size) {
uniformBindings[binding] = size;
return *this;
}
Builder& addTextureBinding(uint32_t binding, XeImage* image) {
imageBindings[binding] = image;
return *this;
}
2022-09-21 20:49:43 +00:00
Builder& setCulling(bool enabled) {
cullingEnabled = enabled;
return *this;
}
2022-09-21 16:36:12 +00:00
std::unique_ptr<XeRenderSystem> build() {
2022-09-21 20:49:43 +00:00
return std::make_unique<XeRenderSystem>(xeEngine, std::move(vert), std::move(frag), std::move(uniformBindings), std::move(imageBindings), std::move(pushCunstantDataSize), std::move(cullingEnabled));
2022-09-21 16:36:12 +00:00
}
private:
std::map<uint32_t, uint32_t> uniformBindings{};
std::map<uint32_t, XeImage*> imageBindings{};
uint32_t pushCunstantDataSize{0};
std::string vert;
std::string frag;
2022-09-21 20:49:43 +00:00
bool cullingEnabled{false};
2022-09-21 16:36:12 +00:00
XeEngine &xeEngine;
};
2022-09-19 16:54:23 +00:00
XeRenderSystem(
2022-09-20 01:28:41 +00:00
XeEngine &xeEngine,
2022-09-19 16:54:23 +00:00
std::string vert,
2022-09-21 16:36:12 +00:00
std::string frag,
std::map<uint32_t, uint32_t> uniformBindings,
std::map<uint32_t, XeImage*> imageBindings,
2022-09-21 20:49:43 +00:00
uint32_t pushCunstantDataSize,
bool cullingEnabled
2022-09-20 01:28:41 +00:00
);
2022-09-19 16:54:23 +00:00
~XeRenderSystem();
XeRenderSystem(const XeRenderSystem &) = delete;
XeRenderSystem operator=(const XeRenderSystem &) = delete;
2022-09-21 02:02:58 +00:00
void start();
void loadPushConstant(void *pushConstantData);
2022-09-21 16:36:12 +00:00
void loadUniformObject(uint32_t binding, void *uniformBufferData);
void loadTexture(uint32_t binding, XeImage *image);
2022-09-20 01:28:41 +00:00
void render(XeGameObject &gameObject);
void stop();
2022-09-19 16:54:23 +00:00
private:
2022-09-20 01:28:41 +00:00
2022-09-21 16:36:12 +00:00
void createTextureSampler();
2022-09-21 02:02:58 +00:00
void createDescriptorSetLayout();
void createUniformBuffers();
2022-09-21 16:36:12 +00:00
void createDescriptorSets();
void updateDescriptorSet(int frameIndex, bool allocate);
2022-09-21 02:02:58 +00:00
void createPipelineLayout();
2022-09-21 20:49:43 +00:00
void createPipeline(VkRenderPass renderPass, std::string vert, std::string frag, bool cullingEnabled);
2022-09-19 16:54:23 +00:00
2022-09-20 01:28:41 +00:00
bool boundPipeline{false};
bool boundDescriptor{false};
2022-09-21 16:36:12 +00:00
2022-09-19 16:54:23 +00:00
XeDevice& xeDevice;
2022-09-20 01:28:41 +00:00
XeRenderer& xeRenderer;
2022-09-19 16:54:23 +00:00
2022-09-21 16:36:12 +00:00
std::map<uint32_t, std::vector<std::unique_ptr<XeBuffer>>> uboBuffers{};
std::map<uint32_t, uint32_t> uniformBindings;
std::map<uint32_t, XeImage*> imageBindings;
2022-09-19 16:54:23 +00:00
std::vector<VkDescriptorSet> descriptorSets;
2022-09-21 16:36:12 +00:00
uint32_t pushCunstantDataSize;
2022-09-21 02:02:58 +00:00
VkSampler textureSampler;
2022-09-19 16:54:23 +00:00
VkPipelineLayout pipelineLayout;
2022-09-21 16:36:12 +00:00
std::unique_ptr<XePipeline> xePipeline;
2022-09-21 03:04:33 +00:00
std::unique_ptr<XeDescriptorPool> &xeDescriptorPool;
2022-09-21 02:02:58 +00:00
std::unique_ptr<XeDescriptorSetLayout> xeDescriptorSetLayout;
2022-09-19 16:54:23 +00:00
};
}