Cogs.Core
IGraphicsDevice.h
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include "Common.h"
7#include "DataFormat.h"
8
9namespace Cogs
10{
11 struct IBuffers;
12 struct ICapabilities;
13 struct IContext;
14 struct IEffects;
15 struct IBindGroups;
16 struct IPipelineStates;
17 struct IRenderTargets;
18 struct ISyncObjects;
19 struct ITextures;
20 struct ResourceCountersWebGPU;
21 struct ResourceStatistics;
22 struct WindowData;
23
24 class ISwapChain;
25
30 {
32 None = 0x0000,
39 Debug = 1 << 0,
78
83 };
84
85 struct IIOHandler;
86
91 {
103
114
118 TextureFormat colorFormat = TextureFormat::R8G8B8A8_UNORM_SRGB;
119
123 TextureFormat depthFormat = TextureFormat::D32_FLOAT;
124
128 int numSamples = 1;
129
136
147
158 void ** sharedSurface = nullptr;
159
162
174 using RedrawRequestCallback = void(*)(void * userData);
175 RedrawRequestCallback redrawRequestCallback = nullptr;
176 void * redrawRequestCallbackUserData = nullptr;
177
187 };
188
191
196 {
197 public:
199 virtual ~IGraphicsDevice() = default;
200
204 virtual bool initializeThread() { return true; }
205
219 virtual SharedGraphicsContext * createSharedContext() { return nullptr; }
220
229
236
240 virtual bool initialize() = 0;
241
245 virtual bool isInitializationFinished() { return true; }
246
247 virtual ResourceCountersWebGPU getResourceCountersWebGPU();
248
249 virtual ResourceStatistics getResourceStatistics();
250
256 virtual std::string getIdentifier() const { return "Unknown"; }
257
264
271 virtual void setSize(int width, int height) = 0;
272
276 virtual bool getSize(int& width, int& height) const = 0;
277
281 virtual void beginFrame() = 0;
282
294 virtual void endFrame(uint32_t syncInterval = 0, PresentFlags presentFlags = PresentFlags::None) = 0;
295
300 virtual void waitForCommandSync() {}
301
305 virtual void releaseResources() = 0;
306
312 virtual ISwapChain* createSwapChain(struct WindowData* /*windowData*/) { return nullptr; }
313
317 virtual void deleteSwapChain(ISwapChain* /*swapChain*/) {}
318
325
331 virtual IBuffers * getBuffers() = 0;
332
338 virtual ITextures * getTextures() = 0;
339
346
352 virtual IEffects * getEffects() = 0;
353
354 virtual IBindGroups* getBindGroups() { return nullptr; } // TOSO: Should be pure virtual
355
362
369
376
383
384 virtual void* getNativeDevice() { return nullptr; }
385 virtual void* getNativeQueue() { return nullptr; }
386
394 virtual bool setSettings(const GraphicsDeviceSettings& newSettings) { settings = newSettings; return true; }
395
396 const GraphicsDeviceSettings & getSettings() const { return settings; }
397
402 void requestRedraw() const
403 {
404 if (settings.redrawRequestCallback) settings.redrawRequestCallback(settings.redrawRequestCallbackUserData);
405 }
406
407 // FIXME: Remove this function when WindowData will be moved to Cogs.Desktop.
411 static void fillGraphicsSettings(struct WindowData* windowData, int requestedSampleCount);
412
413 protected:
414 GraphicsDeviceSettings settings;
415 std::vector<ISwapChain*> swapChains;
416 };
417}
Represents a graphics device used to manage graphics resources and issue drawing commands.
virtual IEffects * getEffects()=0
Get a pointer to the effect management interface.
virtual ISyncObjects * getSyncObjects()=0
Get a pointer to the sync object management interface.
virtual void releaseSharedContext(SharedGraphicsContext *)
Releases the given shared context.
virtual ITextures * getTextures()=0
Get a pointer to the texture management interface.
void requestRedraw() const
Notifies the owning application (via GraphicsDeviceSettings::redrawRequestCallback,...
virtual void waitForCommandSync()
Wait for any GPU commands on the current device to finish before returning.
virtual ~IGraphicsDevice()=default
Destructor.
virtual void deleteSwapChain(ISwapChain *)
Deletes the specified swap chain.
virtual bool setSettings(const GraphicsDeviceSettings &newSettings)
Updates the settings associated with this device.
virtual ISwapChain * createSwapChain(struct WindowData *)
Create a new swap chain for the specified window.
virtual ICapabilities * getCapabilities()=0
Get a pointer to the capability management interface used to query the graphics device capability fla...
virtual IContext * getImmediateContext()=0
Get a pointer to the immediate context used to issue commands to the graphics device.
virtual void releaseResources()=0
Release all resources allocated.
virtual void beginFrame()=0
Signal the beginning of a new frame to the graphics device.
virtual void activateSharedContext(SharedGraphicsContext *)
Activates the given shared context on the calling thread.
virtual bool isInitializationFinished()
Check if async initialization is finished.
static void fillGraphicsSettings(struct WindowData *windowData, int requestedSampleCount)
Set platform specific graphics settings used for window creation e.g.: XVisualInfo on Linux.
virtual IBuffers * getBuffers()=0
Get a pointer to the buffer management interface.
virtual std::string getIdentifier() const
Get the graphics device identifier.
virtual bool initialize()=0
Initializes the graphics device with the settings previous set through calling setSettings.
virtual GraphicsDeviceType getType() const
Get the type of the graphics device.
virtual bool getSize(int &width, int &height) const =0
Retrieve the size previously set by setSize.
virtual void setSize(int width, int height)=0
Set the size of the main drawing buffer used by the graphics device in pixels.
virtual void endFrame(uint32_t syncInterval=0, PresentFlags presentFlags=PresentFlags::None)=0
Signal the end of a frame to the graphics device.
virtual SharedGraphicsContext * createSharedContext()
Create a shared graphics context that can be used to activate another thread for rendering.
virtual IRenderTargets * getRenderTargets()=0
Get a pointer to the render target management interface.
virtual ISwapChain * getDefaultSwapChain()=0
Get a pointer to the default swap chain for this graphics device.
virtual IPipelineStates * getPipelineStates()=0
Get a pointer to the pipeline state management interface.
virtual bool initializeThread()
Initialize the graphics device for operation on the current thread.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
GraphicsDeviceType
Contains types of graphics devices that may be supported.
Definition: Base.h:48
@ Unknown
Unknown type of graphics device.
PresentFlags
Flags controlling presentation.
Definition: Common.h:166
GraphicsDeviceFlags
Flags controlling the behavior of a graphics device.
@ ForceSoftwareRendering
Force software rendering.
@ UseESCompatibility
Instead of creating an ES2 context via WGL, create a full GL context and check for ARB_ES2_compatibil...
@ DumpShaderContents
Dump shader contents for debugging.
@ None
Default flags.
@ EnableDiagnostics
If available, the device will print diagnostic information to the log.
@ EnableShaderCache
Enables using a shader cache to avoid recompiling previously seen shaders.
@ UseOpenGLClipControl
For OpenGL / OpenGLES backends.
@ Debug
If available, the device will operate in debug mode, performing additional validation of input data,...
@ EnableTraceLogging
Enables trace logging.
@ UseSwapEffectDiscard
Under DX11 the default swap effect is FLIP_DISCARD, however there are some systems where this does no...
@ UseSharedSurface
Use shared surface for D3D9 interop.
Settings for graphics device initialization.
int featureLevelMajor
Major feature level.
TextureFormat depthFormat
Depth buffer format.
int numSamples
Number of samples to use for back buffer MSAA.
uint32_t fakeAsyncEffectLoadFrames
Testing aid: simulate asynchronous effect loading by delaying the number of frames given here before ...
void ** sharedSurface
Pointer to storage for a pointer to a shared surface.
struct WindowData * windowData
Native window handle used to initialize the graphics device.
int featureLevelMinor
Minor feature level.
int flags
Flags controlling the behavior of the graphics device.
IIOHandler * ioHandler
Optional pointer to an IO handler.
TextureFormat colorFormat
Back buffer format.
void(*)(void *userData) RedrawRequestCallback
Optional callback invoked when the device wants the owning application to re-run the frame loop and r...
Provides bind group management functionality.
Definition: IBindGroups.h:117
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:158
I/O handler.
Definition: IEffects.h:116
Provides render target management functionality.
Provides sync object management.
Definition: ISyncObjects.h:14
Provides texture management functionality.
Definition: ITextures.h:40