GraphicsApi.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #pragma once
  2. #include "Vec2.h"
  3. #include "Mat4.h"
  4. #include "Ebene3D.h"
  5. // DirectX 11 Types
  6. struct ID3D11Device;
  7. struct ID3D11DeviceContext;
  8. struct IDXGISwapChain;
  9. struct ID3D11Texture2D;
  10. struct ID3D11SamplerState;
  11. struct ID3D11ShaderResourceView;
  12. struct ID3D11RenderTargetView;
  13. struct ID3D11DepthStencilView;
  14. struct ID3D11DepthStencilState;
  15. struct ID3D11RasterizerState;
  16. struct ID3D11BlendState;
  17. struct D3D11_VIEWPORT;
  18. // DirectX 9 Types
  19. struct IDirect3D9;
  20. struct IDirect3DDevice9;
  21. struct IDirect3DSurface9;
  22. struct _D3DLOCKED_RECT;
  23. namespace Framework
  24. {
  25. class WFenster;
  26. class Bild;
  27. class Textur;
  28. class PixelShader;
  29. class VertexShader;
  30. class TexturModel;
  31. class Render3D;
  32. class TexturList;
  33. class Kam3D;
  34. class Model3D;
  35. class DX11Buffer;
  36. class DX11StructuredBuffer;
  37. enum GraphicApiType
  38. {
  39. NOT_SUPPORTED, // no graphic api supported
  40. DIRECTX9, // only 2d
  41. DIRECTX11, // 3d simple phong model without shadows
  42. DIRECTX12 // 3d phong model with raytraycing
  43. };
  44. struct DiffuseLight
  45. {
  46. Vec3<float> direction;
  47. Vec3<float> color;
  48. };
  49. struct PointLight
  50. {
  51. Vec3<float> position;
  52. Vec3<float> color;
  53. float radius;
  54. };
  55. class GraphicsApi
  56. {
  57. protected:
  58. GraphicApiType typ;
  59. WFenster *fenster;
  60. Vec2<int> backBufferSize;
  61. bool fullScreen;
  62. private:
  63. int ref;
  64. public:
  65. __declspec( dllexport ) GraphicsApi( GraphicApiType typ );
  66. __declspec( dllexport ) virtual ~GraphicsApi();
  67. __declspec( dllexport ) virtual void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen );
  68. __declspec( dllexport ) virtual void setBackBufferSize( Vec2< int > size );
  69. __declspec( dllexport ) virtual void setFullScreen( bool fullScreen );
  70. __declspec( dllexport ) virtual void update() = 0;
  71. __declspec( dllexport ) virtual void beginFrame( bool fill2D = 0, bool fill3D = 0, int fillColor = 0 );
  72. __declspec( dllexport ) virtual void renderKamera( Kam3D *zKamera );
  73. __declspec( dllexport ) virtual void presentFrame() = 0;
  74. __declspec( dllexport ) virtual Textur *createOrGetTextur( const char *name, Bild *b = 0 );
  75. __declspec( dllexport ) GraphicApiType getTyp() const;
  76. __declspec( dllexport ) Vec2< int > getBackBufferSize() const;
  77. __declspec( dllexport ) bool isFullScreen() const;
  78. __declspec( dllexport ) virtual Bild *zUIRenderBild() const = 0;
  79. __declspec( dllexport ) GraphicsApi *getThis();
  80. __declspec( dllexport ) GraphicsApi *release();
  81. };
  82. class DirectX9 : public GraphicsApi
  83. {
  84. private:
  85. IDirect3D9 *pDirect3D;
  86. IDirect3DDevice9 *pDevice;
  87. IDirect3DSurface9 *pBackBuffer;
  88. _D3DLOCKED_RECT *backRect;
  89. Bild *uiBild;
  90. public:
  91. __declspec( dllexport ) DirectX9();
  92. __declspec( dllexport ) ~DirectX9();
  93. __declspec( dllexport ) void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
  94. __declspec( dllexport ) void update() override;
  95. __declspec( dllexport ) void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
  96. __declspec( dllexport ) void presentFrame() override;
  97. __declspec( dllexport ) Bild *zUIRenderBild() const override;
  98. };
  99. class DirectX11 : public GraphicsApi
  100. {
  101. private:
  102. ID3D11Device *d3d11Device;
  103. ID3D11DeviceContext *d3d11Context;
  104. IDXGISwapChain *d3d11SpawChain;
  105. Textur *uiTextur;
  106. VertexShader *vertexShader;
  107. PixelShader *pixelShader;
  108. ID3D11SamplerState *sampleState;
  109. ID3D11RenderTargetView *rtview;
  110. ID3D11DepthStencilView *dsView;
  111. ID3D11Texture2D *depthStencilBuffer;
  112. ID3D11DepthStencilState *depthStencilState;
  113. ID3D11DepthStencilState *depthDisabledStencilState;
  114. ID3D11BlendState *blendStateAlphaBlend;
  115. D3D11_VIEWPORT *vp;
  116. TexturModel *texturModel;
  117. TexturList *texturRegister;
  118. ID3D11RasterizerState *texturRS;
  119. ID3D11RasterizerState *meshRS;
  120. Textur *defaultTextur;
  121. DX11StructuredBuffer *diffuseLights;
  122. DX11StructuredBuffer *pointLights;
  123. DX11Buffer *vertexBuffer;
  124. DX11Buffer *indexBuffer;
  125. Mat4< float > matrixBuffer[ MAX_KNOCHEN_ANZ ];
  126. Mat4< float > viewAndProj[ 2 ];
  127. Vec3< float > kamPos;
  128. Ebene3D< float > frustrum[ 6 ];
  129. void renderObject( Model3D *zObj );
  130. // Überprüft, ob eine Kugel in dem Sichtbaren Raum der Welt liegt und gezeichnet werden muss
  131. // pos: Der Mittelpunkt der Kugel
  132. // radius: Der Radius der Kugel
  133. // 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
  134. bool isInFrustrum( const Vec3< float > &pos, float radius, float *dist = 0 ) const;
  135. public:
  136. __declspec( dllexport ) DirectX11();
  137. __declspec( dllexport ) ~DirectX11();
  138. __declspec( dllexport ) void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
  139. __declspec( dllexport ) void update() override;
  140. __declspec( dllexport ) void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
  141. __declspec( dllexport ) void renderKamera( Kam3D *zKamera ) override;
  142. __declspec( dllexport ) void presentFrame() override;
  143. __declspec( dllexport ) Textur *createOrGetTextur( const char *name, Bild *b ) override;
  144. __declspec( dllexport ) Bild *zUIRenderBild() const override;
  145. };
  146. class DirectX12 : public GraphicsApi
  147. {
  148. };
  149. }