From d018df2903bb8952b9c452ad7f3ec8f6232155d5 Mon Sep 17 00:00:00 2001 From: tobigun Date: Wed, 14 May 2008 08:55:29 +0000 Subject: - bugfix: LoadTexture() did not initialize the TTexture result before it was returned in an error case, so for example the TexNum field was set to some undefined result. This bugfix also fixes the videoBG whitescreen bug. Probably it is better to convert TTexture from a record to a class, so we can do the initialization stuff in a constructor and free assigned textures (TexNum) in the destructor with glDeleteTextures. This may help with theme-switching too. - added glext in UVideo.pas for GL_BGR, needed for accelerated colorspace conversion with swscale. This is disabled by default because it did not speed up that much in windows (also it was not slower). In Linux it seems to speeds up very well. 3ms instead of 7ms per frame. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1091 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UTexture.pas | 132 +++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 65 deletions(-) (limited to 'Game/Code/Classes/UTexture.pas') diff --git a/Game/Code/Classes/UTexture.pas b/Game/Code/Classes/UTexture.pas index 56b8ac79..1f5f6e0a 100644 --- a/Game/Code/Classes/UTexture.pas +++ b/Game/Code/Classes/UTexture.pas @@ -93,26 +93,26 @@ type procedure FitTexture(var TexSurface: PSDL_Surface; W,H: Cardinal); procedure ColorizeTexture(TexSurface: PSDL_Surface; Col: Cardinal); public - Limit: integer; - CreateCacheMipmap: boolean; - -// function GetNumberFor - function GetTexture(const Name: string; Typ: TTextureType; FromCache: boolean = true): TTexture; overload; - function GetTexture(const Name: string; Typ: TTextureType; Col: LongWord; FromCache: boolean = true): TTexture; overload; - function FindTexture(const Name: string; Typ: TTextureType; Col: Cardinal): integer; - function LoadTexture(FromRegistry: boolean; const Identifier: string; Typ: TTextureType; Col: LongWord): TTexture; overload; - function LoadTexture(const Identifier: string; Typ: TTextureType; Col: LongWord): TTexture; overload; - function LoadTexture(const Identifier: string): TTexture; overload; - function CreateTexture(var Data: array of byte; const Name: string; W, H: word; Bits: byte): TTexture; - procedure UnloadTexture(const Name: string; Typ: TTextureType; FromCache: boolean); overload; - procedure UnloadTexture(const Name: string; Typ: TTextureType; Col: Cardinal; FromCache: boolean); overload; - //procedure FlushTextureDatabase(); - - Function GetCoverThumbnail(const Name: string): Pointer; - Procedure SetCoverSize(W, H: Integer); - - Constructor Create; - Destructor Destroy; override; + Limit: integer; + CreateCacheMipmap: boolean; + + //function GetNumberFor + function GetTexture(const Name: string; Typ: TTextureType; FromCache: boolean = true): TTexture; overload; + function GetTexture(const Name: string; Typ: TTextureType; Col: LongWord; FromCache: boolean = true): TTexture; overload; + function FindTexture(const Name: string; Typ: TTextureType; Col: Cardinal): integer; + function LoadTexture(FromRegistry: boolean; const Identifier: string; Typ: TTextureType; Col: LongWord): TTexture; overload; + function LoadTexture(const Identifier: string; Typ: TTextureType; Col: LongWord): TTexture; overload; + function LoadTexture(const Identifier: string): TTexture; overload; + function CreateTexture(var Data: array of byte; const Name: string; W, H: word; Bits: byte): TTexture; + procedure UnloadTexture(const Name: string; Typ: TTextureType; FromCache: boolean); overload; + procedure UnloadTexture(const Name: string; Typ: TTextureType; Col: Cardinal; FromCache: boolean); overload; + //procedure FlushTextureDatabase(); + + Function GetCoverThumbnail(const Name: string): Pointer; + Procedure SetCoverSize(W, H: Integer); + + Constructor Create; + Destructor Destroy; override; end; var @@ -349,16 +349,11 @@ var begin Log.BenchmarkStart(4); Mipmapping := true; -(* - Log.LogStatus( '', '' ); - if Identifier = nil then - Log.LogStatus(' ERROR unknown Identifier', 'Id:'''+Identifier+''' Fmt:'''+Format+''' Typ:'''+Typ+'''') - else - Log.LogStatus(' should be ok - trying to load', 'Id:'''+Identifier+''' Fmt:'''+Format+''' Typ:'''+Typ+''''); -*) + // zero texture data + FillChar(Result, SizeOf(Result), 0); - // load texture data into memory + // load texture data into memory {$ifdef blindydebug} Log.LogStatus('',' ----------------------------------------------------'); Log.LogStatus('',' LoadImage('''+Identifier+''') (called by '+Format+')'); @@ -408,40 +403,41 @@ begin {$endif} + (* // don't actually understand, if this is needed... // this should definately be changed... together with all this // cover cache stuff - {if (CreateCacheMipmap) and (Typ = TEXTURE_TYPE_PLAIN) then + if (CreateCacheMipmap) and (Typ = TEXTURE_TYPE_PLAIN) then begin - {$ifdef blindydebug}{ + {$ifdef blindydebug} Log.LogStatus('',' JB-1 : Minimap'); {$endif} - {if (TnWidth <= 256) and (TnHeight <= 256) then + if (TnWidth <= 256) and (TnHeight <= 256) then begin - {$ifdef blindydebug}{ + {$ifdef blindydebug} Log.LogStatus('',' GetScaledTexture('''+inttostr(Covers.W)+''','''+inttostr(Covers.H)+''') (for CacheMipmap)'); - {$endif}{ + {$endif} MipmapSurface:=GetScaledTexture(TexSurface, TnWidth, TnHeight); if assigned(MipmapSurface) then begin - {$ifdef blindydebug}{ + {$ifdef blindydebug} Log.LogStatus('',' ok'); Log.LogStatus('',' BlitSurface Stuff'); - {$endif}{ + {$endif} // creating and freeing the surface could be done once, if Cover.W and Cover.H don't change TnSurface:=SDL_CreateRGBSurfaceFrom(@TnBuffer[0], TnWidth, TnHeight, 24, TnWidth*3, $000000ff, $0000ff00, $00ff0000, 0); SDL_BlitSurface(TnSurface, nil, TnSurface, nil); SDL_FreeSurface(TnSurface); - {$ifdef blindydebug}{ + {$ifdef blindydebug} Log.LogStatus('',' ok'); Log.LogStatus('',' SDL_FreeSurface (CacheMipmap)'); - {$endif}{ + {$endif} SDL_FreeSurface(TnSurface); - {$ifdef blindydebug}{ + {$ifdef blindydebug} Log.LogStatus('',' ok'); - {$endif}{ + {$endif} end else begin @@ -449,7 +445,9 @@ begin end; end; // should i create a cache texture, if Covers.W/H are larger? - end; } + end; + + *) {$ifdef blindydebug} Log.LogStatus('',' JB-2'); @@ -507,36 +505,40 @@ begin {$endif} - Result.X := 0; - Result.Y := 0; - Result.Z := 0; - Result.W := 0; - Result.H := 0; - Result.ScaleW := 1; - Result.ScaleH := 1; - Result.Rot := 0; - Result.TexNum := ActTex; - Result.TexW := oldWidth / newWidth; - Result.TexH := oldHeight / newHeight; - - Result.Int := 1; - Result.ColR := 1; - Result.ColG := 1; - Result.ColB := 1; - Result.Alpha := 1; - - // new test - default use whole texure, taking TexW and TexH as const and changing these - Result.TexX1 := 0; - Result.TexY1 := 0; - Result.TexX2 := 1; - Result.TexY2 := 1; + // setup texture struct + with Result do + begin + X := 0; + Y := 0; + Z := 0; + W := 0; + H := 0; + ScaleW := 1; + ScaleH := 1; + Rot := 0; + TexNum := ActTex; + TexW := oldWidth / newWidth; + TexH := oldHeight / newHeight; + + Int := 1; + ColR := 1; + ColG := 1; + ColB := 1; + Alpha := 1; + + // new test - default use whole texure, taking TexW and TexH as const and changing these + TexX1 := 0; + TexY1 := 0; + TexX2 := 1; + TexY2 := 1; + + Name := Identifier; + end; {$ifdef blindydebug} Log.LogStatus('',' JB-6'); {$endif} - Result.Name := Identifier; - SDL_FreeSurface(TexSurface); {$ifdef blindydebug} -- cgit v1.2.3