Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeus64 committed Jan 9, 2019
1 parent 4e1615d commit 90ab642
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 60 deletions.
86 changes: 85 additions & 1 deletion source/ALFMXTypes3D.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface

uses System.Classes,
{$IFDEF ANDROID}
Androidapi.JNI.GraphicsContentViewText,
FMX.Context.GLES.Android,
{$ELSEIF defined(IOS)}
FMX.Context.GLES.iOS,
Expand Down Expand Up @@ -44,7 +45,10 @@ TALTexture = class(TTexture)
public
constructor Create; override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Assign(Source: TPersistent); overload; override;
{$IF defined(ANDROID)}
procedure Assign(Source: jbitmap); overload;
{$ENDIF}
property isExternalOES: boolean read fisExternalOES write fisExternalOES;
end;

Expand Down Expand Up @@ -141,6 +145,7 @@ implementation

uses system.sysutils,
{$IF defined(ANDROID)}
Androidapi.JNI.OpenGL,
Androidapi.Gles2,
Androidapi.Gles2ext,
FMX.Context.GLES,
Expand Down Expand Up @@ -296,6 +301,85 @@ procedure TALTexture.Assign(Source: TPersistent);

end;

{********************}
{$IF defined(ANDROID)}
procedure TALTexture.Assign(Source: jbitmap);
var Tex: GLuint;
begin

{$IFDEF DEBUG}
if PixelFormat <> TPixelFormat.None then AtomicDecrement(TotalMemoryUsedByTextures, Width * Height * BytesPerPixel);
{$ENDIF}

