Add texture_image_free().

Cleans up deinit code for textures.
This commit is contained in:
Themaister 2013-12-31 19:16:29 +01:00
parent 132c3c46f7
commit 0d3428ad15
8 changed files with 30 additions and 25 deletions

View File

@ -423,25 +423,7 @@ static void *rmenu_init(void)
static void rmenu_free_assets(void *data)
{
#ifdef _XBOX1
if (menu_texture->vertex_buf)
{
menu_texture->vertex_buf->Release();
menu_texture->vertex_buf = NULL;
}
if (menu_texture->pixels)
{
menu_texture->pixels->Release();
menu_texture->pixels = NULL;
}
#else
if (menu_texture->pixels)
{
free(menu_texture->pixels);
menu_texture->pixels = NULL;
}
#endif
texture_image_free(&menu_texture);
menu_texture_inited = false;
}

View File

@ -233,3 +233,9 @@ bool texture_image_load(const char *path, struct texture_image *out_img)
return texture_image_load_argb_shift(path, out_img, 24, 16, 8, 0);
}
void texture_image_free(struct texture_image *img)
{
free(img->pixels);
memset(img, 0, sizeof(*img));
}

View File

@ -39,6 +39,7 @@ struct texture_image
};
bool texture_image_load(const char *path, struct texture_image* img);
void texture_image_free(struct texture_image *img);
#endif

View File

@ -511,8 +511,6 @@ static void load_texture_data(GLuint obj, const struct texture_image *img, bool
glTexImage2D(GL_TEXTURE_2D,
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, img->width, img->height,
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, img->pixels);
free(img->pixels);
}
static bool load_textures(void)
@ -528,7 +526,7 @@ static bool load_textures(void)
RARCH_LOG("Loading image from: \"%s\".\n",
cg_shader->lut[i].path);
struct texture_image img;
struct texture_image img = {0};
if (!texture_image_load(cg_shader->lut[i].path, &img))
{
RARCH_ERR("Failed to load picture ...\n");
@ -538,6 +536,7 @@ static bool load_textures(void)
load_texture_data(lut_textures[i], &img,
cg_shader->lut[i].filter != RARCH_FILTER_NEAREST,
gl_wrap_type_to_enum(cg_shader->lut[i].wrap));
texture_image_free(&img);
}
glBindTexture(GL_TEXTURE_2D, 0);

View File

@ -324,7 +324,7 @@ static bool load_luts(void)
RARCH_GL_FORMAT32, img.pixels);
glBindTexture(GL_TEXTURE_2D, 0);
free(img.pixels);
texture_image_free(&img);
}
return true;

View File

@ -239,10 +239,10 @@ static void input_overlay_free_overlay(struct overlay *overlay)
{
size_t i;
for (i = 0; i < overlay->size; i++)
free(overlay->descs[i].image.pixels);
texture_image_free(&overlay->descs[i].image);
free(overlay->load_images);
free(overlay->descs);
free(overlay->image.pixels);
texture_image_free(&overlay->image);
}
static void input_overlay_free_overlays(input_overlay_t *ol)

View File

@ -314,3 +314,10 @@ bool texture_image_load(const char *path, struct texture_image *out_img)
return true;
}
void texture_image_free(struct texture_image *img)
{
free(img->pixels);
memset(img, 0, sizeof(*img));
}

View File

@ -53,3 +53,13 @@ bool texture_image_load(const char *path, struct texture_image *out_img)
return true;
}
void texture_image_free(struct texture_image *img)
{
if (img->vertex_buf)
img->vertex_buf->Release();
if (img->pixels)
img->pixels->Release();
memset(img, 0, sizeof(*img));
}