NAP
structfillpolicy.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // External includes
8 #include <nap/resource.h>
9 #include <nap/numeric.h>
10 
11 // Local Includes
12 #include "mathutils.h"
13 #include "structbufferdescriptor.h"
14 #include "fillpolicy.h"
15 
16 namespace nap
17 {
19  // StructFillPolicy
21 
37  class NAPAPI StructFillPolicy : public Resource
38  {
39  RTTI_ENABLE(Resource)
40  public:
44  class NAPAPI BaseEntry : public Resource
45  {
46  RTTI_ENABLE(Resource)
47  public:
48  BaseEntry() = default;
49  virtual ~BaseEntry() = default;
50  std::string mName;
51  };
52 
57  template<typename T>
58  class Entry : public BaseEntry
59  {
60  RTTI_ENABLE(BaseEntry)
61  public:
63  };
64 
71  bool fill(StructBufferDescriptor* descriptor, uint8* data, utility::ErrorState& errorState);
72 
73  std::vector<rtti::ObjectPtr<BaseEntry>> mFillPolicies;
74 
75  protected:
83  bool fillFromUniformRecursive(const UniformStruct* uniformStruct, uint8* data, size_t& outElementSize, utility::ErrorState& errorState);
84 
91  template<typename T>
92  const FillPolicy<T>* findPolicy(const std::string& name)
93  {
94  for (const auto& fp : mFillPolicies)
95  {
96  if (fp->mName == name)
97  {
98  const auto* resolved = rtti_cast<const StructFillPolicy::Entry<T>>(fp.get());
99  if (resolved != nullptr)
100  return resolved->mFillPolicy.get();
101 
102  // Names match but types do not
103  assert(false);
104  return nullptr;
105  }
106  }
107  return nullptr;
108  }
109  };
110 
111 
113  // struct fill policy entry type definitions
115 
123 }
nap::StructFillPolicy
Definition: structfillpolicy.h:37
nap::StructFillPolicy::mFillPolicies
std::vector< rtti::ObjectPtr< BaseEntry > > mFillPolicies
Property 'FillPolicies': List of shader variable fill policy entries.
Definition: structfillpolicy.h:73
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::uint8
uint8_t uint8
Definition: numeric.h:16
nap::StructFillPolicy::findPolicy
const FillPolicy< T > * findPolicy(const std::string &name)
Definition: structfillpolicy.h:92
nap::utility::ErrorState
Definition: errorstate.h:19
nap::StructFillPolicy::BaseEntry::mName
std::string mName
Property 'Name': The struct member name of this fill policy entry.
Definition: structfillpolicy.h:50
nap::StructFillPolicy::Entry
Definition: structfillpolicy.h:58
nap::StructBufferDescriptor
Definition: structbufferdescriptor.h:22
nap::StructFillPolicy::BaseEntry
Definition: structfillpolicy.h:44
nap::StructFillPolicy::Entry::mFillPolicy
rtti::ObjectPtr< FillPolicy< T > > mFillPolicy
Property 'FillPolicy': The fill policy associated with the member name.
Definition: structfillpolicy.h:62
nap
Definition: templateapp.h:17
nap::Resource
Definition: resource.h:19
nap::FillPolicy
Definition: fillpolicy.h:47
nap::UniformStruct
Definition: uniform.h:51