1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../../../shared/a_modes.inc}
26 g_base
, g_animations
, // TRectHW, TAnimInfo
32 TGLHints
= (txNoRepeat
);
33 TGLHintsSet
= set of TGLHints
;
37 TGLAtlasNode
= class (TAtlasNode
)
42 constructor Create (base
: TGLAtlas
);
43 destructor Destroy
; override;
45 function GetID (): GLuint
;
47 property base
: TGLAtlas read mBase
;
48 property id
: GLuint read GetID
;
51 TGLAtlas
= class (TAtlas
)
56 constructor Create (ww
, hh
: Integer; id
: GLuint
);
57 destructor Destroy
; override;
59 function CreateNode (): TGLAtlasNode
; override;
60 function Alloc (ww
, hh
: Integer): TGLAtlasNode
; overload
;
62 property id
: GLuint read mID write mID default
0;
70 mTile
: array of TGLAtlasNode
;
74 destructor Destroy
; override;
76 function GetTile (col
, line
: Integer): TGLAtlasNode
;
78 function GetLines (): Integer; inline;
80 property width
: Integer read mWidth
;
81 property height
: Integer read mHeight
;
82 property cols
: Integer read mCols
;
83 property lines
: Integer read GetLines
;
84 property hints
: TGLHintsSet read mHints
;
87 TGLMultiTexture
= class
89 mTexture
: array of TGLTexture
;
92 destructor Destroy
; override;
94 function GetWidth (): Integer; inline;
95 function GetHeight (): Integer; inline;
96 function GetCount (): Integer; inline;
97 function GetTexture (i
: Integer): TGLTexture
; {inline;}
99 property width
: Integer read GetWidth
;
100 property height
: Integer read GetHeight
;
101 property count
: Integer read GetCount
;
104 TGLTextureArray
= array of TGLTexture
;
106 TRectArray
= array of TRectWH
;
108 TGLFont
= class sealed (TFont
)
114 destructor Destroy
; override;
115 function GetChar (c
: AnsiChar): TGLTexture
;
116 function GetWidth (c
: AnsiChar): Integer;
117 function GetMaxWidth (): Integer;
118 function GetMaxHeight (): Integer;
119 function GetSpace (): Integer;
122 TAnimTextInfo
= record
128 TConvProc
= function (x
: Integer): Integer;
130 procedure r_Textures_Initialize
;
131 procedure r_Textures_Finalize
;
133 function r_Textures_LoadFromFile (const filename
: AnsiString; hints
: TGLHintsSet
; log
: Boolean = True): TGLTexture
;
134 function r_Textures_LoadMultiFromFile (const filename
: AnsiString; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
135 function r_Textures_LoadMultiFromFileAndInfo (const filename
: AnsiString; w
, h
, count
: Integer; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
136 function r_Textures_LoadMultiTextFromFile (const filename
: AnsiString; var txt
: TAnimTextInfo
; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
138 function r_Textures_LoadStreamFromFile (const filename
: AnsiString; w
, h
, count
, cw
: Integer; st
: TGLTextureArray
; rs
: TRectArray
; hints
: TGLHintsSet
; log
: Boolean = True): Boolean;
140 function r_Textures_LoadFontFromFile (const filename
: AnsiString; constref f
: TFontInfo
; font2enc
: TConvProc
; log
: Boolean = true): TGLFont
;
142 procedure r_Textures_GL_Bind (id
: GLuint
);
149 e_log
, e_res
, WADReader
, Config
,
150 g_console
, // cvar declaration
151 Imaging
, ImagingTypes
, ImagingUtility
155 r_GL_MaxTexSize
: WORD;
156 r_GL_RepeatOpt
: Boolean;
157 maxTileSize
: Integer;
158 atl
, ratl
: array of TGLAtlas
;
159 currentTexture2D
: GLuint
;
161 procedure r_Textures_GL_Bind (id
: GLuint
);
163 if id
<> currentTexture2D
then
165 glBindTexture(GL_TEXTURE_2D
, id
);
166 currentTexture2D
:= id
;
170 (* --------- TGLAtlasNode --------- *)
172 constructor TGLAtlasNode
.Create (base
: TGLAtlas
);
179 destructor TGLAtlasNode
.Destroy
;
184 function TGLAtlasNode
.GetID (): GLuint
;
186 result
:= self
.base
.id
189 procedure r_Textures_UpdateNode (n
: TGLAtlasNode
; data
: Pointer; x
, y
, w
, h
: Integer);
193 ASSERT(n
.base
<> nil);
197 ASSERT(n
.l
+ x
+ w
- 1 <= n
.r
);
198 ASSERT(n
.t
+ y
+ h
- 1 <= n
.b
);
200 r_Textures_GL_Bind(n
.id
);
201 glTexSubImage2D(GL_TEXTURE_2D
, 0, n
.l
+ x
, n
.t
+ y
, w
, h
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
202 r_Textures_GL_Bind(0);
205 (* --------- TGLAtlas --------- *)
207 constructor TGLAtlas
.Create (ww
, hh
: Integer; id
: GLuint
);
211 inherited Create(ww
, hh
);
215 destructor TGLAtlas
.Destroy
;
220 function TGLAtlas
.CreateNode (): TGLAtlasNode
;
222 result
:= TGLAtlasNode
.Create(self
);
225 function TGLAtlas
.Alloc (ww
, hh
: Integer): TGLAtlasNode
;
227 result
:= TGLAtlasNode(inherited Alloc(ww
, hh
));
230 function r_Textures_AllocHWTexture (w
, h
: Integer): GLuint
;
233 glGenTextures(1, @id
);
236 r_Textures_GL_Bind(id
);
237 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
238 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
239 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
240 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
241 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, w
, h
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, nil);
242 r_Textures_GL_Bind(0);
247 function r_Textures_AllocAtlas (): TGLAtlas
;
248 var i
: Integer; id
: GLuint
;
251 id
:= r_Textures_AllocHWTexture(maxTileSize
, maxTileSize
);
255 SetLength(atl
, i
+ 1);
256 atl
[i
] := TGLAtlas
.Create(maxTileSize
, maxTileSize
, id
);
261 function r_Textures_AllocRepeatAtlas (w
, h
: Integer): TGLAtlas
;
262 var i
: Integer; id
: GLuint
;
265 id
:= r_Textures_AllocHWTexture(w
, h
);
269 SetLength(ratl
, i
+ 1);
270 ratl
[i
] := TGLAtlas
.Create(w
, h
, id
);
275 function r_Textures_AllocNode (w
, h
: Integer): TGLAtlasNode
;
276 var i
: Integer; n
: TGLAtlasNode
; a
: TGLAtlas
;
282 while (i
>= 0) and (n
= nil) do
284 n
:= atl
[i
].Alloc(w
, h
);
290 a
:= r_Textures_AllocAtlas();
297 function r_Textures_AllocRepeatNode (w
, h
: Integer): TGLAtlasNode
;
298 var i
: Integer; n
: TGLAtlasNode
; a
: TGLAtlas
;
304 while (i
>= 0) and (ratl
[i
] <> nil) do DEC(i
);
305 if i
>= 0 then a
:= ratl
[i
];
307 if a
= nil then a
:= r_Textures_AllocRepeatAtlas(w
, h
);
313 i
:= High(ratl
); while (i
>= 0) and (ratl
[i
] <> a
) do DEC(i
);
314 if i
>= 0 then ratl
[i
] := nil;
315 r_Common_FreeAndNil(a
);
321 (* --------- TGLTexture --------- *)
323 destructor TGLTexture
.Destroy
;
324 var i
: Integer; a
: TGLAtlas
;
326 if self
.mTile
<> nil then
328 if TGLHints
.txNoRepeat
in self
.hints
then (* non repeatable texture -> delete tiles only *)
330 for i
:= 0 to High(self
.mTile
) do
332 if self
.mTile
[i
] <> nil then
334 self
.mTile
[i
].Dealloc
;
339 else (* repeatable texture -> delete whole atlas *)
341 a
:= self
.mTile
[0].base
;
342 i
:= High(ratl
); while (i
>= 0) and (ratl
[i
] <> a
) do DEC(i
);
343 if i
>= 0 then ratl
[i
] := nil;
344 r_Common_FreeAndNil(a
);
346 SetLength(self
.mTile
, 0);
351 function TGLTexture
.GetLines (): Integer;
353 ASSERT(self
.mTile
<> nil);
354 result
:= Length(self
.mTile
) div self
.mCols
357 function TGLTexture
.GetTile (col
, line
: Integer): TGLAtlasNode
;
361 ASSERT(col
<= mCols
);
362 ASSERT(self
.mTile
<> nil);
363 i
:= line
* mCols
+ col
;
365 ASSERT(i
< Length(mTile
));
367 ASSERT(result
<> nil)
370 function r_Textures_Alloc (w
, h
: Integer; hints
: TGLHintsSet
): TGLTexture
;
371 var x
, y
, mw
, mh
, cols
, lines
: Integer; t
: TGLTexture
;
375 if TGLHints
.txNoRepeat
in hints
then
377 cols
:= (w
+ maxTileSize
- 1) div maxTileSize
;
378 lines
:= (h
+ maxTileSize
- 1) div maxTileSize
;
379 t
:= TGLTexture
.Create
;
383 // t.mLines := lines;
385 SetLength(t
.mTile
, cols
* lines
);
386 for y
:= 0 to lines
- 1 do
388 mh
:= Min(maxTileSize
, h
- y
* maxTileSize
);
390 for x
:= 0 to cols
- 1 do
392 mw
:= Min(maxTileSize
, w
- x
* maxTileSize
);
394 t
.mTile
[y
* cols
+ x
] := r_Textures_AllocNode(mw
, mh
);
400 t
:= TGLTexture
.Create
;
406 SetLength(t
.mTile
, 1);
407 t
.mTile
[0] := r_Textures_AllocRepeatNode(w
, h
);
412 (* --------- TGLMultiTexture --------- *)
414 destructor TGLMultiTexture
.Destroy
;
417 for i
:= 0 to self
.count
- 1 do
418 r_Common_FreeAndNil(self
.mTexture
[i
]);
419 SetLength(self
.mTexture
, 0);
423 function TGLMultiTexture
.GetWidth (): Integer;
425 result
:= self
.mTexture
[0].width
428 function TGLMultiTexture
.GetHeight (): Integer;
430 result
:= self
.mTexture
[0].height
433 function TGLMultiTexture
.GetCount (): Integer;
435 result
:= Length(self
.mTexture
)
438 function TGLMultiTexture
.GetTexture (i
: Integer): TGLTexture
;
441 ASSERT(i
< self
.count
);
442 result
:= self
.mTexture
[i
];
443 ASSERT(result
<> nil);
446 (* --------- Init / Fin --------- *)
448 function IsPOT (v
: LongWord): Boolean;
450 result
:= (v
<> 0) and ((v
and (v
- 1)) = 0)
453 function NextPOT (v
: LongWord): LongWord;
465 function r_Textures_GetMaxHardwareSize (): Integer;
468 if r_GL_MaxTexSize
<= 0 then
470 // auto, max possible reccomended by driver
471 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, @size
);
472 if size
< 1 then size
:= 64;
477 if IsPOT(r_GL_MaxTexSize
) then
478 size
:= r_GL_MaxTexSize
480 size
:= NextPOT(r_GL_MaxTexSize
);
485 procedure r_Textures_Initialize
;
487 currentTexture2D
:= 0;
488 maxTileSize
:= r_Textures_GetMaxHardwareSize();
489 e_LogWritefln('TEXTURE SIZE: %s', [maxTileSize
]);
492 procedure r_Textures_Finalize
;
497 for i
:= 0 to High(atl
) do
499 glDeleteTextures(1, @atl
[i
].id
);
501 r_Common_FreeAndNil(atl
[i
]);
508 for i
:= 0 to High(ratl
) do
510 glDeleteTextures(1, @ratl
[i
].id
);
512 r_Common_FreeAndNil(ratl
[i
]);
518 function r_Textures_FixImageData (var img
: TImageData
): Boolean;
521 if ConvertImage(img
, TImageFormat
.ifA8R8G8B8
) then
522 if SwapChannels(img
, ChannelRed
, ChannelBlue
) then // wtf
526 function r_Textures_ValidRepeatTexture (w
, h
: Integer; hints
: TGLHintsSet
): Boolean;
528 result
:= r_GL_RepeatOpt
and
529 not (TGLHints
.txNoRepeat
in hints
) and
530 (w
<= maxTileSize
) and
531 (h
<= maxTileSize
) and
536 function r_Textures_LoadFromImage (var img
: TImageData
; hints
: TGLHintsSet
): TGLTexture
; // !!!
537 var t
: TGLTexture
; n
: TGLAtlasNode
; c
: TDynImageDataArray
; cw
, ch
, i
, j
: LongInt;
540 if r_Textures_ValidRepeatTexture(img
.width
, img
.height
, hints
) then
542 t
:= r_Textures_Alloc(img
.width
, img
.height
, hints
- [TGLHints
.txNoRepeat
]);
545 n
:= t
.GetTile(0, 0);
547 r_Textures_UpdateNode(n
, img
.bits
, 0, 0, n
.width
, n
.height
);
551 else if SplitImage(img
, c
, maxTileSize
, maxTileSize
, cw
, ch
, False) then
553 t
:= r_Textures_Alloc(img
.width
, img
.height
, hints
+ [TGLHints
.txNoRepeat
]);
557 ASSERT(ch
= t
.lines
);
558 for j
:= 0 to ch
- 1 do
560 for i
:= 0 to cw
- 1 do
562 n
:= t
.GetTile(i
, j
);
564 r_Textures_UpdateNode(n
, c
[j
* cw
+ i
].bits
, 0, 0, n
.width
, n
.height
)
569 FreeImagesInArray(c
);
573 function r_Textures_LoadFromMemory (data
: Pointer; size
: LongInt; hints
: TGLHintsSet
): TGLTexture
;
577 if (data
<> nil) and (size
> 0) then
581 if LoadImageFromMemory(data
, size
, img
) then
582 if r_Textures_FixImageData(img
) then
583 result
:= r_Textures_LoadFromImage(img
, hints
)
590 function r_Textures_LoadFromFile (const filename
: AnsiString; hints
: TGLHintsSet
; log
: Boolean = True): TGLTexture
;
591 var wad
: TWADFile
; wadName
, resName
: AnsiString; data
: Pointer; size
: Integer;
594 wadName
:= g_ExtractWadName(filename
);
595 wad
:= TWADFile
.Create();
596 if wad
.ReadFile(wadName
) then
598 resName
:= g_ExtractFilePathName(filename
);
599 if wad
.GetResource(resName
, data
, size
, log
) then
601 result
:= r_Textures_LoadFromMemory(data
, size
, hints
);
608 function r_Textures_LoadMultiFromImageAndInfo (var img
: TImageData
; w
, h
, c
: Integer; hints
: TGLHintsSet
): TGLMultiTexture
;
609 var t
: TImageData
; a
: array of TGLTexture
; i
: Integer; m
: TGLMultiTexture
;
616 for i
:= 0 to c
- 1 do
619 if NewImage(w
, h
, img
.Format
, t
) then
620 if CopyRect(img
, w
* i
, 0, w
, h
, t
, 0, 0) then
621 a
[i
] := r_Textures_LoadFromImage(t
, hints
);
625 m
:= TGLMultiTexture
.Create();
627 ASSERT(m
.mTexture
<> nil);
631 function r_Textures_LoadMultiFromDataAndInfo (data
: Pointer; size
: LongInt; w
, h
, c
: Integer; hints
: TGLHintsSet
): TGLMultiTexture
;
638 if (data
<> nil) and (size
> 0) then
642 if LoadImageFromMemory(data
, size
, img
) then
643 if r_Textures_FixImageData(img
) then
644 result
:= r_Textures_LoadMultiFromImageAndInfo(img
, w
, h
, c
, hints
)
651 function r_Textures_LoadTextFromMemory (data
: Pointer; size
: LongInt; var txt
: TAnimTextInfo
): Boolean;
657 cfg
:= TConfig
.CreateMem(data
, size
);
660 txt
.name
:= cfg
.ReadStr('', 'resource', '');
661 txt
.w
:= MAX(0, cfg
.ReadInt('', 'framewidth', 0));
662 txt
.h
:= MAX(0, cfg
.ReadInt('', 'frameheight', 0));
663 txt
.anim
.loop
:= true;
664 txt
.anim
.delay
:= MAX(0, cfg
.ReadInt('', 'waitcount', 0));
665 txt
.anim
.frames
:= MAX(0, cfg
.ReadInt('', 'framecount', 0));
666 txt
.anim
.back
:= cfg
.ReadBool('', 'backanim', false);
668 result
:= (txt
.name
<> '') and (txt
.w
> 0) and (txt
.h
> 0) and (txt
.anim
.delay
> 0) and (txt
.anim
.frames
> 0);
673 function r_Textures_LoadMultiFromWad (wad
: TWADFile
; var txt
: TAnimTextInfo
; hints
: TGLHintsSet
): TGLMultiTexture
;
674 var data
: Pointer; size
: LongInt; img
: TImageData
;
678 if wad
.GetResource('TEXT/ANIM', data
, size
) then
680 if r_Textures_LoadTextFromMemory(data
, size
, txt
) then
683 if wad
.GetResource('TEXTURES/' + txt
.name
, data
, size
) then
687 if LoadImageFromMemory(data
, size
, img
) then
688 if r_Textures_FixImageData(img
) then
689 result
:= r_Textures_LoadMultiFromImageAndInfo(img
, txt
.w
, txt
.h
, txt
.anim
.frames
, hints
);
701 function r_Textures_LoadMultiFromMemory (data
: Pointer; size
: LongInt; var txt
: TAnimTextInfo
; hints
: TGLHintsSet
): TGLMultiTexture
;
702 var wad
: TWADFile
; t
: TGLTexture
; m
: TGLMultiTexture
;
705 if (data
<> nil) and (size
> 0) then
707 t
:= r_Textures_LoadFromMemory(data
, size
, hints
);
710 m
:= TGLMultiTexture
.Create();
711 SetLength(m
.mTexture
, 1);
716 txt
.anim
.loop
:= true;
718 txt
.anim
.frames
:= 1;
719 txt
.anim
.back
:= false;
722 else if IsWadData(data
, size
) then
724 wad
:= TWADFile
.Create();
725 if wad
.ReadMemory(data
, size
) then
727 result
:= r_Textures_LoadMultiFromWad(wad
, txt
, hints
);
734 function r_Textures_LoadMultiTextFromFile (const filename
: AnsiString; var txt
: TAnimTextInfo
; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
735 var wad
: TWADFile
; wadName
, resName
: AnsiString; data
: Pointer; size
: Integer;
738 wadName
:= g_ExtractWadName(filename
);
739 wad
:= TWADFile
.Create();
740 if wad
.ReadFile(wadName
) then
742 resName
:= g_ExtractFilePathName(filename
);
743 if wad
.GetResource(resName
, data
, size
, log
) then
745 result
:= r_Textures_LoadMultiFromMemory(data
, size
, txt
, hints
);
752 function r_Textures_LoadMultiFromFile (const filename
: AnsiString; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
753 var txt
: TAnimTextInfo
;
755 result
:= r_Textures_LoadMultiTextFromFile(filename
, txt
, hints
, log
);
758 function r_Textures_LoadMultiFromFileAndInfo (const filename
: AnsiString; w
, h
, count
: Integer; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
759 var wad
: TWADFile
; wadName
, resName
: AnsiString; data
: Pointer; size
: Integer;
765 wadName
:= g_ExtractWadName(filename
);
766 wad
:= TWADFile
.Create();
767 if wad
.ReadFile(wadName
) then
769 resName
:= g_ExtractFilePathName(filename
);
770 if wad
.GetResource(resName
, data
, size
, log
) then
772 result
:= r_Textures_LoadMultiFromDataAndInfo(data
, size
, w
, h
, count
, hints
);
779 function r_Textures_GetRect (var img
: TImageData
): TRectWH
;
780 var i
, j
, w
, h
: Integer; done
: Boolean;
782 function IsVoid (i
, j
: Integer): Boolean; inline;
784 result
:= GetPixel32(img
, i
, j
).Channels
[3] = 0
791 (* trace x from right to left *)
792 done
:= false; i
:= 0;
793 while not done
and (i
< w
) do
796 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
797 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
802 (* trace y from up to down *)
803 done
:= false; j
:= 0;
804 while not done
and (j
< h
) do
807 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
808 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
813 (* trace x from right to left *)
814 done
:= false; i
:= w
- 1;
815 while not done
and (i
>= 0) do
818 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
819 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
820 result
.width
:= i
- result
.x
+ 1;
824 (* trace y from down to up *)
825 done
:= false; j
:= h
- 1;
826 while not done
and (j
>= 0) do
829 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
830 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
831 result
.height
:= j
- result
.y
+ 1;
836 function r_Textures_LoadStreamFromImage (var img
: TImageData
; w
, h
, c
, cw
: Integer; st
: TGLTextureArray
; rs
: TRectArray
; hints
: TGLHintsSet
): Boolean;
837 var i
, x
, y
: Integer; t
: TImageData
;
843 ASSERT((st
<> nil) and (Length(st
) >= c
));
844 ASSERT((rs
= nil) or (Length(rs
) >= c
));
846 for i
:= 0 to c
- 1 do
852 if NewImage(w
, h
, img
.Format
, t
) then
854 if CopyRect(img
, x
* w
, y
* h
, w
, h
, t
, 0, 0) then
857 rs
[i
] := r_Textures_GetRect(t
);
858 st
[i
] := r_Textures_LoadFromImage(t
, hints
);
861 ASSERT(st
[i
] <> nil);
866 function r_Textures_LoadStreamFromMemory (data
: Pointer; size
: LongInt; w
, h
, c
, cw
: Integer; st
: TGLTextureArray
; rs
: TRectArray
; hints
: TGLHintsSet
): Boolean;
873 ASSERT((st
<> nil) and (Length(st
) >= c
));
874 ASSERT((rs
= nil) or (Length(rs
) >= c
));
876 if (data
<> nil) and (size
> 0) then
880 if LoadImageFromMemory(data
, size
, img
) then
882 if r_Textures_FixImageData(img
) then
884 result
:= r_Textures_LoadStreamFromImage(img
, w
, h
, c
, cw
, st
, rs
, hints
)
893 function r_Textures_LoadStreamFromFile (const filename
: AnsiString; w
, h
, count
, cw
: Integer; st
: TGLTextureArray
; rs
: TRectArray
; hints
: TGLHintsSet
; log
: Boolean = True): Boolean;
894 var wad
: TWADFile
; wadName
, resName
: AnsiString; data
: Pointer; size
: Integer;
900 ASSERT((st
<> nil) and (Length(st
) >= count
));
901 ASSERT((rs
= nil) or (Length(rs
) >= count
));
903 wadName
:= g_ExtractWadName(filename
);
904 wad
:= TWADFile
.Create();
905 if wad
.ReadFile(wadName
) then
907 resName
:= g_ExtractFilePathName(filename
);
908 if wad
.GetResource(resName
, data
, size
, log
) then
910 result
:= r_Textures_LoadStreamFromMemory(data
, size
, w
, h
, count
, cw
, st
, rs
, hints
);
917 (* --------- TGLFont --------- *)
919 function r_Textures_LoadFontFromFile (const filename
: AnsiString; constref f
: TFontInfo
; font2enc
: TConvProc
; log
: Boolean = true): TGLFont
;
920 var i
, ch
: Integer; st
, stch
: TGLTextureArray
; font
: TGLFont
;
924 if r_Textures_LoadStreamFromFile(filename
, f
.w
, f
.h
, 256, 16, st
, nil, [TGLHints
.txNoRepeat
], log
) then
926 font
:= TGLFont
.Create();
929 if Assigned(font2enc
) then
931 SetLength(stch
, 256);
935 ASSERT((ch
>= 0) and (ch
<= 255));
945 destructor TGLFont
.Destroy
;
948 if self
.ch
<> nil then
949 for i
:= 0 to High(self
.ch
) do
954 function TGLFont
.GetChar (c
: AnsiChar): TGLTexture
;
956 result
:= self
.ch
[ORD(c
)];
959 function TGLFont
.GetWidth (c
: AnsiChar): Integer;
961 result
:= self
.info
.ch
[c
].w
;
963 result
:= self
.info
.w
;
964 if self
.info
.kern
< 0 then
965 result
:= result
+ self
.info
.kern
;
968 function TGLFont
.GetMaxWidth (): Integer;
970 result
:= self
.info
.w
;
971 if self
.info
.kern
< 0 then
972 result
:= result
+ self
.info
.kern
;
975 function TGLFont
.GetMaxHeight (): Integer;
977 result
:= self
.info
.h
;
980 function TGLFont
.GetSpace (): Integer;
982 result
:= self
.info
.kern
;
986 conRegVar('r_gl_maxtexsize', @r_GL_MaxTexSize
, '', '');
987 conRegVar('r_gl_repeat', @r_GL_RepeatOpt
, '', '');
988 r_GL_MaxTexSize
:= 0; // default is automatic value
989 r_GL_RepeatOpt
:= true;