xbmc
ShaderTypes.h
1 /*
2  * Copyright (C) 2017-2020 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <algorithm>
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <type_traits>
16 #include <vector>
17 
18 // TODO: remove (see below)
19 #ifdef _WIN32
20 #include <DirectXMath.h>
21 #endif
22 
23 namespace KODI
24 {
25 namespace SHADER
26 {
27 struct ShaderPass;
28 using ShaderPassVec = std::vector<ShaderPass>;
29 
30 class IShaderLut;
31 using ShaderLutPtr = std::shared_ptr<IShaderLut>;
32 using ShaderLutVec = std::vector<ShaderLutPtr>;
33 
34 using ShaderParameterMap = std::map<std::string, float>;
35 
36 enum FILTER_TYPE
37 {
38  FILTER_TYPE_NONE,
39  FILTER_TYPE_LINEAR,
40  FILTER_TYPE_NEAREST
41 };
42 
43 enum WRAP_TYPE
44 {
45  WRAP_TYPE_BORDER,
46  WRAP_TYPE_EDGE,
47  WRAP_TYPE_REPEAT,
48  WRAP_TYPE_MIRRORED_REPEAT,
49 };
50 
51 enum SCALE_TYPE
52 {
53  SCALE_TYPE_INPUT,
54  SCALE_TYPE_ABSOLUTE,
55  SCALE_TYPE_VIEWPORT,
56 };
57 
59 {
60  SCALE_TYPE type = SCALE_TYPE_INPUT;
61  float scale = 1.0;
62  unsigned int abs = 1;
63 };
64 
65 struct FboScale
66 {
67  bool sRgbFramebuffer = false;
68  bool floatFramebuffer = false;
69  FboScaleAxis scaleX;
70  FboScaleAxis scaleY;
71 };
72 
73 struct ShaderLut
74 {
75  std::string strId;
76  std::string path;
77  FILTER_TYPE filter = FILTER_TYPE_NONE;
78  WRAP_TYPE wrap = WRAP_TYPE_BORDER;
79  bool mipmap = false;
80 };
81 
83 {
84  std::string strId;
85  std::string description;
86  float current = 0.0f;
87  float minimum = 0.0f;
88  float initial = 0.0f;
89  float maximum = 0.0f;
90  float step = 0.0f;
91 };
92 
93 struct ShaderPass
94 {
95  std::string sourcePath;
96  std::string vertexSource;
97  std::string fragmentSource;
98  FILTER_TYPE filter = FILTER_TYPE_NONE;
99  WRAP_TYPE wrap = WRAP_TYPE_BORDER;
100  unsigned int frameCountMod = 0;
101  FboScale fbo;
102  bool mipmap = false;
103 
104  std::vector<ShaderLut> luts;
105  std::vector<ShaderParameter> parameters;
106 };
107 
108 struct float2
109 {
110  float2() : x(0), y(0) {}
111 
112  template<typename T>
113  float2(T x_, T y_) : x(static_cast<float>(x_)), y(static_cast<float>(y_))
114  {
115  static_assert(std::is_arithmetic<T>::value, "Not an arithmetic type");
116  }
117 
118  template<typename T>
119  T Max()
120  {
121  return static_cast<T>(std::max(x, y));
122  }
123  template<typename T>
124  T Min()
125  {
126  return static_cast<T>(std::min(x, y));
127  }
128 
129  // TODO: move to CShaderUtilsDX
130 #ifdef _WIN32
131  DirectX::XMFLOAT2 ToDXVector() const
132  {
133  return DirectX::XMFLOAT2(static_cast<float>(x), static_cast<float>(y));
134  }
135 #endif
136 
137  float x;
138  float y;
139 };
140 } // namespace SHADER
141 } // namespace KODI
Definition: ShaderTypes.h:58
Definition: ShaderTypes.h:93
Definition: ShaderTypes.h:73
Definition: ShaderTypes.h:65
Definition: AudioDecoder.h:18
Definition: ShaderTypes.h:82
Definition: ShaderTypes.h:108