Cogs.Core
GraphicsDeviceD3D12.h
1#pragma once
2
3#include "../IGraphicsDevice.h"
4
5#include <memory>
6
7#include "../Base/SyncObjectsCommon.h"
8
9#include "CommonD3D12.h"
10
11#include "CapabilitiesD3D12.h"
12#include "BuffersD3D12.h"
13#include "TexturesD3D12.h"
14#include "EffectsD3D12.h"
15#include "RenderTargetsD3D12.h"
16#include "SyncObjectsD3D12.h"
17#include "ContextD3D12.h"
18
19namespace Cogs
20{
22 {
23 public:
26
27 bool initialize();
28
29 std::string getIdentifier() const override { return "Direct3D12"; }
31
32 void beginFrame() override;
33 void endFrame(uint32_t syncInterval = 0, uint32_t presentFlags = PresentFlags::None) override;
34
35 void waitForPreviousFrame();
36
37 void releaseResources() override;
38
39 void setSize(int width, int height) override;
40 bool getSize(int& w, int& h) const override;
41 void setVerticalSync(bool enabled) { this->verticalSync = enabled; }
42
43 IBuffers * getBuffers() override { return (IBuffers *)&buffers; }
44 ITextures * getTextures() override { return (ITextures *)&textures; }
45 IContext * getImmediateContext() override { return (IContext *)&context; }
46 IEffects * getEffects() override { return (IEffects *)&effects; }
47 IPipelineStates* getPipelineStates() { return nullptr; }
48 IRenderTargets * getRenderTargets() override { return (IRenderTargets *)&renderTargets; }
49 ICapabilities * getCapabilities() override { return &capabilities; }
50 ISyncObjects* getSyncObjects() override { return &syncObjects; }
51 ISwapChain* getDefaultSwapChain() override { return nullptr; }
52
53 void waitForCommandSync() override;
54
55 void * getNativeDevice() override { return device; }
56
57 public:
58 HRESULT initializeDevice();
59 HRESULT initializeDeviceShared();
60 HRESULT initializeDeviceAndSwapChain();
61
62 HRESULT resizeSharedSurfaces();
63
64 HRESULT createRenderTargetView();
65 HRESULT createDepthStencilView();
66
67 int indexLastSwapBuf = 0;
68 const static int numSwapBufs = 2;
69 ResourcePointer<ID3D12Fence> deviceFence;
70 UINT64 currentFence = 0;
71 HANDLE eventHandle = nullptr;
72
73 ResourcePointer<ID3D12Device> device;
74 ResourcePointer<IDXGISwapChain> swapChain;
75 ResourcePointer<ID3D12CommandQueue> commandQueue;
76
77 RenderTargetHandle renderTarget[numSwapBufs];
78 DepthStencilHandle depthTarget;
79 TextureHandle depthTexture;
80
81 ResourcePointer<ID3D12Resource> multisampleBackBuffer;
82
83 ContextD3D12 context;
84 CapabilitiesD3D12 capabilities;
85 BuffersD3D12 buffers;
86 TexturesD3D12 textures;
87 EffectsD3D12 effects;
88 RenderTargetsD3D12 renderTargets;
89 SyncObjectsD3D12 syncObjects;
90
91 int width, height;
92
93 bool fullscreenMode = false;
94 bool verticalSync = true;
95 };
96}
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
@ Direct3D12
Graphics device using the Direct3D 12 API.
void waitForCommandSync() override
Wait for any GPU commands on the current device to finish before returning.
IBuffers * getBuffers() override
Get a pointer to the buffer management interface.
ICapabilities * getCapabilities() override
Get a pointer to the capability management interface used to query the graphics device capability fla...
IPipelineStates * getPipelineStates()
Get a pointer to the pipeline state management interface.
ISwapChain * getDefaultSwapChain() override
Get a pointer to the default swap chain for this graphics device.
std::string getIdentifier() const override
Get the graphics device identifier.
void beginFrame() override
Signal the beginning of a new frame to the graphics device.
IRenderTargets * getRenderTargets() override
Get a pointer to the render target management interface.
IContext * getImmediateContext() override
Get a pointer to the immediate context used to issue commands to the graphics device.
bool initialize()
Initializes the graphics device with the settings previous set through calling setSettings.
void releaseResources() override
Release all resources allocated.
void endFrame(uint32_t syncInterval=0, uint32_t presentFlags=PresentFlags::None) override
Signal the end of a frame to the graphics device.
void setSize(int width, int height) override
Set the size of the main drawing buffer used by the graphics device in pixels.
ISyncObjects * getSyncObjects() override
Get a pointer to the sync object management interface.
bool getSize(int &w, int &h) const override
Retrieve the size previously set by setSize.
GraphicsDeviceType getType() const override
Get the type of the graphics device.
ITextures * getTextures() override
Get a pointer to the texture management interface.
IEffects * getEffects() override
Get a pointer to the effect management interface.
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