index 0114880088cc352459cfd7911021c99978f2d85f..b98c0d3507d98576d6ecafa23291bfd895280ce9 100644 (file)
interface
uses
interface
uses
- {$IFDEF USE_GLES1}
- GLES11,
- {$ELSE}
- GL, GLEXT,
- {$ENDIF}
+ {$I ../../../nogl/noGLuses.inc}
g_base, g_animations, // TRectHW, TAnimInfo
utils,
r_atlas, r_fonts
;
type
g_base, g_animations, // TRectHW, TAnimInfo
utils,
r_atlas, r_fonts
;
type
+ TGLHints = (txNoRepeat);
+ TGLHintsSet = set of TGLHints;
+
TGLAtlas = class;
TGLAtlasNode = class (TAtlasNode)
TGLAtlas = class;
TGLAtlasNode = class (TAtlasNode)
mHeight: Integer;
mCols: Integer;
mTile: array of TGLAtlasNode;
mHeight: Integer;
mCols: Integer;
mTile: array of TGLAtlasNode;
+ mHints: TGLHintsSet;
public
destructor Destroy; override;
public
destructor Destroy; override;
property height: Integer read mHeight;
property cols: Integer read mCols;
property lines: Integer read GetLines;
property height: Integer read mHeight;
property cols: Integer read mCols;
property lines: Integer read GetLines;
+ property hints: TGLHintsSet read mHints;
end;
TGLMultiTexture = class
end;
TGLMultiTexture = class
anim: TAnimInfo;
end;
anim: TAnimInfo;
end;
+ TConvProc = function (x: Integer): Integer;
+
procedure r_Textures_Initialize;
procedure r_Textures_Finalize;
procedure r_Textures_Initialize;
procedure r_Textures_Finalize;
- function r_Textures_LoadFromFile (const filename: AnsiString; log: Boolean = True): TGLTexture;
- function r_Textures_LoadMultiFromFile (const filename: AnsiString; log: Boolean = True): TGLMultiTexture;
- function r_Textures_LoadMultiFromFileAndInfo (const filename: AnsiString; w, h, count: Integer; log: Boolean = True): TGLMultiTexture;
- function r_Textures_LoadMultiTextFromFile (const filename: AnsiString; var txt: TAnimTextInfo; log: Boolean = True): TGLMultiTexture;
+ function r_Textures_LoadFromFile (const filename: AnsiString; hints: TGLHintsSet; log: Boolean = True): TGLTexture;
+ function r_Textures_LoadMultiFromFile (const filename: AnsiString; hints: TGLHintsSet; log: Boolean = True): TGLMultiTexture;
+ function r_Textures_LoadMultiFromFileAndInfo (const filename: AnsiString; w, h, count: Integer; hints: TGLHintsSet; log: Boolean = True): TGLMultiTexture;
+ function r_Textures_LoadMultiTextFromFile (const filename: AnsiString; var txt: TAnimTextInfo; hints: TGLHintsSet; log: Boolean = True): TGLMultiTexture;
- function r_Textures_LoadStreamFromFile (const filename: AnsiString; w, h, count, cw: Integer; st: TGLTextureArray; rs: TRectArray; log: Boolean = True): Boolean;
+ function r_Textures_LoadStreamFromFile (const filename: AnsiString; w, h, count, cw: Integer; st: TGLTextureArray; rs: TRectArray; hints: TGLHintsSet; log: Boolean = True): Boolean;
- function r_Textures_LoadFontFromFile (const filename: AnsiString; constref f: TFontInfo; skipch: Integer; log: Boolean = true): TGLFont;
+ function r_Textures_LoadFontFromFile (const filename: AnsiString; constref f: TFontInfo; font2enc: TConvProc; log: Boolean = true): TGLFont;
+
+ procedure r_Textures_GL_Bind (id: GLuint);
implementation
uses
SysUtils, Classes,
implementation
uses
SysUtils, Classes,
+ r_common,
e_log, e_res, WADReader, Config,
g_console, // cvar declaration
Imaging, ImagingTypes, ImagingUtility
e_log, e_res, WADReader, Config,
g_console, // cvar declaration
Imaging, ImagingTypes, ImagingUtility
var
r_GL_MaxTexSize: WORD;
var
r_GL_MaxTexSize: WORD;
+ r_GL_RepeatOpt: Boolean;
maxTileSize: Integer;
maxTileSize: Integer;
- atl: array of TGLAtlas;
+ atl, ratl: array of TGLAtlas;
+ currentTexture2D: GLuint;
+
+ procedure r_Textures_GL_Bind (id: GLuint);
+ begin
+ if id <> currentTexture2D then
+ begin
+ glBindTexture(GL_TEXTURE_2D, id);
+ currentTexture2D := id;
+ end
+ end;
(* --------- TGLAtlasNode --------- *)
(* --------- TGLAtlasNode --------- *)
ASSERT(n.l + x + w - 1 <= n.r);
ASSERT(n.t + y + h - 1 <= n.b);
ASSERT(n.id > 0);
ASSERT(n.l + x + w - 1 <= n.r);
ASSERT(n.t + y + h - 1 <= n.b);
ASSERT(n.id > 0);
- glBindTexture(GL_TEXTURE_2D, n.id);
+ r_Textures_GL_Bind(n.id);
glTexSubImage2D(GL_TEXTURE_2D, 0, n.l + x, n.t + y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexSubImage2D(GL_TEXTURE_2D, 0, n.l + x, n.t + y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data);
- glBindTexture(GL_TEXTURE_2D, 0);
+ r_Textures_GL_Bind(0);
end;
(* --------- TGLAtlas --------- *)
end;
(* --------- TGLAtlas --------- *)
glGenTextures(1, @id);
if id <> 0 then
begin
glGenTextures(1, @id);
if id <> 0 then
begin
- glBindTexture(GL_TEXTURE_2D, id);
+ r_Textures_GL_Bind(id);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
- glBindTexture(GL_TEXTURE_2D, 0);
+ r_Textures_GL_Bind(0);
end;
result := id
end;
end;
result := id
end;
end;
end;
end;
end;
+ function r_Textures_AllocRepeatAtlas (w, h: Integer): TGLAtlas;
+ var i: Integer; id: GLuint;
+ begin
+ result := nil;
+ id := r_Textures_AllocHWTexture(w, h);
+ if id <> 0 then
+ begin
+ i := Length(ratl);
+ SetLength(ratl, i + 1);
+ ratl[i] := TGLAtlas.Create(w, h, id);
+ result := ratl[i];
+ end;
+ end;
+
function r_Textures_AllocNode (w, h: Integer): TGLAtlasNode;
var i: Integer; n: TGLAtlasNode; a: TGLAtlas;
begin
function r_Textures_AllocNode (w, h: Integer): TGLAtlasNode;
var i: Integer; n: TGLAtlasNode; a: TGLAtlas;
begin
result := n
end;
result := n
end;
+ function r_Textures_AllocRepeatNode (w, h: Integer): TGLAtlasNode;
+ var i: Integer; n: TGLAtlasNode; a: TGLAtlas;
+ begin
+ n := nil; a := nil;
+ if ratl <> nil then
+ begin
+ i := High(ratl);
+ while (i >= 0) and (ratl[i] <> nil) do DEC(i);
+ if i >= 0 then a := ratl[i];
+ end;
+ if a = nil then a := r_Textures_AllocRepeatAtlas(w, h);
+ if a <> nil then
+ begin
+ n := a.Alloc(w, h);
+ if n = nil then
+ begin
+ i := High(ratl); while (i >= 0) and (ratl[i] <> a) do DEC(i);
+ if i >= 0 then ratl[i] := nil;
+ r_Common_FreeAndNil(a);
+ end;
+ end;
+ result := n
+ end;
+
(* --------- TGLTexture --------- *)
destructor TGLTexture.Destroy;
(* --------- TGLTexture --------- *)
destructor TGLTexture.Destroy;
- var i: Integer;
+ var i: Integer; a: TGLAtlas;
begin
if self.mTile <> nil then
begin
begin
if self.mTile <> nil then
begin
- for i := 0 to High(self.mTile) do
+ if TGLHints.txNoRepeat in self.hints then (* non repeatable texture -> delete tiles only *)
begin
begin
- if self.mTile[i] <> nil then
+ for i := 0 to High(self.mTile) do
begin
begin
- self.mTile[i].Dealloc;
- self.mTile[i] := nil;
- end;
+ if self.mTile[i] <> nil then
+ begin
+ self.mTile[i].Dealloc;
+ self.mTile[i] := nil
+ end
+ end
+ end
+ else (* repeatable texture -> delete whole atlas *)
+ begin
+ a := self.mTile[0].base;
+ i := High(ratl); while (i >= 0) and (ratl[i] <> a) do DEC(i);
+ if i >= 0 then ratl[i] := nil;
+ r_Common_FreeAndNil(a);
end;
end;
- self.mTile := nil;
+ SetLength(self.mTile, 0);
end;
inherited;
end;
end;
inherited;
end;
ASSERT(result <> nil)
end;
ASSERT(result <> nil)
end;
- function r_Textures_Alloc (w, h: Integer): TGLTexture;
+ function r_Textures_Alloc (w, h: Integer; hints: TGLHintsSet): TGLTexture;
var x, y, mw, mh, cols, lines: Integer; t: TGLTexture;
begin
ASSERT(w > 0);
ASSERT(h > 0);
var x, y, mw, mh, cols, lines: Integer; t: TGLTexture;
begin
ASSERT(w > 0);
ASSERT(h > 0);
- cols := (w + maxTileSize - 1) div maxTileSize;
- lines := (h + maxTileSize - 1) div maxTileSize;
- t := TGLTexture.Create;
- t.mWidth := w;
- t.mHeight := h;
- t.mCols := cols;
- // t.mLines := lines;
- SetLength(t.mTile, cols * lines);
- for y := 0 to lines - 1 do
- begin
- mh := Min(maxTileSize, h - y * maxTileSize);
- ASSERT(mh > 0);
- for x := 0 to cols - 1 do
+ if TGLHints.txNoRepeat in hints then
+ begin
+ cols := (w + maxTileSize - 1) div maxTileSize;
+ lines := (h + maxTileSize - 1) div maxTileSize;
+ t := TGLTexture.Create;
+ t.mWidth := w;
+ t.mHeight := h;
+ t.mCols := cols;
+ // t.mLines := lines;
+ t.mHints := hints;
+ SetLength(t.mTile, cols * lines);
+ for y := 0 to lines - 1 do
begin
begin
- mw := Min(maxTileSize, w - x * maxTileSize);
- ASSERT(mw > 0);
- t.mTile[y * cols + x] := r_Textures_AllocNode(mw, mh);
- end
+ mh := Min(maxTileSize, h - y * maxTileSize);
+ ASSERT(mh > 0);
+ for x := 0 to cols - 1 do
+ begin
+ mw := Min(maxTileSize, w - x * maxTileSize);
+ ASSERT(mw > 0);
+ t.mTile[y * cols + x] := r_Textures_AllocNode(mw, mh);
+ end
+ end;
+ end
+ else
+ begin
+ t := TGLTexture.Create;
+ t.mWidth := w;
+ t.mHeight := h;
+ t.mCols := 1;
+ // t.mLines := 1
+ t.mHints := hints;
+ SetLength(t.mTile, 1);
+ t.mTile[0] := r_Textures_AllocRepeatNode(w, h);
end;
result := t;
end;
end;
result := t;
end;
var i: Integer;
begin
for i := 0 to self.count - 1 do
var i: Integer;
begin
for i := 0 to self.count - 1 do
- self.mTexture[i].Free;
- self.mTexture := nil;
+ r_Common_FreeAndNil(self.mTexture[i]);
+ SetLength(self.mTexture, 0);
inherited;
end;
inherited;
end;
procedure r_Textures_Initialize;
begin
procedure r_Textures_Initialize;
begin
+ currentTexture2D := 0;
maxTileSize := r_Textures_GetMaxHardwareSize();
e_LogWritefln('TEXTURE SIZE: %s', [maxTileSize]);
end;
maxTileSize := r_Textures_GetMaxHardwareSize();
e_LogWritefln('TEXTURE SIZE: %s', [maxTileSize]);
end;
begin
glDeleteTextures(1, @atl[i].id);
atl[i].id := 0;
begin
glDeleteTextures(1, @atl[i].id);
atl[i].id := 0;
- atl[i].Free;
+ r_Common_FreeAndNil(atl[i]);
+ end;
+ end;
+ SetLength(atl, 0);
+
+ if ratl <> nil then
+ begin
+ for i := 0 to High(ratl) do
+ begin
+ glDeleteTextures(1, @ratl[i].id);
+ ratl[i].id := 0;
+ r_Common_FreeAndNil(ratl[i]);
end;
end;
- atl := nil;
end;
end;
+ SetLength(ratl, 0);
end;
function r_Textures_FixImageData (var img: TImageData): Boolean;
end;
function r_Textures_FixImageData (var img: TImageData): Boolean;
result := true;
end;
result := true;
end;
- function r_Textures_LoadFromImage (var img: TImageData): TGLTexture;
+ function r_Textures_ValidRepeatTexture (w, h: Integer; hints: TGLHintsSet): Boolean;
+ begin
+ result := r_GL_RepeatOpt and
+ not (TGLHints.txNoRepeat in hints) and
+ (w <= maxTileSize) and
+ (h <= maxTileSize) and
+ IsPOT(w) and
+ IsPOT(h)
+ end;
+
+ function r_Textures_LoadFromImage (var img: TImageData; hints: TGLHintsSet): TGLTexture; // !!!
var t: TGLTexture; n: TGLAtlasNode; c: TDynImageDataArray; cw, ch, i, j: LongInt;
begin
result := nil;
var t: TGLTexture; n: TGLAtlasNode; c: TDynImageDataArray; cw, ch, i, j: LongInt;
begin
result := nil;
- if SplitImage(img, c, maxTileSize, maxTileSize, cw, ch, False) then
+ if r_Textures_ValidRepeatTexture(img.width, img.height, hints) then
+ begin
+ t := r_Textures_Alloc(img.width, img.height, hints - [TGLHints.txNoRepeat]);
+ if t <> nil then
+ begin
+ n := t.GetTile(0, 0);
+ ASSERT(n <> nil);
+ r_Textures_UpdateNode(n, img.bits, 0, 0, n.width, n.height);
+ result := t
+ end
+ end
+ else if SplitImage(img, c, maxTileSize, maxTileSize, cw, ch, False) then
begin
begin
- t := r_Textures_Alloc(img.width, img.height);
+ t := r_Textures_Alloc(img.width, img.height, hints + [TGLHints.txNoRepeat]);
if t <> nil then
begin
ASSERT(cw = t.cols);
if t <> nil then
begin
ASSERT(cw = t.cols);
end;
end;
end;
end;
- function r_Textures_LoadFromMemory (data: Pointer; size: LongInt): TGLTexture;
+ function r_Textures_LoadFromMemory (data: Pointer; size: LongInt; hints: TGLHintsSet): TGLTexture;
var img: TImageData;
begin
result := nil;
var img: TImageData;
begin
result := nil;
try
if LoadImageFromMemory(data, size, img) then
if r_Textures_FixImageData(img) then
try
if LoadImageFromMemory(data, size, img) then
if r_Textures_FixImageData(img) then
- result := r_Textures_LoadFromImage(img)
+ result := r_Textures_LoadFromImage(img, hints)
except
end;
FreeImage(img);
end;
end;
except
end;
FreeImage(img);
end;
end;
- function r_Textures_LoadFromFile (const filename: AnsiString; log: Boolean = True): TGLTexture;
+ function r_Textures_LoadFromFile (const filename: AnsiString; hints: TGLHintsSet; log: Boolean = True): TGLTexture;
var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
begin
result := nil;
var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
begin
result := nil;
resName := g_ExtractFilePathName(filename);
if wad.GetResource(resName, data, size, log) then
begin
resName := g_ExtractFilePathName(filename);
if wad.GetResource(resName, data, size, log) then
begin
- result := r_Textures_LoadFromMemory(data, size);
+ result := r_Textures_LoadFromMemory(data, size, hints);
FreeMem(data);
end;
wad.Free
end
end;
FreeMem(data);
end;
wad.Free
end
end;
- function r_Textures_LoadMultiFromImageAndInfo (var img: TImageData; w, h, c: Integer): TGLMultiTexture;
+ function r_Textures_LoadMultiFromImageAndInfo (var img: TImageData; w, h, c: Integer; hints: TGLHintsSet): TGLMultiTexture;
var t: TImageData; a: array of TGLTexture; i: Integer; m: TGLMultiTexture;
begin
ASSERT(w >= 0);
var t: TImageData; a: array of TGLTexture; i: Integer; m: TGLMultiTexture;
begin
ASSERT(w >= 0);
InitImage(t);
if NewImage(w, h, img.Format, t) then
if CopyRect(img, w * i, 0, w, h, t, 0, 0) then
InitImage(t);
if NewImage(w, h, img.Format, t) then
if CopyRect(img, w * i, 0, w, h, t, 0, 0) then
- a[i] := r_Textures_LoadFromImage(t);
+ a[i] := r_Textures_LoadFromImage(t, hints);
ASSERT(a[i] <> nil);
FreeImage(t);
end;
ASSERT(a[i] <> nil);
FreeImage(t);
end;
result := m;
end;
result := m;
end;
- function r_Textures_LoadMultiFromDataAndInfo (data: Pointer; size: LongInt; w, h, c: Integer): TGLMultiTexture;
+ function r_Textures_LoadMultiFromDataAndInfo (data: Pointer; size: LongInt; w, h, c: Integer; hints: TGLHintsSet): TGLMultiTexture;
var img: TImageData;
begin
ASSERT(w > 0);
var img: TImageData;
begin
ASSERT(w > 0);
try
if LoadImageFromMemory(data, size, img) then
if r_Textures_FixImageData(img) then
try
if LoadImageFromMemory(data, size, img) then
if r_Textures_FixImageData(img) then
- result := r_Textures_LoadMultiFromImageAndInfo(img, w, h, c)
+ result := r_Textures_LoadMultiFromImageAndInfo(img, w, h, c, hints)
except
end;
FreeImage(img);
except
end;
FreeImage(img);
end;
end;
end;
end;
- function r_Textures_LoadMultiFromWad (wad: TWADFile; var txt: TAnimTextInfo): TGLMultiTexture;
+ function r_Textures_LoadMultiFromWad (wad: TWADFile; var txt: TAnimTextInfo; hints: TGLHintsSet): TGLMultiTexture;
var data: Pointer; size: LongInt; img: TImageData;
begin
ASSERT(wad <> nil);
var data: Pointer; size: LongInt; img: TImageData;
begin
ASSERT(wad <> nil);
try
if LoadImageFromMemory(data, size, img) then
if r_Textures_FixImageData(img) then
try
if LoadImageFromMemory(data, size, img) then
if r_Textures_FixImageData(img) then
- result := r_Textures_LoadMultiFromImageAndInfo(img, txt.w, txt.h, txt.anim.frames);
+ result := r_Textures_LoadMultiFromImageAndInfo(img, txt.w, txt.h, txt.anim.frames, hints);
finally
FreeMem(data);
end;
finally
FreeMem(data);
end;
end;
end;
end;
end;
- function r_Textures_LoadMultiFromMemory (data: Pointer; size: LongInt; var txt: TAnimTextInfo): TGLMultiTexture;
+ function r_Textures_LoadMultiFromMemory (data: Pointer; size: LongInt; var txt: TAnimTextInfo; hints: TGLHintsSet): TGLMultiTexture;
var wad: TWADFile; t: TGLTexture; m: TGLMultiTexture;
begin
result := nil;
if (data <> nil) and (size > 0) then
begin
var wad: TWADFile; t: TGLTexture; m: TGLMultiTexture;
begin
result := nil;
if (data <> nil) and (size > 0) then
begin
- t := r_Textures_LoadFromMemory(data, size);
+ t := r_Textures_LoadFromMemory(data, size, hints);
if t <> nil then
begin
m := TGLMultiTexture.Create();
if t <> nil then
begin
m := TGLMultiTexture.Create();
wad := TWADFile.Create();
if wad.ReadMemory(data, size) then
begin
wad := TWADFile.Create();
if wad.ReadMemory(data, size) then
begin
- result := r_Textures_LoadMultiFromWad(wad, txt);
+ result := r_Textures_LoadMultiFromWad(wad, txt, hints);
wad.Free;
end
end
end
end;
wad.Free;
end
end
end
end;
- function r_Textures_LoadMultiTextFromFile (const filename: AnsiString; var txt: TAnimTextInfo; log: Boolean = True): TGLMultiTexture;
+ function r_Textures_LoadMultiTextFromFile (const filename: AnsiString; var txt: TAnimTextInfo; hints: TGLHintsSet; log: Boolean = True): TGLMultiTexture;
var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
begin
result := nil;
var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
begin
result := nil;
resName := g_ExtractFilePathName(filename);
if wad.GetResource(resName, data, size, log) then
begin
resName := g_ExtractFilePathName(filename);
if wad.GetResource(resName, data, size, log) then
begin
- result := r_Textures_LoadMultiFromMemory(data, size, txt);
+ result := r_Textures_LoadMultiFromMemory(data, size, txt, hints);
FreeMem(data);
end;
wad.Free
end
end;
FreeMem(data);
end;
wad.Free
end
end;
- function r_Textures_LoadMultiFromFile (const filename: AnsiString; log: Boolean = True): TGLMultiTexture;
+ function r_Textures_LoadMultiFromFile (const filename: AnsiString; hints: TGLHintsSet; log: Boolean = True): TGLMultiTexture;
var txt: TAnimTextInfo;
begin
var txt: TAnimTextInfo;
begin
- result := r_Textures_LoadMultiTextFromFile(filename, txt, log);
+ result := r_Textures_LoadMultiTextFromFile(filename, txt, hints, log);
end;
end;
- function r_Textures_LoadMultiFromFileAndInfo (const filename: AnsiString; w, h, count: Integer; log: Boolean = True): TGLMultiTexture;
+ function r_Textures_LoadMultiFromFileAndInfo (const filename: AnsiString; w, h, count: Integer; hints: TGLHintsSet; log: Boolean = True): TGLMultiTexture;
var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
begin
ASSERT(w > 0);
var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
begin
ASSERT(w > 0);
resName := g_ExtractFilePathName(filename);
if wad.GetResource(resName, data, size, log) then
begin
resName := g_ExtractFilePathName(filename);
if wad.GetResource(resName, data, size, log) then
begin
- result := r_Textures_LoadMultiFromDataAndInfo(data, size, w, h, count);
+ result := r_Textures_LoadMultiFromDataAndInfo(data, size, w, h, count, hints);
FreeMem(data);
end;
wad.Free
FreeMem(data);
end;
wad.Free
end;
end;
end;
end;
- function r_Textures_LoadStreamFromImage (var img: TImageData; w, h, c, cw: Integer; st: TGLTextureArray; rs: TRectArray): Boolean;
+ function r_Textures_LoadStreamFromImage (var img: TImageData; w, h, c, cw: Integer; st: TGLTextureArray; rs: TRectArray; hints: TGLHintsSet): Boolean;
var i, x, y: Integer; t: TImageData;
begin
ASSERT(w >= 0);
var i, x, y: Integer; t: TImageData;
begin
ASSERT(w >= 0);
begin
if rs <> nil then
rs[i] := r_Textures_GetRect(t);
begin
if rs <> nil then
rs[i] := r_Textures_GetRect(t);
- st[i] := r_Textures_LoadFromImage(t);
+ st[i] := r_Textures_LoadFromImage(t, hints);
end;
end;
ASSERT(st[i] <> nil);
end;
end;
ASSERT(st[i] <> nil);
end;
end;
end;
end;
- function r_Textures_LoadStreamFromMemory (data: Pointer; size: LongInt; w, h, c, cw: Integer; st: TGLTextureArray; rs: TRectArray): Boolean;
+ function r_Textures_LoadStreamFromMemory (data: Pointer; size: LongInt; w, h, c, cw: Integer; st: TGLTextureArray; rs: TRectArray; hints: TGLHintsSet): Boolean;
var img: TImageData;
begin
ASSERT(w >= 0);
var img: TImageData;
begin
ASSERT(w >= 0);
begin
if r_Textures_FixImageData(img) then
begin
begin
if r_Textures_FixImageData(img) then
begin
- result := r_Textures_LoadStreamFromImage(img, w, h, c, cw, st, rs)
+ result := r_Textures_LoadStreamFromImage(img, w, h, c, cw, st, rs, hints)
end;
end;
except
end;
end;
except
end;
end;
end;
end;
- function r_Textures_LoadStreamFromFile (const filename: AnsiString; w, h, count, cw: Integer; st: TGLTextureArray; rs: TRectArray; log: Boolean = True): Boolean;
+ function r_Textures_LoadStreamFromFile (const filename: AnsiString; w, h, count, cw: Integer; st: TGLTextureArray; rs: TRectArray; hints: TGLHintsSet; log: Boolean = True): Boolean;
var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
begin
ASSERT(w > 0);
var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
begin
ASSERT(w > 0);
resName := g_ExtractFilePathName(filename);
if wad.GetResource(resName, data, size, log) then
begin
resName := g_ExtractFilePathName(filename);
if wad.GetResource(resName, data, size, log) then
begin
- result := r_Textures_LoadStreamFromMemory(data, size, w, h, count, cw, st, rs);
+ result := r_Textures_LoadStreamFromMemory(data, size, w, h, count, cw, st, rs, hints);
FreeMem(data);
end;
wad.Free
FreeMem(data);
end;
wad.Free
(* --------- TGLFont --------- *)
(* --------- TGLFont --------- *)
- function r_Textures_LoadFontFromFile (const filename: AnsiString; constref f: TFontInfo; skipch: Integer; log: Boolean = true): TGLFont;
- var i: Integer; st: TGLTextureArray; font: TGLFont; t: TGLTexture;
+ function r_Textures_LoadFontFromFile (const filename: AnsiString; constref f: TFontInfo; font2enc: TConvProc; log: Boolean = true): TGLFont;
+ var i, ch: Integer; st, stch: TGLTextureArray; font: TGLFont;
begin
begin
- ASSERT(skipch >= 0);
result := nil;
SetLength(st, 256);
result := nil;
SetLength(st, 256);
- if r_Textures_LoadStreamFromFile(filename, f.w, f.h, 256, 16, st, nil, log) then
+ if r_Textures_LoadStreamFromFile(filename, f.w, f.h, 256, 16, st, nil, [TGLHints.txNoRepeat], log) then
begin
begin
- if skipch > 0 then
+ font := TGLFont.Create();
+ font.info := f;
+ font.ch := st;
+ if Assigned(font2enc) then
begin
begin
+ SetLength(stch, 256);
for i := 0 to 255 do
begin
for i := 0 to 255 do
begin
- t := st[i];
- st[i] := st[(i + skipch) mod 256];
- st[(i + skipch) mod 256] := t;
+ ch := font2enc(i);
+ ASSERT((ch >= 0) and (ch <= 255));
+ stch[ch] := st[i];
end;
end;
+ font.ch := stch;
+ SetLength(st, 0);
end;
end;
- font := TGLFont.Create();
- font.info := f;
- font.ch := st;
result := font;
end;
end;
result := font;
end;
end;
initialization
conRegVar('r_gl_maxtexsize', @r_GL_MaxTexSize, '', '');
initialization
conRegVar('r_gl_maxtexsize', @r_GL_MaxTexSize, '', '');
+ conRegVar('r_gl_repeat', @r_GL_RepeatOpt, '', '');
r_GL_MaxTexSize := 0; // default is automatic value
r_GL_MaxTexSize := 0; // default is automatic value
+ r_GL_RepeatOpt := true;
end.
end.