Nxna2
 All Classes Namespaces Functions Enumerations Enumerator Pages
PipelineState.h
1 #ifndef NXNA_GRAPHICS_PIPELINESTATE_H
2 #define NXNA_GRAPHICS_PIPELINESTATE_H
3 
4 #include "../NxnaCommon.h"
5 
6 namespace Nxna
7 {
8 namespace Graphics
9 {
10  enum class Blend : nxna_byte
11  {
12  Zero,
13  One,
14  SourceAlpha,
15  InverseSourceAlpha,
16  DestinationAlpha,
17  InverseDestinationAlpha
18  };
19 
20  enum class BlendFunction : nxna_byte
21  {
23  Add,
24 
26  Max,
27 
29  Min,
30 
33 
35  Subtract
36  };
37 
39  {
40  bool BlendingEnabled;
41 
42  BlendFunction AlphaBlendFunction;
43  Blend AlphaDestinationBlend;
44  Blend AlphaSourceBlend;
45 
46  BlendFunction ColorBlendFunction;
47  Blend ColorDestinationBlend;
48  Blend ColorSourceBlend;
49  };
50 
52  {
53  bool IndependentBlendEnabled;
54 
55  RenderTargetBlendStateDesc RenderTarget[8];
56  };
57 
58  struct BlendState
59  {
60  union
61  {
62  struct
63  {
64  BlendStateDesc Desc;
65  } OpenGL;
66 #ifdef NXNA_ENABLE_DIRECT3D11
67  struct
68  {
69  ID3D11BlendState* State;
70  } Direct3D11;
71 #endif
72  };
73  };
74 
75  enum class InputElementFormat
76  {
78  Single = 1,
79 
81  Vector2,
82 
84  Vector3,
85 
87  Vector4,
88 
90  Color
91  };
92 
93  enum class InputElementUsage
94  {
95  Position,
96  Normal,
97  TextureCoordinate,
98  Color
99  };
100 
102  {
103  int Offset;
104  InputElementFormat ElementFormat;
105  InputElementUsage ElementUsage;
106  int UsageIndex;
107  };
108 
109 
110  struct Shader
111  {
112  union
113  {
114  struct
115  {
116  unsigned int Handle;
117  } OpenGL;
118 #ifdef NXNA_ENABLE_DIRECT3D11
119  struct
120  {
121  void* Ptr; // D3D11 has different types for VS, PS, etc, so we have to use void*
122  } Direct3D11;
123 #endif
124  };
125  };
126 
128  {
129  const void* Bytecode;
130  unsigned int BytecodeLength;
131  };
132 
134  {
135  Shader* VertexShader;
136  Shader* PixelShader;
137  ShaderBytecode VertexShaderBytecode;
138  InputElement* VertexElements;
139  int NumElements;
140  };
141 
143  {
144  union
145  {
146  struct
147  {
148  unsigned int Pipeline;
149  } OpenGL;
150 #ifdef NXNA_ENABLE_DIRECT3D11
151  struct
152  {
153  void* VertexShader;
154  void* PixelShader;
155  void* Layout;
156  } Direct3D11;
157 #endif
158  };
159  };
160 
161  enum class PrimitiveTopologyType : nxna_byte
162  {
163  Undefined,
164  Points,
165  Lines,
166  Triangles,
167  Patches
168  };
169 
170  enum class CullMode : nxna_byte
171  {
172  None,
173  CullFrontFaces,
174  CullBackFaces
175  };
176 
177  enum class FillMode : nxna_byte
178  {
179  Solid,
180  Wireframe
181  };
182 
184  {
185  CullMode CullingMode;
186  bool FrontCounterClockwise;
187  FillMode FillingMode;
188  bool ScissorTestEnabled;
189  };
190 
192  {
193  union
194  {
195  struct
196  {
197  RasterizerStateDesc Desc;
198  } OpenGL;
199 #ifdef NXNA_ENABLE_DIRECT3D11
200  struct
201  {
202  ID3D11RasterizerState* State;
203  } Direct3D11;
204 #endif
205  };
206  };
207 
209  {
210  ShaderPipeline* Shaders;
211  BlendState* Blending;
212  PrimitiveTopologyType Topology;
213  };
214 
216  {
217  public:
218 
219  union
220  {
221  struct
222  {
223  BlendStateDesc Blending;
224  ShaderPipeline* Shaders;
225  } OpenGL;
226 #ifdef NXNA_ENABLE_DIRECT3D11
227  struct
228  {
229  ShaderPipeline* Shaders;
230  BlendState* Blending;
231  } Direct3D11;
232 #endif
233  };
234  };
235 
236  void GetAdditiveBlendState(BlendStateDesc* state);
237  void GetNonPreMultipliedBlendState(BlendStateDesc* state);
238  void GetOpaqueBlendState(BlendStateDesc* state);
239 
240 #define NXNA_RENDERTARGETBLENDSTATEDESC_ALPHABLEND { \
241  true, \
242  \
243  Nxna::Graphics::BlendFunction::Add, \
244  Nxna::Graphics::Blend::InverseSourceAlpha, \
245  Nxna::Graphics::Blend::One, \
246  \
247  Nxna::Graphics::BlendFunction::Add, \
248  Nxna::Graphics::Blend::InverseSourceAlpha, \
249  Nxna::Graphics::Blend::One \
250  }
251 
252 
253 #define NXNA_RASTERIZERSTATEDESC_CULLNONE { \
254  Nxna::Graphics::CullMode::None, \
255  true, \
256  Nxna::Graphics::FillMode::Solid, \
257  false \
258  }
259 }
260 }
261 
262 #endif // NXNA_GRAPHICS_PIPELINESTATE_H
Four 32-bit floating point numbers.
BlendFunction
Definition: PipelineState.h:20
Subtract source 1 from source 2.
Definition: PipelineState.h:191
Definition: PipelineState.h:142
Subtract source 2 from source 1.
InputElementFormat
Definition: PipelineState.h:75
Definition: PipelineState.h:183
Definition: PipelineState.h:51
Definition: PipelineState.h:58
Definition: PipelineState.h:127
Three 32-bit floating point numbers.
Definition: PipelineState.h:38
Definition: PipelineState.h:208
Two 32-bit floating point numbers.
Definition: PipelineState.h:101
A single 32-bit floating point number.
Definition: PipelineState.h:215
Definition: Color.h:6
Use the maximum of sources 1 and 2.
Use the minimum of sources 1 and 2.
Definition: PipelineState.h:133
Definition: PipelineState.h:110