GraphicsApi.h 8.8 KB

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