LCOV - code coverage report
Current view: top level - xenolith/scene/nodes - XLNodeInfo.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 24 100.0 %
Date: 2024-05-12 00:16:13 Functions: 6 6 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_NODES_XLNODEINFO_H_
      24             : #define XENOLITH_SCENE_NODES_XLNODEINFO_H_
      25             : 
      26             : #include "XLApplicationInfo.h"
      27             : #include "XLSceneConfig.h"
      28             : 
      29             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      30             : 
      31             : using RenderingLevel = core::RenderingLevel;
      32             : 
      33             : using StateId = uint32_t;
      34             : 
      35             : static constexpr StateId StateIdNone = maxOf<StateId>();
      36             : 
      37             : static constexpr uint64_t InvalidTag = maxOf<uint64_t>();
      38             : 
      39             : enum class NodeFlags {
      40             :         None,
      41             :         TransformDirty = 1 << 0,
      42             :         ContentSizeDirty = 1 << 1,
      43             : 
      44             :         DirtyMask = TransformDirty | ContentSizeDirty
      45             : };
      46             : 
      47             : SP_DEFINE_ENUM_AS_MASK(NodeFlags)
      48             : 
      49             : enum class CommandFlags : uint16_t {
      50             :         None,
      51             :         DoNotCount = 1 << 0
      52             : };
      53             : 
      54             : SP_DEFINE_ENUM_AS_MASK(CommandFlags)
      55             : 
      56             : struct MaterialInfo {
      57       42070 :         std::array<uint64_t, config::MaxMaterialImages> images = { 0 };
      58       42070 :         std::array<uint16_t, config::MaxMaterialImages> samplers = { 0 };
      59       42070 :         std::array<core::ColorMode, config::MaxMaterialImages> colorModes = { core::ColorMode() };
      60       42070 :         core::PipelineMaterialInfo pipeline;
      61             : 
      62       42634 :         uint64_t hash() const {
      63       42634 :                 return hash::hash64(reinterpret_cast<const char *>(this), sizeof(MaterialInfo));
      64             :         }
      65             : 
      66             :         String description() const;
      67             : 
      68       42070 :         bool operator==(const MaterialInfo &info) const = default;
      69             :         bool operator!=(const MaterialInfo &info) const = default;
      70             : 
      71             :         bool hasImage(uint64_t id) const;
      72             : 
      73       42286 :         MaterialInfo() {
      74       42286 :                 memset(this, 0, sizeof(MaterialInfo));
      75       42286 :         }
      76             : };
      77             : 
      78             : struct ZOrderLess {
      79      918469 :         bool operator()(const SpanView<ZOrder> &l, const SpanView<ZOrder> &r) const noexcept {
      80      918469 :                 auto len = std::max(l.size(), r.size());
      81             : #if __LCC__ && __LCC__ <= 126
      82             :                 // compiler bug workaround
      83             :                 auto lData = (const ZOrder::Type *)l.data();
      84             :                 auto rData = (const ZOrder::Type *)r.data();
      85             :                 for (size_t i = 0; i < len; ++ i) {
      86             :                         ZOrder::Type valL = (i < l.size()) ? lData[i] : 0;
      87             :                         ZOrder::Type valR = (i < r.size()) ? rData[i] : 0;
      88             :                         if (valL != valR) {
      89             :                                 return valL < valR;
      90             :                         }
      91             :                 }
      92             : #else
      93     3320958 :                 for (size_t i = 0; i < len; ++ i) {
      94     2912078 :                         auto valL = (i < l.size()) ? l.at(i) : ZOrder(0);
      95     2912078 :                         auto valR = (i < r.size()) ? r.at(i) : ZOrder(0);
      96     2912078 :                         if (valL != valR) {
      97      509589 :                                 return valL < valR;
      98             :                         }
      99             :                 }
     100             : #endif
     101      408880 :                 return false;
     102             :         }
     103             : };
     104             : 
     105             : struct DrawStateValues {
     106        1239 :         core::DynamicState enabled = core::DynamicState::None;
     107        1239 :         URect viewport;
     108        1239 :         URect scissor;
     109             : 
     110             :         // used to extend state
     111        1197 :         Rc<Ref> data;
     112             : 
     113        1239 :         bool operator==(const DrawStateValues &) const = default;
     114             : 
     115        5306 :         bool isScissorEnabled() const { return (enabled & core::DynamicState::Scissor) != core::DynamicState::None; }
     116             :         bool isViewportEnabled() const { return (enabled & core::DynamicState::Viewport) != core::DynamicState::None; }
     117             : };
     118             : 
     119             : struct DrawStat {
     120             :         uint32_t vertexes;
     121             :         uint32_t triangles;
     122             :         uint32_t zPaths;
     123             :         uint32_t drawCalls;
     124             : 
     125             :         uint32_t cachedImages;
     126             :         uint32_t cachedFramebuffers;
     127             :         uint32_t cachedImageViews;
     128             :         uint32_t materials;
     129             : 
     130             :         uint32_t solidCmds;
     131             :         uint32_t surfaceCmds;
     132             :         uint32_t transparentCmds;
     133             : 
     134             :         uint32_t vertexInputTime;
     135             : };
     136             : 
     137             : }
     138             : 
     139             : #endif /* XENOLITH_SCENE_XLNODEINFO_H_ */

Generated by: LCOV version 1.14