GraphicsApi.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #pragma once
  2. #include "Vec2.h"
  3. #include "Mat4.h"
  4. #include "Ebene3D.h"
  5. #include "Bildschirm.h"
  6. // DirectX 12 Types
  7. struct ID3D12Debug;
  8. struct ID3D12Device2;
  9. struct ID3D12InfoQueue;
  10. struct ID3D12CommandQueue;
  11. struct IDXGISwapChain4;
  12. struct ID3D12DescriptorHeap;
  13. struct ID3D12Resource;
  14. struct ID3D12CommandAllocator;
  15. struct ID3D12GraphicsCommandList;
  16. struct ID3D12Fence;
  17. struct D3D12_VIEWPORT;
  18. struct D3D12_VERTEX_BUFFER_VIEW;
  19. struct D3D12_INDEX_BUFFER_VIEW;
  20. struct ID3D12RootSignature;
  21. struct ID3D12PipelineState;
  22. // DirectX 11 Types
  23. struct ID3D11Device;
  24. struct ID3D11DeviceContext;
  25. struct IDXGISwapChain;
  26. struct ID3D11Texture2D;
  27. struct ID3D11SamplerState;
  28. struct ID3D11ShaderResourceView;
  29. struct ID3D11RenderTargetView;
  30. struct ID3D11DepthStencilView;
  31. struct ID3D11DepthStencilState;
  32. struct ID3D11RasterizerState;
  33. struct ID3D11BlendState;
  34. struct D3D11_VIEWPORT;
  35. // DirectX 9 Types
  36. struct IDirect3D9;
  37. struct IDirect3DDevice9;
  38. struct IDirect3DSurface9;
  39. struct _D3DLOCKED_RECT;
  40. struct tagRECT;
  41. namespace Framework
  42. {
  43. class WFenster;
  44. class Bild;
  45. class Textur;
  46. class DX11PixelShader;
  47. class DX11VertexShader;
  48. class TexturModel;
  49. class Render3D;
  50. class TexturList;
  51. class Kam3D;
  52. class Model3D;
  53. class DX11Buffer;
  54. class DX11StructuredBuffer;
  55. class DX12Buffer;
  56. class DX12DirectCommandQueue;
  57. class DX12CopyCommandQueue;
  58. class DX12ComputeCommandQueue;
  59. class DX12PixelShader;
  60. class DX12VertexShader;
  61. class DX12VertexBuffer;
  62. class DX12IndexBuffer;
  63. enum GraphicApiType;
  64. struct DiffuseLight
  65. {
  66. Vec3<float> direction;
  67. Vec3<float> color;
  68. };
  69. struct PointLight
  70. {
  71. Vec3<float> position;
  72. Vec3<float> color;
  73. float radius;
  74. };
  75. class GraphicsApi
  76. {
  77. protected:
  78. GraphicApiType typ;
  79. WFenster *fenster;
  80. Vec2<int> backBufferSize;
  81. bool fullScreen;
  82. private:
  83. int ref;
  84. public:
  85. __declspec( dllexport ) GraphicsApi( GraphicApiType typ );
  86. __declspec( dllexport ) virtual ~GraphicsApi();
  87. __declspec( dllexport ) virtual void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen );
  88. __declspec( dllexport ) virtual void setBackBufferSize( Vec2< int > size );
  89. __declspec( dllexport ) virtual void setFullScreen( bool fullScreen );
  90. __declspec( dllexport ) virtual void update() = 0;
  91. __declspec( dllexport ) virtual void beginFrame( bool fill2D = 0, bool fill3D = 0, int fillColor = 0 );
  92. __declspec( dllexport ) virtual void renderKamera( Kam3D *zKamera );
  93. __declspec( dllexport ) virtual void presentFrame() = 0;
  94. __declspec( dllexport ) virtual Textur *createOrGetTextur( const char *name, Bild *b = 0 );
  95. __declspec( dllexport ) GraphicApiType getTyp() const;
  96. __declspec( dllexport ) Vec2< int > getBackBufferSize() const;
  97. __declspec( dllexport ) bool isFullScreen() const;
  98. __declspec( dllexport ) virtual Bild *zUIRenderBild() const = 0;
  99. __declspec( dllexport ) GraphicsApi *getThis();
  100. __declspec( dllexport ) GraphicsApi *release();
  101. };
  102. class DirectX9 : public GraphicsApi
  103. {
  104. private:
  105. IDirect3D9 *pDirect3D;
  106. IDirect3DDevice9 *pDevice;
  107. IDirect3DSurface9 *pBackBuffer;
  108. _D3DLOCKED_RECT *backRect;
  109. Bild *uiBild;
  110. public:
  111. __declspec( dllexport ) DirectX9();
  112. __declspec( dllexport ) ~DirectX9();
  113. __declspec( dllexport ) void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
  114. __declspec( dllexport ) void update() override;
  115. __declspec( dllexport ) void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
  116. __declspec( dllexport ) void presentFrame() override;
  117. __declspec( dllexport ) Bild *zUIRenderBild() const override;
  118. };
  119. class DirectX11 : public GraphicsApi
  120. {
  121. private:
  122. ID3D11Device *d3d11Device;
  123. ID3D11DeviceContext *d3d11Context;
  124. IDXGISwapChain *d3d11SpawChain;
  125. Textur *uiTextur;
  126. DX11VertexShader *vertexShader;
  127. DX11PixelShader *pixelShader;
  128. ID3D11SamplerState *sampleState;
  129. ID3D11RenderTargetView *rtview;
  130. ID3D11DepthStencilView *dsView;
  131. ID3D11Texture2D *depthStencilBuffer;
  132. ID3D11DepthStencilState *depthStencilState;
  133. ID3D11DepthStencilState *depthDisabledStencilState;
  134. ID3D11BlendState *blendStateAlphaBlend;
  135. D3D11_VIEWPORT *vp;
  136. TexturModel *texturModel;
  137. TexturList *texturRegister;
  138. ID3D11RasterizerState *texturRS;
  139. ID3D11RasterizerState *meshRS;
  140. Textur *defaultTextur;
  141. DX11StructuredBuffer *diffuseLights;
  142. DX11StructuredBuffer *pointLights;
  143. DX11Buffer *vertexBuffer;
  144. DX11Buffer *indexBuffer;
  145. Mat4< float > matrixBuffer[ MAX_KNOCHEN_ANZ ];
  146. Mat4< float > viewAndProj[ 2 ];
  147. Vec3< float > kamPos;
  148. Ebene3D< float > frustrum[ 6 ];
  149. void renderObject( Model3D *zObj );
  150. // Überprüft, ob eine Kugel in dem Sichtbaren Raum der Welt liegt und gezeichnet werden muss
  151. // pos: Der Mittelpunkt der Kugel
  152. // radius: Der Radius der Kugel
  153. // dist: Einen Zeiger auf einen float, in dem das quadrat des Abstands zur Kammeraposition gespeichert wird, falls diese Funktion true zurückgiebt und der Zeiger nicht 0 ist
  154. bool isInFrustrum( const Vec3< float > &pos, float radius, float *dist = 0 ) const;
  155. public:
  156. __declspec( dllexport ) DirectX11();
  157. __declspec( dllexport ) ~DirectX11();
  158. __declspec( dllexport ) void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
  159. __declspec( dllexport ) void update() override;
  160. __declspec( dllexport ) void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
  161. __declspec( dllexport ) void renderKamera( Kam3D *zKamera ) override;
  162. __declspec( dllexport ) void presentFrame() override;
  163. __declspec( dllexport ) Textur *createOrGetTextur( const char *name, Bild *b ) override;
  164. __declspec( dllexport ) Bild *zUIRenderBild() const override;
  165. __declspec( dllexport ) static bool isAvailable();
  166. };
  167. class DirectX12 : public GraphicsApi
  168. {
  169. private:
  170. ID3D12Debug *debug;
  171. ID3D12Device2 *device;
  172. ID3D12InfoQueue *infoQueue;
  173. DX12DirectCommandQueue *directCommandQueue;
  174. DX12CopyCommandQueue *copyCommandQueue;
  175. DX12ComputeCommandQueue *computeCommandQueue;
  176. IDXGISwapChain4 *swapChain;
  177. ID3D12DescriptorHeap *rtvHeap;
  178. ID3D12DescriptorHeap *dsvHeap;
  179. ID3D12DescriptorHeap *shaderBufferHeap;
  180. ID3D12Resource *depthBuffer;
  181. ID3D12Resource *backBuffer[ 2 ];
  182. int backBufferIndex;
  183. int tearing;
  184. D3D12_VIEWPORT *viewPort;
  185. tagRECT *allowedRenderArea;
  186. D3D12_VERTEX_BUFFER_VIEW *vertexBufferView;
  187. D3D12_INDEX_BUFFER_VIEW *indexBufferView;
  188. DX12VertexBuffer *vertexBuffer;
  189. DX12IndexBuffer *indexBuffer;
  190. ID3D12RootSignature *signature;
  191. ID3D12PipelineState *pipeline;
  192. Mat4< float > matrixBuffer[ MAX_KNOCHEN_ANZ ];
  193. Mat4< float > viewAndProj[ 2 ];
  194. Vec3< float > kamPos;
  195. Ebene3D< float > frustrum[ 6 ];
  196. TexturModel *texturModel;
  197. Textur *uiTextur;
  198. TexturList *texturRegister;
  199. DX12VertexShader *vertexShader;
  200. DX12PixelShader *pixelShader;
  201. void renderObject( Model3D *zObj );
  202. // Überprüft, ob eine Kugel in dem Sichtbaren Raum der Welt liegt und gezeichnet werden muss
  203. // pos: Der Mittelpunkt der Kugel
  204. // radius: Der Radius der Kugel
  205. // dist: Einen Zeiger auf einen float, in dem das quadrat des Abstands zur Kammeraposition gespeichert wird, falls diese Funktion true zurückgiebt und der Zeiger nicht 0 ist
  206. bool isInFrustrum( const Vec3< float > &pos, float radius, float *dist = 0 ) const;
  207. public:
  208. __declspec( dllexport ) DirectX12();
  209. __declspec( dllexport ) ~DirectX12();
  210. __declspec( dllexport ) void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
  211. __declspec( dllexport ) void update() override;
  212. __declspec( dllexport ) void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
  213. __declspec( dllexport ) void renderKamera( Kam3D *zKamera ) override;
  214. __declspec( dllexport ) void presentFrame() override;
  215. __declspec( dllexport ) Textur *createOrGetTextur( const char *name, Bild *b ) override;
  216. __declspec( dllexport ) Bild *zUIRenderBild() const override;
  217. __declspec( dllexport ) static bool isAvailable();
  218. };
  219. }