瀏覽代碼

Create texture in online() and destroy it in offline()

Daniele Bartolini 12 年之前
父節點
當前提交
9f69f9b972
共有 1 個文件被更改,包括 10 次插入2 次删除
  1. 10 2
      engine/resource/TextureResource.h

+ 10 - 2
engine/resource/TextureResource.h

@@ -32,6 +32,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Bundle.h"
 #include "Allocator.h"
 #include "File.h"
+#include "Device.h"
+#include "Renderer.h"
 
 namespace crown
 {
@@ -74,7 +76,9 @@ public:
 	//-----------------------------------------------------------------------------
 	static void online(void* resource)
 	{
-		CE_ASSERT(resource != NULL, "Resource not loaded");
+		TextureResource* t = (TextureResource*) resource;
+
+		t->m_texture = device()->renderer()->create_texture(t->width(), t->height(), t->format(), t->data());
 	}
 
 	//-----------------------------------------------------------------------------
@@ -87,9 +91,11 @@ public:
 	}
 
 	//-----------------------------------------------------------------------------
-	static void offline(void* /*resource*/)
+	static void offline(void* resource)
 	{
+		TextureResource* t = (TextureResource*) resource;
 
+		device()->renderer()->destroy_texture(t->m_texture);
 	}
 
 public:
@@ -118,6 +124,8 @@ private:
 
 	TextureHeader		m_header;
 	uint8_t*			m_data;
+
+	TextureId m_texture;
 };
 
 } // namespace crown