|
ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
|
Renderer extends Object with ObjectivelyMVC's UI rendering layer. More...
#include <Renderer.h>
Public Member Functions | |
| Class * | _Renderer (void) |
| The Renderer archetype. | |
| void | beginFrame (Renderer *self) |
Prepares this Renderer for a new frame using self->device's current command buffer and framebuffer. | |
| void | beginFrameWith (Renderer *self, CommandBuffer *commands, Framebuffer *framebuffer) |
| Prepares this Renderer for a new frame using the given command buffer and framebuffer. | |
| void | drawBevel (const Renderer *self, const SDL_Rect *rect, int radius, int width, const SDL_Color *topLeft, const SDL_Color *bottomRight) |
| Records a rounded rectangle outline split diagonally into two colors. | |
| void | drawLine (const Renderer *self, const SDL_Point *points, const SDL_Color *color) |
| Records a line segment between two points. | |
| void | drawLines (const Renderer *self, const SDL_Point *points, size_t count, const SDL_Color *color) |
| Records a polyline through the given points. | |
| void | drawPolygon (const Renderer *self, const SDL_Point *points, size_t count, int width, const SDL_Color *color) |
| Records a closed polygon outline of the given width. | |
| void | drawPolygonFilled (const Renderer *self, const SDL_Point *points, size_t count, int angle, const SDL_Color *from, const SDL_Color *to) |
| Records a filled convex polygon, optionally with a linear gradient. | |
| void | drawRect (const Renderer *self, const SDL_Rect *rect, const SDL_Color *color) |
| Records a rectangle outline. | |
| void | drawRectFilled (const Renderer *self, const SDL_Rect *rect, const SDL_Color *color) |
| Records a filled rectangle. | |
| void | drawRoundedRect (const Renderer *self, const SDL_Rect *rect, int radius, int width, const SDL_Color *color) |
Records a rounded rectangle outline of the given width, drawn inside rect. | |
| void | drawRoundedRectFilled (const Renderer *self, const SDL_Rect *rect, int radius, const SDL_Color *color) |
| Records a filled rounded rectangle. | |
| void | drawRoundedRectGradientFilled (const Renderer *self, const SDL_Rect *rect, int radius, int angle, const SDL_Color *from, const SDL_Color *to) |
| Records a rounded rectangle filled with a linear gradient. | |
| void | drawRoundedTexture (const Renderer *self, Texture *texture, const SDL_FRect *dest, int radius, const SDL_Color *color) |
| Records a textured quad clipped to a rounded rectangle. | |
| void | drawRoundedTextureRegion (const Renderer *self, Texture *texture, const SDL_Rect *src, const SDL_FRect *dest, int radius, const SDL_Color *color) |
| Records a region of a texture as a quad clipped to a rounded rectangle. | |
| void | drawTexture (const Renderer *self, Texture *texture, const SDL_FRect *dest, const SDL_Color *color) |
| Records a textured quad in the given destination rectangle. | |
| void | drawTextureRegion (const Renderer *self, Texture *texture, const SDL_Rect *src, const SDL_FRect *dest, const SDL_Color *color) |
| Records a region of a texture as a quad in the given destination rectangle. | |
| void | drawView (Renderer *self, View *view) |
| Sets the clipping frame and invokes View::render for the given View. | |
| void | endFrame (Renderer *self) |
Uploads MVC vertices and executes the UI render pass into the Framebuffer given to beginFrame/beginFrameWith (LOAD_OP_LOAD). | |
| Renderer * | initWithDevice (Renderer *self, RenderDevice *device) |
| Initializes this Renderer with the given RenderDevice. | |
| void | pushDrawArrays (const Renderer *self, const MVC_Vertex *verts, size_t count, Texture *texture, const SDL_Color *color) |
| Appends raw vertices and a draw call record to the frame queue. | |
| void | renderDeviceDidReset (Renderer *self) |
| Recreates MVC GPU resources after the backing RenderDevice resets. | |
| void | renderDeviceWillReset (Renderer *self) |
| Releases MVC GPU resources before the backing RenderDevice resets. | |
| void | setClippingFrame (Renderer *self, const SDL_Rect *clippingFrame) |
| Sets the scissor rectangle for subsequent draw calls. | |
Data Fields | |
| RenderDevice * | device |
| The backing RenderDevice. | |
| Object | object |
| The superclass. | |
Protected Attributes | |
| RendererInterface * | interface [0] |
| The interface type. | |
Renderer extends Object with ObjectivelyMVC's UI rendering layer.
Create a WindowController to instantiate a default Renderer.
Definition at line 75 of file Renderer.h.
| Class * _Renderer | ( | void | ) |
The Renderer archetype.
Definition at line 890 of file Renderer.c.
| void beginFrame | ( | Renderer * | self | ) |
Prepares this Renderer for a new frame using self->device's current command buffer and framebuffer.
Convenience over beginFrameWith for the common case of rendering the UI into the device's own current frame. Equivalent to $(self, beginFrameWith, self->device->commands, self->device->framebuffer).
| self | The Renderer. |
Definition at line 101 of file Renderer.c.
| void beginFrameWith | ( | Renderer * | self, |
| CommandBuffer * | commands, | ||
| Framebuffer * | framebuffer | ||
| ) |
Prepares this Renderer for a new frame using the given command buffer and framebuffer.
| self | The Renderer. |
| commands | The frame's CommandBuffer. The caller retains ownership and must submit and release it. |
| framebuffer | The target Framebuffer for this frame. Borrowed for the duration of the frame. |
Definition at line 109 of file Renderer.c.
| void drawBevel | ( | const Renderer * | self, |
| const SDL_Rect * | rect, | ||
| int | radius, | ||
| int | width, | ||
| const SDL_Color * | topLeft, | ||
| const SDL_Color * | bottomRight | ||
| ) |
Records a rounded rectangle outline split diagonally into two colors.
The outline is drawn inside rect. The half above the bottom-left to top-right diagonal takes topLeft; the other half takes bottomRight.
| self | The Renderer. |
| rect | The rectangle. |
| radius | The corner radius. |
| width | The outline width. |
| topLeft | The color of the top and left edges. |
| bottomRight | The color of the bottom and right edges. |
Definition at line 247 of file Renderer.c.
| void drawLine | ( | const Renderer * | self, |
| const SDL_Point * | points, | ||
| const SDL_Color * | color | ||
| ) |
Records a line segment between two points.
| self | The Renderer. |
| points | Two points defining the line segment. |
| color | The line color. |
Definition at line 266 of file Renderer.c.
| void drawLines | ( | const Renderer * | self, |
| const SDL_Point * | points, | ||
| size_t | count, | ||
| const SDL_Color * | color | ||
| ) |
Records a polyline through the given points.
| self | The Renderer. |
| points | The points. |
| count | The number of points. |
| color | The line color. |
Definition at line 277 of file Renderer.c.
| void drawPolygon | ( | const Renderer * | self, |
| const SDL_Point * | points, | ||
| size_t | count, | ||
| int | width, | ||
| const SDL_Color * | color | ||
| ) |
Records a closed polygon outline of the given width.
The stroke is centered on each edge. Joints are not mitered, so a width well above the one or two pixels a border uses will notch at sharp corners.
| self | The Renderer. |
| points | The points, in order; the last is joined back to the first. |
| count | The number of points; fewer than three draws nothing. |
| width | The stroke width. |
| color | The outline color. |
Definition at line 293 of file Renderer.c.
| void drawPolygonFilled | ( | const Renderer * | self, |
| const SDL_Point * | points, | ||
| size_t | count, | ||
| int | angle, | ||
| const SDL_Color * | from, | ||
| const SDL_Color * | to | ||
| ) |
Records a filled convex polygon, optionally with a linear gradient.
The polygon is triangulated as a fan from its first vertex, so it MUST be convex. It is drawn without the rounded rectangle shader, and so without its anti-aliasing: diagonal edges are hard.
| self | The Renderer. |
| points | The points, in order. |
| count | The number of points; fewer than three draws nothing. |
| angle | The gradient angle in degrees, clockwise from south. Ignored when to is NULL. |
| from | The fill color, and the near color of the gradient. |
| to | The far color of the gradient, or NULL to fill flat with from. |
Definition at line 310 of file Renderer.c.
| void drawRect | ( | const Renderer * | self, |
| const SDL_Rect * | rect, | ||
| const SDL_Color * | color | ||
| ) |
Records a rectangle outline.
| self | The Renderer. |
| rect | The rectangle. |
| color | The outline color. |
Definition at line 365 of file Renderer.c.
| void drawRectFilled | ( | const Renderer * | self, |
| const SDL_Rect * | rect, | ||
| const SDL_Color * | color | ||
| ) |
Records a filled rectangle.
| self | The Renderer. |
| rect | The rectangle. |
| color | The fill color. |
Definition at line 384 of file Renderer.c.
| void drawRoundedRect | ( | const Renderer * | self, |
| const SDL_Rect * | rect, | ||
| int | radius, | ||
| int | width, | ||
| const SDL_Color * | color | ||
| ) |
Records a rounded rectangle outline of the given width, drawn inside rect.
| self | The Renderer. |
| rect | The rectangle. |
| radius | The corner radius. |
| width | The outline width. |
| color | The outline color. |
Definition at line 407 of file Renderer.c.
| void drawRoundedRectFilled | ( | const Renderer * | self, |
| const SDL_Rect * | rect, | ||
| int | radius, | ||
| const SDL_Color * | color | ||
| ) |
Records a filled rounded rectangle.
| self | The Renderer. |
| rect | The rectangle. |
| radius | The corner radius. |
| color | The fill color. |
Definition at line 424 of file Renderer.c.
| void drawRoundedRectGradientFilled | ( | const Renderer * | self, |
| const SDL_Rect * | rect, | ||
| int | radius, | ||
| int | angle, | ||
| const SDL_Color * | from, | ||
| const SDL_Color * | to | ||
| ) |
Records a rounded rectangle filled with a linear gradient.
| self | The Renderer. |
| rect | The rectangle. |
| radius | The corner radius. |
| angle | The gradient angle in degrees, clockwise from south: 0 fills downwards, 90 to the right, 180 upwards. |
| from | The near color of the gradient. |
| to | The far color of the gradient. |
Definition at line 441 of file Renderer.c.
| void drawRoundedTexture | ( | const Renderer * | self, |
| Texture * | texture, | ||
| const SDL_FRect * | dest, | ||
| int | radius, | ||
| const SDL_Color * | color | ||
| ) |
Records a textured quad clipped to a rounded rectangle.
| self | The Renderer. |
| texture | The Texture to sample. |
| dest | The destination rectangle in logical screen coordinates. |
| radius | The corner radius. |
| color | The color multiplier (use &Colors.White for no tint). |
Definition at line 465 of file Renderer.c.
| void drawRoundedTextureRegion | ( | const Renderer * | self, |
| Texture * | texture, | ||
| const SDL_Rect * | src, | ||
| const SDL_FRect * | dest, | ||
| int | radius, | ||
| const SDL_Color * | color | ||
| ) |
Records a region of a texture as a quad clipped to a rounded rectangle.
| self | The Renderer. |
| texture | The Texture to sample. |
| src | The region of texture to sample, in texels, or NULL for all of it. |
| dest | The destination rectangle in logical screen coordinates. |
| radius | The corner radius. |
| color | The color multiplier (use &Colors.White for no tint). |
Definition at line 473 of file Renderer.c.
| void drawTexture | ( | const Renderer * | self, |
| Texture * | texture, | ||
| const SDL_FRect * | dest, | ||
| const SDL_Color * | color | ||
| ) |
Records a textured quad in the given destination rectangle.
| self | The Renderer. |
| texture | The Texture to sample. |
| dest | The destination rectangle in logical screen coordinates. |
dest is a sub-pixel-precise SDL_FRect, not SDL_Rect: a caller that needs the texture drawn at its exact native resolution (e.g. Text, to avoid a fractional stretch that shifts every glyph as the string's pixel width changes) must pass an unrounded size here, since rounding it to the nearest integer logical unit first is precisely what reintroduces that stretch. | color | The color multiplier (use &Colors.White for no tint). |
Definition at line 489 of file Renderer.c.
| void drawTextureRegion | ( | const Renderer * | self, |
| Texture * | texture, | ||
| const SDL_Rect * | src, | ||
| const SDL_FRect * | dest, | ||
| const SDL_Color * | color | ||
| ) |
Records a region of a texture as a quad in the given destination rectangle.
This is how an AtlasImage is drawn: src is its rect within the atlas sheet.
| self | The Renderer. |
| texture | The Texture to sample. |
| src | The region of texture to sample, in texels, or NULL for all of it. |
| dest | The destination rectangle in logical screen coordinates. |
| color | The color multiplier (use &Colors.White for no tint). |
Definition at line 497 of file Renderer.c.
Sets the clipping frame and invokes View::render for the given View.
A View whose View::clippingFrame is empty is culled. Otherwise the scissor is set to the View::clippingFrame of the nearest ancestor with clipsSubviews set, or to the full framebuffer when there is none. A View is therefore NOT clipped to its own frame: one that draws outside its bounds does so visibly, and a container that wants to clip its contents MUST set clipsSubviews.
Definition at line 525 of file Renderer.c.
| void endFrame | ( | Renderer * | self | ) |
Uploads MVC vertices and executes the UI render pass into the Framebuffer given to beginFrame/beginFrameWith (LOAD_OP_LOAD).
The caller is responsible for submitting the command buffer after this returns.
| self | The Renderer. |
Definition at line 555 of file Renderer.c.
Initializes this Renderer with the given RenderDevice.
| self | The Renderer. |
| device | The RenderDevice. |
NULL on error. Definition at line 639 of file Renderer.c.
| void pushDrawArrays | ( | const Renderer * | self, |
| const MVC_Vertex * | verts, | ||
| size_t | count, | ||
| Texture * | texture, | ||
| const SDL_Color * | color | ||
| ) |
Appends raw vertices and a draw call record to the frame queue.
Views that need full draw-call control can call this directly instead of going through the drawLine/drawRect/drawTexture helpers. Consecutive calls that share both texture and the current scissor are merged into one draw call. Only the immediately preceding record is considered, so draw order matters: a quad from another texture between two same-texture quads breaks the run.
| self | The Renderer. |
| verts | The vertices to append (in logical screen coordinates). |
| count | The number of vertices. |
| texture | The texture to bind, or NULL to use the 1×1 white fallback. |
| color | The color to apply to every vertex, or NULL to keep the colors the vertices already carry. MVC_Vertex::color is interpolated across the triangle, so NULL is how a caller draws a gradient. |
Definition at line 660 of file Renderer.c.
| void renderDeviceDidReset | ( | Renderer * | self | ) |
Recreates MVC GPU resources after the backing RenderDevice resets.
| self | The Renderer. |
Definition at line 705 of file Renderer.c.
| void renderDeviceWillReset | ( | Renderer * | self | ) |
Releases MVC GPU resources before the backing RenderDevice resets.
| self | The Renderer. |
Definition at line 820 of file Renderer.c.
| void setClippingFrame | ( | Renderer * | self, |
| const SDL_Rect * | clippingFrame | ||
| ) |
Sets the scissor rectangle for subsequent draw calls.
| self | The Renderer. |
| clippingFrame | The clipping rectangle in logical screen coordinates, or NULL to disable clipping (full window scissor). |
Definition at line 841 of file Renderer.c.
| RenderDevice* Renderer::device |
The backing RenderDevice.
Definition at line 97 of file Renderer.h.
|
protected |
The interface type.
Definition at line 86 of file Renderer.h.
| Object Renderer::object |
The superclass.
Definition at line 80 of file Renderer.h.