GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::graphics::Device Class Reference

Persistent system managing the rendering context of a Window. More...

#include <GREM/graphics/Device.hpp>

Classes

struct  PresentationSubmission
 Information about a frame that has been submitted for presentation. More...

Public Member Functions

 Device (Window &window, const DeviceOptions &options={})
 Construct a device.
 Device (Filesystem &filesystem, Window &window, const DeviceOptions &options={})
 Construct a device with an associated filesystem, allowing for graphics pipelines to be cached.
 ~Device ()
 Destructor.
 Device (const Device &)=delete
 Copying a device is not allowed.
 Device (Device &&)=delete
 Moving a device is not allowed.
Device & operator= (const Device &)=delete
 Copying a device is not allowed.
Device & operator= (Device &&)=delete
 Moving a device is not allowed.
void blit (TextureRegion2DReference renderTarget, TextureRegion2DConstReference renderSource, TextureFilter filter)
 Copy and paste a rectangular region of a texture onto a region of another texture.
void blit (TextureSubresourceReference renderTarget, Offset2D targetOffset, TextureRegion2DConstReference renderSource)
 Copy and paste a rectangular region of a texture at its original size onto another texture at a specific offset.
void blit (TextureSubresourceReference renderTarget, TextureRegion2DConstReference renderSource)
 Copy and paste a rectangular region of a texture at its original size onto another texture at its bottom left corner.
void render (const RenderPass &renderPass)
 Submit a list of graphics commands to be rendered.
void await () noexcept
 Wait for all submitted graphics commands to finish being rendered and presented.
bool awaitPresentation (const Swapchain &swapchain, PresentationSubmissionID presentationSubmissionID, Duration timeout={}) noexcept
 Wait for a specific frame to finish being rendered and presented.
PresentationSubmission present (Swapchain &swapchain)
 Submit the current back buffer of a swapchain for display to its associated window, and acquire the next back buffer frame of the swapchain for subsequent rendering.
const FeatureSupport & getSupportedFeatures () const noexcept
 Get the features supported by the device.
DeviceImplementation * get () noexcept
 Get a pointer to the underlying resource implementation.
const DeviceImplementation * get () const noexcept
 Get a pointer to the underlying resource implementation.

Detailed Description

Persistent system managing the rendering context of a Window.

An instance of this class should typically be kept throughout the lifetime of the application in order to continuously render the visual state of the latest produced frame through the application::Application::display() callback.

Constructor & Destructor Documentation

◆ Device() [1/4]

grem::graphics::Device::Device ( Window & window,
const DeviceOptions & options = {} )
explicit

Construct a device.

Parameters
windowwindow for which to manage the rendering context, and to which frames presented through this device will be rendered. Must outlive the device.
optionsinitial configuration of the device, see DeviceOptions.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ Device() [2/4]

grem::graphics::Device::Device ( Filesystem & filesystem,
Window & window,
const DeviceOptions & options = {} )

Construct a device with an associated filesystem, allowing for graphics pipelines to be cached.

Parameters
filesystemfilesystem to load the shader and graphics pipeline caches from, and save the caches to, when the device is destroyed, if caching is supported by the implementation.
windowwindow for which to manage the rendering context, and to which frames presented through this device will be rendered. Must outlive the device.
optionsinitial configuration of the device, see DeviceOptions.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
Loading/saving the pipeline cache might silently fail if the file doesn't exist or couldn't be written.

◆ ~Device()

grem::graphics::Device::~Device ( )

Destructor.

◆ Device() [3/4]

grem::graphics::Device::Device ( const Device & )
delete

Copying a device is not allowed.

◆ Device() [4/4]

grem::graphics::Device::Device ( Device && )
delete

Moving a device is not allowed.

Member Function Documentation

◆ operator=() [1/2]

Device & grem::graphics::Device::operator= ( const Device & )
delete

Copying a device is not allowed.

◆ operator=() [2/2]

Device & grem::graphics::Device::operator= ( Device && )
delete

Moving a device is not allowed.

◆ blit() [1/3]

void grem::graphics::Device::blit ( TextureRegion2DReference renderTarget,
TextureRegion2DConstReference renderSource,
TextureFilter filter )

Copy and paste a rectangular region of a texture onto a region of another texture.

