ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Renderer.h
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for SDL3 and C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <SDL3/SDL_gpu.h>
27
28#include <Objectively/Object.h>
29#include <Objectively/Vector.h>
30
31#include <ObjectivelyGPU.h>
32
33#include "Types.h"
34
42typedef struct Renderer Renderer;
43typedef struct RendererInterface RendererInterface;
44
51typedef struct {
53 vec2 uv;
54 SDL_Color color;
55 vec4 rect;
56 vec2 shape;
58
63typedef struct {
64 Texture *texture;
65 SDL_Rect scissor;
66 Uint32 firstVertex;
67 Uint32 vertexCount;
68} MVC_DrawArrays;
69
75struct Renderer {
76
80 Object object;
81
86 RendererInterface *interface[0];
87
92 CommandBuffer *commands;
93
97 RenderDevice *device;
98
103 Vector *drawArrays;
104
110 Framebuffer *framebuffer;
111
116 GraphicsPipeline *pipeline;
117
124 Sampler *sampler;
125
130 SDL_Rect scissor;
131
136 Vector *vertices;
137
142 Buffer *vertexBuffer;
143
148 Uint32 vertexBufferCapacity;
149
156 TransferBuffer *transferBuffer;
157
162 Texture *white;
163};
164
168struct RendererInterface {
169
173 ObjectInterface objectInterface;
174
185 void (*beginFrame)(Renderer *self);
186
195 void (*beginFrameWith)(Renderer *self, CommandBuffer *commands, Framebuffer *framebuffer);
196
210 void (*drawBevel)(const Renderer *self, const SDL_Rect *rect, int radius, int width,
211 const SDL_Color *topLeft, const SDL_Color *bottomRight);
212
221 void (*drawLine)(const Renderer *self, const SDL_Point *points, const SDL_Color *color);
222
232 void (*drawLines)(const Renderer *self, const SDL_Point *points, size_t count, const SDL_Color *color);
233
246 void (*drawPolygon)(const Renderer *self, const SDL_Point *points, size_t count, int width,
247 const SDL_Color *color);
248
264 void (*drawPolygonFilled)(const Renderer *self, const SDL_Point *points, size_t count,
265 int angle, const SDL_Color *from, const SDL_Color *to);
266
275 void (*drawRect)(const Renderer *self, const SDL_Rect *rect, const SDL_Color *color);
276
285 void (*drawRectFilled)(const Renderer *self, const SDL_Rect *rect, const SDL_Color *color);
286
297 void (*drawRoundedRect)(const Renderer *self, const SDL_Rect *rect, int radius, int width, const SDL_Color *color);
298
308 void (*drawRoundedRectFilled)(const Renderer *self, const SDL_Rect *rect, int radius, const SDL_Color *color);
309
322 void (*drawRoundedRectGradientFilled)(const Renderer *self, const SDL_Rect *rect, int radius,
323 int angle, const SDL_Color *from, const SDL_Color *to);
324
335 void (*drawRoundedTexture)(const Renderer *self, Texture *texture, const SDL_FRect *dest, int radius, const SDL_Color *color);
336
348 void (*drawRoundedTextureRegion)(const Renderer *self, Texture *texture, const SDL_Rect *src, const SDL_FRect *dest, int radius, const SDL_Color *color);
349
364 void (*drawTexture)(const Renderer *self, Texture *texture, const SDL_FRect *dest, const SDL_Color *color);
365
377 void (*drawTextureRegion)(const Renderer *self, Texture *texture, const SDL_Rect *src, const SDL_FRect *dest, const SDL_Color *color);
378
391 void (*drawView)(Renderer *self, View *view);
392
401 void (*endFrame)(Renderer *self);
402
411 Renderer *(*initWithDevice)(Renderer *self, RenderDevice *device);
412
430 void (*pushDrawArrays)(const Renderer *self, const MVC_Vertex *verts, size_t count,
431 Texture *texture, const SDL_Color *color);
432
439 void (*renderDeviceDidReset)(Renderer *self);
440
447 void (*renderDeviceWillReset)(Renderer *self);
448
457 void (*setClippingFrame)(Renderer *self, const SDL_Rect *clippingFrame);
458};
459
static Texture * texture(ImageAtlas *self, RenderDevice *device)
Definition ImageAtlas.c:289
OBJECTIVELYMVC_EXPORT Class * _Renderer(void)
Definition Renderer.c:890
ObjectivelyMVC base types.
#define OBJECTIVELYMVC_EXPORT
Definition Types.h:40
static SDL_Rect clippingFrame(const View *self)
Definition View.c:606
Interleaved position + texcoord + color + rounded rect shape vertex for GPU upload.
Definition Renderer.h:51
SDL_Color color
Definition Renderer.h:54
vec2 uv
Definition Renderer.h:53
vec4 rect
Definition Renderer.h:55
vec2 position
Definition Renderer.h:52
vec2 shape
Definition Renderer.h:56
Renderer extends Object with ObjectivelyMVC's UI rendering layer.
Definition Renderer.h:75
RendererInterface * interface[0]
The interface type.
Definition Renderer.h:86
RenderDevice * device
The backing RenderDevice.
Definition Renderer.h:97
Object object
The superclass.
Definition Renderer.h:80
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:225