DX11GraphicsApi.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #include "GraphicsApi.h"
  3. #include "Plane3D.h"
  4. //! DirectX 11 Types
  5. struct ID3D11Device;
  6. struct ID3D11DeviceContext;
  7. struct IDXGISwapChain;
  8. struct ID3D11Texture2D;
  9. struct ID3D11SamplerState;
  10. struct ID3D11ShaderResourceView;
  11. struct ID3D11RenderTargetView;
  12. struct ID3D11DepthStencilView;
  13. struct ID3D11DepthStencilState;
  14. struct ID3D11RasterizerState;
  15. struct ID3D11BlendState;
  16. struct D3D11_VIEWPORT;
  17. namespace Framework
  18. {
  19. class DX11StructuredBuffer;
  20. class DX11PixelShader;
  21. class DX11VertexShader;
  22. class DX11Buffer;
  23. class TextureList;
  24. class Model3D;
  25. class TextureModel;
  26. class DirectX11 : public GraphicsApi
  27. {
  28. private:
  29. ID3D11Device* d3d11Device;
  30. ID3D11DeviceContext* d3d11Context;
  31. IDXGISwapChain* d3d11SpawChain;
  32. Texture* uiTexture;
  33. DX11VertexShader* vertexShader;
  34. DX11PixelShader* pixelShader;
  35. ID3D11SamplerState* sampleState;
  36. ID3D11RenderTargetView* rtview;
  37. ID3D11DepthStencilView* dsView;
  38. ID3D11Texture2D* depthStencilBuffer;
  39. ID3D11DepthStencilState* depthStencilState;
  40. ID3D11DepthStencilState* depthDisabledStencilState;
  41. ID3D11BlendState* blendStateAlphaBlend;
  42. D3D11_VIEWPORT* vp;
  43. TextureModel* texturModel;
  44. TextureList* texturRegister;
  45. Texture* defaultTexture;
  46. DX11StructuredBuffer* diffuseLights;
  47. DX11StructuredBuffer* pointLights;
  48. Mat4<float> matrixBuffer[MAX_KNOCHEN_ANZ];
  49. Mat4<float> viewAndProj[2];
  50. Vec3<float> kamPos;
  51. Plane3D<float> frustrum[6];
  52. int lastModelId;
  53. DX11Buffer** indexBuffers;
  54. DX11Buffer** vertexBuffers;
  55. void renderObject(Model3D* zObj);
  56. DX11Buffer* createIndexBuffer();
  57. DX11Buffer* createVertexBuffer();
  58. protected:
  59. Critical deviceLock;
  60. ID3D11RasterizerState* texturRS;
  61. ID3D11RasterizerState* meshRS;
  62. DLLEXPORT virtual DX11VertexShader* initializeVertexShader(
  63. unsigned char* byteCode, int size);
  64. DLLEXPORT virtual DX11PixelShader* initializePixelShader(
  65. unsigned char* byteCode, int size);
  66. DLLEXPORT ID3D11DeviceContext* zContext();
  67. public:
  68. DLLEXPORT DirectX11();
  69. DLLEXPORT ~DirectX11();
  70. DLLEXPORT void initialize(NativeWindow* fenster,
  71. Vec2<int> backBufferSize,
  72. bool fullScreen) override;
  73. DLLEXPORT void beginFrame(
  74. bool fill2D, bool fill3D, int fillColor) override;
  75. DLLEXPORT void renderKamera(Cam3D* zKamera) override;
  76. DLLEXPORT void renderKamera(Cam3D* zKamera, Texture* zTarget) override;
  77. DLLEXPORT void presentFrame() override;
  78. DLLEXPORT Texture* createOrGetTexture(
  79. const char* name, Image* b, TextureDirection dir) override;
  80. DLLEXPORT Image* zUIRenderImage() const override;
  81. DLLEXPORT virtual DXBuffer* createStructuredBuffer(int eSize) override;
  82. DLLEXPORT virtual Model3DData* createModel(const char* name) override;
  83. //! Checks whether a sphere is in the visible space of the world and
  84. //! needs to be drawn \param pos The center of the sphere \param
  85. //! radius The radius of the sphere \param dist A pointer to a
  86. //! float where the square of the distance to the camera position
  87. //! is stored if this function returns true and the pointer is not 0
  88. DLLEXPORT bool isInFrustrum(
  89. const Vec3<float>& pos, float radius, float* dist = 0) const;
  90. DLLEXPORT bool isInFrustrum(
  91. const Vec3<float>& pos, Vec3<float> radius, float* dist = 0) const;
  92. DLLEXPORT static bool isAvailable();
  93. };
  94. } // namespace Framework