rolmodl
C++ API for the Simple Directmedia Library 2 (SDL2)
|
Go to the documentation of this file.
8 #include "forwarddecl/Ren.hpp"
10 #include "forwarddecl/Win.hpp"
11 #include "forwarddecl/Tex.hpp"
12 #include "forwarddecl/Base.hpp"
47 namespace blendMode::unsafe {
50 if (m == SDL_BLENDMODE_NONE)
52 if (m == SDL_BLENDMODE_BLEND)
54 if (m == SDL_BLENDMODE_ADD)
62 return SDL_BLENDMODE_NONE;
64 return SDL_BLENDMODE_BLEND;
66 return SDL_BLENDMODE_ADD;
68 return SDL_BLENDMODE_MOD;
77 constexpr
Flip() noexcept :
84 return Flip(data_ | static_cast<uint32_t>(SDL_FLIP_HORIZONTAL));
88 return Flip(data_ | static_cast<uint32_t>(SDL_FLIP_VERTICAL));
94 return Flip(data_ | static_cast<uint32_t>(SDL_FLIP_HORIZONTAL));
98 return Flip(data_ | static_cast<uint32_t>(SDL_FLIP_VERTICAL));
104 return Flip(data_ & ~static_cast<uint32_t>(SDL_FLIP_HORIZONTAL));
108 return Flip(data_ & ~static_cast<uint32_t>(SDL_FLIP_VERTICAL));
113 return static_cast<SDL_RendererFlip>(data_);
116 constexpr uint32_t
raw() const noexcept {
120 explicit constexpr
Flip(
const uint32_t data) noexcept :
146 return (data_ & static_cast<uint32_t>(SDL_RENDERER_SOFTWARE)) != 0;
150 return (data_ & static_cast<uint32_t>(SDL_RENDERER_ACCELERATED)) != 0;
154 return (data_ & static_cast<uint32_t>(SDL_RENDERER_PRESENTVSYNC)) != 0;
158 return (data_ & static_cast<uint32_t>(SDL_RENDERER_TARGETTEXTURE)) != 0;
164 return Flags(data_ | static_cast<uint32_t>(SDL_RENDERER_SOFTWARE));
168 return Flags(data_ | static_cast<uint32_t>(SDL_RENDERER_ACCELERATED));
172 return Flags(data_ | static_cast<uint32_t>(SDL_RENDERER_PRESENTVSYNC));
176 return Flags(data_ | static_cast<uint32_t>(SDL_RENDERER_TARGETTEXTURE));
182 return Flags(data_ & ~static_cast<uint32_t>(SDL_RENDERER_SOFTWARE));
186 return Flags(data_ & ~static_cast<uint32_t>(SDL_RENDERER_ACCELERATED));
190 return Flags(data_ & ~static_cast<uint32_t>(SDL_RENDERER_PRESENTVSYNC));
194 return Flags(data_ & ~static_cast<uint32_t>(SDL_RENDERER_TARGETTEXTURE));
198 constexpr uint32_t
raw() const noexcept {
206 explicit constexpr
Flags(
const uint32_t data) noexcept :
235 unsigned int count();
268 return SrcRectXY(tmp.x, tmp.y, tmp.x1, tmp.y1);
273 return SrcRectWH(tmp.x, tmp.y, tmp.w, tmp.h);
289 return DstRectXY(tmp.x, tmp.y, tmp.x1, tmp.y1);
294 return DstRectWH(tmp.x, tmp.y, tmp.w, tmp.h);
330 Ren(
const Ren& that) =
delete;
345 const SDL_Renderer*
unsafeRaw()
const noexcept;
Rendering scaling factors.
~Ren() noexcept
Free the underlying SDL_Renderer.
constexpr Flags withToTexture() const noexcept
Create a version of this configuration that corresponds to a renderer capable of rendering to texture...
constexpr BlendMode fromSDLEnum(const SDL_BlendMode m) noexcept
Convert an SDL_BlendMode value to a rolmodl::BlendMode value.
Alpha-blending. Treats the alpha value as transparency. Equivalent SDL enum is SDL_BLENDMODE_BLEND.
void setBlendMode(const BlendMode m)
Set the blending mode used for draw operations to m. Does not effect how textures are blended.
Rectangle specifying the source rectangle for a rendering operation by its top left corner coordinate...
constexpr uint32_t raw() const noexcept
Return the underlying bitfield representation of this configuration.
SDL_Texture * unsafeGetTarget() noexcept
Query the current rendering target. Unsafe because it returns a raw non-owning pointer to the texture...
constexpr Flip withoutVertical() const noexcept
Create a version of this configuration that does not have vertical flipping enabled....
Renderer class that does not support rendering to texture. Use rolmodl::TexRen for rendering to textu...
constexpr Flags withoutToTexture() const noexcept
Create a version of this configuration that corresponds to a renderer that is not capable of renderin...
constexpr SDL_BlendMode toSDLEnum(const BlendMode m) noexcept
Convert a rolmodl::BlendMode value to an SDL_BlendMode value.
constexpr bool isToTexture() const noexcept
Test whether this configuration corresponds to a renderer capable of rendering to texture....
constexpr DstRectXY xy() const noexcept
Convert to an equivalent rolmodl::DstRectXY.
RenScale scale() noexcept
Query the rendering scaling factors.
Renderer class that supports rendering to texture. Use rolmodl::Ren if you do not need support for re...
void setTarget(RenTex &tex)
Set the rendering target.
geom::Size maxTexSize
Maximum texture size supported by the driver.
void setDefaultTarget()
Reset the rendering target to the default one. Usually it is the window for which the renderer was cr...
RGBA color type. Has an alpha component.
void fillRect(const geom::RectWH r)
Fill the width-height rect r with the drawing color.
constexpr Flags withoutVsync() const noexcept
Create a version of this configuration that corresponds to a renderer that is not VSync....
constexpr Flip withHorizontal() const noexcept
Create a version of this configuration that has horizontal flipping enabled. The SDL flag equivalent ...
constexpr DstRectWH wh() const noexcept
Convert to an equivalent rolmodl::DstRectWH.
Rectangle specifying the destination rectangle for a rendering operation by its top left corner coord...
constexpr Flip withoutHorizontal() const noexcept
Create a version of this configuration that does not have horizontal flipping enabled....
geom::Size getRealSize()
Query the target resolution in device pixels.
constexpr bool isSoftware() const noexcept
Test whether this configuration corresponds to a software renderer. The SDL flag equivalent is SDL_RE...
Ren & operator=(const Ren &that)=delete
Copying rolmodl renderers is not allowed because their lifetime is tied to the underlying SDL_Rendere...
int dimensions data type. The value is in pixels. Semantically different from rolmodl::geom::Pos.
void drawRect(const geom::RectWH r)
Draw the outline of the width-height rect r with the drawing color.
constexpr SDL_RendererFlip toSDLEnum() const noexcept
Return the underlying bitfield representation of this configuration as the SDL enum type SDL_Renderer...
std::vector< pixelfmt::Id > pixelFmts
Pixel formats supported by the driver.
constexpr SrcRectWH wh() const noexcept
Convert to an equivalent rolmodl::SrcRectWH.
Window class for use with accelerated rendering (rolmodl::Ren).
void fillScreen()
Fill the rendering target with the drawing color.
void setColor(const RGBA c)
Set the drawing color to c.
void setScale(const RenScale s)
Set the rendering scaling factors to s.
constexpr RectXY xy() const noexcept
Convert to an equivalent rolmodl::geom::RectXY.
constexpr RectWH(const int argX, const int argY, const int argW, const int argH) noexcept
Initialize with the given top left corner x and y, width, and height.
const char * name
Name of the driver.
void outlineScreen()
Draw an outline around the rendering target with the drawing color.
BlendMode getBlendMode()
Get the blending mode used for draw operations. Textures have their own separate belnding mode.
Rectangle represented by its top left corner coordinates and its bottom right corner coordinates.
Additive blending. Equivalent SDL enum is SDL_BLENDMODE_ADD.
constexpr Flip isHorizontal() const noexcept
Test whether this configuration has horizontal flipping enabled. The SDL flag equivalent is SDL_FLIP_...
Rectangle represented by its top left corner coordinates, width, and height.
void clear()
Paint over the entire rendering target with the current color.
void drawLine(const geom::Pos a, const geom::Pos b)
Draw a line from point a to point b with the drawing color.
TexRen(Win &win, int i, ren::Flags flags)
Initialize a renderer for window win, using the ith rendering driver, with a version of configuration...
unsigned int count()
Query the amount of available rendering drivers.
constexpr RectWH wh() const noexcept
Convert to an equivalent rolmodl::geom::RectWH.
constexpr SrcRectXY xy() const noexcept
Convert to an equivalent rolmodl::SrcRectXY.
Information about a rendering driver.
std::optional< geom::Size > logicalSize() noexcept
Query the device-independent resolution.
constexpr Flip withVertical() const noexcept
Create a version of this configuration that has vertical flipping enabled. The SDL flag equivalent is...
RGBA color()
Query the current drawing color.
Rendering flip configuration container.
constexpr Flags() noexcept
Create a configuration corresponding to a default renderer.
constexpr bool isVsync() const noexcept
Test whether this configuration corresponds to a VSync renderer. The SDL flag equivalent is SDL_RENDE...
Do not blend. Equivalent SDL enum is SDL_BLENDMODE_NONE.
Rectangle specifying the destination rectangle for a rendering operation by its top left and bottom r...
constexpr uint32_t raw() const noexcept
Return the underlying bitfield representation of this configuration.
bool isClipOn() noexcept
Query whether the clipping rectangle has been set.
void setLogicalSize(const geom::Size s)
Set the device-independent resolution to s.
constexpr Flip isVertical() const noexcept
Test whether this configuration has vertical flipping enabled. The SDL flag equivalent is SDL_FLIP_VE...
void disableClip()
Unset the clipping rectangle.
Renderer configuration (flags) container.
constexpr RectXY(const int argX, const int argY, const int argX1, const int argY1) noexcept
Initialize with the given top left corner x and y, and the bottom right corner x and y.
constexpr Flags withAccelerated() const noexcept
Create a version of this configuration that corresponds to an accelerated renderer....
void drawTex(Tex &tex)
Copy the entire texture tex to fill the entire rendering target.
void setClipRect(const geom::RectWH r)
Set the clipping rectangle to r.
constexpr Flags withSoftware() const noexcept
Create a version of this configuration that corresponds to a software renderer. The SDL flag equivale...
constexpr bool isAccelerated() const noexcept
Test whether this configuration corresponds to an accelerated renderer. The SDL flag equivalent is SD...
Color modulation blending. Equivalent SDL enum is SDL_BLENDMODE_MOD.
geom::RectWH viewport() noexcept
Query the subarea of the target used for drawing.
BlendMode
Describes how colors are combined when rendering twice to the same place.
int point data type. The value is in pixels. Semantically different from rolmodl::geom::Size.
constexpr Flags withoutSoftware() const noexcept
Create a version of this configuration that corresponds to a renderer that is not software....
constexpr Flip() noexcept
Create a configuration corresponding to no flipping. The SDL flag equivalent is SDL_FLIP_NONE.
std::optional< geom::RectWH > clipRect() noexcept
Get the clipping rectangle. std::nullopt is returned if the clipping rectangle has not been set.
void present() noexcept
Push the backbuffer to screen, displaying any changes made since the last present....
constexpr Flags withoutAccelerated() const noexcept
Create a version of this configuration that corresponds to a renderer that is not accelerated....
Info info(const unsigned int i)
Query the driver info for the ith rendering driver.
void drawPoint(const geom::Pos p)
Set the pixel at point p to the drawing color.
Rectangle specifying the source rectangle for a rendering operation by its top left and bottom right ...
constexpr Flags withVsync() const noexcept
Create a version of this configuration that corresponds to a VSync renderer. The SDL flag equivalent ...
friend void swap(Ren &a, Ren &b) noexcept
Exchange the underlying SDL_Renderer with that.
Flags flags
Maximal renderer configuration supported by the driver.
constexpr static Flags unsafeFromRaw(const uint32_t data) noexcept
Create a configuration representing the bitfield data. Unsafe because data is not verified as represe...
void setViewport(const geom::RectWH r)
Set the subarea of the target used for drawing to the rectangle r.
SDL_Renderer * unsafeRaw() noexcept
Get the underlying SDL_Renderer*. Unsafe because this value might be nullptr and using it with some S...