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
;
147 e_log
, e_res
, WADReader
, Config
,
148 g_console
, // cvar declaration
149 Imaging
, ImagingTypes
, ImagingUtility
153 r_GL_MaxTexSize
: WORD;
154 r_GL_RepeatOpt
: Boolean;
155 maxTileSize
: Integer;
156 atl
, ratl
: array of TGLAtlas
;
158 (* --------- TGLAtlasNode --------- *)
160 constructor TGLAtlasNode
.Create (base
: TGLAtlas
);
167 destructor TGLAtlasNode
.Destroy
;
172 function TGLAtlasNode
.GetID (): GLuint
;
174 result
:= self
.base
.id
177 procedure r_Textures_UpdateNode (n
: TGLAtlasNode
; data
: Pointer; x
, y
, w
, h
: Integer);
181 ASSERT(n
.base
<> nil);
185 ASSERT(n
.l
+ x
+ w
- 1 <= n
.r
);
186 ASSERT(n
.t
+ y
+ h
- 1 <= n
.b
);
188 glBindTexture(GL_TEXTURE_2D
, n
.id
);
189 glTexSubImage2D(GL_TEXTURE_2D
, 0, n
.l
+ x
, n
.t
+ y
, w
, h
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
190 glBindTexture(GL_TEXTURE_2D
, 0);
193 (* --------- TGLAtlas --------- *)
195 constructor TGLAtlas
.Create (ww
, hh
: Integer; id
: GLuint
);
199 inherited Create(ww
, hh
);
203 destructor TGLAtlas
.Destroy
;
208 function TGLAtlas
.CreateNode (): TGLAtlasNode
;
210 result
:= TGLAtlasNode
.Create(self
);
213 function TGLAtlas
.Alloc (ww
, hh
: Integer): TGLAtlasNode
;
215 result
:= TGLAtlasNode(inherited Alloc(ww
, hh
));
218 function r_Textures_AllocHWTexture (w
, h
: Integer): GLuint
;
221 glGenTextures(1, @id
);
224 glBindTexture(GL_TEXTURE_2D
, id
);
225 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
226 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
227 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
228 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
229 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, w
, h
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, nil);
230 glBindTexture(GL_TEXTURE_2D
, 0);
235 function r_Textures_AllocAtlas (): TGLAtlas
;
236 var i
: Integer; id
: GLuint
;
239 id
:= r_Textures_AllocHWTexture(maxTileSize
, maxTileSize
);
243 SetLength(atl
, i
+ 1);
244 atl
[i
] := TGLAtlas
.Create(maxTileSize
, maxTileSize
, id
);
249 function r_Textures_AllocRepeatAtlas (w
, h
: Integer): TGLAtlas
;
250 var i
: Integer; id
: GLuint
;
253 id
:= r_Textures_AllocHWTexture(w
, h
);
257 SetLength(ratl
, i
+ 1);
258 ratl
[i
] := TGLAtlas
.Create(w
, h
, id
);
263 function r_Textures_AllocNode (w
, h
: Integer): TGLAtlasNode
;
264 var i
: Integer; n
: TGLAtlasNode
; a
: TGLAtlas
;
270 while (i
>= 0) and (n
= nil) do
272 n
:= atl
[i
].Alloc(w
, h
);
278 a
:= r_Textures_AllocAtlas();
285 function r_Textures_AllocRepeatNode (w
, h
: Integer): TGLAtlasNode
;
286 var i
: Integer; n
: TGLAtlasNode
; a
: TGLAtlas
;
292 while (i
>= 0) and (ratl
[i
] <> nil) do DEC(i
);
293 if i
>= 0 then a
:= ratl
[i
];
295 if a
= nil then a
:= r_Textures_AllocRepeatAtlas(w
, h
);
301 i
:= High(ratl
); while (i
>= 0) and (ratl
[i
] <> a
) do DEC(i
);
302 if i
>= 0 then ratl
[i
] := nil;
303 r_Common_FreeAndNil(a
);
309 (* --------- TGLTexture --------- *)
311 destructor TGLTexture
.Destroy
;
312 var i
: Integer; a
: TGLAtlas
;
314 if self
.mTile
<> nil then
316 if TGLHints
.txNoRepeat
in self
.hints
then (* non repeatable texture -> delete tiles only *)
318 for i
:= 0 to High(self
.mTile
) do
320 if self
.mTile
[i
] <> nil then
322 self
.mTile
[i
].Dealloc
;
327 else (* repeatable texture -> delete whole atlas *)
329 a
:= self
.mTile
[0].base
;
330 i
:= High(ratl
); while (i
>= 0) and (ratl
[i
] <> a
) do DEC(i
);
331 if i
>= 0 then ratl
[i
] := nil;
332 r_Common_FreeAndNil(a
);
334 SetLength(self
.mTile
, 0);
339 function TGLTexture
.GetLines (): Integer;
341 ASSERT(self
.mTile
<> nil);
342 result
:= Length(self
.mTile
) div self
.mCols
345 function TGLTexture
.GetTile (col
, line
: Integer): TGLAtlasNode
;
349 ASSERT(col
<= mCols
);
350 ASSERT(self
.mTile
<> nil);
351 i
:= line
* mCols
+ col
;
353 ASSERT(i
< Length(mTile
));
355 ASSERT(result
<> nil)
358 function r_Textures_Alloc (w
, h
: Integer; hints
: TGLHintsSet
): TGLTexture
;
359 var x
, y
, mw
, mh
, cols
, lines
: Integer; t
: TGLTexture
;
363 if TGLHints
.txNoRepeat
in hints
then
365 cols
:= (w
+ maxTileSize
- 1) div maxTileSize
;
366 lines
:= (h
+ maxTileSize
- 1) div maxTileSize
;
367 t
:= TGLTexture
.Create
;
371 // t.mLines := lines;
373 SetLength(t
.mTile
, cols
* lines
);
374 for y
:= 0 to lines
- 1 do
376 mh
:= Min(maxTileSize
, h
- y
* maxTileSize
);
378 for x
:= 0 to cols
- 1 do
380 mw
:= Min(maxTileSize
, w
- x
* maxTileSize
);
382 t
.mTile
[y
* cols
+ x
] := r_Textures_AllocNode(mw
, mh
);
388 t
:= TGLTexture
.Create
;
394 SetLength(t
.mTile
, 1);
395 t
.mTile
[0] := r_Textures_AllocRepeatNode(w
, h
);
400 (* --------- TGLMultiTexture --------- *)
402 destructor TGLMultiTexture
.Destroy
;
405 for i
:= 0 to self
.count
- 1 do
406 r_Common_FreeAndNil(self
.mTexture
[i
]);
407 SetLength(self
.mTexture
, 0);
411 function TGLMultiTexture
.GetWidth (): Integer;
413 result
:= self
.mTexture
[0].width
416 function TGLMultiTexture
.GetHeight (): Integer;
418 result
:= self
.mTexture
[0].height
421 function TGLMultiTexture
.GetCount (): Integer;
423 result
:= Length(self
.mTexture
)
426 function TGLMultiTexture
.GetTexture (i
: Integer): TGLTexture
;
429 ASSERT(i
< self
.count
);
430 result
:= self
.mTexture
[i
];
431 ASSERT(result
<> nil);
434 (* --------- Init / Fin --------- *)
436 function IsPOT (v
: LongWord): Boolean;
438 result
:= (v
<> 0) and ((v
and (v
- 1)) = 0)
441 function NextPOT (v
: LongWord): LongWord;
453 function r_Textures_GetMaxHardwareSize (): Integer;
456 if r_GL_MaxTexSize
<= 0 then
458 // auto, max possible reccomended by driver
459 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, @size
);
460 if size
< 1 then size
:= 64;
465 if IsPOT(r_GL_MaxTexSize
) then
466 size
:= r_GL_MaxTexSize
468 size
:= NextPOT(r_GL_MaxTexSize
);
473 procedure r_Textures_Initialize
;
475 maxTileSize
:= r_Textures_GetMaxHardwareSize();
476 e_LogWritefln('TEXTURE SIZE: %s', [maxTileSize
]);
479 procedure r_Textures_Finalize
;
484 for i
:= 0 to High(atl
) do
486 glDeleteTextures(1, @atl
[i
].id
);
488 r_Common_FreeAndNil(atl
[i
]);
495 for i
:= 0 to High(ratl
) do
497 glDeleteTextures(1, @ratl
[i
].id
);
499 r_Common_FreeAndNil(ratl
[i
]);
505 function r_Textures_FixImageData (var img
: TImageData
): Boolean;
508 if ConvertImage(img
, TImageFormat
.ifA8R8G8B8
) then
509 if SwapChannels(img
, ChannelRed
, ChannelBlue
) then // wtf
513 function r_Textures_ValidRepeatTexture (w
, h
: Integer; hints
: TGLHintsSet
): Boolean;
515 result
:= r_GL_RepeatOpt
and
516 not (TGLHints
.txNoRepeat
in hints
) and
517 (w
<= maxTileSize
) and
518 (h
<= maxTileSize
) and
523 function r_Textures_LoadFromImage (var img
: TImageData
; hints
: TGLHintsSet
): TGLTexture
; // !!!
524 var t
: TGLTexture
; n
: TGLAtlasNode
; c
: TDynImageDataArray
; cw
, ch
, i
, j
: LongInt;
527 if r_Textures_ValidRepeatTexture(img
.width
, img
.height
, hints
) then
529 t
:= r_Textures_Alloc(img
.width
, img
.height
, hints
- [TGLHints
.txNoRepeat
]);
532 n
:= t
.GetTile(0, 0);
534 r_Textures_UpdateNode(n
, img
.bits
, 0, 0, n
.width
, n
.height
);
538 else if SplitImage(img
, c
, maxTileSize
, maxTileSize
, cw
, ch
, False) then
540 t
:= r_Textures_Alloc(img
.width
, img
.height
, hints
+ [TGLHints
.txNoRepeat
]);
544 ASSERT(ch
= t
.lines
);
545 for j
:= 0 to ch
- 1 do
547 for i
:= 0 to cw
- 1 do
549 n
:= t
.GetTile(i
, j
);
551 r_Textures_UpdateNode(n
, c
[j
* cw
+ i
].bits
, 0, 0, n
.width
, n
.height
)
556 FreeImagesInArray(c
);
560 function r_Textures_LoadFromMemory (data
: Pointer; size
: LongInt; hints
: TGLHintsSet
): TGLTexture
;
564 if (data
<> nil) and (size
> 0) then
568 if LoadImageFromMemory(data
, size
, img
) then
569 if r_Textures_FixImageData(img
) then
570 result
:= r_Textures_LoadFromImage(img
, hints
)
577 function r_Textures_LoadFromFile (const filename
: AnsiString; hints
: TGLHintsSet
; log
: Boolean = True): TGLTexture
;
578 var wad
: TWADFile
; wadName
, resName
: AnsiString; data
: Pointer; size
: Integer;
581 wadName
:= g_ExtractWadName(filename
);
582 wad
:= TWADFile
.Create();
583 if wad
.ReadFile(wadName
) then
585 resName
:= g_ExtractFilePathName(filename
);
586 if wad
.GetResource(resName
, data
, size
, log
) then
588 result
:= r_Textures_LoadFromMemory(data
, size
, hints
);
595 function r_Textures_LoadMultiFromImageAndInfo (var img
: TImageData
; w
, h
, c
: Integer; hints
: TGLHintsSet
): TGLMultiTexture
;
596 var t
: TImageData
; a
: array of TGLTexture
; i
: Integer; m
: TGLMultiTexture
;
603 for i
:= 0 to c
- 1 do
606 if NewImage(w
, h
, img
.Format
, t
) then
607 if CopyRect(img
, w
* i
, 0, w
, h
, t
, 0, 0) then
608 a
[i
] := r_Textures_LoadFromImage(t
, hints
);
612 m
:= TGLMultiTexture
.Create();
614 ASSERT(m
.mTexture
<> nil);
618 function r_Textures_LoadMultiFromDataAndInfo (data
: Pointer; size
: LongInt; w
, h
, c
: Integer; hints
: TGLHintsSet
): TGLMultiTexture
;
625 if (data
<> nil) and (size
> 0) then
629 if LoadImageFromMemory(data
, size
, img
) then
630 if r_Textures_FixImageData(img
) then
631 result
:= r_Textures_LoadMultiFromImageAndInfo(img
, w
, h
, c
, hints
)
638 function r_Textures_LoadTextFromMemory (data
: Pointer; size
: LongInt; var txt
: TAnimTextInfo
): Boolean;
644 cfg
:= TConfig
.CreateMem(data
, size
);
647 txt
.name
:= cfg
.ReadStr('', 'resource', '');
648 txt
.w
:= MAX(0, cfg
.ReadInt('', 'framewidth', 0));
649 txt
.h
:= MAX(0, cfg
.ReadInt('', 'frameheight', 0));
650 txt
.anim
.loop
:= true;
651 txt
.anim
.delay
:= MAX(0, cfg
.ReadInt('', 'waitcount', 0));
652 txt
.anim
.frames
:= MAX(0, cfg
.ReadInt('', 'framecount', 0));
653 txt
.anim
.back
:= cfg
.ReadBool('', 'backanim', false);
655 result
:= (txt
.name
<> '') and (txt
.w
> 0) and (txt
.h
> 0) and (txt
.anim
.delay
> 0) and (txt
.anim
.frames
> 0);
660 function r_Textures_LoadMultiFromWad (wad
: TWADFile
; var txt
: TAnimTextInfo
; hints
: TGLHintsSet
): TGLMultiTexture
;
661 var data
: Pointer; size
: LongInt; img
: TImageData
;
665 if wad
.GetResource('TEXT/ANIM', data
, size
) then
667 if r_Textures_LoadTextFromMemory(data
, size
, txt
) then
670 if wad
.GetResource('TEXTURES/' + txt
.name
, data
, size
) then
674 if LoadImageFromMemory(data
, size
, img
) then
675 if r_Textures_FixImageData(img
) then
676 result
:= r_Textures_LoadMultiFromImageAndInfo(img
, txt
.w
, txt
.h
, txt
.anim
.frames
, hints
);
688 function r_Textures_LoadMultiFromMemory (data
: Pointer; size
: LongInt; var txt
: TAnimTextInfo
; hints
: TGLHintsSet
): TGLMultiTexture
;
689 var wad
: TWADFile
; t
: TGLTexture
; m
: TGLMultiTexture
;
692 if (data
<> nil) and (size
> 0) then
694 t
:= r_Textures_LoadFromMemory(data
, size
, hints
);
697 m
:= TGLMultiTexture
.Create();
698 SetLength(m
.mTexture
, 1);
703 txt
.anim
.loop
:= true;
705 txt
.anim
.frames
:= 1;
706 txt
.anim
.back
:= false;
709 else if IsWadData(data
, size
) then
711 wad
:= TWADFile
.Create();
712 if wad
.ReadMemory(data
, size
) then
714 result
:= r_Textures_LoadMultiFromWad(wad
, txt
, hints
);
721 function r_Textures_LoadMultiTextFromFile (const filename
: AnsiString; var txt
: TAnimTextInfo
; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
722 var wad
: TWADFile
; wadName
, resName
: AnsiString; data
: Pointer; size
: Integer;
725 wadName
:= g_ExtractWadName(filename
);
726 wad
:= TWADFile
.Create();
727 if wad
.ReadFile(wadName
) then
729 resName
:= g_ExtractFilePathName(filename
);
730 if wad
.GetResource(resName
, data
, size
, log
) then
732 result
:= r_Textures_LoadMultiFromMemory(data
, size
, txt
, hints
);
739 function r_Textures_LoadMultiFromFile (const filename
: AnsiString; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
740 var txt
: TAnimTextInfo
;
742 result
:= r_Textures_LoadMultiTextFromFile(filename
, txt
, hints
, log
);
745 function r_Textures_LoadMultiFromFileAndInfo (const filename
: AnsiString; w
, h
, count
: Integer; hints
: TGLHintsSet
; log
: Boolean = True): TGLMultiTexture
;
746 var wad
: TWADFile
; wadName
, resName
: AnsiString; data
: Pointer; size
: Integer;
752 wadName
:= g_ExtractWadName(filename
);
753 wad
:= TWADFile
.Create();
754 if wad
.ReadFile(wadName
) then
756 resName
:= g_ExtractFilePathName(filename
);
757 if wad
.GetResource(resName
, data
, size
, log
) then
759 result
:= r_Textures_LoadMultiFromDataAndInfo(data
, size
, w
, h
, count
, hints
);
766 function r_Textures_GetRect (var img
: TImageData
): TRectWH
;
767 var i
, j
, w
, h
: Integer; done
: Boolean;
769 function IsVoid (i
, j
: Integer): Boolean; inline;
771 result
:= GetPixel32(img
, i
, j
).Channels
[3] = 0
778 (* trace x from right to left *)
779 done
:= false; i
:= 0;
780 while not done
and (i
< w
) do
783 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
784 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
789 (* trace y from up to down *)
790 done
:= false; j
:= 0;
791 while not done
and (j
< h
) do
794 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
795 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
800 (* trace x from right to left *)
801 done
:= false; i
:= w
- 1;
802 while not done
and (i
>= 0) do
805 while (j
< h
) and IsVoid(i
, j
) do inc(j
);
806 done
:= (j
< h
) and (IsVoid(i
, j
) = false);
807 result
.width
:= i
- result
.x
+ 1;
811 (* trace y from down to up *)
812 done
:= false; j
:= h
- 1;
813 while not done
and (j
>= 0) do
816 while (i
< w
) and IsVoid(i
, j
) do inc(i
);
817 done
:= (i
< w
) and (IsVoid(i
, j
) = false);
818 result
.height
:= j
- result
.y
+ 1;
823 function r_Textures_LoadStreamFromImage (var img
: TImageData
; w
, h
, c
, cw
: Integer; st
: TGLTextureArray
; rs
: TRectArray
; hints
: TGLHintsSet
): Boolean;
824 var i
, x
, y
: Integer; t
: TImageData
;
830 ASSERT((st
<> nil) and (Length(st
) >= c
));
831 ASSERT((rs
= nil) or (Length(rs
) >= c
));
833 for i
:= 0 to c
- 1 do
839 if NewImage(w
, h
, img
.Format
, t
) then
841 if CopyRect(img
, x
* w
, y
* h
, w
, h
, t
, 0, 0) then
844 rs
[i
] := r_Textures_GetRect(t
);
845 st
[i
] := r_Textures_LoadFromImage(t
, hints
);
848 ASSERT(st
[i
] <> nil);
853 function r_Textures_LoadStreamFromMemory (data
: Pointer; size
: LongInt; w
, h
, c
, cw
: Integer; st
: TGLTextureArray
; rs
: TRectArray
; hints
: TGLHintsSet
): Boolean;
860 ASSERT((st
<> nil) and (Length(st
) >= c
));
861 ASSERT((rs
= nil) or (Length(rs
) >= c
));
863 if (data
<> nil) and (size
> 0) then
867 if LoadImageFromMemory(data
, size
, img
) then
869 if r_Textures_FixImageData(img
) then
871 result
:= r_Textures_LoadStreamFromImage(img
, w
, h
, c
, cw
, st
, rs
, hints
)
880 function r_Textures_LoadStreamFromFile (const filename
: AnsiString; w
, h
, count
, cw
: Integer; st
: TGLTextureArray
; rs
: TRectArray
; hints
: TGLHintsSet
; log
: Boolean = True): Boolean;
881 var wad
: TWADFile
; wadName
, resName
: AnsiString; data
: Pointer; size
: Integer;
887 ASSERT((st
<> nil) and (Length(st
) >= count
));
888 ASSERT((rs
= nil) or (Length(rs
) >= count
));
890 wadName
:= g_ExtractWadName(filename
);
891 wad
:= TWADFile
.Create();
892 if wad
.ReadFile(wadName
) then
894 resName
:= g_ExtractFilePathName(filename
);
895 if wad
.GetResource(resName
, data
, size
, log
) then
897 result
:= r_Textures_LoadStreamFromMemory(data
, size
, w
, h
, count
, cw
, st
, rs
, hints
);
904 (* --------- TGLFont --------- *)
906 function r_Textures_LoadFontFromFile (const filename
: AnsiString; constref f
: TFontInfo
; font2enc
: TConvProc
; log
: Boolean = true): TGLFont
;
907 var i
, ch
: Integer; st
, stch
: TGLTextureArray
; font
: TGLFont
;
911 if r_Textures_LoadStreamFromFile(filename
, f
.w
, f
.h
, 256, 16, st
, nil, [TGLHints
.txNoRepeat
], log
) then
913 font
:= TGLFont
.Create();
916 if Assigned(font2enc
) then
918 SetLength(stch
, 256);
922 ASSERT((ch
>= 0) and (ch
<= 255));
932 destructor TGLFont
.Destroy
;
935 if self
.ch
<> nil then
936 for i
:= 0 to High(self
.ch
) do
941 function TGLFont
.GetChar (c
: AnsiChar): TGLTexture
;
943 result
:= self
.ch
[ORD(c
)];
946 function TGLFont
.GetWidth (c
: AnsiChar): Integer;
948 result
:= self
.info
.ch
[c
].w
;
950 result
:= self
.info
.w
;
951 if self
.info
.kern
< 0 then
952 result
:= result
+ self
.info
.kern
;
955 function TGLFont
.GetMaxWidth (): Integer;
957 result
:= self
.info
.w
;
958 if self
.info
.kern
< 0 then
959 result
:= result
+ self
.info
.kern
;
962 function TGLFont
.GetMaxHeight (): Integer;
964 result
:= self
.info
.h
;
967 function TGLFont
.GetSpace (): Integer;
969 result
:= self
.info
.kern
;
973 conRegVar('r_gl_maxtexsize', @r_GL_MaxTexSize
, '', '');
974 conRegVar('r_gl_repeat', @r_GL_RepeatOpt
, '', '');
975 r_GL_MaxTexSize
:= 0; // default is automatic value
976 r_GL_RepeatOpt
:= true;