From efef73dfde7de1692afb9aa8a9d51dcafc59fbb2 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 20 Sep 2007 10:53:12 +0000 Subject: started re-factoring TTextureUnit.LoadTexture only done BPM and JPEG for now. will do more as I add support for it to lazarus. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@418 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UTexture.pas | 69 +++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 31 deletions(-) (limited to 'Game/Code/Classes') diff --git a/Game/Code/Classes/UTexture.pas b/Game/Code/Classes/UTexture.pas index 364bbcc8..e7038e78 100644 --- a/Game/Code/Classes/UTexture.pas +++ b/Game/Code/Classes/UTexture.pas @@ -90,7 +90,8 @@ type TTextureUnit = class private - function LoadBitmap( aSourceStream : TStream; aBMP : TBitMap ): boolean; + function LoadBitmap( aSourceStream : TStream; aIMG : TBitMap ): boolean; + function LoadJpeg( aSourceStream : TStream; aIMG : TBitMap ): boolean; public Limit: integer; CreateCacheMipmap: boolean; @@ -311,12 +312,40 @@ begin end; -function TTextureUnit.LoadBitmap( aSourceStream : TStream; aBMP : TBitMap ): boolean; +function TTextureUnit.LoadBitmap( aSourceStream : TStream; aIMG : TBitMap ): boolean; begin - aSourceStream.position := 0; - boolean := aBMP.LoadFromStream( aSourceStream ) > 0; + result := false; + try + aSourceStream.position := 0; + aIMG.LoadFromStream( aSourceStream ); + finally + result := aSourceStream.position > 0; + end; +end; + +function TTextureUnit.LoadJpeg( aSourceStream : TStream; aIMG : TBitMap ): boolean; +var + TextureJ: TJPEGImage; +begin + result := false; + try + aSourceStream.position := 0; + + TextureJ := TJPEGImage.Create; + try + TextureJ.LoadFromStream( aSourceStream ); + aIMG.Assign(TextureJ); + finally + TextureJ.Free; + end; + finally + result := aSourceStream.position > 0; + end; end; + + + function TTextureUnit.LoadTexture(FromRegistry: boolean; Identifier, Format, Typ: PChar; Col: LongWord): TTexture; var Res: TResourceStream; @@ -381,38 +410,16 @@ begin end; end; - if FromRegistry or - ((not FromRegistry) and FileExists(Identifier)) then +// if FromRegistry or +// ((not FromRegistry) and FileExists(Identifier)) then begin - TextureB := TBitmap.Create; + TextureB := TBitmap.Create; if Format = 'BMP' then - begin - LoadBitmap( aSourceStream : TStream; TextureB ); - - if FromRegistry then - TextureB.LoadFromStream(Res) - else - TextureB.LoadFromFile(Identifier); - end + LoadBitmap( lTextureStream , TextureB ) else if Format = 'JPG' then - begin - TextureJ := TJPEGImage.Create; - - if FromRegistry then - TextureJ.LoadFromStream(Res) - else - begin - if FileExists(Identifier) then - TextureJ.LoadFromFile(Identifier) - else - Exit; - end; - - TextureB.Assign(TextureJ); - TextureJ.Free; - end + LoadJpeg( lTextureStream , TextureB ) else if Format = 'PNG' then begin {$IFNDEF FPC} -- cgit v1.2.3