From 8518ace21e44c6d62f0f662dfc0c7d367335e7ec Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 28 Jul 2020 18:47:22 +0800 Subject: [PATCH] move Bitmap2DLoader codes to TextureLoader.h --- inc/hgl/graph/TextureLoader.h | 22 ++++++++++++++ src/SceneGraph/Texture2DLoader.cpp | 47 ++++++++++++------------------ 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/inc/hgl/graph/TextureLoader.h b/inc/hgl/graph/TextureLoader.h index 242f3cf5..b4182613 100644 --- a/inc/hgl/graph/TextureLoader.h +++ b/inc/hgl/graph/TextureLoader.h @@ -3,6 +3,7 @@ #include #include +#include namespace hgl { namespace graph @@ -54,6 +55,27 @@ namespace hgl bool Load(io::InputStream *is); bool Load(const OSString &filename); };//class Texture2DLoader + + /** + * 2D位图加载 + */ + class Bitmap2DLoader:public Texture2DLoader + { + protected: + + BitmapData *bmp=nullptr; + + public: + + ~Bitmap2DLoader(); + + void *OnBegin(uint32 total_bytes) override; + void OnEnd() override {} + + BitmapData *GetBitmap(); + };//class Bitmap2DLoader + + BitmapData *LoadBitmapFromFile(const OSString &filename); }//namespace graph }//namespace hgl #endif//HGL_GRAPH_TEXTURE_LOADER_INCLUDE diff --git a/src/SceneGraph/Texture2DLoader.cpp b/src/SceneGraph/Texture2DLoader.cpp index e1093b74..1ebcb171 100644 --- a/src/SceneGraph/Texture2DLoader.cpp +++ b/src/SceneGraph/Texture2DLoader.cpp @@ -53,41 +53,32 @@ namespace hgl namespace graph { - class Bitmap2DLoader:public Texture2DLoader + Bitmap2DLoader::~Bitmap2DLoader() { - protected: + SAFE_CLEAR(bmp); + } - BitmapData *bmp=nullptr; + void *Bitmap2DLoader::OnBegin(uint32 total_bytes) + { + SAFE_CLEAR(bmp); - public: + bmp=new BitmapData; - ~Bitmap2DLoader() - { - SAFE_CLEAR(bmp); - } + bmp->width =file_header.width; + bmp->height =file_header.height; + bmp->total_bytes=total_bytes; - void *OnBegin(uint32 total_bytes) override - { - bmp=new BitmapData; + bmp->data=new char[total_bytes]; - bmp->width =file_header.width; - bmp->height =file_header.height; - bmp->total_bytes=total_bytes; + return bmp->data; + } - bmp->data=new char[total_bytes]; - - return bmp->data; - } - - void OnEnd() override {} - - BitmapData *GetBitmap() - { - BitmapData *result=bmp; - bmp=nullptr; - return result; - } - };//class Bitmap2DLoader + BitmapData *Bitmap2DLoader::GetBitmap() + { + BitmapData *result=bmp; + bmp=nullptr; + return result; + } BitmapData *LoadBitmapFromFile(const OSString &filename) {