unit ant_resources;

//
//  Most of the game resources are loaded and stored here.
//

{$MODE FPC}
{$MODESWITCH DEFAULTPARAMETERS}
{$MODESWITCH OUT}
{$MODESWITCH RESULT}

interface

uses
  {$I deng_app_units.inc},
  dstream,
  dstreamfile,
  {$IFDEF ANDROID}GLES,{$ELSE}GL, GLext,{$ENDIF} // TODO move all OpenGL-related part to DEng
  DDrawFrameBuffer,
  DEng_glsl,
  DDrawTex,
  DDrawShader,
  dengcache,
  ant_mesh;

type
TPBRTextures = record
  Diffuse: TDrawTex;
  Displacement: TDrawTex;
  Normal: TDrawTex;
  Roughness: TDrawTex;
end;

var
Res: record
  Ground: TPBRTextures;
  Shaders: record
    Diffuse: TShader;
    Ground: TShader;
  end;
  Buffer: TAntBuffer;
  Cube: TAntMesh;
  Icon: record
    Resource: TDrawTex;
    Arrows: TDrawTex;
    Plus: TDrawTex;
    Sword: TDrawTex;
  end;
end;

procedure LoadAllResources;
procedure UnloadAllResources;

implementation

procedure LoadPBR(var PBR: TPBRTextures; const PathPrefix: AnsiString);
begin
  PBR.Diffuse.Init(nil, @Eng, Asset(PathPrefix + 'diff.png'));
  PBR.Displacement.Init(nil, @Eng, Asset(PathPrefix + 'disp.png'));
  PBR.Normal.Init(nil, @Eng, Asset(PathPrefix + 'nor.png'));
  PBR.Roughness.Init(nil, @Eng, Asset(PathPrefix + 'rough.png'));
end;

procedure LoadAllResources;
begin
  // TODO FIXME should be in DEng
  if not Load_GL_version_2_0 then begin
    Log('FAILED Load_GL_version_2_0');
    Halt(0);
  end;
  if not glext_LoadExtension('GL_EXT_framebuffer_object') then begin
    Log('FAILED GL_EXT_framebuffer_object');
    Halt(0);
  end;

  LoadPBR(Res.Ground, 'data/tex/ground/rocks/');

  Res.Shaders.Diffuse.Init('data/shader/diffuse.vert', 'data/shader/diffuse.frag');
  Res.Shaders.Ground.Init('data/shader/ground.vert', 'data/shader/ground.frag');

  Res.Buffer.Init;
  Res.Cube.Init(@Res.Buffer, 'data/model/cube.antmesh');

  Res.Icon.Resource.Init(nil, @Eng, Asset('data/tex/icon/resource.png'));
  Res.Icon.Arrows.Init(nil, @Eng, Asset('data/tex/icon/arrows.png'));
  Res.Icon.Plus.Init(nil, @Eng, Asset('data/tex/icon/plus.png'));
  Res.Icon.Sword.Init(nil, @Eng, Asset('data/tex/icon/sword.png'));
end;

procedure UnloadAllResources;
begin
  // TODO :)
end;

end.
