Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2010-04-13 16:51:03 +0400
committerJoseph Eagar <joeedh@gmail.com>2010-04-13 16:51:03 +0400
commit86aa4e5c3d7e0b95d9e55bab027f968b42a3eda6 (patch)
tree9208dfc29a7f163ea7af988ad663cfc7c78d2ae1 /source/blender/gpu
parente50f7986476a2fe5604d78db6dea784384d3e38f (diff)
prevent images from freeing gpu buffers if not run within the main thread, instead they are queued to be freed the next time GPU_image_free() is run from the main thread.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/intern/gpu_draw.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index d3a4621c793..652902e3035 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -62,6 +62,9 @@
#include "BKE_object.h"
#include "BKE_utildefines.h"
+#include "BLI_threads.h"
+#include "BLI_blenlib.h"
+
#include "GPU_extensions.h"
#include "GPU_material.h"
#include "GPU_draw.h"
@@ -781,8 +784,42 @@ void GPU_create_smoke(SmokeModifierData *smd, int highres)
smd->domain->tex_shadow = GPU_texture_create_3D(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2], smd->domain->shadow);
}
+ListBase image_free_queue = {NULL, NULL};
+static void flush_queued_free(void)
+{
+ Image *ima, *imanext;
+
+ BLI_lock_thread(LOCK_IMAGE);
+
+ ima = image_free_queue.first;
+ image_free_queue.first = image_free_queue.last = NULL;
+ for (; ima; ima=imanext) {
+ imanext = (Image*)ima->id.next;
+ GPU_free_image(ima);
+ MEM_freeN(ima);
+ }
+
+ BLI_unlock_thread(LOCK_IMAGE);
+}
+
+static void queue_image_for_free(Image *ima)
+{
+ Image *cpy = MEM_dupallocN(ima);
+
+ BLI_lock_thread(LOCK_IMAGE);
+ BLI_addtail(&image_free_queue, cpy);
+ BLI_unlock_thread(LOCK_IMAGE);
+}
+
void GPU_free_image(Image *ima)
{
+ if (!BLI_thread_is_main()) {
+ queue_image_for_free(ima);
+ return;
+ } else if (image_free_queue.first) {
+ flush_queued_free();
+ }
+
/* free regular image binding */
if(ima->bindcode) {
glDeleteTextures(1, (GLuint *)&ima->bindcode);