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 ResourceStatistics;
20 struct WindowData;
21
22 class ISwapChain;
23
28 {
30 None = 0x0000,
37 Debug = 1 << 0,
76
81 };
82
83 struct IIOHandler;
84
89 {
101
112
116 TextureFormat colorFormat = TextureFormat::R8G8B8A8_UNORM_SRGB;
117
121 TextureFormat depthFormat = TextureFormat::D32_FLOAT;
122
126 int numSamples = 1;
127
134
145
156 void ** sharedSurface = nullptr;
157
160 };
161
164
169 {
170 public:
172 virtual ~IGraphicsDevice() = default;
173
177 virtual bool initializeThread() { return true; }
178
192 virtual SharedGraphicsContext * createSharedContext() { return nullptr; }
193
202
209
213 virtual bool initialize() = 0;
214
218 virtual bool isInitializationFinished() { return true; }
219
220 virtual ResourceStatistics getResourceStatistics();
221
227 virtual std::string getIdentifier() const { return "Unknown"; }
228
235
242 virtual void setSize(int width, int height) = 0;
243
247 virtual bool getSize(int& width, int& height) const = 0;
248
252 virtual void beginFrame() = 0;
253
265 virtual void endFrame(uint32_t syncInterval = 0, uint32_t presentFlags = PresentFlags::None) = 0;
266
271 virtual void waitForCommandSync() {}
272
276 virtual void releaseResources() = 0;
277
283 virtual ISwapChain* createSwapChain(struct WindowData* /*windowData*/) { return nullptr; }
284
288 virtual void deleteSwapChain(ISwapChain* /*swapChain*/) {}
289
296
302 virtual IBuffers * getBuffers() = 0;
303
309 virtual ITextures * getTextures() = 0;
310
317
323 virtual IEffects * getEffects() = 0;
324
331
338
345
352
353 virtual void* getNativeDevice() { return nullptr; }
354
362 virtual bool setSettings(const GraphicsDeviceSettings& newSettings) { settings = newSettings; return true; }
363
364 const GraphicsDeviceSettings & getSettings() const { return settings; }
365
366 // FIXME: Remove this function when WindowData will be moved to Cogs.Desktop.
370 static void fillGraphicsSettings(struct WindowData* windowData, int requestedSampleCount);
371
372 protected:
373 GraphicsDeviceSettings settings;
374 std::vector<ISwapChain*> swapChains;
375 };
376}
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 void endFrame(uint32_t syncInterval=0, uint32_t presentFlags=PresentFlags::None)=0
Signal the end of a frame to the graphics device.
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 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.
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
@ None
No flags.
Definition: Common.h:177