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_XL2DVKSHADOW_H_ 24 : #define XENOLITH_RENDERER_BASIC2D_BACKEND_VK_XL2DVKSHADOW_H_ 25 : 26 : #include "XL2dVkMaterial.h" 27 : #include "XLVkQueuePass.h" 28 : #include "XL2dCommandList.h" 29 : 30 : namespace STAPPLER_VERSIONIZED stappler::xenolith::basic2d::vk { 31 : 32 : class ShadowLightDataAttachment : public BufferAttachment { 33 : public: 34 : virtual ~ShadowLightDataAttachment(); 35 : 36 : virtual bool init(AttachmentBuilder &) override; 37 : 38 : virtual bool validateInput(const Rc<core::AttachmentInputData> &) const override; 39 : 40 : protected: 41 : using BufferAttachment::init; 42 : 43 : virtual Rc<AttachmentHandle> makeFrameHandle(const FrameQueue &) override; 44 : }; 45 : 46 : // this attachment should provide vertex & index buffers 47 : class ShadowVertexAttachment : public BufferAttachment { 48 : public: 49 : virtual ~ShadowVertexAttachment(); 50 : 51 : virtual bool init(AttachmentBuilder &) override; 52 : 53 : virtual bool validateInput(const Rc<core::AttachmentInputData> &) const override; 54 : 55 : protected: 56 : using BufferAttachment::init; 57 : 58 : virtual Rc<AttachmentHandle> makeFrameHandle(const FrameQueue &) override; 59 : }; 60 : 61 : // this attachment should provide vertex & index buffers 62 : class ShadowPrimitivesAttachment : public BufferAttachment { 63 : public: 64 : virtual ~ShadowPrimitivesAttachment(); 65 : 66 : virtual bool init(AttachmentBuilder &) override; 67 : 68 : protected: 69 : using BufferAttachment::init; 70 : 71 : virtual Rc<AttachmentHandle> makeFrameHandle(const FrameQueue &) override; 72 : }; 73 : 74 : class ShadowSdfImageAttachment : public ImageAttachment { 75 : public: 76 : virtual ~ShadowSdfImageAttachment(); 77 : 78 : virtual bool init(AttachmentBuilder &, Extent2 extent); 79 : 80 : protected: 81 : virtual Rc<AttachmentHandle> makeFrameHandle(const FrameQueue &) override; 82 : }; 83 : 84 : class ShadowVertexAttachmentHandle : public BufferAttachmentHandle { 85 : public: 86 : virtual ~ShadowVertexAttachmentHandle(); 87 : 88 : virtual void submitInput(FrameQueue &, Rc<core::AttachmentInputData> &&, Function<void(bool)> &&) override; 89 : 90 : bool empty() const; 91 : 92 11019 : uint32_t getTrianglesCount() const { return _trianglesCount; } 93 11019 : uint32_t getCirclesCount() const { return _circlesCount; } 94 11369 : uint32_t getRectsCount() const { return _rectsCount; } 95 11490 : uint32_t getRoundedRectsCount() const { return _roundedRectsCount; } 96 11389 : uint32_t getPolygonsCount() const { return _polygonsCount; } 97 4640 : float getMaxValue() const { return _maxValue; } 98 : 99 1105 : const Rc<Buffer> &getVertexes() const { return _vertexes; } 100 : 101 : protected: 102 : virtual bool loadVertexes(FrameHandle &, const Rc<FrameContextHandle2d> &); 103 : 104 : Rc<Buffer> _indexes; 105 : Rc<Buffer> _vertexes; 106 : Rc<Buffer> _transforms; 107 : Rc<Buffer> _circles; 108 : Rc<Buffer> _rects; 109 : Rc<Buffer> _roundedRects; 110 : Rc<Buffer> _polygons; 111 : uint32_t _trianglesCount = 0; 112 : uint32_t _circlesCount = 0; 113 : uint32_t _rectsCount = 0; 114 : uint32_t _roundedRectsCount = 0; 115 : uint32_t _polygonsCount = 0; 116 : float _maxValue = 0.0f; 117 : }; 118 : 119 : class ShadowLightDataAttachmentHandle : public BufferAttachmentHandle { 120 : public: 121 : virtual ~ShadowLightDataAttachmentHandle(); 122 : 123 : virtual void submitInput(FrameQueue &, Rc<core::AttachmentInputData> &&, Function<void(bool)> &&) override; 124 : 125 : virtual bool isDescriptorDirty(const PassHandle &, const PipelineDescriptor &, 126 : uint32_t, bool isExternal) const override; 127 : 128 : virtual bool writeDescriptor(const core::QueuePassHandle &, DescriptorBufferInfo &) override; 129 : 130 : void allocateBuffer(DeviceFrameHandle *, const ShadowVertexAttachmentHandle *vertexes, uint32_t gridCells); 131 : 132 : float getBoxOffset(float value) const; 133 : 134 : uint32_t getLightsCount() const; 135 : uint32_t getObjectsCount() const; 136 : 137 1105 : const ShadowData &getShadowData() const { return _shadowData; } 138 19665 : const Rc<Buffer> &getBuffer() const { return _data; } 139 : 140 : protected: 141 : Rc<Buffer> _data; 142 : Rc<FrameContextHandle2d> _input; 143 : ShadowData _shadowData; 144 : }; 145 : 146 : class ShadowPrimitivesAttachmentHandle : public BufferAttachmentHandle { 147 : public: 148 : virtual ~ShadowPrimitivesAttachmentHandle(); 149 : 150 : void allocateBuffer(DeviceFrameHandle *, const ShadowData &); 151 : 152 9060 : const Rc<Buffer> &getObjects() const { return _objects; } 153 11270 : const Rc<Buffer> &getGridSize() const { return _gridSize; } 154 9060 : const Rc<Buffer> &getGridIndex() const { return _gridIndex; } 155 : 156 : protected: 157 : Rc<Buffer> _objects; 158 : Rc<Buffer> _gridSize; 159 : Rc<Buffer> _gridIndex; 160 : }; 161 : 162 : class ShadowSdfImageAttachmentHandle : public ImageAttachmentHandle { 163 : public: 164 9300 : virtual ~ShadowSdfImageAttachmentHandle() { } 165 : 166 : virtual void submitInput(FrameQueue &, Rc<core::AttachmentInputData> &&, Function<void(bool)> &&) override; 167 : 168 : ImageInfo getImageInfo() const { return _currentImageInfo; } 169 : float getShadowDensity() const { return _shadowDensity; } 170 : float getSceneDensity() const { return _sceneDensity; } 171 : 172 : protected: 173 : float _sceneDensity = 1.0f; 174 : float _shadowDensity = 1.0f; 175 : ImageInfo _currentImageInfo; 176 : }; 177 : 178 : } 179 : 180 : #endif /* XENOLITH_RENDERER_BASIC2D_BACKEND_VK_XL2DVKSHADOW_H_ */