NAP
surfacedescriptor.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 #include "rtti/typeinfo.h"
8 
9 // External Includes
10 
11 namespace nap
12 {
16  enum class ESurfaceDataType : int
17  {
18  BYTE = 0,
19  USHORT = 1,
20  FLOAT = 2
21  };
22 
26  enum class ESurfaceChannels : int
27  {
28  R = 0,
29  RGBA = 1,
30  BGRA = 2,
31  D = 3
32  };
33 
37  enum class EColorSpace : int
38  {
39  Linear,
40  sRGB
41  };
42 
46  struct NAPAPI SurfaceDescriptor
47  {
48  RTTI_ENABLE()
49 
50  public:
51  SurfaceDescriptor() = default;
52  virtual ~SurfaceDescriptor() = default;
53  SurfaceDescriptor(uint32_t width, uint32_t height, ESurfaceDataType dataType, ESurfaceChannels channels);
54  SurfaceDescriptor(uint32_t width, uint32_t height, ESurfaceDataType dataType, ESurfaceChannels channels, EColorSpace colorSpace);
55 
59  int getWidth() const { return mWidth; }
60 
64  int getHeight() const { return mHeight; }
65 
69  int getPitch() const;
70 
74  int getNumChannels() const;
75 
79  int getChannelSize() const;
80 
84  int getBytesPerPixel() const;
85 
89  uint64_t getSizeInBytes() const;
90 
94  ESurfaceDataType getDataType() const { return mDataType; }
95 
99  ESurfaceChannels getChannels() const { return mChannels; }
100 
104  EColorSpace getColorSpace() const { return mColorSpace; }
105 
109  bool isValid() const { return mWidth != 0 && mHeight != 0; }
110 
111  bool operator==(const SurfaceDescriptor& other) const;
112  bool operator!=(const SurfaceDescriptor& other) const;
113 
114  public:
115  uint32_t mWidth = 0;
116  uint32_t mHeight = 0;
120  };
121 }
122 
123 namespace std
124 {
125  template <>
126  struct hash<nap::ESurfaceChannels>
127  {
128  size_t operator()(const nap::ESurfaceChannels& v) const
129  {
130  return hash<int>()(static_cast<int>(v));
131  }
132  };
133 
134  template <>
135  struct hash<nap::ESurfaceDataType>
136  {
137  size_t operator()(const nap::ESurfaceDataType& v) const
138  {
139  return hash<int>()(static_cast<int>(v));
140  }
141  };
142 
143  template <>
144  struct hash<nap::EColorSpace>
145  {
146  size_t operator()(const nap::EColorSpace& v) const
147  {
148  return hash<int>()(static_cast<int>(v));
149  }
150  };
151 }
nap::ESurfaceChannels::RGBA
@ RGBA
RGBA red, green, blue and alpha component.
nap::ESurfaceChannels
ESurfaceChannels
Definition: surfacedescriptor.h:26
nap::EColorSpace::sRGB
@ sRGB
Non-linear, sRGB color space.
nap::ESurfaceDataType::FLOAT
@ FLOAT
32 bit bitmap
nap::SurfaceDescriptor::isValid
bool isValid() const
Definition: surfacedescriptor.h:109
nap::EColorSpace::Linear
@ Linear
Linear color space.
nap::SurfaceDescriptor::getColorSpace
EColorSpace getColorSpace() const
Definition: surfacedescriptor.h:104
nap::ESurfaceDataType::USHORT
@ USHORT
16 bit bitmap
nap::SurfaceDescriptor
Definition: surfacedescriptor.h:46
nap::ESurfaceChannels::BGRA
@ BGRA
BGRA blue, green, red and alpha component.
nap::SurfaceDescriptor::getDataType
ESurfaceDataType getDataType() const
Definition: surfacedescriptor.h:94
nap::ESurfaceDataType::BYTE
@ BYTE
08 bit bitmap
nap::SurfaceDescriptor::getHeight
int getHeight() const
Definition: surfacedescriptor.h:64
nap::SurfaceDescriptor::getChannels
ESurfaceChannels getChannels() const
Definition: surfacedescriptor.h:99
nap::ESurfaceChannels::D
@ D
D component, for depth-only textures.
nap
Definition: templateapp.h:17
nap::ESurfaceChannels::R
@ R
R red component.
nap::ESurfaceDataType
ESurfaceDataType
Definition: surfacedescriptor.h:16
nap::SurfaceDescriptor::getWidth
int getWidth() const
Definition: surfacedescriptor.h:59
nap::EColorSpace
EColorSpace
Definition: surfacedescriptor.h:37