rolmodl
C++ API for the Simple Directmedia Library 2 (SDL2)
|
14 namespace ren::driver {
16 int res = SDL_GetNumRenderDrivers();
18 return static_cast<unsigned int>(res);
24 SDL_RendererInfo tmp{};
25 throwOnErr(SDL_GetRenderDriverInfo(static_cast<int>(i), &tmp));
32 for (
unsigned int j = 0; j < tmp.num_texture_formats; ++j)
33 res.pixelFmts[j] = pixelfmt::id::unsafe::fromSDLEnum(tmp.texture_formats[j]);
35 res.maxTexSize =
geom::Size{tmp.max_texture_width, tmp.max_texture_height};
45 h_(SDL_CreateRenderer(win.unsafeRaw(), i, flags.raw()))
51 Ren(win, -1, flags) {}
52 Ren::Ren(
Win& win,
int i) :
53 Ren(win, i, ren::Flags()) {}
59 SDL_DestroyRenderer(h_);
64 Ren::Ren(
Ren&& that) noexcept :
87 assert(h_ !=
nullptr);
91 assert(h_ !=
nullptr);
109 SDL_Rect tmp = src.
sdl();
117 SDL_Rect tmp = dst.
sdl();
125 SDL_Rect srcTmp = src.
sdl();
126 SDL_Rect dstTmp = dst.
sdl();
147 SDL_Point p{rotCenter.x, rotCenter.y};
158 SDL_Rect srcTmp = src.
sdl();
165 SDL_Rect srcTmp = src.
sdl();
166 SDL_Point p{rotCenter.x, rotCenter.y};
170 drawTex(tex, src.
wh(), rot, rotCenter, flip);
180 SDL_Rect dstTmp = dst.
sdl();
187 SDL_Rect dstTmp = dst.
sdl();
188 SDL_Point p{rotCenter.x, rotCenter.y};
192 drawTex(tex, dst.
wh(), rot, rotCenter, flip);
196 drawTex(tex, src, dst, 0, flip);
208 SDL_Rect srcTmp = src.
sdl();
209 SDL_Rect dstTmp = dst.
sdl();
222 SDL_Rect srcTmp = src.
sdl();
223 SDL_Rect dstTmp = dst.
sdl();
224 SDL_Point p{rotCenter.x, rotCenter.y};
228 drawTex(tex, src, dst.
wh(), rot, rotCenter, flip);
231 drawTex(tex, src.
wh(), dst, rot, rotCenter, flip);
234 drawTex(tex, src.
wh(), dst.
wh(), rot, rotCenter, flip);
248 SDL_Rect tmp = r.sdl();
257 SDL_Rect tmp = r.sdl();
274 SDL_RenderGetClipRect(
unsafeRaw(), &tmp);
275 if (tmp.w != 0 || tmp.h != 0)
280 SDL_Rect tmp = r.sdl();
290 return SDL_RenderIsClipEnabled(
unsafeRaw()) == SDL_TRUE;
295 SDL_RenderGetLogicalSize(
unsafeRaw(), &tmp.w, &tmp.h);
296 if (tmp.w != 0 || tmp.h != 0)
312 SDL_RenderGetScale(
unsafeRaw(), &res.x, &res.y);
321 SDL_RenderGetViewport(
unsafeRaw(), &tmp);
325 SDL_Rect tmp = r.sdl();
330 SDL_BlendMode tmp = SDL_BLENDMODE_NONE;
352 Ren(win, i, flags.withToTexture()) {}
354 Ren(win, flags.withToTexture()) {}
356 Ren(win, i, ren::Flags().withToTexture()) {}
358 Ren(win, ren::Flags().withToTexture()) {}
Rendering scaling factors.
~Ren() noexcept
Free the underlying SDL_Renderer.
int throwOnErr(const int code)
Throw a rolmodl::sdlexception if code < 0.
constexpr BlendMode fromSDLEnum(const SDL_BlendMode m) noexcept
Convert an SDL_BlendMode value to a rolmodl::BlendMode value.
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...
SDL_Texture * unsafeGetTarget() noexcept
Query the current rendering target. Unsafe because it returns a raw non-owning pointer to the texture...
Renderer class that does not support rendering to texture. Use rolmodl::TexRen for rendering to textu...
constexpr SDL_BlendMode toSDLEnum(const BlendMode m) noexcept
Convert a rolmodl::BlendMode value to an SDL_BlendMode value.
RenScale scale() noexcept
Query the rendering scaling factors.
constexpr SDL_Rect sdl() const noexcept
Convert to an SDL_Rect.
void setTarget(RenTex &tex)
Set the rendering target.
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 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...
geom::Size getRealSize()
Query the target resolution in device pixels.
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...
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.
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.
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.
Information about a rendering driver.
std::optional< geom::Size > logicalSize() noexcept
Query the device-independent resolution.
RGBA color()
Query the current drawing color.
Rendering flip configuration container.
Rectangle specifying the destination rectangle for a rendering operation by its top left and bottom r...
bool isClipOn() noexcept
Query whether the clipping rectangle has been set.
void setLogicalSize(const geom::Size s)
Set the device-independent resolution to s.
void disableClip()
Unset the clipping rectangle.
Renderer configuration (flags) container.
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.
Exception type containing an error code and the last SDL error at the moment of creation.
BlendMode
Describes how colors are combined when rendering twice to the same place.
geom::RectWH viewport() noexcept
Query the subarea of the target used for drawing.
int point data type. The value is in pixels. Semantically different from rolmodl::geom::Size.
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....
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 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...