diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 17:41:00 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:18:11 +0300 |
commit | d140e70c496122915eb5c05aba83153e2e0d7998 (patch) | |
tree | 1e589247d69da64aa7b0e7802319237ec050b5d6 /source/blender/makesrna/intern/rna_image_api.c | |
parent | 147bd16ed1bb3415b30408b0eab110d0854eadd2 (diff) | |
parent | 295d0c52a26730edc6d4ed1276e4051cce006be5 (diff) |
Merge branch 'master' into temp-ghash-experimentstemp-ghash-experiments
Note that 'store hash' feature was removed for now - to complex to maintain (conflicts)
and relatively easy to re-add if we ever really want this one day.
Conflicts:
source/blender/blenlib/BLI_ghash.h
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/hash_mm2a.c
source/blender/bmesh/tools/bmesh_region_match.c
tests/gtests/blenlib/BLI_ghash_performance_test.cc
tests/gtests/blenlib/BLI_ghash_test.cc
tests/gtests/blenlib/CMakeLists.txt
Diffstat (limited to 'source/blender/makesrna/intern/rna_image_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_image_api.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index 357490924f2..c3c152a10b6 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -35,6 +35,7 @@ #include <time.h> #include "DNA_packedFile_types.h" +#include "DNA_userdef_types.h" #include "BLI_utildefines.h" #include "BLI_path_util.h" @@ -55,8 +56,8 @@ #include "IMB_imbuf.h" #include "IMB_colormanagement.h" -#include "BIF_gl.h" #include "GPU_draw.h" +#include "GPU_debug.h" #include "DNA_image_types.h" #include "DNA_scene_types.h" @@ -115,9 +116,14 @@ static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *r BLI_strncpy(filename, image->name, sizeof(filename)); BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id)); - if (image->packedfile) { - if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) { - BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'", image->id.name + 2, image->name); + if (BKE_image_has_packedfile(image)) { + ImagePackedFile *imapf; + + for (imapf = image->packedfiles.first; imapf; imapf = imapf->next) { + if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) { + BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'", + image->id.name + 2, imapf->filepath); + } } } else if (IMB_saveiff(ibuf, filename, ibuf->flags)) { @@ -152,20 +158,17 @@ static void rna_Image_pack( BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG"); } else { - if (image->packedfile) { - freePackedFile(image->packedfile); - image->packedfile = NULL; - } + BKE_image_free_packedfiles(image); if (as_png) { BKE_image_memorypack(image); } else if (data) { char *data_dup = MEM_mallocN(sizeof(*data_dup) * (size_t)data_len, __func__); memcpy(data_dup, data, (size_t)data_len); - image->packedfile = newPackedFileMemory(data_dup, data_len); + BKE_image_packfiles_from_mem(reports, image, data_dup, (size_t)data_len); } else { - image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(bmain, &image->id)); + BKE_image_packfiles(reports, image, ID_BLEND_PATH(bmain, &image->id)); } } @@ -175,7 +178,7 @@ static void rna_Image_pack( static void rna_Image_unpack(Image *image, ReportList *reports, int method) { - if (!image->packedfile) { + if (!BKE_image_has_packedfile(image)) { BKE_report(reports, RPT_ERROR, "Image not packed"); } else if (BKE_image_is_animated(image)) { @@ -232,31 +235,23 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int f ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); + /* clean glError buffer */ + while (glGetError() != GL_NO_ERROR) {} + if (ibuf == NULL || ibuf->rect == NULL) { BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2); BKE_image_release_ibuf(image, ibuf, NULL); return (int)GL_INVALID_OPERATION; } - /* could be made into a function? */ - glGenTextures(1, (GLuint *)bind); - glBindTexture(GL_TEXTURE_2D, *bind); - - if (filter != GL_NEAREST && filter != GL_LINEAR) - error = (int)gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); + GPU_create_gl_tex(bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, + (filter != GL_NEAREST && filter != GL_LINEAR), false, image); - if (!error) { - /* clean glError buffer */ - while (glGetError() != GL_NO_ERROR) {} + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint)filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLint)mag); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, image->tpageflag & IMA_CLAMP_U ? GL_CLAMP : GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, image->tpageflag & IMA_CLAMP_V ? GL_CLAMP : GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint)filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLint)mag); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); - error = (int)glGetError(); - } + error = glGetError(); if (error) { glDeleteTextures(1, (GLuint *)bind); @@ -294,6 +289,11 @@ static void rna_Image_filepath_from_user(Image *image, ImageUser *image_user, ch BKE_image_user_file_path(image_user, image, filepath); } +static void rna_Image_buffers_free(Image *image) +{ + BKE_image_free_buffers(image); +} + #else void RNA_api_image(StructRNA *srna) @@ -380,6 +380,9 @@ void RNA_api_image(StructRNA *srna) RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */ RNA_def_function_output(func, parm); + func = RNA_def_function(srna, "buffers_free", "rna_Image_buffers_free"); + RNA_def_function_ui_description(func, "Free the image buffers from memory"); + /* TODO, pack/unpack, maybe should be generic functions? */ } |