Cogs.Core
GraphicsDeviceD3D11.h
1#pragma once
2
3#include "../IGraphicsDevice.h"
4
5#include "BuffersD3D11.h"
6#include "CapabilitiesD3D11.h"
7#include "ContextD3D11.h"
8#include "EffectsD3D11.h"
9#include "RenderTargetsD3D11.h"
10#include "SwapChainD3D11.h"
11#include "TexturesD3D11.h"
12#include "SyncObjectsD3D11.h"
13
14#include "Foundation/Memory/Allocator.h"
15
16namespace Cogs
17{
19 {
20 public:
22 ~GraphicsDeviceD3D11() = default;
23
24 bool initialize();
25
26 std::string getIdentifier() const override { return "Direct3D11"; }
28
29 void beginFrame();
30 void endFrame(uint32_t syncInterval = 0, uint32_t presentFlags = PresentFlags::None);
31
32 void releaseResources();
33
34 virtual ISwapChain* createSwapChain(struct WindowData* windowData) override;
35 virtual void deleteSwapChain(ISwapChain* swapChain) override;
36
37 void setSize(int newWidth, int newHeight);
38 bool getSize(int& w, int& h) const override;
39 bool resizeSharedSurfaces();
40
41 IBuffers * getBuffers() { return &buffers; }
42 ITextures * getTextures() { return &textures; }
43 IContext * getImmediateContext() { return &context; }
44 IEffects * getEffects() { return &effects; }
45 IPipelineStates* getPipelineStates() { return nullptr; }
46 IRenderTargets * getRenderTargets() { return &renderTargets; }
47 ICapabilities * getCapabilities() { return &capabilities; }
48 ISyncObjects* getSyncObjects() override { return &syncObjects; }
49 SwapChainD3D11 * getDefaultSwapChain() override { return &defaultSwapChain; }
50
51 virtual void* getNativeDevice() override { return device; }
52 ResourcePointer<ID3D11Device>& getDevice() { return device; }
53 Memory::Allocator * getResourceAllocator() { return resourceAllocator.get(); }
54 ResourceStatistics getResourceStatistics() override;
55
56 private:
57 bool initializeDeviceAndSwapChain();
58 bool initializeDeviceShared();
59
60 void setupDebugging();
61
62 // Note: Allocator needs to be declared _before_ resources, so it
63 // is destroyed _after_ the resources (that uses this allocator)
64 // has been destroyed.
65 std::unique_ptr<Memory::Allocator> resourceAllocator;
66
67#ifdef COGS_RENDERING_D3D9SUPPORT
68 std::unique_ptr<struct SharedResources> sharedResources;
69#endif
70
71 ResourcePointer<ID3D11Device> device;
72 ResourcePointer<ID3D11Device1> device1;
73 ResourcePointer<ID3D11Device5> device5;
74 ResourcePointer<ID3D11InfoQueue> infoQueue;
75
76 SwapChainD3D11 defaultSwapChain;
77 ContextD3D11 context;
78 CapabilitiesD3D11 capabilities;
79 BuffersD3D11 buffers;
80 TexturesD3D11 textures;
81 EffectsD3D11 effects;
82 RenderTargetsD3D11 renderTargets;
83 SyncObjectsD3D11 syncObjects;
84
85 bool inFrame = false;
86
87 HRESULT createDevice(IDXGIAdapter* adapter,
88 D3D_DRIVER_TYPE driverType,
89 UINT flags,
90 const std::vector<D3D_FEATURE_LEVEL>& featureLevelsRequested,
91 D3D_FEATURE_LEVEL& apiFeatureLevel);
92 };
93}
Represents a graphics device used to manage graphics resources and issue drawing commands.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
GraphicsDeviceType
Contains types of graphics devices that may be supported.
Definition: Base.h:48
@ Direct3D11
Graphics device using the Direct3D 11 API.
ITextures * getTextures()
Get a pointer to the texture management interface.
bool initialize()
Initializes the graphics device with the settings previous set through calling setSettings.
SwapChainD3D11 * getDefaultSwapChain() override
Get a pointer to the default swap chain for this graphics device.
IPipelineStates * getPipelineStates()
Get a pointer to the pipeline state management interface.
ICapabilities * getCapabilities()
Get a pointer to the capability management interface used to query the graphics device capability fla...
void setSize(int newWidth, int newHeight)
Set the size of the main drawing buffer used by the graphics device in pixels.
IBuffers * getBuffers()
Get a pointer to the buffer management interface.
ISyncObjects * getSyncObjects() override
Get a pointer to the sync object management interface.
IContext * getImmediateContext()
Get a pointer to the immediate context used to issue commands to the graphics device.
void beginFrame()
Signal the beginning of a new frame to the graphics device.
IRenderTargets * getRenderTargets()
Get a pointer to the render target management interface.
IEffects * getEffects()
Get a pointer to the effect management interface.
void endFrame(uint32_t syncInterval=0, uint32_t presentFlags=PresentFlags::None)
Signal the end of a frame to the graphics device.
virtual ISwapChain * createSwapChain(struct WindowData *windowData) override
Create a new swap chain for the specified window.
void releaseResources()
Release all resources allocated.
GraphicsDeviceType getType() const override
Get the type of the graphics device.
virtual void deleteSwapChain(ISwapChain *swapChain) override
Deletes the specified swap chain.
bool getSize(int &w, int &h) const override
Retrieve the size previously set by setSize.
std::string getIdentifier() const override
Get the graphics device identifier.
Provides buffer management functionality.
Definition: IBuffers.h:13
Provides capability query functionality.
Represents a graphics device context which can receive rendering commands.
Definition: IContext.h:43
Provides effects and shader management functionality.
Definition: IEffects.h:148
Provides render target management functionality.
Provides sync object management.
Definition: ISyncObjects.h:14
Provides texture management functionality.
Definition: ITextures.h:40
@ None
No flags.
Definition: Common.h:177
Allocation information.
Definition: Base.h:35