coastline 0.0.4
Loading...
Searching...
No Matches
coastline::GpuWindow Class Reference

The window of the game and the GPU device that draws into it. More...

#include <gpu.h>

Public Types

using OutputOverlay
 Draw directly over the output texture after scaling and screen filters.

Public Member Functions

 ~GpuWindow ()
 Release presentation resources and the window after all device-dependent users.
 GpuWindow (const GpuWindow &)=delete
 Prevent copying the window and GPU device.
GpuWindow & operator= (const GpuWindow &)=delete
 Prevent assignment of the window and GPU device.
bool WideMenus () const
float FieldOfViewScale () const
float DrawDistanceScale () const
bool N64Effects () const
bool N64WindowReflections () const
bool ApplyLiveOptions (const DisplayOptions &options)
 Apply camera, particle, frame-size, post-processing, and pacing settings between frames.
bool ApplyRendererOptions (const DisplayOptions &options)
 Update sampling and texture filtering, then apply live settings.
SDL_Window * Window () const
SDL_GPUDevice * Device () const
Uint64 GpuMemoryBytes () const
std::string DeviceName () const
const std::string & GpuPreference () const
bool NvmlAllowed () const
float AspectRatio () const
void SetFramerateUnlocked (bool unlocked)
 Set uncapped presentation while retaining the configured present mode.
bool FramerateUnlocked () const
Uint64 PresentationWaitNanoseconds () const
bool Fullscreen () const
bool SetFullscreen (bool fullscreen)
 Cover the display, at the desktop mode or the exclusive mode of the options, or return to a window.
SDL_GPUPresentMode PresentMode () const
void SetPresentMode (SDL_GPUPresentMode mode)
 Present the frames with mode, with the other mode that does not wait and then vertical sync in the place of a mode the window does not support.
Uint64 RefreshPeriod () const
bool PresentClear (SDL_FColor color, const std::filesystem::path *capture=nullptr)
 Clear the frame texture to color, present it, and save it when capture is given.
bool Present (SDL_GPUCommandBuffer *commands, const std::filesystem::path *capture=nullptr, const OutputOverlay &overlay={})
 Scale the frame texture to the window and submit commands, which drew the frame.
SDL_GPUTexture * FrameTexture () const
Uint32 FrameWidth () const
Uint32 FrameHeight () const
void UpdateFrameSize ()
 Give the frame the size of the window in pixels times the render scale, or the size of the options, recreating the frame texture when the size changes.
int Antialias () const
TextureFilter Filter () const
bool AlphaToCoverage () const
int Anisotropy () const

Static Public Member Functions

static std::unique_ptr< GpuWindow > Create (const char *title, const DisplayOptions &options)
 Create the window, a GPU device for it, and the frame texture.
static constexpr SDL_GPUTextureFormat FrameFormat ()

Friends

SDL_GPUTexture * CreateGpuTexture (SDL_GPUDevice *device, const SDL_GPUTextureCreateInfo *info)
 SDL_CreateGPUTexture(), recording bytes of every level and sample in GpuWindow::GpuMemoryBytes().
SDL_GPUBuffer * CreateGpuBuffer (SDL_GPUDevice *device, const SDL_GPUBufferCreateInfo *info)
 SDL_CreateGPUBuffer(), recording its size in GpuWindow::GpuMemoryBytes().
SDL_GPUTransferBuffer * CreateGpuTransferBuffer (SDL_GPUDevice *device, const SDL_GPUTransferBufferCreateInfo *info)
 SDL_CreateGPUTransferBuffer(), recording its size in GpuWindow::GpuMemoryBytes().
void ReleaseGpuTexture (SDL_GPUDevice *device, SDL_GPUTexture *texture)
 SDL_ReleaseGPUTexture(), subtracting its bytes from GpuWindow::GpuMemoryBytes().
void ReleaseGpuBuffer (SDL_GPUDevice *device, SDL_GPUBuffer *buffer)
 SDL_ReleaseGPUBuffer(), subtracting its bytes from GpuWindow::GpuMemoryBytes().
void ReleaseGpuTransferBuffer (SDL_GPUDevice *device, SDL_GPUTransferBuffer *buffer)
 SDL_ReleaseGPUTransferBuffer(), subtracting its bytes from GpuWindow::GpuMemoryBytes().

Detailed Description

The window of the game and the GPU device that draws into it.

Each frame is drawn into a texture of its own, which is scaled to the window when presented and can be read back.

Member Typedef Documentation

◆ OutputOverlay

Initial value:
std::function<void(SDL_GPUCommandBuffer *, SDL_GPUTexture *, Uint32, Uint32)>

Draw directly over the output texture after scaling and screen filters.

Constructor & Destructor Documentation

◆ ~GpuWindow()

coastline::GpuWindow::~GpuWindow ( )

Release presentation resources and the window after all device-dependent users.

◆ GpuWindow()

coastline::GpuWindow::GpuWindow ( const GpuWindow & )
delete

Prevent copying the window and GPU device.

Member Function Documentation

◆ Create()

