1 #if !defined(_BTK_RENDERER_HPP_) 2 #define _BTK_RENDERER_HPP_ 15 #include <SDL2/SDL_rect.h> 16 typedef SDL_Rect BtkRect;
17 typedef SDL_Point BtkVec2;
24 typedef struct BtkTexture BtkTexture;
29 typedef struct BtkRenderer BtkRenderer;
43 BtkRenderer *(*CreateRenderer)(SDL_Window *win,
int index,Uint32 flags);
48 BtkTexture *(*CreateTexture)(BtkRenderer*,Uint32 fmt,
int access,
int w,
int h);
49 BtkTexture *(*CreateTextureFrom)(BtkRenderer*,SDL_Surface*);
54 BtkTexture *(*LoadTextureFrom)(BtkRenderer*,SDL_RWops*);
60 void (*DestroyRenderer)(BtkRenderer *);
62 void (*RenderPresent)(BtkRenderer *);
64 int (*RenderDrawRect) (BtkRenderer*,
const BtkRect *);
65 int (*RenderDrawRects)(BtkRenderer*,
const BtkRect *,
int n);
66 int (*RenderDrawBox )(BtkRenderer*,
const BtkRect *);
67 int (*RenderDrawBoxs)(BtkRenderer*,
const BtkRect *,
int n);
68 int (*RenderDrawLine)(BtkRenderer*,
int x1,
int y1,
int x2,
int y2);
69 int (*RenderDrawLines)(BtkRenderer*,
const BtkVec2 *vec2s,
int n);
70 int (*RenderDrawPoint)(BtkRenderer*,
int x1,
int y1);
71 int (*RenderDrawPoints)(BtkRenderer*,
const BtkVec2 *points,
int n);
73 int (*RenderSetDrawColor)(BtkRenderer*,Uint8 r,Uint8 g,Uint8 b,Uint8 a);
74 int (*RenderGetDrawColor)(BtkRenderer*,Uint8 *r,Uint8 *g,Uint8 *b,Uint8 *a);
76 void (*RenderGetClipRect)(BtkRenderer*,BtkRect *cliprect);
77 int (*RenderSetClipRect)(BtkRenderer*,
const BtkRect *cliprect);
79 void (*RenderGetViewPort)(BtkRenderer*,BtkRect *viewport);
80 int (*RenderSetViewPort)(BtkRenderer*,
const BtkRect *viewport);
82 int (*RenderCopy)(BtkRenderer*,BtkTexture *t,
const BtkRect *src,
const BtkRect *dst);
83 int (*RenderClear)(BtkRenderer*);
85 int (*QueryTexture)(BtkTexture*,Uint32 *fmt,
int *access,
int *w,
int *h);
86 int (*UpdateTexture)(BtkTexture*,
const BtkRect *rect,
const void *pixels,
int pitch);
88 int (*LockTexture)(BtkTexture*,
const BtkRect *rect,
void **pixels,
int *pitch);
89 void (*UnlockTexture)(BtkTexture *);
93 int (*SetError)(
const char *fmt,...);
94 const char *(*GetError)();
96 extern BTKAPI
struct BtkTable btk_rtbl;
98 BTKAPI
void Btk_ResetRITable();
99 #define Btk_CreateRenderer (btk_rtbl.CreateRenderer) 100 #define Btk_CreateTexture (btk_rtbl.CreateTexture) 101 #define Btk_DestroyTexture (btk_rtbl.DestroyTexture) 102 #define Btk_DestroyRenderer (btk_rtbl.DestroyRenderer) 104 #define Btk_RenderDrawRect (btk_rtbl.RenderDrawRect) 105 #define Btk_RenderDrawRects (btk_rtbl.RenderDrawRects) 107 #define Btk_RenderDrawBox (btk_rtbl.RenderDrawBox) 108 #define Btk_RenderDrawBoxs (btk_rtbl.RenderDrawBoxs) 110 #define Btk_RenderDrawLine (btk_rtbl.RenderDrawLine) 111 #define Btk_RenderDrawLines (btk_rtbl.RenderDrawLines) 113 #define Btk_RenderDrawPoint (btk_rtbl.RenderDrawPoint) 114 #define Btk_RenderDrawPoints (btk_rtbl.RenderDrawPoints) 116 #define Btk_RenderSetClipRect (btk_rtbl.RenderSetClipRect) 117 #define Btk_RenderGetClipRect (btk_rtbl.RenderGetClipRect) 119 #define Btk_RenderSetViewPort (btk_rtbl.RenderSetViewPort) 120 #define Btk_RenderGetViewPort (btk_rtbl.RenderGetViewPort) 122 #define Btk_RenderSetDrawColor (btk_rtbl.RenderSetDrawColor) 124 #define Btk_RenderCopy (btk_rtbl.RenderCopy) 125 #define Btk_RenderClear (btk_rtbl.RenderClear) 126 #define Btk_RenderPresent (btk_rtbl.RenderPresent) 129 #define Btk_QueryTexture (btk_rtbl.QueryTexture) 130 #define Btk_UpdateTexture (btk_rtbl.UpdateTexture) 132 #define Btk_LockTexture (btk_rtbl.LockTexture) 133 #define Btk_UnlockTexture (btk_rtbl.UnlockTexture) 135 #define Btk_CreateTextureFromSurface (btk_rtbl.CreateTextureFrom) 136 #define Btk_CreateTextureFrom (btk_rtbl.CreateTextureFrom) 137 #define Btk_LoadTexture (btk_rtbl.LoadTextureFrom) 139 #define Btk_RISetError (btk_rtbl.SetError) 140 #define Btk_RIGetError (btk_rtbl.GetError) 151 class BTKAPI Renderer{
153 Renderer(SDL_Window *win);
154 Renderer(
const Renderer &) =
delete;
158 Btk_RenderGetClipRect(render,&rect);
162 return Btk_RenderSetClipRect(render,
nullptr);
164 int set_cliprect(
const Rect &r){
165 return Btk_RenderSetClipRect(render,&r);
170 Btk_RenderGetViewPort(render,&rect);
174 return Btk_RenderSetViewPort(render,
nullptr);
176 int set_viewport(
const Rect &r){
177 return Btk_RenderSetViewPort(render,&r);
181 int copy(
const Texture &t,
const Rect *src,
const Rect *dst){
182 return Btk_RenderCopy(render,t.get(),src,dst);
184 int copy(
const Texture &t,
const Rect &src,
const Rect *dst){
185 return Btk_RenderCopy(render,t.get(),&src,dst);
187 int copy(
const Texture &t,
const Rect *src,
const Rect &dst){
188 return Btk_RenderCopy(render,t.get(),src,&dst);
190 int copy(
const Texture &t,
const Rect &src,
const Rect &dst){
191 return Btk_RenderCopy(render,t.get(),&src,&dst);
195 return Btk_RenderClear(render);
198 Btk_RenderPresent(render);
205 Btk_DestroyRenderer(render);
213 int line(
int x1,
int y1,
int x2,
int y2,Color c);
214 int line(
const Vec2 &beg,
const Vec2 &end,Color c){
215 return line(beg.x,beg.y,end.x,end.y,c);
217 int aaline(
int x1,
int y1,
int x2,
int y2,Color c);
219 int rect(
const Rect &r,Color c);
220 int box(
const Rect &r,Color c);
222 int rounded_box(
const Rect &r,
int rad,Color c);
223 int rounded_rect(
const Rect &r,
int rad,Color c);
230 Texture create_from(
const PixBuf &pixbuf);
240 Texture create(Uint32 fmt,TextureAccess access,
int w,
int h);
247 Texture load(std::string_view fname);
248 Texture load(RWops &);
258 int copy(
const PixBuf &pixbuf,
const Rect *src,
const Rect *dst);
259 int copy(
const PixBuf &pixbuf,
const Rect *src,
const Rect &dst){
260 return copy(pixbuf,src,&dst);
262 int copy(
const PixBuf &pixbuf,
const Rect &src,
const Rect *dst){
263 return copy(pixbuf,&src,dst);
265 int copy(
const PixBuf &pixbuf,
const Rect &src,
const Rect &dst){
266 return copy(pixbuf,&src,&dst);
269 BtkRenderer *render =
nullptr;
270 BtkTexture *cache =
nullptr;
274 struct LockGuard<BtkTexture*>{
275 LockGuard(BtkTexture *t,
const Rect *r =
nullptr){
277 Btk_LockTexture(texture,r,&pixels,&pitch);
279 LockGuard(BtkTexture *t,
const Rect &r){
281 Btk_LockTexture(texture,&r,&pixels,&pitch);
283 LockGuard(
const LockGuard &) =
delete;
285 Btk_UnlockTexture(texture);
294 #endif // _BTK_RENDERER_HPP_ a SDL_Rect with methods
Definition: rect.hpp:10
Renderer Interface Table.
Definition: render.hpp:34
This header include many useful containers.
Definition: async.hpp:7
void(* DestroyTexture)(BtkTexture *)
Destroy a texture.
Definition: render.hpp:59