diff --git a/src/texture.c b/src/texture.c index d920c5f..dd7131c 100644 --- a/src/texture.c +++ b/src/texture.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "texture.h" #include "util.h" #include "io_util.h" @@ -34,9 +35,40 @@ texture_create(void) t->font = NULL; t->lastAccess = SDL_GetTicks(); t->path = ""; + t->textureAccessType = SDL_TEXTUREACCESS_STATIC; + t->locked = false; return t; } +void +texture_create_blank(Texture *t, + SDL_TextureAccess access, + SDL_Renderer *renderer) +{ + t->texture = SDL_CreateTexture(renderer, + SDL_PIXELFORMAT_RGBA8888, + access, + t->dim.width, + t->dim.height); + t->textureAccessType = access; +} + +void +texture_lock(Texture *t, SDL_Rect *rect, void **pixels, int *pitch) +{ + assert (!t->locked); + t->locked = true; + SDL_LockTexture(t->texture, rect, pixels, pitch); +} + +void +texture_unlock(Texture *t) +{ + assert (t->locked); + t->locked = false; + SDL_UnlockTexture(t->texture); +} + void texture_load_from_file(Texture *texture, const char *path, diff --git a/src/texture.h b/src/texture.h index 489a01a..04db976 100644 --- a/src/texture.h +++ b/src/texture.h @@ -31,11 +31,24 @@ typedef struct { Dimension dim; const char *path; unsigned long lastAccess; + SDL_TextureAccess textureAccessType; + bool locked; } Texture; Texture* texture_create(void); +void +texture_create_blank(Texture *t, + SDL_TextureAccess, + SDL_Renderer*); + +void +texture_lock(Texture*, SDL_Rect*, void **pixels, int *pitch); + +void +texture_unlock(Texture*); + void texture_load_from_file(Texture*, const char *path, SDL_Renderer*);