std::unique_ptr< GpuWindow > coastline::GpuWindow::Create ( const char * title,
const DisplayOptions & options )
static

Create the window, a GPU device for it, and the frame texture.

Parameters
titleThe title of the window.
optionsThe size and the driver.
Returns
The window, or nothing with the reason logged.

◆ operator=()

GpuWindow & coastline::GpuWindow::operator= ( const GpuWindow & )
delete

Prevent assignment of the window and GPU device.

◆ WideMenus()

bool coastline::GpuWindow::WideMenus ( ) const
Returns
Whether wide menu background rendering is enabled. Automatic mode requires a 16:9 internal frame, allowing at most one pixel of width rounding error.

◆ FieldOfViewScale()

float coastline::GpuWindow::FieldOfViewScale ( ) const
inline
Returns
The configured multiplier of the race camera's field of view.

◆ DrawDistanceScale()

float coastline::GpuWindow::DrawDistanceScale ( ) const
inline
Returns
The race draw-distance multiplier, from 1 to 4.

◆ N64Effects()

bool coastline::GpuWindow::N64Effects ( ) const
inline
Returns
Whether console particle textures, opacity, and skid-mark rules are selected.

◆ N64WindowReflections()

bool coastline::GpuWindow::N64WindowReflections ( ) const
inline
Returns
Whether car windows use N64 RSP reflection coordinates instead of PC mapping.

◆ ApplyLiveOptions()

bool coastline::GpuWindow::ApplyLiveOptions ( const DisplayOptions & options)

Apply camera, particle, frame-size, post-processing, and pacing settings between frames.

Parameters
optionsThe replacement live settings; window and adapter selection are unchanged.
Returns
False if preparing newly enabled filters fails; allocated resources are not rolled back. Later presentation-mode and frame-resize failures are only logged.

◆ ApplyRendererOptions()

bool coastline::GpuWindow::ApplyRendererOptions ( const DisplayOptions & options)

Update sampling and texture filtering, then apply live settings.

Parameters
optionsThe replacement renderer settings; rebuild scene resources after this call.
Returns
The result of ApplyLiveOptions(); sampling settings change even on failure.

◆ Window()

SDL_Window * coastline::GpuWindow::Window ( ) const
inline
Returns
The window.

◆ Device()

SDL_GPUDevice * coastline::GpuWindow::Device ( ) const
inline
Returns
The GPU device.

◆ GpuMemoryBytes()

Uint64 coastline::GpuWindow::GpuMemoryBytes ( ) const
inline
Returns
Bytes of the GPU device's textures, buffers, and transfer buffers created by the game and not released, excluding allocations internal to the driver.

◆ DeviceName()

std::string coastline::GpuWindow::DeviceName ( ) const
Returns
The actual adapter reported by SDL.

◆ GpuPreference()

const std::string & coastline::GpuWindow::GpuPreference ( ) const
inline
Returns
The requested GPU-selection preference used when the device was created.

◆ NvmlAllowed()

bool coastline::GpuWindow::NvmlAllowed ( ) const
Returns
Whether the active adapter is identified as NVIDIA.

◆ AspectRatio()

float coastline::GpuWindow::AspectRatio ( ) const
inline
Returns
The requested output aspect ratio, or zero to fill the window.

◆ SetFramerateUnlocked()

void coastline::GpuWindow::SetFramerateUnlocked ( bool unlocked)

Set uncapped presentation while retaining the configured present mode.

Parameters
unlockedWhether to disable software pacing and request an uncapped present mode.

◆ FramerateUnlocked()

bool coastline::GpuWindow::FramerateUnlocked ( ) const
inline
Returns
Whether software and presentation pacing are disabled.

◆ PresentationWaitNanoseconds()

Uint64 coastline::GpuWindow::PresentationWaitNanoseconds ( ) const
inline
Returns
Cumulative nanoseconds spent acquiring and submitting presentation buffers.

◆ Fullscreen()

bool coastline::GpuWindow::Fullscreen ( ) const
inline
Returns
Whether the window covers the display.

◆ SetFullscreen()

bool coastline::GpuWindow::SetFullscreen ( bool fullscreen)

Cover the display, at the desktop mode or the exclusive mode of the options, or return to a window.

An exclusive mode the display does not have falls back to the desktop mode.

Parameters
fullscreenWhether the window covers the display.
Returns
Whether the window changed, with the reason logged when it did not.

◆ PresentMode()

SDL_GPUPresentMode coastline::GpuWindow::PresentMode ( ) const
inline
Returns
The present mode of the options or of the last SetPresentMode().

◆ SetPresentMode()

void coastline::GpuWindow::SetPresentMode ( SDL_GPUPresentMode mode)

Present the frames with mode, with the other mode that does not wait and then vertical sync in the place of a mode the window does not support.

Vertical sync of a Wayland window presents to the mailbox at the refresh rate of the display, unless the options choose fifo.

Parameters
modeHow frames are presented.

◆ RefreshPeriod()