{$IF CompilerVersion > 32} // tokyo
{$MESSAGE WARN 'Check if the full flow of FMX.Types3D.TTexture.Assign is still the same as below and adjust the IFDEF'}
{$ENDIF}
{$IF CompilerVersion >= 32} // tokyo
//TMonitor.Enter(Self);
//try
{$ENDIF}
if Handle <> 0 then TContextManager.DefaultContextClass.FinalizeTexture(Self);
Style := [TTextureStyle.Dynamic, TTextureStyle.Volatile];
SetSize(Source.getWidth, Source.getHeight);
if not (IsEmpty) then begin
if PixelFormat = TPixelFormat.None then PixelFormat := TCustomAndroidContext.PixelFormat;
{$IF CompilerVersion <= 31} // berlin
TCustomAndroidContext.SharedContext; // >> because stupidly CreateSharedContext is protected :(
if TCustomAndroidContext.IsContextAvailable then
{$ELSE} // Tokyo
if TCustomAndroidContext.Valid then
{$ENDIF}
begin
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, @Tex);
glBindTexture(GL_TEXTURE_2D, Tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
case MagFilter of
TTextureFilter.Nearest: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
TTextureFilter.Linear: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
end;
if TTextureStyle.MipMaps in Style then
begin
case MinFilter of
TTextureFilter.Nearest: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
TTextureFilter.Linear: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
end;
end
else
begin
case MinFilter of
TTextureFilter.Nearest: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
TTextureFilter.Linear: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
end;
end;
TJGLUtils.JavaClass.texImage2D(GL_TEXTURE_2D, // target: Integer;
0, // level: Integer;
Source, // bitmap: JBitmap;
0); // border: Integer => glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Texture.Width, Texture.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
glBindTexture(GL_TEXTURE_2D, 0);
ITextureAccess(self).Handle := Tex;
if (TCustomAndroidContext.GLHasAnyErrors()) then
RaiseContextExceptionFmt(@SCannotCreateTexture, ['TALTexture']);
end;
end;
{$IF CompilerVersion >= 32} // tokyo
//finally
// TMonitor.exit(Self);
//end;
{$ENDIF}

{$IFDEF DEBUG}
if PixelFormat <> TPixelFormat.None then AtomicIncrement(TotalMemoryUsedByTextures, Width * Height * BytesPerPixel);
if TThread.GetTickCount - AtomicCmpExchange(LastTotalMemoryUsedByTexturesLog, 0, 0) > 1000 then begin // every 1 sec
AtomicExchange(LastTotalMemoryUsedByTexturesLog, TThread.GetTickCount); // oki maybe 2 or 3 log can be show simultaneously. i will not died for this !
ALLog('TALTexture', 'TotalMemoryUsedByTextures: ' + ALFormatFloatU('0.##', AtomicCmpExchange(TotalMemoryUsedByTextures, 0, 0) / 1000000, ALDefaultFormatSettingsU) +' MB', TalLogType.verbose);
end;
{$ENDIF}

end;
{$ENDIF}

{************************************}
constructor TALBiPlanarTexture.Create;
begin
Expand Down
60 changes: 1 addition & 59 deletions source/ALGraphics.pas
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ implementation
Androidapi.JNIBridge,
Androidapi.JNI.JavaTypes,
Androidapi.Helpers,
Androidapi.JNI.OpenGL,
Androidapi.Gles2,
Androidapi.JNI.Media,
FMX.Context.GLES,
Expand Down Expand Up @@ -273,71 +272,14 @@ implementation
{********************}
{$IF defined(ANDROID)}
function ALJBitmaptoTexture(const aBitmap: Jbitmap): TTexture;
var Tex: GLuint;
begin

{$IF CompilerVersion > 32} // tokyo
{$MESSAGE WARN 'Check if the full flow of FMX.Types3D.TTexture.Assign is still the same as below and adjust the IFDEF'}
{$ENDIF}
result := TALTexture.Create;
try
result.Style := [TTextureStyle.Dynamic, TTextureStyle.Volatile];
result.SetSize(aBitmap.getWidth, aBitmap.getHeight);
if not (result.IsEmpty) then begin
if result.PixelFormat = TPixelFormat.None then result.PixelFormat := TCustomAndroidContext.PixelFormat;
{$IF CompilerVersion <= 31} // berlin
TCustomAndroidContext.SharedContext; // >> because stupidly CreateSharedContext is protected :(
if TCustomAndroidContext.IsContextAvailable then
{$ELSE} // Tokyo
if TCustomAndroidContext.Valid then
{$ENDIF}
begin
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, @Tex);
glBindTexture(GL_TEXTURE_2D, Tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
case result.MagFilter of
TTextureFilter.Nearest: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
TTextureFilter.Linear: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
end;
if TTextureStyle.MipMaps in result.Style then
begin
case result.MinFilter of
TTextureFilter.Nearest: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
TTextureFilter.Linear: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
end;
end
else
begin
case result.MinFilter of
TTextureFilter.Nearest: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
TTextureFilter.Linear: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
end;
end;
TJGLUtils.JavaClass.texImage2D(GL_TEXTURE_2D, // target: Integer;
0, // level: Integer;
aBitmap, // bitmap: JBitmap;
0); // border: Integer => glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Texture.Width, Texture.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
glBindTexture(GL_TEXTURE_2D, 0);
ITextureAccess(result).Handle := Tex;
if (TCustomAndroidContext.GLHasAnyErrors()) then
RaiseContextExceptionFmt(@SCannotCreateTexture, ['TALTexture']);
end;
end;
TALTexture(result).Assign(aBitmap);
except
ALFreeAndNil(result);
raise;
end;

{$IFDEF DEBUG}
if result.PixelFormat <> TPixelFormat.None then AtomicIncrement(TotalMemoryUsedByTextures, result.Width * result.Height * result.BytesPerPixel);
if TThread.GetTickCount - AtomicCmpExchange(LastTotalMemoryUsedByTexturesLog, 0, 0) > 1000 then begin // every 1 sec
AtomicExchange(LastTotalMemoryUsedByTexturesLog, TThread.GetTickCount); // oki maybe 2 or 3 log can be show simultaneously. i will not died for this !
ALLog('TALTexture', 'TotalMemoryUsedByTextures: ' + ALFormatFloatU('0.##', AtomicCmpExchange(TotalMemoryUsedByTextures, 0, 0) / 1000000, ALDefaultFormatSettingsU) +' MB', TalLogType.verbose);
end;
{$ENDIF}

end;
{$ENDIF}

Expand Down

0 comments on commit 90ab642

Please sign in to comment.