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

The renderer of a frame. More...

#include <scenerenderer.h>

Public Member Functions

 ~SceneRenderer ()
 Release renderer resources before the associated window and GPU device are destroyed.
 SceneRenderer (const SceneRenderer &)=delete
 Prevent copying pipelines, frame targets, and queued draws.
SceneRenderer & operator= (const SceneRenderer &)=delete
 Prevent assignment of pipelines, frame targets, and queued draws.
GpuWindow & Window ()
void SetFrontendCamera (std::optional< Matrix4 > view)
const std::optional< Matrix4 > & FrontendCamera () const
void Begin (std::array< float, 4 > clear)
 Start a frame, cleared to a colour.
void SetTextureTime (std::uint32_t milliseconds)
 Set the time the animated textures of the frame show, from 0 at Begin().
void SetSnow (bool snow, bool tint)
 Set whether the textures of the snow of a track show the snow, false from Begin().
void SetHiddenInstanceFlags (std::uint32_t flags)
 Set the instances of a track the frame does not draw, none from Begin().
void SetInstanceMatrices (std::function< const float *(int)> matrix)
 Place the instances of a track at the matrices the race moves them to, the default places from Begin().
void SetFog (std::optional< Fog > fog)
 Set the fog the models of the frame are drawn in, none from Begin().
void SetMirrored (bool mirrored)
 Set whether the models drawn after it are drawn through a projection that mirrors them across, their faces then turning the other way, not from Begin().
void SetViewport (std::optional< SDL_Rect > view)
 Set the rectangle of the frame the draws after it fill, as a view of a split screen fills its part of the screen, the whole frame from Begin().
void SetGhost (bool ghost)
 Set whether the models drawn after it are ghosts, not from Begin().
void SetDamage (const CarDamage &damage)
 Set the damage the damaged images of the models drawn after it show, not from Begin().
std::shared_ptr< const VertexDisplacement > CreateDisplacement (std::span< const std::array< float, 3 > > offsets)
 Upload how far each vertex of a model is moved.
void SetDisplacement (std::shared_ptr< const VertexDisplacement > displacement)
 Set how far the vertices of the models drawn after it are moved, those without a pose of a vertex animation and with no more vertices than the displacement, not from Begin().
void SetDrawnInOrder (bool inOrder)
 Set whether the models drawn after it draw their translucent parts straight after their opaque parts, before the next draw, rather than after every opaque draw, not from Begin().
void DrawModel (const RenderModel &model, const Matrix4 &world, const Matrix4 &viewProjection, const Lighting &lighting, std::optional< MorphPose > pose, bool depth, std::optional< SDL_Rect > scissor=std::nullopt)
 Draw a model, its opaque parts now and its translucent ones after every opaque draw.
void DrawModel (const RenderModel &model, const Matrix4 &world, const Matrix4 &viewProjection, const Lighting &lighting, std::vector< MorphPose > poses, bool depth, std::optional< SDL_Rect > scissor=std::nullopt)
 Draw a model whose vertices take the sum of the poses of several vertex animations, each moving its own vertices, as the parts of the start lights move.
void DrawReflectingModel (const RenderModel &model, const Matrix4 &world, const Matrix4 &viewProjection, const Lighting &lighting, const Reflection &reflection, std::optional< SDL_Rect > scissor=std::nullopt)
 Draw a car whose parts with texture coordinates from their normals and no texture of their own reflect the sky.
void DrawHighlight (const RenderModel &model, const Matrix4 &world, const Matrix4 &viewProjection, const Highlight &highlight)
 Draw the specular highlight of a car over the parts drawn before it.
void DrawShadowedModel (const RenderModel &model, const Matrix4 &world, const Matrix4 &viewProjection, const Lighting &lighting, std::vector< int > instances, std::vector< CarShadow > shadows)
 Draw instances of a track in an order, with the shadows of cars on the instances near them.
void DrawQuads (std::span< const FlatVertex > corners, const FlatMaterial &material, const Matrix4 &projection, bool depthTest=false)
 Draw flat quads over everything drawn before them, blended by their alpha.
