31inline constexpr Matrix4 IDENTITY_MATRIX{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
42 {{63 / 255.0f, 63 / 255.0f, 51 / 255.0f},
43 {127 / 255.0f, 127 / 255.0f, 102 / 255.0f},
44 {190 / 255.0f, 190 / 255.0f, 153 / 255.0f},
45 {1.0f, 1.0f, 204 / 255.0f}}};
327 SDL_GPUDevice *m_device;
328 SDL_GPUBuffer *m_buffer;
347 bool repeat =
false);
391 SDL_GPUTexture *texture,
392 SDL_GPUSampler *sampler,
395 SDL_GPUDevice *m_device;
396 SDL_GPUTexture *m_texture;
397 SDL_GPUSampler *m_sampler;
399 SDL_GPUTransferBuffer *m_transfer =
nullptr;
403 bool m_threePoint =
false;
699 bool depthTest =
false);
715 bool depthTest =
false);
724 const std::function<
void(SDL_GPUCommandBuffer *, SDL_GPUTexture *, Uint32, Uint32)>
737 SDL_GPUTexture *target,
The window of the game and the GPU device that draws into it.
Definition gpu.h:112
std::size_t PaintCount() const
friend class RenderModel
Definition scenerenderer.h:245
static std::shared_ptr< RenderDocument > Load(SceneRenderer &renderer, const std::filesystem::path &path, const ModelOptions &options={})
Read a glTF document of the import, upload its vertices and the images no paint colours,...
RenderDocument & operator=(const RenderDocument &)=delete
Prevent assignment of uploaded document resources.
RenderDocument(const RenderDocument &)=delete
Prevent copying uploaded document resources.
~RenderDocument()
Release shared document storage and GPU resources before the GPU device is destroyed.
static std::unique_ptr< RenderModel > Load(SceneRenderer &renderer, const std::filesystem::path &path, const ModelOptions &options={})
Read a glTF document of the import and upload its images and vertices.
std::span< const std::array< float, 3 > > Positions() const
void SetVariant(int variant)
Pick the palette variant the images with variants show in the draws of the model until the next call.
RenderModel & operator=(const RenderModel &)=delete
Prevent assignment of model resources and animation progress.
RenderModel(const RenderModel &)=delete
Prevent copying model resources and animation progress.
static std::unique_ptr< RenderModel > Load(std::shared_ptr< RenderDocument > document, const ModelOptions &options={})
Take the parts of a document already read, painting the images of its materials in the colour of the ...
std::array< float, 3 > Centre() const
friend class SceneRenderer
Definition scenerenderer.h:308
const std::vector< VertexAnimationInfo > & Animations() const
~RenderModel()
Release model resources and its shared document reference before GPU device destruction.
RenderQuadBuffer(const RenderQuadBuffer &)=delete
Prevent copying persistent quad GPU storage.
~RenderQuadBuffer()
Release persistent quad storage before the GPU device is destroyed.
RenderQuadBuffer & operator=(const RenderQuadBuffer &)=delete
Prevent assignment of persistent quad GPU storage.
void Update(std::uint32_t slot, std::span< const FlatVertex, 4 > corners)
Replace one persistent quad before the frame is submitted.
friend class SceneRenderer
Definition scenerenderer.h:442
static std::unique_ptr< RenderQuadBuffer > Create(SceneRenderer &renderer, std::size_t quads)
A texture of the renderer for flat pictures and text.
Definition scenerenderer.h:333
~RenderTexture()
Release the texture, sampler, and upload storage before GPU device destruction.
RenderTexture & operator=(const RenderTexture &)=delete
Prevent assignment of texture allocation and upload resources.
static std::unique_ptr< RenderTexture > FromTexels(SceneRenderer &renderer, int width, int height, std::span< const std::uint8_t > rgba, bool linear, bool repeat)
Upload texels the game has in memory, such as a texture of the race built into the engine.
static std::unique_ptr< RenderTexture > Load(SceneRenderer &renderer, const std::filesystem::path &path, bool linear, bool repeat=false)
Read a PNG image.
friend class SceneRenderer
Definition scenerenderer.h:389
bool Update(std::span< const std::uint8_t > rgba)
Replace the texels in place, through an upload the texture keeps.
RenderTexture(const RenderTexture &)=delete
Prevent copying texture allocation and upload resources.
The renderer of a frame.
Definition scenerenderer.h:467
std::shared_ptr< const VertexDisplacement > CreateDisplacement(std::span< const std::array< float, 3 > > offsets)
Upload how far each vertex of a model is moved.
friend class RenderModel
Definition scenerenderer.h:744
const std::optional< Matrix4 > & FrontendCamera() const
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 SetFog(std::optional< Fog > fog)
Set the fog the models of the frame are drawn in, none from Begin().
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.
friend class RenderTexture
Definition scenerenderer.h:745
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 ani...
void SetDrawnInOrder(bool inOrder)
Set whether the models drawn after it draw their translucent parts straight after their opaque parts,...
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,...
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.
SceneRenderer & operator=(const SceneRenderer &)=delete
Prevent assignment of pipelines, frame targets, and queued draws.
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 SetSnow(bool snow, bool tint)
Set whether the textures of the snow of a track show the snow, false from Begin().
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 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 reflec...
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 SetHiddenInstanceFlags(std::uint32_t flags)
Set the instances of a track the frame does not draw, none from Begin().
friend class RenderDocument
Definition scenerenderer.h:743
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 SetGhost(bool ghost)
Set whether the models drawn after it are ghosts, not from Begin().
void SetTextureTime(std::uint32_t milliseconds)
Set the time the animated textures of the frame show, from 0 at Begin().
friend class RenderQuadBuffer
Definition scenerenderer.h:746
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...
~SceneRenderer()
Release renderer resources before the associated window and GPU device are destroyed.
void SetFrontendCamera(std::optional< Matrix4 > view)
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 SetDamage(const CarDamage &damage)
Set the damage the damaged images of the models drawn after it show, not from Begin().
SceneRenderer(const SceneRenderer &)=delete
Prevent copying pipelines, frame targets, and queued draws.
void Begin(std::array< float, 4 > clear)
Start a frame, cleared to a colour.
void SetMirrored(bool mirrored)
Set whether the models drawn after it are drawn through a projection that mirrors them across,...
static std::unique_ptr< SceneRenderer > Create(GpuWindow &window, bool outputOverlay=false)
Create the pipelines of the renderer for a window.
VertexDisplacement & operator=(const VertexDisplacement &)=delete
Prevent assignment of the GPU displacement buffer.
~VertexDisplacement()
Release the displacement buffer before the GPU device is destroyed.
friend class SceneRenderer
Definition scenerenderer.h:325
VertexDisplacement(const VertexDisplacement &)=delete
Prevent copying the GPU displacement buffer.
Definition assetimport.h:11
constexpr int CAR_DAMAGE_LEVELS
The levels of damage of a car after the first, as LoadCarPaintTextures() makes them.
Definition scenerenderer.h:155
constexpr int CAR_DAMAGE_SIDES
The number of sides of a car that take damage, as IncrementDamageTextureLevel() counts them.
Definition scenerenderer.h:152
std::array< int, CAR_DAMAGE_SIDES > CarDamage
The levels of damage of the sides of a car, each from 0 for none to CAR_DAMAGE_LEVELS.
Definition scenerenderer.h:158
Matrix4 MultiplyMatrices(const Matrix4 &a, const Matrix4 &b)
std::array< float, 16 > Matrix4
A 4 by 4 matrix, column by column.
Definition scenerenderer.h:28
constexpr Matrix4 IDENTITY_MATRIX
The matrix that changes nothing.
Definition scenerenderer.h:31
constexpr std::array< std::array< float, 3 >, 4 > CLEAR_LIGHT_RAMP
The ambient colours of a ramped instance of a track on a clear day, from 0 to 1.
Definition scenerenderer.h:41
std::optional< MorphPose > PoseAtTime(const VertexAnimationInfo &animation, float time)
The pose of a vertex animation at a time, as the console blends its keys.
constexpr std::size_t MAX_CAR_SHADOWS
The most shadows of cars that fall on an instance of a track.
Definition scenerenderer.h:139
The shadow of a car on the track, as RenderTrackInstance() lays its texture on the ground under the c...
Definition scenerenderer.h:127
float along
Definition scenerenderer.h:131
const RenderTexture * texture
Definition scenerenderer.h:128
float across
Definition scenerenderer.h:132
float x
Definition scenerenderer.h:129
std::array< float, 2 > forward
Definition scenerenderer.h:133
float y
Definition scenerenderer.h:130
std::array< float, 4 > color
Definition scenerenderer.h:134
std::vector< int > instances
Definition scenerenderer.h:135
How a run of flat quads is coloured: the textures and the colour combiner of the RDP.
Definition scenerenderer.h:449
float alphaCut
Definition scenerenderer.h:459
std::array< std::uint32_t, 2 > combine
Definition scenerenderer.h:453
bool ditherOpacity
Definition scenerenderer.h:460
bool twoCycle
Definition scenerenderer.h:454
const RenderTexture * texel1
Definition scenerenderer.h:451
std::array< float, 4 > env
Definition scenerenderer.h:456
std::array< float, 4 > texel1Transform
The scale of u and v, then their offset, from the texels of texel0 to those of texel1.
Definition scenerenderer.h:458
std::array< float, 4 > prim
Definition scenerenderer.h:455
const RenderTexture * texel0
Definition scenerenderer.h:450
A corner of a flat quad: its place in the space of the flat draws, its texels, and its colour.
Definition scenerenderer.h:408
float x
Definition scenerenderer.h:409
float z
Definition scenerenderer.h:414
float u
Definition scenerenderer.h:411
float v
Definition scenerenderer.h:412
std::array< std::uint8_t, 4 > color
Definition scenerenderer.h:413
float y
Definition scenerenderer.h:410
The fog of the PC release: each vertex shows the share of its colour of the range by the reciprocal o...
Definition scenerenderer.h:118
float range
Definition scenerenderer.h:120
std::array< float, 3 > color
Definition scenerenderer.h:119
A glTF or GLB document with buffers joined and buffer-view offsets adjusted.
Definition gltfdocument.h:14
The specular highlight of a car, as the PC release generates its coordinates for the tile of gDPSetHi...
Definition scenerenderer.h:103
float t
Definition scenerenderer.h:109
std::array< std::uint32_t, 2 > combine
Definition scenerenderer.h:110
std::array< float, 3 > up
Definition scenerenderer.h:107
std::array< float, 4 > primitive
Definition scenerenderer.h:111
float s
Definition scenerenderer.h:108
const RenderTexture * texture
Definition scenerenderer.h:104
std::array< float, 3 > across
Definition scenerenderer.h:106
The damage of an image of a car, as LoadCarPaintTextures() damages the image of a paint set.
Definition scenerenderer.h:161
std::array< int, 4 > rectangle
The left, right, top, and bottom of the paint set, in texels of twice the size of the image,...
Definition scenerenderer.h:165
int side
Definition scenerenderer.h:162
The lights of a model, an ambient colour and a directional colour from a direction in the space the m...
Definition scenerenderer.h:52
std::array< float, 3 > direction
Definition scenerenderer.h:53
std::array< float, 3 > directional
Definition scenerenderer.h:55
std::array< float, 3 > ambient
Definition scenerenderer.h:54
std::array< float, 3 > nightLit
Definition scenerenderer.h:57
std::array< std::array< float, 3 >, 4 > ramp
Definition scenerenderer.h:56
What of a glTF document a RenderModel takes, and how.
Definition scenerenderer.h:172
const GltfDocument * imageDocument
A document in memory taken in place of images, or null.
Definition scenerenderer.h:192
int variants
The number of palette variants of the images of materials, such as the lights of a car.
Definition scenerenderer.h:195
std::optional< std::array< std::uint8_t, 3 > > paint
The red, green, and blue of the colour of a car, which paints the first two colours of the images of ...
Definition scenerenderer.h:179
bool oneCycle
Whether the caller of the display lists sets one cycle, as RenderSkybox() and RenderVehicleHeadlightB...
Definition scenerenderer.h:211
const std::array< std::vector< std::uint8_t >, CAR_DAMAGE_LEVELS > * damageMasks
The 64 by 64 intensities of the damage of each level after the first, row by row from the top,...
Definition scenerenderer.h:204
std::function< bool(SDL_Palette *, int material, int variant)> paletteVariant
Change the palette of an image of a material for a variant, and report whether the image has variants...
Definition scenerenderer.h:198
std::function< bool(const std::string &)> parts
Whether a node of a mesh is drawn, by its name, or none for every node.
Definition scenerenderer.h:181
std::optional< std::filesystem::path > images
Another glTF document of the same model whose images take the place of these, one for one,...
Definition scenerenderer.h:189
bool optional
Whether the document may have nothing to draw, such as a part a level of detail of a car does not hav...
Definition scenerenderer.h:207
std::optional< std::string > node
The name of a node to draw in place of the default scene, such as the sky of a track or a wheel of a ...
Definition scenerenderer.h:175
bool reflects
Whether every part of the model reflects the sky whatever its materials set, as RenderVehicleModel() ...
Definition scenerenderer.h:185
std::function< std::optional< ImageDamage >(int set)> damage
The damage of the image of a paint set of the document, by the set, or none for an image the damage d...
Definition scenerenderer.h:201
The pose of the vertices of an animated model: two keys and the share of the second.
Definition scenerenderer.h:61
int first
Definition scenerenderer.h:62
float blend
Definition scenerenderer.h:64
int second
Definition scenerenderer.h:63
The reflection of the sky on a car: the image the parts whose texture coordinates come from their nor...
Definition scenerenderer.h:84
float column
Definition scenerenderer.h:88
bool n64
Use RSP texture generation and tile shifts instead of the PC coordinate conversion.
Definition scenerenderer.h:95
const RenderTexture * texture
Definition scenerenderer.h:85
std::array< float, 4 > environment
The environment colour the reflection blends towards by its alpha, the fog.
Definition scenerenderer.h:90
bool linear
Select G_TEXTURE_GEN_LINEAR instead of regular texture generation.
Definition scenerenderer.h:93
std::array< float, 3 > up
Definition scenerenderer.h:87
std::array< float, 3 > across
Definition scenerenderer.h:86
A vertex animation of a model, as the game plays it.
Definition scenerenderer.h:68
float time
Definition scenerenderer.h:73
int firstTarget
Definition scenerenderer.h:74
std::vector< float > keyTimes
Definition scenerenderer.h:69
float endTime
Definition scenerenderer.h:72
float startTime
Definition scenerenderer.h:71
std::uint16_t flags
Definition scenerenderer.h:70