GraphicsApi.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 : public virtual ReferenceCounter
  76. {
  77. protected:
  78. GraphicApiType typ;
  79. WFenster *fenster;
  80. Vec2<int> backBufferSize;
  81. bool fullScreen;
  82. public:
  83. DLLEXPORT GraphicsApi( GraphicApiType typ );
  84. DLLEXPORT virtual ~GraphicsApi();
  85. DLLEXPORT virtual void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen );
  86. DLLEXPORT virtual void setBackBufferSize( Vec2< int > size );
  87. DLLEXPORT virtual void setFullScreen( bool fullScreen );
  88. DLLEXPORT virtual void update() = 0;
  89. DLLEXPORT virtual void beginFrame( bool fill2D = 0, bool fill3D = 0, int fillColor = 0 );
  90. DLLEXPORT virtual void renderKamera( Kam3D *zKamera );
  91. DLLEXPORT virtual void presentFrame() = 0;
  92. DLLEXPORT virtual Textur *createOrGetTextur( const char *name, Bild *b = 0 );
  93. DLLEXPORT GraphicApiType getTyp() const;
  94. DLLEXPORT Vec2< int > getBackBufferSize() const;
  95. DLLEXPORT bool isFullScreen() const;
  96. DLLEXPORT virtual Bild *zUIRenderBild() const = 0;
  97. };
  98. class DirectX9 : public GraphicsApi
  99. {
  100. private:
  101. IDirect3D9 *pDirect3D;
  102. IDirect3DDevice9 *pDevice;
  103. IDirect3DSurface9 *pBackBuffer;
  104. _D3DLOCKED_RECT *backRect;
  105. Bild *uiBild;
  106. public:
  107. DLLEXPORT DirectX9();
  108. DLLEXPORT ~DirectX9();
  109. DLLEXPORT void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
  110. DLLEXPORT void update() override;
  111. DLLEXPORT void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
  112. DLLEXPORT void renderKamera( Kam3D *zKamera ) override;
  113. DLLEXPORT void presentFrame() override;
  114. DLLEXPORT Textur *createOrGetTextur( const char *name, Bild *b ) override;
  115. DLLEXPORT Bild *zUIRenderBild() const override;
  116. };
  117. class DirectX11 : public GraphicsApi
  118. {
  119. private:
  120. ID3D11Device *d3d11Device;
  121. ID3D11DeviceContext *d3d11Context;
  122. IDXGISwapChain *d3d11SpawChain;
  123. Textur *uiTextur;
  124. DX11VertexShader *vertexShader;
  125. DX11PixelShader *pixelShader;
  126. ID3D11SamplerState *sampleState;
  127. ID3D11RenderTargetView *rtview;
  128. ID3D11DepthStencilView *dsView;
  129. ID3D11Texture2D *depthStencilBuffer;
  130. ID3D11DepthStencilState *depthStencilState;
  131. ID3D11DepthStencilState *depthDisabledStencilState;
  132. ID3D11BlendState *blendStateAlphaBlend;
  133. D3D11_VIEWPORT *vp;
  134. TexturModel *texturModel;
  135. TexturList *texturRegister;
  136. ID3D11RasterizerState *texturRS;
  137. ID3D11RasterizerState *meshRS;
  138. Textur *defaultTextur;
  139. DX11StructuredBuffer *diffuseLights;
  140. DX11StructuredBuffer *pointLights;
  141. DX11Buffer *vertexBuffer;
  142. DX11Buffer *indexBuffer;
  143. Mat4< float > matrixBuffer[ MAX_KNOCHEN_ANZ ];
  144. Mat4< float > viewAndProj[ 2 ];
  145. Vec3< float > kamPos;
  146. Ebene3D< float > frustrum[ 6 ];
  147. int lastModelId = -1;
  148. void renderObject( Model3D *zObj );
  149. //! Überprüft, ob eine Kugel in dem Sichtbaren Raum der Welt liegt und gezeichnet werden muss
  150. //! \param pos Der Mittelpunkt der Kugel
  151. //! \param radius Der Radius der Kugel
  152. //! \param 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
  153. bool isInFrustrum( const Vec3< float > &pos, float radius, float *dist = 0 ) const;
  154. public:
  155. DLLEXPORT DirectX11();
  156. DLLEXPORT ~DirectX11();
  157. DLLEXPORT void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
  158. DLLEXPORT void update() override;
  159. DLLEXPORT void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
  160. DLLEXPORT void renderKamera( Kam3D *zKamera ) override;
  161. DLLEXPORT void presentFrame() override;
  162. DLLEXPORT Textur *createOrGetTextur( const char *name, Bild *b ) override;
  163. DLLEXPORT Bild *zUIRenderBild() const override;
  164. DLLEXPORT static bool isAvailable();
  165. };
  166. class DirectX12 : public GraphicsApi
  167. {
  168. private:
  169. ID3D12Debug *debug;
  170. ID3D12Device2 *device;
  171. ID3D12InfoQueue *infoQueue;
  172. DX12DirectCommandQueue *directCommandQueue;
  173. DX12CopyCommandQueue *copyCommandQueue;
  174. DX12ComputeCommandQueue *computeCommandQueue;
  175. IDXGISwapChain4 *swapChain;
  176. ID3D12DescriptorHeap *rtvHeap;
  177. ID3D12DescriptorHeap *dsvHeap;
  178. ID3D12DescriptorHeap *shaderBufferHeap;
  179. ID3D12Resource *depthBuffer;
  180. ID3D12Resource *backBuffer[ 2 ];
  181. int backBufferIndex;
  182. int tearing;
  183. D3D12_VIEWPORT *viewPort;
  184. tagRECT *allowedRenderArea;
  185. D3D12_VERTEX_BUFFER_VIEW *vertexBufferView;
  186. D3D12_INDEX_BUFFER_VIEW *indexBufferView;
  187. DX12VertexBuffer *vertexBuffer;
  188. DX12IndexBuffer *indexBuffer;
  189. ID3D12RootSignature *signature;
  190. ID3D12PipelineState *pipeline;
  191. Mat4< float > matrixBuffer[ MAX_KNOCHEN_ANZ ];
  192. Mat4< float > viewAndProj[ 2 ];
  193. Vec3< float > kamPos;
  194. Ebene3D< float > frustrum[ 6 ];
  195. TexturModel *texturModel;
  196. Textur *uiTextur;
  197. TexturList *texturRegister;
  198. DX12VertexShader *vertexShader;
  199. DX12PixelShader *pixelShader;
  200. void renderObject( Model3D *zObj );
  201. //! Überprüft, ob eine Kugel in dem Sichtbaren Raum der Welt liegt und gezeichnet werden muss
  202. //! \param pos Der Mittelpunkt der Kugel
  203. //! \param radius Der Radius der Kugel
  204. //! \param 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
  205. bool isInFrustrum( const Vec3< float > &pos, float radius, float *dist = 0 ) const;
  206. public:
  207. DLLEXPORT DirectX12();
  208. DLLEXPORT ~DirectX12();
  209. DLLEXPORT void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
  210. DLLEXPORT void update() override;
  211. DLLEXPORT void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
  212. DLLEXPORT void renderKamera( Kam3D *zKamera ) override;
  213. DLLEXPORT void presentFrame() override;
  214. DLLEXPORT Textur *createOrGetTextur( const char *name, Bild *b ) override;
  215. DLLEXPORT Bild *zUIRenderBild() const override;
  216. DLLEXPORT static bool isAvailable();
  217. };
  218. }