void DrawBufferedQuads (RenderQuadBuffer &buffer, std::span< const std::uint32_t > order, const FlatMaterial &material, const Matrix4 &projection, bool depthTest=false)
 Draw persistent slots in order, using the same material and depth rules as DrawQuads().
void End (const std::filesystem::path *capture, const std::function< void(SDL_GPUCommandBuffer *, SDL_GPUTexture *, Uint32, Uint32)> &overlay={})
 Draw the frame and present it.
void RenderInto (SDL_GPUCommandBuffer *commands, SDL_GPUTexture *target, Uint32 width, Uint32 height, bool clear=false)
 Record draws into a target without submitting the command buffer.

Static Public Member Functions

static std::unique_ptr< SceneRenderer > Create (GpuWindow &window, bool outputOverlay=false)
 Create the pipelines of the renderer for a window.

Friends

class RenderDocument
class RenderModel
class RenderTexture
class RenderQuadBuffer

Detailed Description

The renderer of a frame.

Begin() starts it, the draws record what it shows, and End() uploads the vertices of the flat draws, draws the frame, and presents it.

Constructor & Destructor Documentation

◆ ~SceneRenderer()

coastline::SceneRenderer::~SceneRenderer ( )

Release renderer resources before the associated window and GPU device are destroyed.

◆ SceneRenderer()

coastline::SceneRenderer::SceneRenderer ( const SceneRenderer & )
delete

Prevent copying pipelines, frame targets, and queued draws.

Member Function Documentation

◆ Create()

std::unique_ptr< SceneRenderer > coastline::SceneRenderer::Create ( GpuWindow & window,
bool outputOverlay = false )
static

Create the pipelines of the renderer for a window.

Parameters
windowThe window to draw into.
outputOverlayWhether to omit depth and multisampled targets for an output overlay.
Returns
The renderer, or nothing with the reason logged.

◆ operator=()

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

Prevent assignment of pipelines, frame targets, and queued draws.

◆ Window()

GpuWindow & coastline::SceneRenderer::Window ( )
Returns
The window the renderer draws into.

◆ SetFrontendCamera()

void coastline::SceneRenderer::SetFrontendCamera ( std::optional< Matrix4 > view)
Parameters
viewOptional eye-space free-camera transform for menus and logos.

◆ FrontendCamera()

const std::optional< Matrix4 > & coastline::SceneRenderer::FrontendCamera ( ) const
Returns
The menu and logo camera override, or no override during normal rendering.

◆ Begin()

void coastline::SceneRenderer::Begin ( std::array< float, 4 > clear)

Start a frame, cleared to a colour.

Parameters
clearThe red, green, blue, and alpha of the clear, from 0 to 1.

◆ SetTextureTime()

void coastline::SceneRenderer::SetTextureTime ( std::uint32_t milliseconds)

Set the time the animated textures of the frame show, from 0 at Begin().

Parameters
millisecondsThe time, such as the elapsed time of a race.

◆ SetSnow()

void coastline::SceneRenderer::SetSnow ( bool snow,
bool tint )

Set whether the textures of the snow of a track show the snow, false from Begin().

Parameters
snowWhether the race is in the snow.
tintWhether a race in the snow also draws the primitive and environment colours of the snow and holds the animated textures that stay still in the snow on their first frame.

◆ SetHiddenInstanceFlags()

void coastline::SceneRenderer::SetHiddenInstanceFlags ( std::uint32_t flags)

Set the instances of a track the frame does not draw, none from Begin().

Parameters
flagsThe TRACK_INSTANCE_ flags, any of which hides an instance.

◆ SetInstanceMatrices()

void coastline::SceneRenderer::SetInstanceMatrices ( std::function< const float *(int)> matrix)

Place the instances of a track at the matrices the race moves them to, the default places from Begin().

Parameters
matrixThe 16 values of the matrix of an instance by its number, or none for its place in the model.

◆ SetFog()

void coastline::SceneRenderer::SetFog ( std::optional< Fog > fog)

