Ocular Engine
D3D11GraphicsDriver.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_D3D11_GRAPHICS_DRIVER__H__
19 #define __H__OCULAR_D3D11_GRAPHICS_DRIVER__H__
20 
21 #define OCULAR_D3D_11_0 100
22 #define OCULAR_D3D_11_1 200
23 #define OCULAR_D3D_11_2 300
24 
25 #if OCULAR_D3D_11_VERSION > 200
26 #define OCULAR_D3D_USE_11_2
27 #elif OCULAR_D3D11_VERSION > 100
28 #define OCULAR_D3D_USE_11_1
29 #else
30 #define OCULAR_D3D_USE_11_0
31 #endif
32 
33 //------------------------------------------------------------------------------------------
34 
35 #include "Graphics/GraphicsDriver.hpp"
36 #include "Events/AEventListener.hpp"
37 
38 #if defined(OCULAR_D3D_USE_11_0)
39 #include <d3d11.h>
40 #elif defined(OCULAR_D3D_USE_11_1)
41 #include <d3d11_1.h>
42 #elif defined(OCULAR_D3D_USE_11_2)
43 #include <d3d11_2.h>
44 #endif
45 
46 #if defined(OCULAR_D3D_USE_11_0)
47 using OD3D11Device = ID3D11Device;
48 using OD3D11DeviceContext = ID3D11DeviceContext;
49 using OD3DSwapChain = IDXGISwapChain;
50 #elif defined(OCULAR_D3D_USE_11_1)
51 using OD3D11Device = ID3D11Device1;
52 using OD3D11DeviceContext = ID3D11DeviceContext1;
53 using OD3DSwapChain = IDXGISwapChain1;
54 #elif defined(OCULAR_D3D_USE_11_2)
55 using OD3D11Device = ID3D11Device2;
56 using OD3D11DeviceContext = ID3D11DeviceContext2;
57 using OD3DSwapChain = IDXGISwapChain1;
58 #endif
59 
60 //------------------------------------------------------------------------------------------
61 
66 namespace Ocular
67 {
68  namespace Core
69  {
70  class AWindow;
71  class WindowWin32;
72  }
73 
78  namespace Graphics
79  {
84  {
85  public:
86 
89 
90  //------------------------------------------------------------
91  // Inherited Methods
92 
93  virtual bool initialize() override;
94 
95  virtual void clearBuffers(Core::Color const& clearColor = Core::Color::DefaultClearGray()) override;
96  virtual void clearDepthBuffer(float value = 1.0f) override;
97  virtual void clearStencilBuffer(uint32_t value = 0) override;
98  virtual void swapBuffers() override;
99 
100  virtual void setRenderTexture(RenderTexture* texture) override;
101  virtual void setDepthTexture(DepthTexture* texture) override;
102 
103  virtual Material* createMaterial() const override;
104  virtual Viewport* createViewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f) const override;
105 
106  virtual Texture* createTexture(TextureDescriptor const& descriptor) const override;
107  virtual Texture2D* createTexture2D(TextureDescriptor const& descriptor) const override;
108  virtual RenderTexture* createRenderTexture(TextureDescriptor const& descriptor) const override;
109  virtual DepthTexture* createDepthTexture(TextureDescriptor const& descriptor) const override;
110  virtual uint32_t getMaxBoundTextures() const override;
111 
112  virtual VertexShader* createVertexShader() const override;
113  virtual GeometryShader* createGeometryShader() const override;
114  virtual FragmentShader* createFragmentShader() const override;
115  virtual PreTessellationShader* createPreTessellationShader() const override;
116  virtual PostTessellationShader* createPostTessellationShader() const override;
117 
118  virtual UniformBuffer* createUniformBuffer(UniformBufferType type) const override;
119  virtual IndexBuffer* createIndexBuffer() const override;
120  virtual VertexBuffer* createVertexBuffer() const override;
121  virtual GPUBuffer* createGPUBuffer(GPUBufferDescriptor const& descriptor) const override;
122 
123  virtual bool renderMesh(Mesh* mesh, uint32_t submesh = 0) override;
124  virtual bool renderBounds(Core::SceneObject* object, Math::BoundsType type) override;
125 
126  //------------------------------------------------------------
127  // D3D Specific Methods
128 
129  OD3D11Device* getD3DDevice() const;
130  OD3D11DeviceContext* getD3DDeviceContext() const;
131  OD3DSwapChain* getD3DSwapChain() const;
132 
133  static bool ConvertTextureDescriptor(TextureDescriptor const& source, D3D11_TEXTURE2D_DESC& dest);
134  static bool ConvertTextureDescriptor(D3D11_TEXTURE2D_DESC const& source, TextureDescriptor& dest);
135 
136  protected:
137 
138  virtual bool onEvent(std::shared_ptr<Core::AEvent> event) override;
139  void resizeSwapChain(uint32_t width, uint32_t height);
140 
141  bool validateWindow(std::shared_ptr<Core::AWindow> window, HWND& hwnd) const;
142  bool createDeviceAndSwapChain(Core::WindowWin32 const* window, HWND const hwnd);
143 
144 #if defined(OCULAR_D3D_USE_11_0)
145  DXGI_SWAP_CHAIN_DESC createSwapChainDescription(Core::WindowWin32 const* window) const;
146 #else
147  DXGI_SWAP_CHAIN_DESC1 createSwapChainDescription(Core::WindowWin32 const* window) const;
148 #endif
149 
150  bool fetchDeviceAndSwapChain1(ID3D11Device* device, ID3D11DeviceContext* context, Core::WindowWin32 const* window);
151  bool fetchDeviceAndSwapChain2(ID3D11Device* device, ID3D11DeviceContext* context, Core::WindowWin32 const* window);
152 
153  static bool ValidateTextureDescriptor(TextureDescriptor const& descriptor);
154 
155  void printD3DDebug();
156 
157  private:
158 
159  OD3D11Device* m_D3DDevice;
160  OD3D11DeviceContext* m_D3DDeviceContext;
161  OD3DSwapChain* m_D3DSwapChain;
162  };
163  }
167 }
172 //------------------------------------------------------------------------------------------
173 
174 #endif
Definition: VertexBuffer.hpp:78
virtual void clearDepthBuffer(float value=1.0f) override
Definition: D3D11GraphicsDriver.cpp:214
virtual void setRenderTexture(RenderTexture *texture) override
Definition: D3D11GraphicsDriver.cpp:292
Definition: Texture2D.hpp:45
static bool ValidateTextureDescriptor(TextureDescriptor const &descriptor)
Definition: D3D11GraphicsDriver.cpp:1448
Definition: FragmentShader.hpp:40
Definition: VertexShader.hpp:40
virtual GPUBuffer * createGPUBuffer(GPUBufferDescriptor const &descriptor) const override
Definition: D3D11GraphicsDriver.cpp:487
virtual IndexBuffer * createIndexBuffer() const override
Definition: D3D11GraphicsDriver.cpp:477
A special texture that stores high precision depth information for each pixel.
Definition: DepthTexture.hpp:41
A special texture that can be rendered directly to.
Definition: RenderTexture.hpp:41
virtual Texture * createTexture(TextureDescriptor const &descriptor) const override
Definition: D3D11GraphicsDriver.cpp:360
Definition: D3D11GraphicsDriver.hpp:83
Definition: AEventListener.hpp:43
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
Definition: PreTessellationShader.hpp:40
virtual Material * createMaterial() const override
Definition: D3D11GraphicsDriver.cpp:346
Definition: Color.hpp:40
virtual bool renderBounds(Core::SceneObject *object, Math::BoundsType type) override
Definition: D3D11GraphicsDriver.cpp:530
Combination of a VertexBuffer and IndexBuffer.
Definition: Mesh.hpp:49
Definition: TextureDescriptor.hpp:45
virtual RenderTexture * createRenderTexture(TextureDescriptor const &descriptor) const override
Definition: D3D11GraphicsDriver.cpp:402
static Color const & DefaultClearGray()
Definition: Color.cpp:173
A generic buffer that can be uploaded to the GPU.
Definition: GPUBuffer.hpp:81
virtual void swapBuffers() override
Definition: D3D11GraphicsDriver.cpp:260
virtual VertexBuffer * createVertexBuffer() const override
Definition: D3D11GraphicsDriver.cpp:482
Definition: SceneObject.hpp:93
virtual DepthTexture * createDepthTexture(TextureDescriptor const &descriptor) const override
Definition: D3D11GraphicsDriver.cpp:418
Definition: GPUBuffer.hpp:62
virtual VertexShader * createVertexShader() const override
Definition: D3D11GraphicsDriver.cpp:443
virtual UniformBuffer * createUniformBuffer(UniformBufferType type) const override
Definition: D3D11GraphicsDriver.cpp:472
virtual Texture2D * createTexture2D(TextureDescriptor const &descriptor) const override
Definition: D3D11GraphicsDriver.cpp:386
virtual PostTessellationShader * createPostTessellationShader() const override
Definition: D3D11GraphicsDriver.cpp:463
virtual FragmentShader * createFragmentShader() const override
Definition: D3D11GraphicsDriver.cpp:453
Definition: IndexBuffer.hpp:77
Definition: PostTessellationShader.hpp:40
virtual uint32_t getMaxBoundTextures() const override
Definition: D3D11GraphicsDriver.cpp:434
Definition: Viewport.hpp:40
virtual PreTessellationShader * createPreTessellationShader() const override
Definition: D3D11GraphicsDriver.cpp:458
virtual void clearBuffers(Core::Color const &clearColor=Core::Color::DefaultClearGray()) override
Definition: D3D11GraphicsDriver.cpp:182
virtual GeometryShader * createGeometryShader() const override
Definition: D3D11GraphicsDriver.cpp:448
Generic buffer for storing and binding of shader uniforms.
Definition: UniformBuffer.hpp:73
virtual bool renderMesh(Mesh *mesh, uint32_t submesh=0) override
Definition: D3D11GraphicsDriver.cpp:503
virtual void setDepthTexture(DepthTexture *texture) override
Definition: D3D11GraphicsDriver.cpp:319
virtual void clearStencilBuffer(uint32_t value=0) override
Definition: D3D11GraphicsDriver.cpp:237
virtual bool initialize() override
Definition: D3D11GraphicsDriver.cpp:99
Definition: GeometryShader.hpp:40
Definition: Material.hpp:62
Base class for all texture objects.
Definition: Texture.hpp:45
Definition: GraphicsDriver.hpp:59