[Bf-blender-cvs] [cf4646b] master: commiting patch to fix T30173

Benoit Bolsee noreply at git.blender.org
Sat Feb 21 13:21:52 CET 2015


Commit: cf4646b95f7dac74fb67300a2df43bc973e7709d
Author: Benoit Bolsee
Date:   Mon May 26 10:38:12 2014 +0100
Branches: master
https://developer.blender.org/rBcf4646b95f7dac74fb67300a2df43bc973e7709d

commiting patch to fix T30173

===================================================================

M	source/gameengine/VideoTexture/Texture.cpp
M	source/gameengine/VideoTexture/Texture.h

===================================================================

diff --git a/source/gameengine/VideoTexture/Texture.cpp b/source/gameengine/VideoTexture/Texture.cpp
index 74f3620..5eb609c 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 c85b122..1befb62 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




More information about the Bf-blender-cvs mailing list