Set the fog the models of the frame are drawn in, none from Begin().

Parameters
fogThe fog, or none.

◆ SetMirrored()

void coastline::SceneRenderer::SetMirrored ( bool mirrored)

Set whether the models drawn after it are drawn through a projection that mirrors them across, their faces then turning the other way, not from Begin().

Parameters
mirroredWhether the projection mirrors the frame.

◆ SetViewport()

void coastline::SceneRenderer::SetViewport ( std::optional< SDL_Rect > view)

Set the rectangle of the frame the draws after it fill, as a view of a split screen fills its part of the screen, the whole frame from Begin().

The draws are cut to the rectangle, and the fog and the hidden instances of each draw are those set when it is made.

Parameters
viewThe rectangle in pixels, or none for the whole frame.

◆ SetGhost()

void coastline::SceneRenderer::SetGhost ( bool ghost)

Set whether the models drawn after it are ghosts, not from Begin().

Every part of a ghost is drawn after the opaque draws, its colour by itself added to the frame without writing the depth, as BRD3D draws a ghost.

Parameters
ghostWhether the models are ghosts.

◆ SetDamage()

void coastline::SceneRenderer::SetDamage ( const CarDamage & damage)

Set the damage the damaged images of the models drawn after it show, not from Begin().

Parameters
damageThe levels of damage of the sides of a car.

◆ CreateDisplacement()

std::shared_ptr< const VertexDisplacement > coastline::SceneRenderer::CreateDisplacement ( std::span< const std::array< float, 3 > > offsets)

Upload how far each vertex of a model is moved.

Parameters
offsetsThe displacement of each vertex, in the units of the document of the model.
Returns
The displacement, or nothing when the upload failed.

◆ SetDisplacement()

void coastline::SceneRenderer::SetDisplacement ( std::shared_ptr< const VertexDisplacement > displacement)

Set how far the vertices of the models drawn after it are moved, those without a pose of a vertex animation and with no more vertices than the displacement, not from Begin().

Parameters
displacementThe displacement, or none.

◆ SetDrawnInOrder()

void coastline::SceneRenderer::SetDrawnInOrder ( bool inOrder)

Set whether the models drawn after it draw their translucent parts straight after their opaque parts, before the next draw, rather than after every opaque draw, not from Begin().

Parameters
inOrderWhether the models are drawn in order.

◆ DrawModel() [1/2]

void coastline::SceneRenderer::DrawModel ( const RenderModel & model,
const Matrix4 & world,
const Matrix4 & viewProjection,
const Lighting & lighting,
std::optional< MorphPose > pose,
bool depth,
std::optional< SDL_Rect > scissor = std::nullopt )

Draw a model, its opaque parts now and its translucent ones after every opaque draw.

Parameters
modelThe model.
worldThe place of the model.
viewProjectionThe camera and its projection, to a depth from 0 to 1.
lightingThe lights of the model.
poseThe pose of its vertices, or none for the pose of the document.
depthWhether the model tests and writes the depth.
scissorThe rectangle of the frame in pixels the model is cut to, or none for the whole frame.

◆ DrawModel() [2/2]

void coastline::SceneRenderer::DrawModel ( const RenderModel & model,
const Matrix4 & world,
const Matrix4 & viewProjection,
const Lighting & lighting,
std::vector< MorphPose > poses,
bool depth,
std::optional< SDL_Rect > scissor = std::nullopt )

Draw a model whose vertices take the sum of the poses of several vertex animations, each moving its own vertices, as the parts of the start lights move.

Parameters
modelThe model.
worldThe place of the model.
viewProjectionThe camera and its projection, to a depth from 0 to 1.
lightingThe lights of the model.
posesThe pose of each animation, the first 64 of them.
depthWhether the model tests and writes the depth.
scissorThe rectangle of the frame in pixels the model is cut to, or none for the whole frame.

◆ DrawReflectingModel()

