From cf4646b95f7dac74fb67300a2df43bc973e7709d Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Mon, 26 May 2014 10:38:12 +0100 Subject: commiting patch to fix T30173 --- source/gameengine/VideoTexture/Texture.cpp | 12 ++++++++++++ source/gameengine/VideoTexture/Texture.h | 4 ++++ 2 files changed, 16 insertions(+) (limited to 'source') diff --git a/source/gameengine/VideoTexture/Texture.cpp b/source/gameengine/VideoTexture/Texture.cpp index 74f36207774..5eb609c0823 100644 --- a/source/gameengine/VideoTexture/Texture.cpp +++ b/source/gameengine/VideoTexture/Texture.cpp @@ -41,6 +41,7 @@ #include "DNA_meshdata_types.h" #include "DNA_image_types.h" #include "IMB_imbuf_types.h" +#include "BKE_image.h" #include "MEM_guardedalloc.h" @@ -158,6 +159,7 @@ static PyObject *Texture_new(PyTypeObject *type, PyObject *args, PyObject *kwds) // initialize object structure self->m_actTex = 0; self->m_orgSaved = false; + self->m_imgBuf = NULL; self->m_imgTexture = NULL; self->m_matTexture = NULL; self->m_mipmap = false; @@ -282,7 +284,11 @@ PyObject *Texture_close(Texture * self) if (self->m_useMatTexture) self->m_matTexture->swapTexture(self->m_orgTex); else + { self->m_imgTexture->bindcode = self->m_orgTex; + BKE_image_release_ibuf(self->m_imgTexture, self->m_imgBuf, NULL); + self->m_imgBuf = NULL; + } // drop actual texture if (self->m_actTex != 0) { @@ -331,6 +337,12 @@ static PyObject *Texture_refresh(Texture *self, PyObject *args) self->m_orgTex = self->m_matTexture->swapTexture(self->m_actTex); else { + // Swapping will work only if the GPU has already loaded the image. + // If not, it will delete and overwrite our texture on next render. + // To avoid that, we acquire the image buffer now. + // WARNING: GPU has a ImageUser to pass, we don't. Using NULL + // works on image file, not necessarily on other type of image. + self->m_imgBuf = BKE_image_acquire_ibuf(self->m_imgTexture, NULL, NULL); self->m_orgTex = self->m_imgTexture->bindcode; self->m_imgTexture->bindcode = self->m_actTex; } diff --git a/source/gameengine/VideoTexture/Texture.h b/source/gameengine/VideoTexture/Texture.h index c85b1228864..1befb620447 100644 --- a/source/gameengine/VideoTexture/Texture.h +++ b/source/gameengine/VideoTexture/Texture.h @@ -43,6 +43,8 @@ #include "Exception.h" +struct ImBuf; + // type Texture declaration struct Texture { @@ -58,6 +60,8 @@ struct Texture // original texture saved bool m_orgSaved; + // kernel image buffer, to make sure the image is loaded before we swap the bindcode + struct ImBuf *m_imgBuf; // texture image for game materials Image * m_imgTexture; // texture for blender materials -- cgit v1.2.3