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 IPipelineStates;
16 struct IRenderTargets;
17 struct ISyncObjects;
18 struct ITextures;
19 struct ResourceCountersWebGPU;
20 struct ResourceStatistics;
21 struct WindowData;
22
23 class ISwapChain;
24
29 {
31 None = 0x0000,
38 Debug = 1 << 0,
77
82 };
83
84 struct IIOHandler;
85
90 {
102
113
117 TextureFormat colorFormat = TextureFormat::R8G8B8A8_UNORM_SRGB;
118
122 TextureFormat depthFormat = TextureFormat::D32_FLOAT;
123
127 int numSamples = 1;
128
135
146
157 void ** sharedSurface = nullptr;
158
161 };
162
165
170 {
171 public:
173 virtual ~IGraphicsDevice() = default;
174
178 virtual bool initializeThread() { return true; }
179
193 virtual SharedGraphicsContext * createSharedContext() { return nullptr; }
194
203
210
214 virtual bool initialize() = 0;
215
219 virtual bool isInitializationFinished() { return true; }
220
221 virtual ResourceCountersWebGPU getResourceCountersWebGPU();
222
223 virtual ResourceStatistics getResourceStatistics();
224
230 virtual std::string getIdentifier() const { return "Unknown"; }
231
238
245 virtual void setSize(int width, int height) = 0;
246
250 virtual bool getSize(int& width, int& height) const = 0;
251
255 virtual void beginFrame() = 0;
256
268 virtual void endFrame(uint32_t syncInterval = 0, PresentFlags presentFlags = PresentFlags::None) = 0;
269
274 virtual void waitForCommandSync() {}
275
279 virtual void releaseResources() = 0;
280
286 virtual ISwapChain* createSwapChain(struct WindowData* /*windowData*/) { return nullptr; }
287
291 virtual void deleteSwapChain(ISwapChain* /*swapChain*/) {}
292
299
305 virtual IBuffers * getBuffers() = 0;
306
312 virtual ITextures * getTextures() = 0;
313
320
326 virtual IEffects * getEffects() = 0;
327
334
341
348
355
356 virtual void* getNativeDevice() { return nullptr; }
357 virtual void* getNativeQueue() { return nullptr; }
358
366 virtual bool setSettings(const GraphicsDeviceSettings& newSettings) { settings = newSettings; return true; }
367
368 const GraphicsDeviceSettings & getSettings() const { return settings; }
369
370 // FIXME: Remove this function when WindowData will be moved to Cogs.Desktop.
374 static void fillGraphicsSettings(struct WindowData* windowData, int requestedSampleCount);
375
376 protected:
377 GraphicsDeviceSettings settings;
378 std::vector<ISwapChain*> swapChains;
379 };
380}
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.
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.
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.
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
I/O handler.
Definition: IEffects.h:106
Provides render target management functionality.
Provides sync object management.
Definition: ISyncObjects.h:14
Provides texture management functionality.
Definition: ITextures.h:40