SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_render.h
1#ifndef SDL3PP_RENDER_H_
2#define SDL3PP_RENDER_H_
3
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"
13
14namespace SDL {
15
46// Forward decl
47struct TextureLock;
48
49// Forward decl
50struct RendererBase;
51
52// Forward decl
53struct RendererRef;
54
55// Forward decl
56struct Renderer;
57
58// Forward decl
59struct TextureBase;
60
61// Forward decl
62struct TextureRef;
63
64// Forward decl
65struct Texture;
66
74
75#ifdef SDL3PP_DOC
76
82#define SDL_SOFTWARE_RENDERER "software"
83
84#endif // SDL3PP_DOC
85
91using Vertex = SDL_Vertex;
92
98using TextureAccess = SDL_TextureAccess;
99
101 SDL_TEXTUREACCESS_STATIC;
102
104 SDL_TEXTUREACCESS_STREAMING;
105
107 SDL_TEXTUREACCESS_TARGET;
108
114using RendererLogicalPresentation = SDL_RendererLogicalPresentation;
115
117 SDL_LOGICAL_PRESENTATION_DISABLED;
118
123 SDL_LOGICAL_PRESENTATION_STRETCH;
124
130 SDL_LOGICAL_PRESENTATION_LETTERBOX;
131
137 SDL_LOGICAL_PRESENTATION_OVERSCAN;
138
144 SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
145
156struct RendererBase : Resource<SDL_Renderer*>
157{
158 using Resource::Resource;
159
175 : Resource(SDL_CreateRenderer(window.get(), nullptr))
176 {
177 }
178
214 : Resource(CheckError(SDL_CreateRenderer(window.get(), name)))
215 {
216 }
217
270 : Resource(CheckError(SDL_CreateRendererWithProperties(props.get())))
271 {
272 }
273
292 : Resource(CheckError(SDL_CreateSoftwareRenderer(surface.get())))
293 {
294 }
295
306 WindowRef GetWindow() { return CheckError(SDL_GetRenderWindow(get())); }
307
319 const char* GetName() const { return CheckError(SDL_GetRendererName(get())); }
320
331 {
332 Point p;
333 GetOutputSize(&p.x, &p.y);
334 return p;
335 }
336
356 void GetOutputSize(int* w, int* h) const
357 {
358 CheckError(SDL_GetRenderOutputSize(get(), w, h));
359 }
360
378 {
379 Point p;
380 GetCurrentOutputSize(&p.x, &p.y);
381 return p;
382 }
383
404 void GetCurrentOutputSize(int* w, int* h) const
405 {
406 CheckError(SDL_GetCurrentRenderOutputSize(get(), w, h));
407 }
408
493 {
494 return CheckError(SDL_GetRendererProperties(get()));
495 }
496
511 void ResetTarget();
512
536 void SetTarget(OptionalTexture texture);
537
553 TextureRef GetTarget() const;
554
606 {
607 CheckError(SDL_SetRenderLogicalPresentation(get(), size.x, size.y, mode));
608 }
609
626 void GetLogicalPresentation(SDL_Point* size,
628 {
629 if (!size) return GetLogicalPresentation(nullptr, nullptr, mode);
630 return GetLogicalPresentation(&size->x, &size->y, mode);
631 }
632
654 int* h,
655 RendererLogicalPresentation* mode) const
656 {
657 CheckError(SDL_GetRenderLogicalPresentation(get(), w, h, mode));
658 }
659
681 {
682 FRect rect;
683 CheckError(SDL_GetRenderLogicalPresentationRect(get(), &rect));
684 return rect;
685 }
686
708 FPoint RenderCoordinatesFromWindow(const SDL_FPoint& window_coord) const
709 {
710 FPoint p;
711 CheckError(SDL_RenderCoordinatesFromWindow(
712 get(), window_coord.x, window_coord.y, &p.x, &p.y));
713 return p;
714 }
715
738 FPoint RenderCoordinatesToWindow(const SDL_FPoint& coord) const
739 {
740 FPoint p;
742 SDL_RenderCoordinatesToWindow(get(), coord.x, coord.y, &p.x, &p.y));
743 return p;
744 }
745
779 {
780 CheckError(SDL_ConvertEventToRenderCoordinates(get(), event));
781 }
782
798 void ResetViewport() { SetViewport(std::nullopt); }
799
824 {
825 CheckError(SDL_SetRenderViewport(get(), rect));
826 }
827
845 {
846 Rect rect;
847 CheckError(SDL_GetRenderViewport(get(), &rect));
848 return rect;
849 }
850
870 bool IsViewportSet() const { return SDL_RenderViewportSet(get()); }
871
890 {
891 Rect rect;
892 CheckError(SDL_GetRenderSafeArea(get(), &rect));
893 return rect;
894 }
895
912
932 {
933 CheckError(SDL_SetRenderClipRect(get(), rect));
934 }
935
954 {
955 Rect rect;
956 CheckError(SDL_GetRenderClipRect(get(), &rect));
957 return rect;
958 }
959
976 bool IsClipEnabled() const { return SDL_RenderClipEnabled(get()); }
977
1001 void SetScale(SDL_FPoint scale)
1002 {
1003 CheckError(SDL_SetRenderScale(get(), scale.x, scale.y));
1004 }
1005
1022 {
1023 FPoint p;
1024 GetScale(&p.x, &p.y);
1025 return p;
1026 }
1027
1044 void GetScale(float* scaleX, float* scaleY) const
1045 {
1046 CheckError(SDL_GetRenderScale(get(), scaleX, scaleY));
1047 }
1048
1064 void SetDrawColor(SDL_Color c)
1065 {
1066 CheckError(SDL_SetRenderDrawColor(get(), c.r, c.g, c.b, c.a));
1067 }
1068
1084 void SetDrawColor(SDL_FColor c)
1085 {
1086 CheckError(SDL_SetRenderDrawColorFloat(get(), c.r, c.g, c.b, c.a));
1087 }
1088
1103 {
1104 FColor color;
1105 GetDrawColor(&color);
1106 return color;
1107 }
1108
1123 void GetDrawColor(SDL_Color* c) const
1124 {
1125 GetDrawColor(&c->r, &c->g, &c->b, &c->a);
1126 }
1127
1142 void GetDrawColor(SDL_FColor* c) const
1143 {
1144 GetDrawColor(&c->r, &c->g, &c->b, &c->a);
1145 }
1146
1166 void GetDrawColor(Uint8* r, Uint8* g, Uint8* b, Uint8* a) const
1167 {
1168 CheckError(SDL_GetRenderDrawColor(get(), r, g, b, a));
1169 }
1170
1190 void GetDrawColor(float* r, float* g, float* b, float* a) const
1191 {
1192 CheckError(SDL_GetRenderDrawColorFloat(get(), r, g, b, a));
1193 }
1194
1215 void SetColorScale(float scale)
1216 {
1217 CheckError(SDL_SetRenderColorScale(get(), scale));
1218 }
1219
1232 float GetColorScale() const
1233 {
1234 float scale;
1235 CheckError(SDL_GetRenderColorScale(get(), &scale));
1236 return scale;
1237 }
1238
1254 {
1255 CheckError(SDL_SetRenderDrawBlendMode(get(), blendMode));
1256 }
1257
1271 {
1272 BlendMode blendMode;
1273 CheckError(SDL_GetRenderDrawBlendMode(get(), &blendMode));
1274 return blendMode;
1275 }
1276
1293 void RenderClear() { CheckError(SDL_RenderClear(get())); }
1294
1307 void RenderPoint(SDL_FPoint p)
1308 {
1309 CheckError(SDL_RenderPoint(get(), p.x, p.y));
1310 }
1311
1325 {
1326 SDL_assert_paranoid(points.size() < SDL_MAX_SINT32);
1327 CheckError(SDL_RenderPoints(get(), points.data(), points.size()));
1328 }
1329
1343 void RenderLine(SDL_FPoint p1, SDL_FPoint p2)
1344 {
1345 CheckError(SDL_RenderLine(get(), p1.x, p1.y, p2.x, p2.y));
1346 }
1347
1362 {
1363 SDL_assert_paranoid(points.size() < SDL_MAX_SINT32);
1364 CheckError(SDL_RenderLines(get(), points.data(), points.size()));
1365 }
1366
1381 {
1382 CheckError(SDL_RenderRect(get(), rect));
1383 }
1384
1399 {
1400 SDL_assert_paranoid(rects.size() < SDL_MAX_SINT32);
1401 CheckError(SDL_RenderRects(get(), rects.data(), rects.size()));
1402 }
1403
1419 {
1420 CheckError(SDL_RenderFillRect(get(), rect));
1421 }
1422
1437 {
1438 SDL_assert_paranoid(rects.size() < SDL_MAX_SINT32);
1439 CheckError(SDL_RenderFillRects(get(), rects.data(), rects.size()));
1440 }
1441
1460 void RenderTexture(TextureBase& texture,
1463
1488 void RenderTextureRotated(TextureBase& texture,
1491 double angle,
1493 FlipMode flip = SDL_FLIP_NONE);
1494
1519 void RenderTextureAffine(TextureBase& texture,
1520 OptionalRef<const SDL_FRect> srcrect,
1521 OptionalRef<const SDL_FPoint> origin,
1522 OptionalRef<const SDL_FPoint> right,
1523 OptionalRef<const SDL_FPoint> down);
1524
1548 void RenderTextureTiled(TextureBase& texture,
1549 OptionalRef<const SDL_FRect> srcrect,
1550 float scale,
1551 OptionalRef<const SDL_FRect> dstrect);
1552
1583 void RenderTexture9Grid(TextureBase& texture,
1584 OptionalRef<const SDL_FRect> srcrect,
1585 float left_width,
1586 float right_width,
1587 float top_height,
1588 float bottom_height,
1589 float scale,
1590 OptionalRef<const SDL_FRect> dstrect);
1591
1610 void RenderGeometry(OptionalTexture texture,
1611 std::span<const Vertex> vertices,
1612 std::span<const int> indices = {});
1613
1641 const float* xy,
1642 int xy_stride,
1643 const FColor* color,
1644 int color_stride,
1645 const float* uv,
1646 int uv_stride,
1647 int num_vertices,
1648 const void* indices,
1649 int num_indices,
1650 int size_indices);
1651
1678 {
1679 return Surface(CheckError(SDL_RenderReadPixels(get(), rect)));
1680 }
1681
1729 void Present() { CheckError(SDL_RenderPresent(get())); }
1730
1760 void Flush() { CheckError(SDL_FlushRenderer(get())); }
1761
1783 void SetVSync(int vsync) { CheckError(SDL_SetRenderVSync(get(), vsync)); }
1784
1797 int GetVSync() const
1798 {
1799 int vsync;
1800 CheckError(SDL_GetRenderVSync(get(), &vsync));
1801 return vsync;
1802 }
1803
1841 {
1842 CheckError(SDL_RenderDebugText(get(), p.x, p.y, str));
1843 }
1844
1870 template<class... ARGS>
1871 void RenderDebugTextFormat(FPoint p, std::string_view fmt, ARGS... args)
1872 {
1873 RenderDebugText(p, std::vformat(fmt, std::make_format_args(args...)));
1874 }
1875};
1876
1886{
1888
1892 constexpr RendererRef(const RendererRef& other)
1893 : RendererBase(other.get())
1894 {
1895 }
1896
1900 constexpr RendererRef(RendererRef&& other)
1901 : RendererBase(other.release())
1902 {
1903 }
1904
1908 constexpr ~RendererRef() = default;
1909
1914 {
1915 release(other.release());
1916 return *this;
1917 }
1918
1931 void reset(SDL_Renderer* newResource = {})
1932 {
1933 SDL_DestroyRenderer(release(newResource));
1934 }
1935};
1936
1946{
1948
1952 constexpr explicit Renderer(SDL_Renderer* resource = {})
1953 : RendererRef(resource)
1954 {
1955 }
1956
1957 constexpr Renderer(const Renderer& other) = delete;
1958
1962 constexpr Renderer(Renderer&& other) = default;
1963
1968
1973 {
1974 reset(other.release());
1975 return *this;
1976 }
1977};
1978
1994struct TextureBase : Resource<SDL_Texture*>
1995{
1996 using Resource::Resource;
1997
2011 TextureBase(RendererBase& renderer, StringParam file);
2012
2027 TextureBase(RendererBase& renderer, IOStream& src);
2028
2049 PixelFormat format,
2050 TextureAccess access,
2051 const SDL_Point& size)
2053 SDL_CreateTexture(renderer.get(), format, access, size.x, size.y)))
2054 {
2055 }
2056
2080 : Resource(
2081 CheckError(SDL_CreateTextureFromSurface(renderer.get(), surface.get())))
2082 {
2083 }
2084
2197 SDL_CreateTextureWithProperties(renderer.get(), props.get())))
2198 {
2199 }
2200
2287 {
2288 return CheckError(SDL_GetTextureProperties(get()));
2289 }
2290
2301 RendererRef GetRenderer() const { return SDL_GetRendererFromTexture(get()); }
2302
2326 {
2327 SetColorMod(c.r, c.g, c.b);
2328 SetAlphaMod(c.a);
2329 }
2330
2354 {
2355 SetColorMod(c.r, c.g, c.b);
2356 SetAlphaMod(c.a);
2357 }
2358
2373 {
2374 FColor color;
2375 GetMod(&color);
2376 return color;
2377 }
2378
2392 void GetMod(Color* c) const
2393 {
2394 SDL_assert_paranoid(c != nullptr);
2395 GetColorMod(&c->r, &c->g, &c->b);
2396 GetAlphaMod(&c->a);
2397 }
2398
2412 void GetMod(FColor* c) const
2413 {
2414 SDL_assert_paranoid(c != nullptr);
2415 GetColorMod(&c->r, &c->g, &c->b);
2416 GetAlphaMod(&c->a);
2417 }
2418
2443 void SetColorMod(Uint8 r, Uint8 g, Uint8 b)
2444 {
2445 CheckError(SDL_SetTextureColorMod(get(), r, g, b));
2446 }
2447
2472 void SetColorMod(float r, float g, float b)
2473 {
2474 CheckError(SDL_SetTextureColorModFloat(get(), r, g, b));
2475 }
2476
2492 void GetColorMod(Uint8* r, Uint8* g, Uint8* b) const
2493 {
2494 CheckError(SDL_GetTextureColorMod(get(), r, g, b));
2495 }
2496
2512 void GetColorMod(float* r, float* g, float* b) const
2513 {
2514 CheckError(SDL_GetTextureColorModFloat(get(), r, g, b));
2515 }
2516
2538 void SetAlphaMod(Uint8 alpha)
2539 {
2540 CheckError(SDL_SetTextureAlphaMod(get(), alpha));
2541 }
2542
2564 void SetAlphaMod(float alpha)
2565 {
2566 CheckError(SDL_SetTextureAlphaModFloat(get(), alpha));
2567 }
2568
2577 float GetAlphaMod() const
2578 {
2579 float alpha;
2580 GetAlphaMod(&alpha);
2581 return alpha;
2582 }
2583
2597 void GetAlphaMod(Uint8* alpha) const
2598 {
2599 CheckError(SDL_GetTextureAlphaMod(get(), alpha));
2600 }
2601
2615 void GetAlphaMod(float* alpha) const
2616 {
2617 CheckError(SDL_GetTextureAlphaModFloat(get(), alpha));
2618 }
2619
2635 void SetBlendMode(BlendMode blendMode)
2636 {
2637 CheckError(SDL_SetTextureBlendMode(get(), blendMode));
2638 }
2639
2653 {
2654 BlendMode blendMode;
2655 CheckError(SDL_GetTextureBlendMode(get(), &blendMode));
2656 return blendMode;
2657 }
2658
2675 void SetScaleMode(ScaleMode scaleMode)
2676 {
2677 CheckError(SDL_SetTextureScaleMode(get(), scaleMode));
2678 }
2679
2693 {
2694 ScaleMode scaleMode;
2695 CheckError(SDL_GetTextureScaleMode(get(), &scaleMode));
2696 return scaleMode;
2697 }
2698
2729 void Update(OptionalRef<const SDL_Rect> rect, const void* pixels, int pitch)
2730 {
2731 CheckError(SDL_UpdateTexture(get(), rect, pixels, pitch));
2732 }
2733
2763 const Uint8* Yplane,
2764 int Ypitch,
2765 const Uint8* Uplane,
2766 int Upitch,
2767 const Uint8* Vplane,
2768 int Vpitch)
2769 {
2770 CheckError(SDL_UpdateYUVTexture(
2771 get(), rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch));
2772 }
2773
2799 const Uint8* Yplane,
2800 int Ypitch,
2801 const Uint8* UVplane,
2802 int UVpitch)
2803 {
2804 CheckError(
2805 SDL_UpdateNVTexture(get(), rect, Yplane, Ypitch, UVplane, UVpitch));
2806 }
2807
2831
2835 int GetWidth() const { return get()->w; }
2836
2840 int GetHeight() const { return get()->h; }
2841
2845 Point GetSize() const { return Point(GetWidth(), GetHeight()); }
2846
2850 PixelFormat GetFormat() const { return get()->format; }
2851};
2852
2862{
2864
2868 constexpr TextureRef(const TextureRef& other)
2869 : TextureBase(other.get())
2870 {
2871 }
2872
2876 constexpr TextureRef(TextureRef&& other)
2877 : TextureBase(other.release())
2878 {
2879 }
2880
2884 constexpr ~TextureRef() = default;
2885
2890 {
2891 release(other.release());
2892 return *this;
2893 }
2894
2907 void reset(SDL_Texture* newResource = {})
2908 {
2909 SDL_DestroyTexture(release(newResource));
2910 }
2911};
2912
2922{
2924
2928 constexpr explicit Texture(SDL_Texture* resource = {})
2929 : TextureRef(resource)
2930 {
2931 }
2932
2933 constexpr Texture(const Texture& other) = delete;
2934
2938 constexpr Texture(Texture&& other) = default;
2939
2944
2949 {
2950 reset(other.release());
2951 return *this;
2952 }
2953};
2954
2959{
2960 TextureRef texture;
2961
2965 explicit TextureLock(TextureRef texture, OptionalRef<const SDL_Rect> rect)
2966 : texture(std::move(texture))
2967 {
2968 SDL_Surface* maybeLock;
2969 if (SDL_LockTextureToSurface(this->texture.get(), rect, &maybeLock)) {
2970 release(maybeLock);
2971 } else {
2972 texture.release();
2973 }
2974 }
2975
2976public:
2978 constexpr TextureLock() = default;
2979
2980 // Copy ctor
2981 TextureLock(const TextureLock& other) = delete;
2982
2985 : SurfaceBase(other.release())
2986 , texture(other.texture.release())
2987 {
2988 }
2989
2995
2998 {
2999 Unlock();
3000 SurfaceBase::release(other.get());
3001 std::swap(texture, other.texture);
3002 return *this;
3003 }
3004
3022 void Unlock()
3023 {
3024 if (texture) {
3026 SDL_UnlockTexture(texture.release());
3027 }
3028 }
3029
3033 void* GetPixels() const { return get()->pixels; }
3034
3038 int GetPitch() const { return get()->pitch; }
3039
3041 void reset() { Unlock(); }
3042
3043 friend class TextureBase;
3044};
3045
3064inline int GetNumRenderDrivers() { return SDL_GetNumRenderDrivers(); }
3065
3088inline const char* GetRenderDriver(int index)
3089{
3090 return SDL_GetRenderDriver(index);
3091}
3092
3110inline std::pair<Window, Renderer> CreateWindowAndRenderer(
3111 StringParam title,
3112 SDL_Point size,
3113 WindowFlags window_flags = 0)
3114{
3115 SDL_Window* window;
3116 SDL_Renderer* renderer;
3117 CheckError(SDL_CreateWindowAndRenderer(
3118 title, size.x, size.y, window_flags, &window, &renderer));
3119 return {Window{window}, Renderer{renderer}};
3120}
3121
3122namespace prop::Renderer {
3123
3124constexpr auto CREATE_NAME_STRING = SDL_PROP_RENDERER_CREATE_NAME_STRING;
3125
3126constexpr auto CREATE_WINDOW_POINTER = SDL_PROP_RENDERER_CREATE_WINDOW_POINTER;
3127
3128constexpr auto CREATE_SURFACE_POINTER =
3129 SDL_PROP_RENDERER_CREATE_SURFACE_POINTER;
3130
3131constexpr auto CREATE_OUTPUT_COLORSPACE_NUMBER =
3132 SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER;
3133
3134constexpr auto CREATE_PRESENT_VSYNC_NUMBER =
3135 SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER;
3136
3137constexpr auto CREATE_VULKAN_INSTANCE_POINTER =
3138 SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER;
3139
3140constexpr auto CREATE_VULKAN_SURFACE_NUMBER =
3141 SDL_PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER;
3142
3143constexpr auto CREATE_VULKAN_PHYSICAL_DEVICE_POINTER =
3144 SDL_PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER;
3145
3146constexpr auto CREATE_VULKAN_DEVICE_POINTER =
3147 SDL_PROP_RENDERER_CREATE_VULKAN_DEVICE_POINTER;
3148
3149constexpr auto CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER =
3150 SDL_PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER;
3151
3152constexpr auto CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER =
3153 SDL_PROP_RENDERER_CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER;
3154
3155constexpr auto NAME_STRING = SDL_PROP_RENDERER_NAME_STRING;
3156
3157constexpr auto WINDOW_POINTER = SDL_PROP_RENDERER_WINDOW_POINTER;
3158
3159constexpr auto SURFACE_POINTER = SDL_PROP_RENDERER_SURFACE_POINTER;
3160
3161constexpr auto VSYNC_NUMBER = SDL_PROP_RENDERER_VSYNC_NUMBER;
3162
3163constexpr auto MAX_TEXTURE_SIZE_NUMBER =
3164 SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER;
3165
3166constexpr auto TEXTURE_FORMATS_POINTER =
3167 SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER;
3168
3169constexpr auto OUTPUT_COLORSPACE_NUMBER =
3170 SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER;
3171
3172constexpr auto HDR_ENABLED_BOOLEAN = SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN;
3173
3174constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT;
3175
3176constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_RENDERER_HDR_HEADROOM_FLOAT;
3177
3178constexpr auto D3D9_DEVICE_POINTER = SDL_PROP_RENDERER_D3D9_DEVICE_POINTER;
3179
3180constexpr auto D3D11_DEVICE_POINTER = SDL_PROP_RENDERER_D3D11_DEVICE_POINTER;
3181
3182constexpr auto D3D11_SWAPCHAIN_POINTER =
3183 SDL_PROP_RENDERER_D3D11_SWAPCHAIN_POINTER;
3184
3185constexpr auto D3D12_DEVICE_POINTER = SDL_PROP_RENDERER_D3D12_DEVICE_POINTER;
3186
3187constexpr auto D3D12_SWAPCHAIN_POINTER =
3188 SDL_PROP_RENDERER_D3D12_SWAPCHAIN_POINTER;
3189
3190constexpr auto D3D12_COMMAND_QUEUE_POINTER =
3191 SDL_PROP_RENDERER_D3D12_COMMAND_QUEUE_POINTER;
3192
3193constexpr auto VULKAN_INSTANCE_POINTER =
3194 SDL_PROP_RENDERER_VULKAN_INSTANCE_POINTER;
3195
3196constexpr auto VULKAN_SURFACE_NUMBER = SDL_PROP_RENDERER_VULKAN_SURFACE_NUMBER;
3197
3198constexpr auto VULKAN_PHYSICAL_DEVICE_POINTER =
3199 SDL_PROP_RENDERER_VULKAN_PHYSICAL_DEVICE_POINTER;
3200
3201constexpr auto VULKAN_DEVICE_POINTER = SDL_PROP_RENDERER_VULKAN_DEVICE_POINTER;
3202
3203constexpr auto VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER =
3204 SDL_PROP_RENDERER_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER;
3205
3206constexpr auto VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER =
3207 SDL_PROP_RENDERER_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER;
3208
3209constexpr auto VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER =
3210 SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER;
3211
3212constexpr auto GPU_DEVICE_POINTER = SDL_PROP_RENDERER_GPU_DEVICE_POINTER;
3213
3214} // namespace prop::Renderer
3215
3227{
3228 return CheckError(SDL_GetRenderer(get()));
3229}
3230
3231namespace prop::Texture {
3232
3233constexpr auto CREATE_COLORSPACE_NUMBER =
3234 SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER;
3235
3236constexpr auto CREATE_FORMAT_NUMBER = SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER;
3237
3238constexpr auto CREATE_ACCESS_NUMBER = SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER;
3239
3240constexpr auto CREATE_WIDTH_NUMBER = SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER;
3241
3242constexpr auto CREATE_HEIGHT_NUMBER = SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER;
3243
3244constexpr auto CREATE_SDR_WHITE_POINT_FLOAT =
3245 SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT;
3246
3247constexpr auto CREATE_HDR_HEADROOM_FLOAT =
3248 SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT;
3249
3250constexpr auto CREATE_D3D11_TEXTURE_POINTER =
3251 SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER;
3252
3253constexpr auto CREATE_D3D11_TEXTURE_U_POINTER =
3254 SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER;
3255
3256constexpr auto CREATE_D3D11_TEXTURE_V_POINTER =
3257 SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER;
3258
3259constexpr auto CREATE_D3D12_TEXTURE_POINTER =
3260 SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER;
3261
3262constexpr auto CREATE_D3D12_TEXTURE_U_POINTER =
3263 SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER;
3264
3265constexpr auto CREATE_D3D12_TEXTURE_V_POINTER =
3266 SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER;
3267
3268constexpr auto CREATE_METAL_PIXELBUFFER_POINTER =
3269 SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER;
3270
3271constexpr auto CREATE_OPENGL_TEXTURE_NUMBER =
3272 SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER;
3273
3274constexpr auto CREATE_OPENGL_TEXTURE_UV_NUMBER =
3275 SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER;
3276
3277constexpr auto CREATE_OPENGL_TEXTURE_U_NUMBER =
3278 SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER;
3279
3280constexpr auto CREATE_OPENGL_TEXTURE_V_NUMBER =
3281 SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER;
3282
3283constexpr auto CREATE_OPENGLES2_TEXTURE_NUMBER =
3284 SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER;
3285
3286constexpr auto CREATE_OPENGLES2_TEXTURE_UV_NUMBER =
3287 SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER;
3288
3289constexpr auto CREATE_OPENGLES2_TEXTURE_U_NUMBER =
3290 SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER;
3291
3292constexpr auto CREATE_OPENGLES2_TEXTURE_V_NUMBER =
3293 SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER;
3294
3295constexpr auto CREATE_VULKAN_TEXTURE_NUMBER =
3296 SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER;
3297
3298constexpr auto COLORSPACE_NUMBER = SDL_PROP_TEXTURE_COLORSPACE_NUMBER;
3299
3300constexpr auto FORMAT_NUMBER = SDL_PROP_TEXTURE_FORMAT_NUMBER;
3301
3302constexpr auto ACCESS_NUMBER = SDL_PROP_TEXTURE_ACCESS_NUMBER;
3303
3304constexpr auto WIDTH_NUMBER = SDL_PROP_TEXTURE_WIDTH_NUMBER;
3305
3306constexpr auto HEIGHT_NUMBER = SDL_PROP_TEXTURE_HEIGHT_NUMBER;
3307
3308constexpr auto SDR_WHITE_POINT_FLOAT = SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT;
3309
3310constexpr auto HDR_HEADROOM_FLOAT = SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT;
3311
3312constexpr auto D3D11_TEXTURE_POINTER = SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER;
3313
3314constexpr auto D3D11_TEXTURE_U_POINTER =
3315 SDL_PROP_TEXTURE_D3D11_TEXTURE_U_POINTER;
3316
3317constexpr auto D3D11_TEXTURE_V_POINTER =
3318 SDL_PROP_TEXTURE_D3D11_TEXTURE_V_POINTER;
3319
3320constexpr auto D3D12_TEXTURE_POINTER = SDL_PROP_TEXTURE_D3D12_TEXTURE_POINTER;
3321
3322constexpr auto D3D12_TEXTURE_U_POINTER =
3323 SDL_PROP_TEXTURE_D3D12_TEXTURE_U_POINTER;
3324
3325constexpr auto D3D12_TEXTURE_V_POINTER =
3326 SDL_PROP_TEXTURE_D3D12_TEXTURE_V_POINTER;
3327
3328constexpr auto OPENGL_TEXTURE_NUMBER = SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER;
3329
3330constexpr auto OPENGL_TEXTURE_UV_NUMBER =
3331 SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER;
3332
3333constexpr auto OPENGL_TEXTURE_U_NUMBER =
3334 SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER;
3335
3336constexpr auto OPENGL_TEXTURE_V_NUMBER =
3337 SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER;
3338
3339constexpr auto OPENGL_TEXTURE_TARGET_NUMBER =
3340 SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER;
3341
3342constexpr auto OPENGL_TEX_W_FLOAT = SDL_PROP_TEXTURE_OPENGL_TEX_W_FLOAT;
3343
3344constexpr auto OPENGL_TEX_H_FLOAT = SDL_PROP_TEXTURE_OPENGL_TEX_H_FLOAT;
3345
3346constexpr auto OPENGLES2_TEXTURE_NUMBER =
3347 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER;
3348
3349constexpr auto OPENGLES2_TEXTURE_UV_NUMBER =
3350 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER;
3351
3352constexpr auto OPENGLES2_TEXTURE_U_NUMBER =
3353 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER;
3354
3355constexpr auto OPENGLES2_TEXTURE_V_NUMBER =
3356 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER;
3357
3358constexpr auto OPENGLES2_TEXTURE_TARGET_NUMBER =
3359 SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER;
3360
3361constexpr auto VULKAN_TEXTURE_NUMBER = SDL_PROP_TEXTURE_VULKAN_TEXTURE_NUMBER;
3362
3363} // namespace prop::Texture
3364
3366{
3367 CheckError(SDL_SetRenderTarget(get(), texture.get()));
3368}
3369
3371{
3372 return SDL_GetRenderTarget(get());
3373}
3374
3378{
3379 CheckError(SDL_RenderTexture(get(), texture.get(), srcrect, dstrect));
3380}
3381
3383 TextureBase& texture,
3386 double angle,
3388 FlipMode flip)
3389{
3390 CheckError(SDL_RenderTextureRotated(
3391 get(), texture.get(), srcrect, dstrect, angle, center, flip));
3392}
3393
3395 TextureBase& texture,
3400{
3401 CheckError(SDL_RenderTextureAffine(
3402 get(), texture.get(), srcrect, origin, right, down));
3403}
3404
3406 TextureBase& texture,
3408 float scale,
3410{
3411 CheckError(
3412 SDL_RenderTextureTiled(get(), texture.get(), srcrect, scale, dstrect));
3413}
3414
3416 TextureBase& texture,
3418 float left_width,
3419 float right_width,
3420 float top_height,
3421 float bottom_height,
3422 float scale,
3424{
3425 CheckError(SDL_RenderTexture9Grid(get(),
3426 texture.get(),
3427 srcrect,
3428 left_width,
3429 right_width,
3430 top_height,
3431 bottom_height,
3432 scale,
3433 dstrect));
3434}
3435
3437 std::span<const Vertex> vertices,
3438 std::span<const int> indices)
3439{
3440 CheckError(SDL_RenderGeometry(get(),
3441 texture.get(),
3442 vertices.data(),
3443 vertices.size(),
3444 indices.data(),
3445 indices.size()));
3446}
3447
3449 const float* xy,
3450 int xy_stride,
3451 const FColor* color,
3452 int color_stride,
3453 const float* uv,
3454 int uv_stride,
3455 int num_vertices,
3456 const void* indices,
3457 int num_indices,
3458 int size_indices)
3459{
3460 CheckError(SDL_RenderGeometryRaw(get(),
3461 texture.get(),
3462 xy,
3463 xy_stride,
3464 color,
3465 color_stride,
3466 uv,
3467 uv_stride,
3468 num_vertices,
3469 indices,
3470 num_indices,
3471 size_indices));
3472}
3473
3490inline void* GetRenderMetalLayer(RendererBase& renderer)
3491{
3492 return CheckError(SDL_GetRenderMetalLayer(renderer.get()));
3493}
3494
3517{
3518 return CheckError(SDL_GetRenderMetalCommandEncoder(renderer.get()));
3519}
3520
3549 Uint32 wait_stage_mask,
3550 Sint64 wait_semaphore,
3551 Sint64 signal_semaphore)
3552{
3553 CheckError(SDL_AddVulkanRenderSemaphores(
3554 renderer.get(), wait_stage_mask, wait_semaphore, signal_semaphore));
3555}
3556
3557#ifdef SDL3PP_DOC
3558
3560#define SDL_RENDERER_VSYNC_DISABLED 0
3561
3563#define SDL_RENDERER_VSYNC_ADAPTIVE (-1)
3564
3574#define SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE 8
3575
3576#endif // SDL3PP_DOC
3577
3578#pragma region impl
3579
3580inline void RendererBase::ResetTarget() { return SetTarget(nullptr); }
3581
3583{
3584 return TextureLock{get(), rect};
3585}
3586
3599{
3600 Surface surface{LoadBMP(src)};
3601 return Texture(renderer, surface);
3602}
3603
3615{
3616 Surface surface{SDL_LoadBMP(file)};
3617 return Texture(renderer, surface);
3618}
3619
3620#pragma endregion impl
3621
3623
3624} // namespace SDL
3625
3626#endif /* SDL3PP_RENDER_H_ */
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
A optional reference to resource.
Definition SDL3pp_resource.h:88
Pixel format.
Definition SDL3pp_pixels.h:374
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