1#ifndef SDL3PP_RENDER_H_
2#define SDL3PP_RENDER_H_
4#include <SDL3/SDL_render.h>
5#include "SDL3pp_blendmode.h"
6#include "SDL3pp_events.h"
7#include "SDL3pp_pixels.h"
8#include "SDL3pp_properties.h"
9#include "SDL3pp_rect.h"
10#include "SDL3pp_stdinc.h"
11#include "SDL3pp_surface.h"
12#include "SDL3pp_video.h"
82#define SDL_SOFTWARE_RENDERER "software"
101 SDL_TEXTUREACCESS_STATIC;
104 SDL_TEXTUREACCESS_STREAMING;
107 SDL_TEXTUREACCESS_TARGET;
117 SDL_LOGICAL_PRESENTATION_DISABLED;
123 SDL_LOGICAL_PRESENTATION_STRETCH;
130 SDL_LOGICAL_PRESENTATION_LETTERBOX;
137 SDL_LOGICAL_PRESENTATION_OVERSCAN;
144 SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
175 :
Resource(SDL_CreateRenderer(window.
get(), nullptr))
607 CheckError(SDL_SetRenderLogicalPresentation(
get(), size.x, size.y, mode));
657 CheckError(SDL_GetRenderLogicalPresentation(
get(), w, h, mode));
683 CheckError(SDL_GetRenderLogicalPresentationRect(
get(), &rect));
712 get(), window_coord.x, window_coord.y, &p.x, &p.y));
742 SDL_RenderCoordinatesToWindow(
get(), coord.x, coord.y, &p.x, &p.y));
780 CheckError(SDL_ConvertEventToRenderCoordinates(
get(), event));
1066 CheckError(SDL_SetRenderDrawColor(
get(), c.r, c.g, c.b, c.a));
1086 CheckError(SDL_SetRenderDrawColorFloat(
get(), c.r, c.g, c.b, c.a));
1327 CheckError(SDL_RenderPoints(
get(), points.data(), points.size()));
1364 CheckError(SDL_RenderLines(
get(), points.data(), points.size()));
1401 CheckError(SDL_RenderRects(
get(), rects.data(), rects.size()));
1439 CheckError(SDL_RenderFillRects(
get(), rects.data(), rects.size()));
1520 OptionalRef<const SDL_FRect> srcrect,
1521 OptionalRef<const SDL_FPoint> origin,
1522 OptionalRef<const SDL_FPoint> right,
1523 OptionalRef<const SDL_FPoint> down);
1549 OptionalRef<const SDL_FRect> srcrect,
1551 OptionalRef<const SDL_FRect> dstrect);
1584 OptionalRef<const SDL_FRect> srcrect,
1588 float bottom_height,
1590 OptionalRef<const SDL_FRect> dstrect);
1611 std::span<const Vertex> vertices,
1612 std::span<const int> indices = {});
1643 const FColor* color,
1648 const void* indices,
1870 template<
class... ARGS>
1873 RenderDebugText(p, std::vformat(fmt, std::make_format_args(args...)));
1931 void reset(SDL_Renderer* newResource = {})
1933 SDL_DestroyRenderer(
release(newResource));
1952 constexpr explicit Renderer(SDL_Renderer* resource = {})
1957 constexpr Renderer(
const Renderer& other) =
delete;
2051 const SDL_Point& size)
2053 SDL_CreateTexture(renderer.
get(), format, access, size.x, size.y)))
2197 SDL_CreateTextureWithProperties(renderer.
get(), props.
get())))
2763 const Uint8* Yplane,
2765 const Uint8* Uplane,
2767 const Uint8* Vplane,
2771 get(), rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch));
2799 const Uint8* Yplane,
2801 const Uint8* UVplane,
2805 SDL_UpdateNVTexture(
get(), rect, Yplane, Ypitch, UVplane, UVpitch));
2907 void reset(SDL_Texture* newResource = {})
2909 SDL_DestroyTexture(
release(newResource));
2928 constexpr explicit Texture(SDL_Texture* resource = {})
2933 constexpr Texture(
const Texture& other) =
delete;
2966 : texture(std::move(texture))
2968 SDL_Surface* maybeLock;
2969 if (SDL_LockTextureToSurface(this->texture.
get(), rect, &maybeLock)) {
2986 , texture(other.texture.
release())
3001 std::swap(texture, other.texture);
3026 SDL_UnlockTexture(texture.
release());
3090 return SDL_GetRenderDriver(index);
3116 SDL_Renderer* renderer;
3118 title, size.x, size.y, window_flags, &window, &renderer));
3122namespace prop::Renderer {
3124constexpr auto CREATE_NAME_STRING = SDL_PROP_RENDERER_CREATE_NAME_STRING;
3126constexpr auto CREATE_WINDOW_POINTER = SDL_PROP_RENDERER_CREATE_WINDOW_POINTER;
3128constexpr auto CREATE_SURFACE_POINTER =
3129 SDL_PROP_RENDERER_CREATE_SURFACE_POINTER;
3131constexpr auto CREATE_OUTPUT_COLORSPACE_NUMBER =
3132 SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER;
3134constexpr auto CREATE_PRESENT_VSYNC_NUMBER =
3135 SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER;
3137constexpr auto CREATE_VULKAN_INSTANCE_POINTER =
3138 SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER;
3140constexpr auto CREATE_VULKAN_SURFACE_NUMBER =
3141 SDL_PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER;
3143constexpr auto CREATE_VULKAN_PHYSICAL_DEVICE_POINTER =
3144 SDL_PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER;
3146constexpr auto CREATE_VULKAN_DEVICE_POINTER =
3147 SDL_PROP_RENDERER_CREATE_VULKAN_DEVICE_POINTER;
3149constexpr auto CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER =
3150 SDL_PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER;
3152constexpr auto CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER =
3153 SDL_PROP_RENDERER_CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER;
3155constexpr auto NAME_STRING = SDL_PROP_RENDERER_NAME_STRING;
3157constexpr auto WINDOW_POINTER = SDL_PROP_RENDERER_WINDOW_POINTER;
3159constexpr auto SURFACE_POINTER = SDL_PROP_RENDERER_SURFACE_POINTER;
3161constexpr auto VSYNC_NUMBER = SDL_PROP_RENDERER_VSYNC_NUMBER;
3163constexpr auto MAX_TEXTURE_SIZE_NUMBER =
3164 SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER;
3166constexpr auto TEXTURE_FORMATS_POINTER =
3167 SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER;
3169constexpr auto OUTPUT_COLORSPACE_NUMBER =
3170 SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER;
3172constexpr auto HDR_ENABLED_BOOLEAN = SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN;
3174constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT;
3176constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_RENDERER_HDR_HEADROOM_FLOAT;
3178constexpr auto D3D9_DEVICE_POINTER = SDL_PROP_RENDERER_D3D9_DEVICE_POINTER;
3180constexpr auto D3D11_DEVICE_POINTER = SDL_PROP_RENDERER_D3D11_DEVICE_POINTER;
3182constexpr auto D3D11_SWAPCHAIN_POINTER =
3183 SDL_PROP_RENDERER_D3D11_SWAPCHAIN_POINTER;
3185constexpr auto D3D12_DEVICE_POINTER = SDL_PROP_RENDERER_D3D12_DEVICE_POINTER;
3187constexpr auto D3D12_SWAPCHAIN_POINTER =
3188 SDL_PROP_RENDERER_D3D12_SWAPCHAIN_POINTER;
3190constexpr auto D3D12_COMMAND_QUEUE_POINTER =
3191 SDL_PROP_RENDERER_D3D12_COMMAND_QUEUE_POINTER;
3193constexpr auto VULKAN_INSTANCE_POINTER =
3194 SDL_PROP_RENDERER_VULKAN_INSTANCE_POINTER;
3196constexpr auto VULKAN_SURFACE_NUMBER = SDL_PROP_RENDERER_VULKAN_SURFACE_NUMBER;
3198constexpr auto VULKAN_PHYSICAL_DEVICE_POINTER =
3199 SDL_PROP_RENDERER_VULKAN_PHYSICAL_DEVICE_POINTER;
3201constexpr auto VULKAN_DEVICE_POINTER = SDL_PROP_RENDERER_VULKAN_DEVICE_POINTER;
3203constexpr auto VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER =
3204 SDL_PROP_RENDERER_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER;
3206constexpr auto VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER =
3207 SDL_PROP_RENDERER_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER;
3209constexpr auto VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER =
3210 SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER;
3212constexpr auto GPU_DEVICE_POINTER = SDL_PROP_RENDERER_GPU_DEVICE_POINTER;
3231namespace prop::Texture {
3233constexpr auto CREATE_COLORSPACE_NUMBER =
3234 SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER;
3236constexpr auto CREATE_FORMAT_NUMBER = SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER;
3238constexpr auto CREATE_ACCESS_NUMBER = SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER;
3240constexpr auto CREATE_WIDTH_NUMBER = SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER;
3242constexpr auto CREATE_HEIGHT_NUMBER = SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER;
3244constexpr auto CREATE_SDR_WHITE_POINT_FLOAT =
3245 SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT;
3247constexpr auto CREATE_HDR_HEADROOM_FLOAT =
3248 SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT;
3250constexpr auto CREATE_D3D11_TEXTURE_POINTER =
3251 SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER;
3253constexpr auto CREATE_D3D11_TEXTURE_U_POINTER =
3254 SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER;
3256constexpr auto CREATE_D3D11_TEXTURE_V_POINTER =
3257 SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER;
3259constexpr auto CREATE_D3D12_TEXTURE_POINTER =
3260 SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER;
3262constexpr auto CREATE_D3D12_TEXTURE_U_POINTER =
3263 SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER;
3265constexpr auto CREATE_D3D12_TEXTURE_V_POINTER =
3266 SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER;
3268constexpr auto CREATE_METAL_PIXELBUFFER_POINTER =
3269 SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER;
3271constexpr auto CREATE_OPENGL_TEXTURE_NUMBER =
3272 SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER;
3274constexpr auto CREATE_OPENGL_TEXTURE_UV_NUMBER =
3275 SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER;
3277constexpr auto CREATE_OPENGL_TEXTURE_U_NUMBER =
3278 SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER;
3280constexpr auto CREATE_OPENGL_TEXTURE_V_NUMBER =
3281 SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER;
3283constexpr auto CREATE_OPENGLES2_TEXTURE_NUMBER =
3284 SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER;
3286constexpr auto CREATE_OPENGLES2_TEXTURE_UV_NUMBER =
3287 SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER;
3289constexpr auto CREATE_OPENGLES2_TEXTURE_U_NUMBER =
3290 SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER;
3292constexpr auto CREATE_OPENGLES2_TEXTURE_V_NUMBER =
3293 SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER;
3295constexpr auto CREATE_VULKAN_TEXTURE_NUMBER =
3296 SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER;
3298constexpr auto COLORSPACE_NUMBER = SDL_PROP_TEXTURE_COLORSPACE_NUMBER;
3300constexpr auto FORMAT_NUMBER = SDL_PROP_TEXTURE_FORMAT_NUMBER;
3302constexpr auto ACCESS_NUMBER = SDL_PROP_TEXTURE_ACCESS_NUMBER;
3304constexpr auto WIDTH_NUMBER = SDL_PROP_TEXTURE_WIDTH_NUMBER;
3306constexpr auto HEIGHT_NUMBER = SDL_PROP_TEXTURE_HEIGHT_NUMBER;
3308constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT;
3310constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT;
3312constexpr auto D3D11_TEXTURE_POINTER = SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER;
3314constexpr auto D3D11_TEXTURE_U_POINTER =
3315 SDL_PROP_TEXTURE_D3D11_TEXTURE_U_POINTER;
3317constexpr auto D3D11_TEXTURE_V_POINTER =
3318 SDL_PROP_TEXTURE_D3D11_TEXTURE_V_POINTER;
3320constexpr auto D3D12_TEXTURE_POINTER = SDL_PROP_TEXTURE_D3D12_TEXTURE_POINTER;
3322constexpr auto D3D12_TEXTURE_U_POINTER =
3323 SDL_PROP_TEXTURE_D3D12_TEXTURE_U_POINTER;
3325constexpr auto D3D12_TEXTURE_V_POINTER =
3326 SDL_PROP_TEXTURE_D3D12_TEXTURE_V_POINTER;
3328constexpr auto OPENGL_TEXTURE_NUMBER = SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER;
3330constexpr auto OPENGL_TEXTURE_UV_NUMBER =
3331 SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER;
3333constexpr auto OPENGL_TEXTURE_U_NUMBER =
3334 SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER;
3336constexpr auto OPENGL_TEXTURE_V_NUMBER =
3337 SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER;
3339constexpr auto OPENGL_TEXTURE_TARGET_NUMBER =
3340 SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER;
3342constexpr auto OPENGL_TEX_W_FLOAT = SDL_PROP_TEXTURE_OPENGL_TEX_W_FLOAT;
3344constexpr auto OPENGL_TEX_H_FLOAT = SDL_PROP_TEXTURE_OPENGL_TEX_H_FLOAT;
3346constexpr auto OPENGLES2_TEXTURE_NUMBER =
3347 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER;
3349constexpr auto OPENGLES2_TEXTURE_UV_NUMBER =
3350 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER;
3352constexpr auto OPENGLES2_TEXTURE_U_NUMBER =
3353 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER;
3355constexpr auto OPENGLES2_TEXTURE_V_NUMBER =
3356 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER;
3358constexpr auto OPENGLES2_TEXTURE_TARGET_NUMBER =
3359 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER;
3361constexpr auto VULKAN_TEXTURE_NUMBER = SDL_PROP_TEXTURE_VULKAN_TEXTURE_NUMBER;
3372 return SDL_GetRenderTarget(
get());
3391 get(), texture.
get(), srcrect, dstrect, angle, center, flip));
3402 get(), texture.
get(), srcrect, origin, right, down));
3412 SDL_RenderTextureTiled(
get(), texture.
get(), srcrect, scale, dstrect));
3421 float bottom_height,
3437 std::span<const Vertex> vertices,
3438 std::span<const int> indices)
3456 const void* indices,
3518 return CheckError(SDL_GetRenderMetalCommandEncoder(renderer.
get()));
3549 Uint32 wait_stage_mask,
3550 Sint64 wait_semaphore,
3551 Sint64 signal_semaphore)
3554 renderer.
get(), wait_stage_mask, wait_semaphore, signal_semaphore));
3560#define SDL_RENDERER_VSYNC_DISABLED 0
3563#define SDL_RENDERER_VSYNC_ADAPTIVE (-1)
3574#define SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE 8
3601 return Texture(renderer, surface);
3616 Surface surface{SDL_LoadBMP(file)};
3617 return Texture(renderer, surface);
3620#pragma endregion impl
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
A optional reference to resource.
Definition SDL3pp_resource.h:88
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr SDL_Renderer * release(SDL_Renderer * newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr SDL_Renderer * get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
span-like for empty-derived structs
Definition SDL3pp_spanRef.h:24
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Locks a Texture for access to its pixels.
Definition SDL3pp_render.h:2959
void reset()
Definition SDL3pp_render.h:3041
constexpr TextureLock()=default
default ctor
TextureLock(TextureLock &&other)
Move ctor.
Definition SDL3pp_render.h:2984
~TextureLock()
destructor
Definition SDL3pp_render.h:2994
TextureLock & operator=(TextureLock other)
Assignment operator.
Definition SDL3pp_render.h:2997
int GetPitch() const
Get pitch (the number of bytes between the start of one row the next)
Definition SDL3pp_render.h:3038
void Unlock()
Unlock a texture, uploading the changes to video memory, if needed.
Definition SDL3pp_render.h:3022
void * GetPixels() const
Get the pixels.
Definition SDL3pp_render.h:3033
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:374
Uint32 BlendMode
A set of blend modes used in drawing operations.
Definition SDL3pp_blendmode.h:35
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
SDL_Event Event
The structure for all events in SDL.
Definition SDL3pp_events.h:1010
RendererRef GetRenderer() const
Get the renderer associated with a window.
Definition SDL3pp_render.h:3226
TextureLock Lock(OptionalRef< const SDL_Rect > rect={}) &
Lock a portion of the texture for write-only pixel access.
Definition SDL3pp_render.h:3582
void ResetTarget()
Set target texture back to window.
Definition SDL3pp_render.h:3580
void AddVulkanRenderSemaphores(RendererBase &renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore)
Add a set of synchronization semaphores for the current frame.
Definition SDL3pp_render.h:3548
Texture LoadTextureBMP(RendererBase &renderer, IOStreamBase &src)
Load a BMP texture from a seekable SDL data stream.
Definition SDL3pp_render.h:3598
void RenderTexture9Grid(TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, OptionalRef< const SDL_FRect > dstrect)
Perform a scaled copy using the 9-grid algorithm to the current rendering target at subpixel precisio...
Definition SDL3pp_render.h:3415
std::pair< Window, Renderer > CreateWindowAndRenderer(StringParam title, SDL_Point size, WindowFlags window_flags=0)
Create a window and default renderer.
Definition SDL3pp_render.h:3110
SDL_Vertex Vertex
Vertex structure.
Definition SDL3pp_render.h:91
void RenderTextureTiled(TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, float scale, OptionalRef< const SDL_FRect > dstrect)
Tile a portion of the texture to the current rendering target at subpixel precision.
Definition SDL3pp_render.h:3405
void * GetRenderMetalLayer(RendererBase &renderer)
Get the CAMetalLayer associated with the given Metal renderer.
Definition SDL3pp_render.h:3490
OptionalResource< TextureRef, Texture > OptionalTexture
A texture parameter that might own its value.
Definition SDL3pp_render.h:73
void RenderTexture(TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FRect > dstrect)
Copy a portion of the texture to the current rendering target at subpixel precision.
Definition SDL3pp_render.h:3375
void RenderGeometryRaw(OptionalTexture texture, const float *xy, int xy_stride, const FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices)
Render a list of triangles, optionally using a texture and indices into the vertex arrays Color and a...
Definition SDL3pp_render.h:3448
SDL_TextureAccess TextureAccess
The access pattern allowed for a texture.
Definition SDL3pp_render.h:98
constexpr RendererLogicalPresentation LOGICAL_PRESENTATION_OVERSCAN
The rendered content is fit to the smallest dimension and the other dimension extends beyond the outp...
Definition SDL3pp_render.h:136
constexpr RendererLogicalPresentation LOGICAL_PRESENTATION_DISABLED
There is no logical size in effect.
Definition SDL3pp_render.h:116
SDL_RendererLogicalPresentation RendererLogicalPresentation
How the logical size is mapped to the output.
Definition SDL3pp_render.h:114
constexpr TextureAccess TEXTUREACCESS_TARGET
Texture can be used as a render target.
Definition SDL3pp_render.h:106
void SetTarget(OptionalTexture texture)
Set a texture as the current rendering target.
Definition SDL3pp_render.h:3365
void RenderTextureRotated(TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FRect > dstrect, double angle, OptionalRef< const SDL_FPoint > center={}, FlipMode flip=SDL_FLIP_NONE)
Copy a portion of the source texture to the current rendering target, with rotation and flipping,...
Definition SDL3pp_render.h:3382
TextureRef GetTarget() const
Get the current render target.
Definition SDL3pp_render.h:3370
constexpr TextureAccess TEXTUREACCESS_STATIC
Changes rarely, not lockable.
Definition SDL3pp_render.h:100
constexpr RendererLogicalPresentation LOGICAL_PRESENTATION_INTEGER_SCALE
The rendered content is scaled up by integer multiples to fit the output resolution.
Definition SDL3pp_render.h:143
constexpr TextureAccess TEXTUREACCESS_STREAMING
Changes frequently, lockable.
Definition SDL3pp_render.h:103
constexpr RendererLogicalPresentation LOGICAL_PRESENTATION_LETTERBOX
The rendered content is fit to the largest dimension and the other dimension is letterboxed with blac...
Definition SDL3pp_render.h:129
void * GetRenderMetalCommandEncoder(RendererBase &renderer)
Get the Metal command encoder for the current frame.
Definition SDL3pp_render.h:3516
constexpr RendererLogicalPresentation LOGICAL_PRESENTATION_STRETCH
The rendered content is stretched to the output resolution.
Definition SDL3pp_render.h:122
int GetNumRenderDrivers()
Get the number of 2D rendering drivers available for the current display.
Definition SDL3pp_render.h:3064
const char * GetRenderDriver(int index)
Use this function to get the name of a built in 2D rendering driver.
Definition SDL3pp_render.h:3088
void RenderGeometry(OptionalTexture texture, std::span< const Vertex > vertices, std::span< const int > indices={})
Render a list of triangles, optionally using a texture and indices into the vertex array Color and al...
Definition SDL3pp_render.h:3436
void RenderTextureAffine(TextureBase &texture, OptionalRef< const SDL_FRect > srcrect, OptionalRef< const SDL_FPoint > origin, OptionalRef< const SDL_FPoint > right, OptionalRef< const SDL_FPoint > down)
Copy a portion of the source texture to the current rendering target, with affine transform,...
Definition SDL3pp_render.h:3394
SDL_FlipMode FlipMode
The flip mode.
Definition SDL3pp_surface.h:96
SDL_ScaleMode ScaleMode
The scaling mode.
Definition SDL3pp_surface.h:74
Surface LoadBMP(IOStreamBase &src)
Load a BMP image from a seekable SDL data stream.
Definition SDL3pp_surface.h:2013
SDL_WindowFlags WindowFlags
The flags on a window.
Definition SDL3pp_video.h:138
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
A structure that represents a color as RGBA components.
Definition SDL3pp_pixels.h:1621
The bits of this structure can be directly reinterpreted as a float-packed color which uses the PIXEL...
Definition SDL3pp_pixels.h:1816
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:479
A rectangle, with the origin at the upper left (using floats).
Definition SDL3pp_rect.h:1439
The read/write operation structure.
Definition SDL3pp_iostream.h:107
Handle to an owned iOStream.
Definition SDL3pp_iostream.h:1613
The structure that defines a point (using integers)
Definition SDL3pp_rect.h:41
Wrap properties id.
Definition SDL3pp_properties.h:203
Handle to a non owned properties.
Definition SDL3pp_properties.h:693
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:817
A structure representing rendering state.
Definition SDL3pp_render.h:157
void SetDrawBlendMode(BlendMode blendMode)
Set the blend mode used for drawing operations (Fill and Line).
Definition SDL3pp_render.h:1253
void SetLogicalPresentation(SDL_Point size, RendererLogicalPresentation mode)
Set a device-independent resolution and presentation mode for rendering.
Definition SDL3pp_render.h:605
FRect GetLogicalPresentationRect() const
Get the final presentation rectangle for rendering.
Definition SDL3pp_render.h:680
Rect GetSafeArea() const
Get the safe area for rendering within the current viewport.
Definition SDL3pp_render.h:889
void GetScale(float *scaleX, float *scaleY) const
Get the drawing scale for the current target.
Definition SDL3pp_render.h:1044
void SetDrawColor(SDL_FColor c)
Set the color used for drawing operations (Rect, Line and Clear).
Definition SDL3pp_render.h:1084
void RenderPoint(SDL_FPoint p)
Draw a point on the current rendering target at subpixel precision.
Definition SDL3pp_render.h:1307
void SetVSync(int vsync)
Toggle VSync of the given renderer.
Definition SDL3pp_render.h:1783
void Flush()
Force the rendering context to flush any pending commands and state.
Definition SDL3pp_render.h:1760
Point GetCurrentOutputSize() const
Get the current output size in pixels of a rendering context.
Definition SDL3pp_render.h:377
void RenderDebugText(FPoint p, StringParam str)
Draw debug text to an RendererBase.
Definition SDL3pp_render.h:1840
void RenderRects(SpanRef< const SDL_FRect > rects)
Draw some number of rectangles on the current rendering target at subpixel precision.
Definition SDL3pp_render.h:1398
bool IsViewportSet() const
Return whether an explicit rectangle was set as the viewport.
Definition SDL3pp_render.h:870
void ConvertEventToRenderCoordinates(Event *event) const
Convert the coordinates in an event to render coordinates.
Definition SDL3pp_render.h:778
bool IsClipEnabled() const
Get whether clipping is enabled on the given render target.
Definition SDL3pp_render.h:976
void ResetClipRect()
Reset the clip rectangle for rendering to the entire render target.
Definition SDL3pp_render.h:911
void SetScale(SDL_FPoint scale)
Set the drawing scale for rendering on the current target.
Definition SDL3pp_render.h:1001
void RenderClear()
Clear the current rendering target with the drawing color.
Definition SDL3pp_render.h:1293
void GetDrawColor(float *r, float *g, float *b, float *a) const
Get the color used for drawing operations (Rect, Line and Clear).
Definition SDL3pp_render.h:1190
void GetLogicalPresentation(SDL_Point *size, RendererLogicalPresentation *mode)
Get device independent resolution and presentation mode for rendering.
Definition SDL3pp_render.h:626
void GetDrawColor(SDL_Color *c) const
Get the color used for drawing operations (Rect, Line and Clear).
Definition SDL3pp_render.h:1123
FPoint RenderCoordinatesToWindow(const SDL_FPoint &coord) const
Get a point in window coordinates when given a point in render coordinates.
Definition SDL3pp_render.h:738
RendererBase(WindowRef window)
Create a 2D rendering context for a window.
Definition SDL3pp_render.h:174
Rect GetClipRect() const
Get the clip rectangle for the current target.
Definition SDL3pp_render.h:953
Rect GetViewport() const
Get the drawing area for the current target.
Definition SDL3pp_render.h:844
void SetDrawColor(SDL_Color c)
Set the color used for drawing operations.
Definition SDL3pp_render.h:1064
void RenderRect(OptionalRef< const SDL_FRect > rect)
Draw a rectangle on the current rendering target at subpixel precision.
Definition SDL3pp_render.h:1380
void GetDrawColor(Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const
Get the color used for drawing operations (Rect, Line and Clear).
Definition SDL3pp_render.h:1166
void RenderFillRects(SpanRef< const SDL_FRect > rects)
Fill some number of rectangles on the current rendering target with the drawing color at subpixel pre...
Definition SDL3pp_render.h:1436
void RenderLine(SDL_FPoint p1, SDL_FPoint p2)
Draw a line on the current rendering target at subpixel precision.
Definition SDL3pp_render.h:1343
void RenderPoints(SpanRef< const SDL_FPoint > points)
Draw multiple points on the current rendering target at subpixel precision.
Definition SDL3pp_render.h:1324
WindowRef GetWindow()
Get the window associated with a renderer.
Definition SDL3pp_render.h:306
int GetVSync() const
Get VSync of the given renderer.
Definition SDL3pp_render.h:1797
void GetLogicalPresentation(int *w, int *h, RendererLogicalPresentation *mode) const
Get device independent resolution and presentation mode for rendering.
Definition SDL3pp_render.h:653
void ResetViewport()
Reset the drawing area for rendering to the entire target.
Definition SDL3pp_render.h:798
Surface ReadPixels(OptionalRef< const SDL_Rect > rect={}) const
Read pixels from the current rendering target.
Definition SDL3pp_render.h:1677
FColor GetDrawColor() const
Get the color used for drawing operations (Rect, Line and Clear).
Definition SDL3pp_render.h:1102
RendererBase(WindowBase &window, StringParam name)
Create a 2D rendering context for a window.
Definition SDL3pp_render.h:213
void Present()
Update the screen with any rendering performed since the previous call.
Definition SDL3pp_render.h:1729
BlendMode GetDrawBlendMode() const
Get the blend mode used for drawing operations.
Definition SDL3pp_render.h:1270
RendererBase(SurfaceBase &surface)
Create a 2D software rendering context for a surface.
Definition SDL3pp_render.h:291
void RenderFillRect(OptionalRef< const SDL_FRect > rect)
Fill a rectangle on the current rendering target with the drawing color at subpixel precision.
Definition SDL3pp_render.h:1418
void GetOutputSize(int *w, int *h) const
Get the output size in pixels of a rendering context.
Definition SDL3pp_render.h:356
void GetDrawColor(SDL_FColor *c) const
Get the color used for drawing operations (Rect, Line and Clear).
Definition SDL3pp_render.h:1142
float GetColorScale() const
Get the color scale used for render operations.
Definition SDL3pp_render.h:1232
Point GetOutputSize() const
Get the output size in pixels of a rendering context.
Definition SDL3pp_render.h:330
void GetCurrentOutputSize(int *w, int *h) const
Get the current output size in pixels of a rendering context.
Definition SDL3pp_render.h:404
FPoint RenderCoordinatesFromWindow(const SDL_FPoint &window_coord) const
Get a point in render coordinates when given a point in window coordinates.
Definition SDL3pp_render.h:708
const char * GetName() const
Get the name of a renderer.
Definition SDL3pp_render.h:319
void RenderLines(SpanRef< const SDL_FPoint > points)
Draw a series of connected lines on the current rendering target at subpixel precision.
Definition SDL3pp_render.h:1361
void SetClipRect(OptionalRef< const SDL_Rect > rect)
Set the clip rectangle for rendering on the specified target.
Definition SDL3pp_render.h:931
FPoint GetScale() const
Get the drawing scale for the current target.
Definition SDL3pp_render.h:1021
void SetViewport(OptionalRef< const SDL_Rect > rect)
Set the drawing area for rendering on the current target.
Definition SDL3pp_render.h:823
void SetColorScale(float scale)
Set the color scale used for render operations.
Definition SDL3pp_render.h:1215
PropertiesRef GetProperties() const
Get the properties associated with a renderer.
Definition SDL3pp_render.h:492
RendererBase(PropertiesBase &props)
Create a 2D rendering context for a window, with the specified properties.
Definition SDL3pp_render.h:269
void RenderDebugTextFormat(FPoint p, std::string_view fmt, ARGS... args)
Draw debug text to an SDL_Renderer.
Definition SDL3pp_render.h:1871
Handle to a non owned renderer.
Definition SDL3pp_render.h:1886
constexpr ~RendererRef()=default
Default constructor.
constexpr RendererRef(RendererRef &&other)
Move constructor.
Definition SDL3pp_render.h:1900
RendererRef & operator=(RendererRef other)
Assignment operator.
Definition SDL3pp_render.h:1913
constexpr RendererRef(const RendererRef &other)
Copy constructor.
Definition SDL3pp_render.h:1892
void reset(SDL_Renderer *newResource={})
Destroy the rendering context for a window and free all associated textures.
Definition SDL3pp_render.h:1931
Handle to an owned renderer.
Definition SDL3pp_render.h:1946
constexpr Renderer(SDL_Renderer *resource={})
Constructs from the underlying resource.
Definition SDL3pp_render.h:1952
constexpr Renderer(Renderer &&other)=default
Move constructor.
Renderer & operator=(Renderer other)
Assignment operator.
Definition SDL3pp_render.h:1972
~Renderer()
Frees up resource when object goes out of scope.
Definition SDL3pp_render.h:1967
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:138
Handle to an owned surface.
Definition SDL3pp_surface.h:1873
An efficient driver-specific representation of pixel data.
Definition SDL3pp_render.h:1995
void SetAlphaMod(Uint8 alpha)
Set an additional alpha value multiplied into render copy operations.
Definition SDL3pp_render.h:2538
void GetAlphaMod(Uint8 *alpha) const
Get the additional alpha value multiplied into render copy operations.
Definition SDL3pp_render.h:2597
PropertiesRef GetProperties() const
Get the properties associated with a texture.
Definition SDL3pp_render.h:2286
TextureBase(RendererBase &renderer, StringParam file)
Load an image from a filesystem path into a software surface.
Definition SDL3pp_image.h:2199
void SetColorMod(float r, float g, float b)
Set an additional color value multiplied into render copy operations.
Definition SDL3pp_render.h:2472
void GetColorMod(float *r, float *g, float *b) const
Get the additional color value multiplied into render copy operations.
Definition SDL3pp_render.h:2512
void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
Set an additional color value multiplied into render copy operations.
Definition SDL3pp_render.h:2443
void SetMod(Color c)
Set an additional color and alpha values multiplied into render copy operations.
Definition SDL3pp_render.h:2325
void GetAlphaMod(float *alpha) const
Get the additional alpha value multiplied into render copy operations.
Definition SDL3pp_render.h:2615
void GetMod(Color *c) const
Get the additional color value multiplied into render copy operations.
Definition SDL3pp_render.h:2392
void UpdateYUV(OptionalRef< const SDL_Rect > rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
Update a rectangle within a planar YV12 or IYUV texture with new pixel data.
Definition SDL3pp_render.h:2762
FColor GetMod() const
Get the additional color value multiplied into render copy operations.
Definition SDL3pp_render.h:2372
void SetMod(FColor c)
Set an additional color and alpha values multiplied into render copy operations.
Definition SDL3pp_render.h:2353
int GetWidth() const
Get the width in pixels.
Definition SDL3pp_render.h:2835
void Update(OptionalRef< const SDL_Rect > rect, const void *pixels, int pitch)
Update the given texture rectangle with new pixel data.
Definition SDL3pp_render.h:2729
float GetAlphaMod() const
Get the additional alpha value multiplied into render copy operations.
Definition SDL3pp_render.h:2577
void GetColorMod(Uint8 *r, Uint8 *g, Uint8 *b) const
Get the additional color value multiplied into render copy operations.
Definition SDL3pp_render.h:2492
ScaleMode GetScaleMode() const
Get the scale mode used for texture scale operations.
Definition SDL3pp_render.h:2692
BlendMode GetBlendMode() const
Get the blend mode used for texture copy operations.
Definition SDL3pp_render.h:2652
void SetAlphaMod(float alpha)
Set an additional alpha value multiplied into render copy operations.
Definition SDL3pp_render.h:2564
Point GetSize() const
Get the size in pixels.
Definition SDL3pp_render.h:2845
TextureBase(RendererBase &renderer, PropertiesBase &props)
Create a texture for a rendering context with the specified properties.
Definition SDL3pp_render.h:2195
PixelFormat GetFormat() const
Get the pixel format.
Definition SDL3pp_render.h:2850
int GetHeight() const
Get the height in pixels.
Definition SDL3pp_render.h:2840
void UpdateNV(OptionalRef< const SDL_Rect > rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch)
Update a rectangle within a planar NV12 or NV21 texture with new pixels.
Definition SDL3pp_render.h:2798
void SetBlendMode(BlendMode blendMode)
Set the blend mode for a texture, used by RendererBase.RenderTexture().
Definition SDL3pp_render.h:2635
void GetMod(FColor *c) const
Get the additional color value multiplied into render copy operations.
Definition SDL3pp_render.h:2412
void SetScaleMode(ScaleMode scaleMode)
Set the scale mode used for texture scale operations.
Definition SDL3pp_render.h:2675
TextureBase(RendererBase &renderer, PixelFormat format, TextureAccess access, const SDL_Point &size)
Create a texture for a rendering context.
Definition SDL3pp_render.h:2048
RendererRef GetRenderer() const
Get the renderer that created an TextureBase.
Definition SDL3pp_render.h:2301
TextureBase(RendererBase &renderer, SurfaceBase &surface)
Create a texture from an existing surface.
Definition SDL3pp_render.h:2079
Handle to a non owned texture.
Definition SDL3pp_render.h:2862
TextureRef & operator=(TextureRef other)
Assignment operator.
Definition SDL3pp_render.h:2889
constexpr TextureRef(const TextureRef &other)
Copy constructor.
Definition SDL3pp_render.h:2868
constexpr ~TextureRef()=default
Default constructor.
constexpr TextureRef(TextureRef &&other)
Move constructor.
Definition SDL3pp_render.h:2876
void reset(SDL_Texture *newResource={})
Destroy the specified texture.
Definition SDL3pp_render.h:2907
Handle to an owned texture.
Definition SDL3pp_render.h:2922
constexpr Texture(SDL_Texture *resource={})
Constructs from the underlying resource.
Definition SDL3pp_render.h:2928
Texture & operator=(Texture other)
Assignment operator.
Definition SDL3pp_render.h:2948
constexpr Texture(Texture &&other)=default
Move constructor.
~Texture()
Frees up resource when object goes out of scope.
Definition SDL3pp_render.h:2943
Represents a handle to a window.
Definition SDL3pp_video.h:838
Handle to a non owned window.
Definition SDL3pp_video.h:2778
Handle to an owned window.
Definition SDL3pp_video.h:2872