Parameters
renderTargettarget region to paste to. Must reference a valid region of a non-multisampled texture.
renderSourcesource region to copy from. Must reference a valid region of a non-multisampled texture.
filtertexture filtering method to use if the target and source extents don't match.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
Use the unscaled version of blit() instead to allow for multisampled textures.

◆ blit() [2/3]

void grem::graphics::Device::blit ( TextureSubresourceReference renderTarget,
Offset2D targetOffset,
TextureRegion2DConstReference renderSource )

Copy and paste a rectangular region of a texture at its original size onto another texture at a specific offset.

Parameters
renderTargettarget to paste to. Must reference a valid subresource of a valid texture.
targetOffsetoffset, in texels, from the bottom left corner of the target texture at which to paste the copied texture region.
renderSourcesource region to copy from. Must reference a valid region of a valid texture that fits into the render target at the specified offset.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
This version of blit() may be used to resolve a multisampled texture into a non-multisampled one. However, for better performance, it should generally be preferred to use a resolve render target directly in the render pass that performed the multisampling instead.
Warning
If the source texture is multisampled and the target texture is not, the target and source textures must have the same texture format.

◆ blit() [3/3]

void grem::graphics::Device::blit ( TextureSubresourceReference renderTarget,
TextureRegion2DConstReference renderSource )
inline

Copy and paste a rectangular region of a texture at its original size onto another texture at its bottom left corner.

Parameters
renderTargettarget to paste to. Must reference a valid subresource of a valid texture.
renderSourcesource region to copy from. Must reference a valid region of a valid texture that fits into the render target.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
This version of blit() may be used to resolve a multisampled texture into a non-multisampled one. However, for better performance, it should generally be preferred to use a resolve render target directly in the render pass that performed the multisampling instead.
Warning
If the source texture is multisampled and the target texture is not, the target and source textures must have the same texture format.

◆ render()

void grem::graphics::Device::render ( const RenderPass & renderPass)

Submit a list of graphics commands to be rendered.

Parameters
renderPasslist of commands to execute.
Exceptions
graphics::Erroron failure to render the render pass.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ await()

void grem::graphics::Device::await ( )
noexcept

Wait for all submitted graphics commands to finish being rendered and presented.

◆ awaitPresentation()

bool grem::graphics::Device::awaitPresentation ( const Swapchain & swapchain,
PresentationSubmissionID presentationSubmissionID,
Duration timeout = {} )
noexcept

Wait for a specific frame to finish being rendered and presented.

Parameters
swapchainswapchain that the frame was presented to.
presentationSubmissionIDidentifier for the frame to wait for. Must be a valid identifier acquired from a call to present() on this device with the given swapchain.
timeoutmaximum duration to wait before returning early, or a non-positive value for an infinite timeout.
Returns
true if the frame was successfully awaited, false otherwise.
Note
This function requires frame waiting to be supported, which can be queried using device.getSupportedFeatures().supportsAwaitPresentation. If the feature is not supported, awaitPresentation() will immediately return false.

◆ present()

PresentationSubmission grem::graphics::Device::present ( Swapchain & swapchain)

Submit the current back buffer of a swapchain for display to its associated window, and acquire the next back buffer frame of the swapchain for subsequent rendering.

Parameters
swapchainswapchain to present the back buffer of.
Exceptions
graphics::Erroron failure to acquire the next frame.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Returns
information about the submitted frame.

◆ getSupportedFeatures()

const FeatureSupport & grem::graphics::Device::getSupportedFeatures ( ) const
nodiscardnoexcept

Get the features supported by the device.

Returns
a read-only reference to the supported features.

◆ get() [1/2]

DeviceImplementation * grem::graphics::Device::get ( )
inlinenodiscardnoexcept

Get a pointer to the underlying resource implementation.

Returns
a non-owning pointer to the underlying resource.
Note
The type of the returned resource is backend-specific and has no meaning to application code.

◆ get() [2/2]

const DeviceImplementation * grem::graphics::Device::get ( ) const
inlinenodiscardnoexcept

Get a pointer to the underlying resource implementation.

Returns
a non-owning read-only pointer to the underlying resource.
Note
The type of the returned resource is backend-specific and has no meaning to application code.

The documentation for this class was generated from the following file: