Prepare for texture streaming and locking.

The intention is to static stream the gui areas into one big texture.
This commit is contained in:
Linus Probert 2018-05-08 16:34:22 +10:00
parent 9d7669fd35
commit 2122300f6e
2 changed files with 45 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <physfs.h>
#include <stdlib.h>
#include <assert.h>
#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,

View File

@ -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*);