Uint64 coastline::GpuWindow::RefreshPeriod ( ) const
Returns
The nanoseconds between the frames the game paces itself to, one refresh of the display of the window when vertical sync presents to the mailbox, or 0 for no pacing.

◆ PresentClear()

bool coastline::GpuWindow::PresentClear ( SDL_FColor color,
const std::filesystem::path * capture = nullptr )

Clear the frame texture to color, present it, and save it when capture is given.

Parameters
colorThe clear colour.
captureA PNG file a thread writes the frame to, logging the result.
Returns
Whether the frame was submitted, and copied for saving when requested.

◆ Present()

bool coastline::GpuWindow::Present ( SDL_GPUCommandBuffer * commands,
const std::filesystem::path * capture = nullptr,
const OutputOverlay & overlay = {} )

Scale the frame texture to the window and submit commands, which drew the frame.

Parameters
commandsThe command buffer of the frame, submitted here.
captureA PNG file a thread writes the frame to, logging the result.
overlayOptional draws over the full output after presentation filters.
Returns
Whether the frame was submitted, and copied for saving when requested.

◆ FrameTexture()

SDL_GPUTexture * coastline::GpuWindow::FrameTexture ( ) const
inline
Returns
The texture each frame is drawn into.

◆ FrameFormat()

constexpr SDL_GPUTextureFormat coastline::GpuWindow::FrameFormat ( )
inlinestaticconstexpr
Returns
The format of the frame texture.

◆ FrameWidth()

Uint32 coastline::GpuWindow::FrameWidth ( ) const
inline
Returns
The width of the frame texture in pixels.

◆ FrameHeight()

Uint32 coastline::GpuWindow::FrameHeight ( ) const
inline
Returns
The height of the frame texture in pixels.

◆ UpdateFrameSize()

void coastline::GpuWindow::UpdateFrameSize ( )

Give the frame the size of the window in pixels times the render scale, or the size of the options, recreating the frame texture when the size changes.

A frame of a size the device cannot create remains at the size before.

◆ Antialias()

int coastline::GpuWindow::Antialias ( ) const
inline
Returns
The samples of each pixel the options requested, 1 for no anti-aliasing.

◆ Filter()

TextureFilter coastline::GpuWindow::Filter ( ) const
inline
Returns
How the textures the game filters are filtered.

◆ AlphaToCoverage()

bool coastline::GpuWindow::AlphaToCoverage ( ) const
inline
Returns
Whether the alpha of cut texels covers the samples of a multisampled pixel.

◆ Anisotropy()

int coastline::GpuWindow::Anisotropy ( ) const
inline
Returns
The most samples of anisotropic filtering of the options, 0 for no mipmaps.

◆ CreateGpuTexture

SDL_GPUTexture * CreateGpuTexture ( SDL_GPUDevice * device,
const SDL_GPUTextureCreateInfo * info )
friend

SDL_CreateGPUTexture(), recording bytes of every level and sample in GpuWindow::GpuMemoryBytes().

Parameters
deviceThe GPU device.
infoThe texture to create.
Returns
The texture, or null when the device cannot create it.

◆ CreateGpuBuffer

SDL_GPUBuffer * CreateGpuBuffer ( SDL_GPUDevice * device,
const SDL_GPUBufferCreateInfo * info )
friend

SDL_CreateGPUBuffer(), recording its size in GpuWindow::GpuMemoryBytes().

Parameters
deviceThe GPU device.
infoThe buffer to create.
Returns
The buffer, or null when the device cannot create it.

◆ CreateGpuTransferBuffer

SDL_GPUTransferBuffer * CreateGpuTransferBuffer ( SDL_GPUDevice * device,
const SDL_GPUTransferBufferCreateInfo * info )
friend

SDL_CreateGPUTransferBuffer(), recording its size in GpuWindow::GpuMemoryBytes().

Parameters
deviceThe GPU device.
infoThe transfer buffer to create.
Returns
The transfer buffer, or null when the device cannot create it.

◆ ReleaseGpuTexture

void ReleaseGpuTexture ( SDL_GPUDevice * device,
SDL_GPUTexture * texture )
friend

SDL_ReleaseGPUTexture(), subtracting its bytes from GpuWindow::GpuMemoryBytes().

Parameters
deviceThe GPU device.
textureA texture of CreateGpuTexture(), or null.

◆ ReleaseGpuBuffer

void ReleaseGpuBuffer ( SDL_GPUDevice * device,
SDL_GPUBuffer * buffer )
friend

SDL_ReleaseGPUBuffer(), subtracting its bytes from GpuWindow::GpuMemoryBytes().

Parameters
deviceThe GPU device.
bufferA buffer of CreateGpuBuffer(), or null.

◆ ReleaseGpuTransferBuffer

void ReleaseGpuTransferBuffer ( SDL_GPUDevice * device,
SDL_GPUTransferBuffer * buffer )
friend

SDL_ReleaseGPUTransferBuffer(), subtracting its bytes from GpuWindow::GpuMemoryBytes().

Parameters
deviceThe GPU device.
bufferA transfer buffer of CreateGpuTransferBuffer(), or null.

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