LCOV - code coverage report
Current view: top level - xenolith/scene/director - XLFrameContext.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 12 100.0 %
Date: 2024-05-12 00:16:13 Functions: 3 3 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_SCENE_DIRECTOR_XLFRAMECONTEXT_H_
      24             : #define XENOLITH_SCENE_DIRECTOR_XLFRAMECONTEXT_H_
      25             : 
      26             : #include "XLResourceOwner.h"
      27             : #include "XLCoreQueue.h"
      28             : #include "XLCoreMaterial.h"
      29             : #include "XLNodeInfo.h"
      30             : 
      31             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      32             : 
      33             : struct FrameInfo;
      34             : struct FrameContextHandle;
      35             : 
      36             : class Scene;
      37             : class Director;
      38             : 
      39             : class FrameContext : public ResourceOwner {
      40             : public:
      41             :         virtual ~FrameContext();
      42             : 
      43             :         virtual bool init();
      44             : 
      45             :         virtual void onEnter(Scene *);
      46             :         virtual void onExit();
      47             : 
      48             :         virtual Rc<FrameContextHandle> makeHandle(FrameInfo &);
      49             :         virtual void submitHandle(FrameInfo &, FrameContextHandle *);
      50             : 
      51             :         virtual uint64_t getMaterial(const MaterialInfo &) const;
      52             :         virtual uint64_t acquireMaterial(const MaterialInfo &, Vector<core::MaterialImage> &&images, Ref *data, bool revokable);
      53             : 
      54             :         virtual void revokeImages(SpanView<uint64_t>);
      55             : 
      56             : protected:
      57             :         struct PipelineLayoutData {
      58             :                 const core::PipelineLayoutData *layout;
      59             :                 HashMap<size_t, Vector<const core::GraphicPipelineData *>> pipelines;
      60             :         };
      61             : 
      62             :         struct ContextMaterialInfo {
      63             :                 MaterialInfo info;
      64             :                 core::MaterialId id;
      65             :                 bool revokable;
      66             :         };
      67             : 
      68             :         void readMaterials(core::MaterialAttachment *a);
      69             :         MaterialInfo getMaterialInfo(const Rc<core::Material> &material) const;
      70             : 
      71             :         void addPendingMaterial(Rc<core::Material> &&);
      72             :         void addMaterial(const MaterialInfo &, core::MaterialId, bool revokable);
      73             :         String listMaterials() const;
      74             : 
      75             :         virtual core::ImageViewInfo getImageViewForMaterial(const MaterialInfo &, uint32_t idx, const core::ImageData *) const;
      76             : 
      77             :         virtual const core::GraphicPipelineData *getPipelineForMaterial(const MaterialInfo &) const;
      78             :         virtual bool isPipelineMatch(const core::GraphicPipelineData *, const MaterialInfo &) const;
      79             : 
      80             :         virtual void submitMaterials(const FrameInfo &);
      81             : 
      82             :         Scene *_scene = nullptr;
      83             :         Rc<core::Queue> _queue;
      84             : 
      85             :         const core::MaterialAttachment *_materialAttachment = nullptr;
      86             :         Vector<PipelineLayoutData> _layouts;
      87             : 
      88             :         HashMap<uint64_t, Vector<ContextMaterialInfo>> _materials;
      89             : 
      90             :         Vector<Rc<core::Material>> _pendingMaterialsToAdd;
      91             :         Vector<uint32_t> _pendingMaterialsToRemove;
      92             : 
      93             :         Rc<core::DependencyEvent> _materialDependency;
      94             : 
      95             :         // отозванные ид могут быть выданы новым отзываемым материалам, чтобы не засорять биндинги
      96             :         Vector<core::MaterialId> _revokedIds;
      97             : };
      98             : 
      99             : struct FrameContextHandle : public core::AttachmentInputData {
     100             :         Rc<Director> director; // allow to access director from rendering pipeline (to send stats)
     101             :         FrameContext *context = nullptr;
     102             : 
     103             :         memory::vector<StateId> stateStack;
     104             :         memory::vector<DrawStateValues> states;
     105             : 
     106        3277 :         StateId addState(DrawStateValues values) {
     107        3277 :                 auto it = std::find(states.begin(), states.end(), values);
     108        3277 :                 if (it != states.end()) {
     109             :                         //log::verbose("FrameContextHandle", "addStateRet ", it - states.begin(), " ", values.scissor);
     110         420 :                         return it - states.begin();
     111             :                 } else {
     112        2857 :                         states.emplace_back(values);
     113             :                         //log::verbose("FrameContextHandle", "addState ", states.size() - 1, " ", values.scissor);
     114        2857 :                         return states.size() - 1;
     115             :                 }
     116             :         }
     117             : 
     118       28843 :         const DrawStateValues *getState(StateId state) const {
     119       28843 :                 if (state < states.size()) {
     120       12460 :                         return &states.at(state);
     121             :                 } else {
     122       16383 :                         return nullptr;
     123             :                 }
     124             :         }
     125             : 
     126       31863 :         StateId getCurrentState() const {
     127       31863 :                 return stateStack.empty() ? maxOf<StateId>() : stateStack.back();
     128             :         }
     129             : };
     130             : 
     131             : }
     132             : 
     133             : #endif /* XENOLITH_SCENE_DIRECTOR_XLFRAMECONTEXT_H_ */

Generated by: LCOV version 1.14