LCOV - code coverage report
Current view: top level - xenolith/renderer/basic2d/backend/vk - XL2dVkShadowPass.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 11 100.0 %
Date: 2024-05-12 00:16:13 Functions: 15 15 100.0 %

          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_XL2DVKSHADOWPASS_H_
      24             : #define XENOLITH_RENDERER_BASIC2D_BACKEND_VK_XL2DVKSHADOWPASS_H_
      25             : 
      26             : #include "XL2dVkVertexPass.h"
      27             : #include "XL2dVkShadow.h"
      28             : 
      29             : namespace STAPPLER_VERSIONIZED stappler::xenolith::basic2d::vk {
      30             : 
      31             : class ShadowPass : public VertexPass {
      32             : public:
      33             :         static constexpr StringView ShadowPipeline = "ShadowPipeline";
      34             : 
      35             :         enum class Flags {
      36             :                 None = 0,
      37             :         };
      38             : 
      39             :         struct RenderQueueInfo {
      40             :                 Application *target = nullptr;
      41             :                 Extent2 extent;
      42             :                 Flags flags = Flags::None;
      43             :         };
      44             : 
      45             :         struct PassCreateInfo {
      46             :                 Application *target = nullptr;
      47             :                 Extent2 extent;
      48             :                 Flags flags;
      49             : 
      50             :                 const AttachmentData *shadowSdfAttachment = nullptr;
      51             :                 const AttachmentData *lightsAttachment = nullptr;
      52             :                 const AttachmentData *sdfPrimitivesAttachment = nullptr;
      53             :         };
      54             : 
      55             :         static bool makeDefaultRenderQueue(Queue::Builder &, RenderQueueInfo &);
      56             : 
      57          20 :         virtual ~ShadowPass() { }
      58             : 
      59             :         virtual bool init(Queue::Builder &queueBuilder, QueuePassBuilder &passBuilder, const PassCreateInfo &info);
      60             : 
      61        4640 :         const AttachmentData *getLightsData() const { return _lightsData; }
      62        4640 :         const AttachmentData *getShadowPrimitives() const { return _shadowPrimitives; }
      63        4640 :         const AttachmentData *getSdf() const { return _sdf; }
      64             : 
      65             :         virtual Rc<QueuePassHandle> makeFrameHandle(const FrameQueue &) override;
      66             : 
      67             : protected:
      68             :         using QueuePass::init;
      69             : 
      70             :         Flags _flags = Flags::None;
      71             : 
      72             :         // shadows
      73             :         const AttachmentData *_lightsData = nullptr;
      74             :         const AttachmentData *_shadowPrimitives = nullptr;
      75             :         const AttachmentData *_sdf = nullptr;
      76             : };
      77             : 
      78             : SP_DEFINE_ENUM_AS_MASK(ShadowPass::Flags)
      79             : 
      80             : class ShadowPassHandle : public VertexPassHandle {
      81             : public:
      82        9300 :         virtual ~ShadowPassHandle() { }
      83             : 
      84             :         virtual bool prepare(FrameQueue &q, Function<void(bool)> &&cb) override;
      85             : 
      86             : protected:
      87             :         virtual void prepareRenderPass(CommandBuffer &) override;
      88             :         virtual void prepareMaterialCommands(core::MaterialSet * materials, CommandBuffer &buf) override;
      89             : 
      90             :         // shadows
      91             :         const ShadowLightDataAttachmentHandle *_shadowData = nullptr;
      92             :         const ShadowPrimitivesAttachmentHandle *_shadowPrimitives = nullptr;
      93             :         const ImageAttachmentHandle *_sdfImage = nullptr;
      94             : };
      95             : 
      96             : class ComputeShadowPass : public QueuePass {
      97             : public:
      98             :         static constexpr StringView SdfTrianglesComp = "SdfTrianglesComp";
      99             :         static constexpr StringView SdfCirclesComp = "SdfCirclesComp";
     100             :         static constexpr StringView SdfRectsComp = "SdfRectsComp";
     101             :         static constexpr StringView SdfRoundedRectsComp = "SdfRoundedRectsComp";
     102             :         static constexpr StringView SdfPolygonsComp = "SdfPolygonsComp";
     103             :         static constexpr StringView SdfImageComp = "SdfImageComp";
     104             : 
     105          20 :         virtual ~ComputeShadowPass() { }
     106             : 
     107             :         virtual bool init(Queue::Builder &queueBuilder, QueuePassBuilder &passBuilder, Extent2 defaultExtent);
     108             : 
     109        4650 :         const AttachmentData *getLights() const { return _lights; }
     110        4640 :         const AttachmentData *getVertexes() const { return _vertexes; }
     111        4650 :         const AttachmentData *getPrimitives() const { return _primitives; }
     112        4650 :         const AttachmentData *getSdf() const { return _sdf; }
     113             : 
     114             :         virtual Rc<QueuePassHandle> makeFrameHandle(const FrameQueue &) override;
     115             : 
     116             : protected:
     117             :         using QueuePass::init;
     118             : 
     119             :         const AttachmentData *_lights = nullptr;
     120             :         const AttachmentData *_vertexes = nullptr;
     121             :         const AttachmentData *_primitives = nullptr;
     122             :         const AttachmentData *_sdf = nullptr;
     123             : };
     124             : 
     125             : class ComputeShadowPassHandle : public QueuePassHandle {
     126             : public:
     127        9300 :         virtual ~ComputeShadowPassHandle() { }
     128             : 
     129             :         virtual bool prepare(FrameQueue &, Function<void(bool)> &&) override;
     130             : 
     131             : protected:
     132             :         virtual void writeShadowCommands(RenderPass *, CommandBuffer &);
     133             :         virtual Vector<const CommandBuffer *> doPrepareCommands(FrameHandle &) override;
     134             : 
     135             :         const ShadowLightDataAttachmentHandle *_lightsBuffer = nullptr;
     136             :         const ShadowVertexAttachmentHandle *_vertexBuffer = nullptr;
     137             :         const ShadowPrimitivesAttachmentHandle *_primitivesBuffer = nullptr;
     138             :         const ShadowSdfImageAttachmentHandle *_sdfImage = nullptr;
     139             : 
     140             :         uint32_t _gridCellSize = 64;
     141             : };
     142             : 
     143             : }
     144             : 
     145             : #endif /* XENOLITH_RENDERER_BASIC2D_BACKEND_VK_XL2DVKSHADOWPASS_H_ */

Generated by: LCOV version 1.14