NAP
sampler.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 // Local Includes
8 #include "samplerdeclaration.h"
9 #include "materialcommon.h"
10 
11 // External Includes
12 #include <rtti/objectptr.h>
13 #include <utility/dllexport.h>
14 #include <nap/resource.h>
15 #include <nap/numeric.h>
16 
17 namespace nap
18 {
19  // Forward Declares
20  class Texture2D;
21  class TextureCube;
22  class SamplerInstance;
23  class RenderService;
24 
25  namespace sampler
26  {
27  constexpr const char* texture = "Texture";
28  constexpr const char* textures = "Textures";
29  }
30 
34  enum class EFilterMode : uint32
35  {
36  Nearest = 0,
37  Linear
38  };
39 
40 
44  enum class EAddressMode : uint32
45  {
46  Repeat = 0,
48  ClampToEdge,
50  };
51 
52 
57  {
58  Default = 0,
59  Four = 4,
60  Eight = 8,
61  Sixteen = 16
62  };
63 
64 
68  enum class EBorderColor : uint32
69  {
76  };
77 
78 
80  // Sampler
82 
86  class NAPAPI Sampler : public Resource
87  {
88  RTTI_ENABLE(Resource)
89  public:
90  Sampler() = default;
91 
92  std::string mName;
96  EAddressMode mAddressModeVertical = EAddressMode::ClampToEdge;
97  EAddressMode mAddressModeHorizontal = EAddressMode::ClampToEdge;
101  bool mEnableCompare = false;
102  float mLodBias = 0.0f;
103  uint32 mMinLodLevel = 0;
104  uint32 mMaxLodLevel = 1000;
105  };
106 
107 
109  // Sampler2D
111 
121  class NAPAPI Sampler2D : public Sampler
122  {
123  RTTI_ENABLE(Sampler)
124  public:
125  Sampler2D() = default;
126  mutable rtti::ObjectPtr<Texture2D> mTexture = nullptr;
127  };
128 
129 
131  // SamplerCube
133 
143  class NAPAPI SamplerCube : public Sampler
144  {
145  RTTI_ENABLE(Sampler)
146  public:
147  SamplerCube() = default;
149  };
150 
151 
153  // SamplerArray
155 
159  class NAPAPI SamplerArray : public Sampler
160  {
161  RTTI_ENABLE(Sampler)
162 
163  public:
168  virtual int getNumElements() const = 0;
169  };
170 
171 
173  // Sampler2DArray
175 
185  class NAPAPI Sampler2DArray : public SamplerArray
186  {
187  RTTI_ENABLE(SamplerArray)
188  public:
189 
190  Sampler2DArray() = default;
191  Sampler2DArray(int inSize) :
192  mTextures(inSize) { }
193 
197  virtual int getNumElements() const override { return mTextures.size(); }
198 
199  std::vector<rtti::ObjectPtr<Texture2D>> mTextures;
200  };
201 
202 
204  // SamplerCubeArray
206 
216  class NAPAPI SamplerCubeArray : public SamplerArray
217  {
218  RTTI_ENABLE(SamplerArray)
219  public:
220 
221  SamplerCubeArray() = default;
222  SamplerCubeArray(int inSize) :
223  mTextures(inSize) { }
224 
228  virtual int getNumElements() const override { return mTextures.size(); }
229 
230  std::vector<rtti::ObjectPtr<TextureCube>> mTextures;
231  };
232 }
nap::EBorderColor::IntOpaqueBlack
@ IntOpaqueBlack
Integer opaque black, sampler default.
nap::EDepthCompareMode
EDepthCompareMode
Definition: materialcommon.h:54
nap::SamplerCubeArray
Definition: sampler.h:216
nap::Sampler2DArray::Sampler2DArray
Sampler2DArray(int inSize)
Definition: sampler.h:191
nap::SamplerArray
Definition: sampler.h:159
nap::EFilterMode::Nearest
@ Nearest
Nearest sampling.
nap::EBorderColor::FloatOpaqueBlack
@ FloatOpaqueBlack
Float opaque black.
nap::EAnisotropicSamples::Four
@ Four
Four samples.
nap::Sampler2DArray::mTextures
std::vector< rtti::ObjectPtr< Texture2D > > mTextures
Property: 'Textures' textures to bind, must be of the same length as the shader declaration.
Definition: sampler.h:199
nap::Sampler2D
Definition: sampler.h:121
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::EAnisotropicSamples::Sixteen
@ Sixteen
Sixteen samples.
nap::EAnisotropicSamples
EAnisotropicSamples
Definition: sampler.h:56
nap::sampler::textures
constexpr const char * textures
Definition: sampler.h:28
nap::EBorderColor::IntTransparentBlack
@ IntTransparentBlack
Integer transparent black.
nap::EAddressMode::ClampToBorder
@ ClampToBorder
ClampToBorder.
nap::EAnisotropicSamples::Eight
@ Eight
Eight samples.
nap::EFilterMode
EFilterMode
Definition: sampler.h:34
nap::Sampler::mName
std::string mName
Property: 'Name' sampler shader name.
Definition: sampler.h:92
nap::Sampler
Definition: sampler.h:86
nap::EBorderColor::FloatOpaqueWhite
@ FloatOpaqueWhite
Float opaque white.
nap::uint32
uint32_t uint32
Definition: numeric.h:20
nap::Sampler2DArray
Definition: sampler.h:185
nap::Sampler2DArray::getNumElements
virtual int getNumElements() const override
Definition: sampler.h:197
nap::sampler::texture
constexpr const char * texture
Definition: sampler.h:27
nap::EAddressMode::Repeat
@ Repeat
Repeat.
nap::SamplerCube::mTextureCube
rtti::ObjectPtr< TextureCube > mTextureCube
Property: 'Texture' the texture to bind.
Definition: sampler.h:148
nap::EAddressMode::ClampToEdge
@ ClampToEdge
ClampToEdge.
nap::SamplerCubeArray::getNumElements
virtual int getNumElements() const override
Definition: sampler.h:228
nap::EAddressMode::MirroredRepeat
@ MirroredRepeat
MirroredRepeat.
nap::SamplerCubeArray::mTextures
std::vector< rtti::ObjectPtr< TextureCube > > mTextures
Property: 'Textures' textures to bind, must be of the same length as the shader declaration.
Definition: sampler.h:230
nap
Definition: templateapp.h:17
nap::Resource
Definition: resource.h:19
nap::EBorderColor
EBorderColor
Definition: sampler.h:68
nap::EDepthCompareMode::LessOrEqual
@ LessOrEqual
nap::EAnisotropicSamples::Default
@ Default
Pick system default, as defined by the render service configuration.
nap::EBorderColor::FloatTransparentBlack
@ FloatTransparentBlack
Float transparent black.
nap::EFilterMode::Linear
@ Linear
Linear sampling.
nap::EBorderColor::IntOpaqueWhite
@ IntOpaqueWhite
Integer opaque white.
nap::SamplerCube
Definition: sampler.h:143
nap::EAddressMode
EAddressMode
Definition: sampler.h:44
nap::SamplerCubeArray::SamplerCubeArray
SamplerCubeArray(int inSize)
Definition: sampler.h:222