void coastline::SceneRenderer::DrawReflectingModel ( const RenderModel & model,
const Matrix4 & world,
const Matrix4 & viewProjection,
const Lighting & lighting,
const Reflection & reflection,
std::optional< SDL_Rect > scissor = std::nullopt )

Draw a car whose parts with texture coordinates from their normals and no texture of their own reflect the sky.

Parameters
modelThe model.
worldThe place of the model.
viewProjectionThe camera and its projection, to a depth from 0 to 1.
lightingThe lights of the model.
reflectionThe reflection of the sky.
scissorThe rectangle of the frame in pixels the model is cut to, or none for the whole frame.

◆ DrawHighlight()

void coastline::SceneRenderer::DrawHighlight ( const RenderModel & model,
const Matrix4 & world,
const Matrix4 & viewProjection,
const Highlight & highlight )

Draw the specular highlight of a car over the parts drawn before it.

Parameters
modelThe model of the highlighted parts.
worldThe place of the model.
viewProjectionThe camera and its projection, to a depth from 0 to 1.
highlightThe highlight.

◆ DrawShadowedModel()

void coastline::SceneRenderer::DrawShadowedModel ( const RenderModel & model,
const Matrix4 & world,
const Matrix4 & viewProjection,
const Lighting & lighting,
std::vector< int > instances,
std::vector< CarShadow > shadows )

Draw instances of a track in an order, with the shadows of cars on the instances near them.

Parameters
modelThe model of the track.
worldThe place of the model.
viewProjectionThe camera and its projection, to a depth from 0 to 1.
lightingThe lights of the model.
instancesThe instances drawn, in their order, with -1 for the nodes of no instance.
shadowsThe shadows of the cars, laid on an instance one after another in their order, the first MAX_CAR_SHADOWS of those that fall on it.

◆ DrawQuads()

void coastline::SceneRenderer::DrawQuads ( std::span< const FlatVertex > corners,
const FlatMaterial & material,
const Matrix4 & projection,
bool depthTest = false )

Draw flat quads over everything drawn before them, blended by their alpha.

Parameters
cornersFour corners for each quad, clockwise from the top left.
materialHow the quads are coloured.
projectionThe matrix from the space of the corners to the screen.
depthTestWhether the quads are hidden behind what is nearer, as the puffs of a race are, without writing the depth.

◆ DrawBufferedQuads()

void coastline::SceneRenderer::DrawBufferedQuads ( RenderQuadBuffer & buffer,
std::span< const std::uint32_t > order,
const FlatMaterial & material,
const Matrix4 & projection,
bool depthTest = false )

Draw persistent slots in order, using the same material and depth rules as DrawQuads().

The buffer must remain valid until End().

Parameters
bufferQuad storage created with this renderer's device.
orderThe zero-based slots in draw order, copied when this call records the draw.
materialThe textures and combiner; textures must remain valid through submission.
projectionThe matrix from corner coordinates into clip space.
depthTestWhether nearer geometry hides quads, without writing depth.

◆ End()

void coastline::SceneRenderer::End ( const std::filesystem::path * capture,
const std::function< void(SDL_GPUCommandBuffer *, SDL_GPUTexture *, Uint32, Uint32)> & overlay = {} )

Draw the frame and present it.

Parameters
captureA PNG file to write the frame to, or null.
overlayOptional draws at output resolution after presentation filters.

◆ RenderInto()

void coastline::SceneRenderer::RenderInto ( SDL_GPUCommandBuffer * commands,
SDL_GPUTexture * target,
Uint32 width,
Uint32 height,
bool clear = false )

Record draws into a target without submitting the command buffer.

Parameters
commandsThe acquired command buffer; the caller submits it after this call.
targetThe colour target, compatible with GpuWindow::FrameFormat().
widthThe positive target width in pixels.
heightThe positive target height in pixels.
clearWhether to clear the target to Begin()'s colour instead of preserving pixels.

◆ RenderDocument

friend class RenderDocument
friend

◆ RenderModel

friend class RenderModel
friend

◆ RenderTexture

friend class RenderTexture
friend

◆ RenderQuadBuffer

friend class RenderQuadBuffer
friend

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