From 76bae46dbc167838531eaae85b0d41aab5e0741f Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 21 Sep 2022 12:36:12 -0400 Subject: self define descriptors --- engine/xe_render_system.hpp | 66 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) (limited to 'engine/xe_render_system.hpp') diff --git a/engine/xe_render_system.hpp b/engine/xe_render_system.hpp index d6b24b5..ae68f53 100644 --- a/engine/xe_render_system.hpp +++ b/engine/xe_render_system.hpp @@ -10,19 +10,55 @@ #include "xe_image.hpp" #include +#include namespace xe { class XeRenderSystem { public: + 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; + } + + std::unique_ptr build() { + return std::make_unique(xeEngine, std::move(vert), std::move(frag), std::move(uniformBindings), std::move(imageBindings), std::move(pushCunstantDataSize)); + } + + private: + + std::map uniformBindings{}; + std::map imageBindings{}; + uint32_t pushCunstantDataSize{0}; + + std::string vert; + std::string frag; + + XeEngine &xeEngine; + }; + XeRenderSystem( XeEngine &xeEngine, std::string vert, - std::string frag, - uint32_t pushCunstantDataSize, - uint32_t uniformBufferDataSize, - XeImage *image + std::string frag, + std::map uniformBindings, + std::map imageBindings, + uint32_t pushCunstantDataSize ); ~XeRenderSystem(); @@ -32,37 +68,39 @@ class XeRenderSystem { void start(); void loadPushConstant(void *pushConstantData); - void loadUniformObject(void *uniformBufferData); - void loadTexture(XeImage *image); + void loadUniformObject(uint32_t binding, void *uniformBufferData); + void loadTexture(uint32_t binding, XeImage *image); void render(XeGameObject &gameObject); void stop(); private: + void createTextureSampler(); void createDescriptorSetLayout(); void createUniformBuffers(); - void createDescriptorSets(XeImage *image); - void updateDescriptorSet(XeImage *image, int frameIndex, bool allocate); + void createDescriptorSets(); + void updateDescriptorSet(int frameIndex, bool allocate); void createPipelineLayout(); void createPipeline(VkRenderPass renderPass, std::string vert, std::string frag); bool boundPipeline{false}; bool boundDescriptor{false}; - uint32_t uniformBufferDataSize; - uint32_t pushCunstantDataSize; - bool textureSamplerBinding; - + XeDevice& xeDevice; XeRenderer& xeRenderer; - std::unique_ptr xePipeline; - std::vector> uboBuffers; + std::map>> uboBuffers{}; + std::map uniformBindings; + std::map imageBindings; std::vector descriptorSets; + uint32_t pushCunstantDataSize; + VkSampler textureSampler; VkPipelineLayout pipelineLayout; + std::unique_ptr xePipeline; std::unique_ptr &xeDescriptorPool; std::unique_ptr xeDescriptorSetLayout; -- cgit v1.2.3-freya