Line data Source code
1 : /** 2 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev> 3 : 4 : Permission is hereby granted, free of charge, to any person obtaining a copy 5 : of this software and associated documentation files (the "Software"), to deal 6 : in the Software without restriction, including without limitation the rights 7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 : copies of the Software, and to permit persons to whom the Software is 9 : furnished to do so, subject to the following conditions: 10 : 11 : The above copyright notice and this permission notice shall be included in 12 : all copies or substantial portions of the Software. 13 : 14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 : THE SOFTWARE. 21 : **/ 22 : 23 : #ifndef XENOLITH_RENDERER_BASIC2D_BACKEND_VK_XL2DVKVERTEXPASS_H_ 24 : #define XENOLITH_RENDERER_BASIC2D_BACKEND_VK_XL2DVKVERTEXPASS_H_ 25 : 26 : #include "XL2dVkMaterial.h" 27 : #include "XL2dCommandList.h" 28 : 29 : namespace STAPPLER_VERSIONIZED stappler::xenolith::basic2d::vk { 30 : 31 : class VertexAttachment : public BufferAttachment { 32 : public: 33 : virtual ~VertexAttachment(); 34 : 35 : virtual bool init(AttachmentBuilder &builder, const BufferInfo &, const AttachmentData *); 36 : 37 4650 : const AttachmentData *getMaterials() const { return _materials; } 38 : 39 : protected: 40 : using BufferAttachment::init; 41 : 42 : virtual Rc<AttachmentHandle> makeFrameHandle(const FrameQueue &) override; 43 : 44 : const AttachmentData *_materials = nullptr; 45 : }; 46 : 47 : class VertexAttachmentHandle : public BufferAttachmentHandle { 48 : public: 49 : virtual ~VertexAttachmentHandle(); 50 : 51 : virtual bool setup(FrameQueue &, Function<void(bool)> &&) override; 52 : 53 : virtual void submitInput(FrameQueue &, Rc<core::AttachmentInputData> &&, Function<void(bool)> &&) override; 54 : 55 4640 : const Vector<VertexSpan> &getVertexData() const { return _spans; } 56 4640 : const Rc<Buffer> &getVertexes() const { return _vertexes; } 57 9280 : const Rc<Buffer> &getIndexes() const { return _indexes; } 58 : 59 : Rc<FrameContextHandle2d> popCommands() const; 60 : 61 : bool empty() const; 62 : 63 : protected: 64 : virtual bool loadVertexes(FrameHandle &, const Rc<FrameContextHandle2d> &); 65 : 66 0 : virtual bool isGpuTransform() const { return false; } 67 : 68 : Rc<Buffer> _indexes; 69 : Rc<Buffer> _vertexes; 70 : Rc<Buffer> _transforms; 71 : Vector<VertexSpan> _spans; 72 : 73 : Rc<core::MaterialSet> _materialSet; 74 : const MaterialAttachmentHandle *_materials = nullptr; 75 : mutable Rc<FrameContextHandle2d> _commands; 76 : DrawStat _drawStat; 77 : }; 78 : 79 : class VertexPass : public QueuePass { 80 : public: 81 : using AttachmentHandle = core::AttachmentHandle; 82 : 83 : static core::ImageFormat selectDepthFormat(SpanView<core::ImageFormat> formats); 84 : 85 10 : virtual ~VertexPass() { } 86 : 87 4640 : const AttachmentData *getVertexes() const { return _vertexes; } 88 4640 : const AttachmentData *getMaterials() const { return _materials; } 89 : 90 : virtual Rc<QueuePassHandle> makeFrameHandle(const FrameQueue &) override; 91 : 92 : protected: 93 : using QueuePass::init; 94 : 95 : const AttachmentData *_output = nullptr; 96 : const AttachmentData *_shadow = nullptr; 97 : const AttachmentData *_depth2d = nullptr; 98 : 99 : const AttachmentData *_vertexes = nullptr; 100 : const AttachmentData *_materials = nullptr; 101 : }; 102 : 103 : class VertexPassHandle : public QueuePassHandle { 104 : public: 105 4650 : virtual ~VertexPassHandle() { } 106 : 107 : virtual bool prepare(FrameQueue &, Function<void(bool)> &&) override; 108 : 109 : protected: 110 : virtual Vector<const CommandBuffer *> doPrepareCommands(FrameHandle &) override; 111 : 112 : virtual void prepareRenderPass(CommandBuffer &); 113 : virtual void prepareMaterialCommands(core::MaterialSet * materials, CommandBuffer &); 114 : virtual void finalizeRenderPass(CommandBuffer &); 115 : 116 : const VertexAttachmentHandle *_vertexBuffer = nullptr; 117 : const MaterialAttachmentHandle *_materialBuffer = nullptr; 118 : }; 119 : 120 : } 121 : 122 : #endif /* XENOLITH_RENDERER_BASIC2D_BACKEND_VK_XL2DVKVERTEXPASS_H_ */