unit _Resources;

interface

uses
  QuadEngine,
  Classes;

const
  UNITS_SIZE = 128;

  type
TResources = class
  private
    const UNIT_SIZE = 128;
    const PATH = 'Data/';  
  private
    FQuad: IQuadDevice;
  public
    Intro,
    QuadTexture:  IQuadTexture;
    LogoTexture:  IQuadTexture;
    UnitTexture:  IQuadTexture;
    DummyTexture: IQuadTexture;
    NoiseTexture: IQuadTexture;
    CraterTexture:IQuadTexture;
    SmokeTexture: IQuadTexture;
    TileTexture:  IQuadTexture;
    ArrowTexture: IQuadTexture;
    AimTexture:   IQuadTexture;
    RayTexture:   IQuadTexture;

    MapShift: Array [0..1] of Single;
    TopColor: Array [0..2] of Single;
    BottomColor: Array [0..2] of Single;
    MapGenerationShader: IQuadShader;   
    MapLightningShader: IQuadShader;

    Font: IQuadFont;
    
    constructor Load(QuadDevice: IQuadDevice);
    destructor Destroy; override;
    property Quad: IQuadDevice read FQuad;
  end;

var
  Resources: TResources;

implementation

//TResources
constructor TResources.Load(QuadDevice: IQuadDevice);
begin
  FQuad:= QuadDevice;
  FQuad.CreateAndLoadTexture(0, PATH + 'quad.png', QuadTexture);
  FQuad.CreateAndLoadTexture(0, PATH + 'logo.png', LogoTexture);
  FQuad.CreateAndLoadTexture(0, PATH + 'units.png', UnitTexture, UNIT_SIZE, UNIT_SIZE);
  FQuad.CreateAndLoadTexture(0, PATH + 'dummy.png', DummyTexture);
  FQuad.CreateAndLoadTexture(0, PATH + 'noise.png', NoiseTexture);
  FQuad.CreateAndLoadTexture(0, PATH + 'smoke.png', SmokeTexture);
  FQuad.CreateAndLoadTexture(0, PATH + 'crater.png', CraterTexture);   
  FQuad.CreateAndLoadTexture(0, PATH + 'tile.png', TileTexture);
  FQuad.CreateAndLoadTexture(0, PATH + 'arrow.png', ArrowTexture);
  FQuad.CreateAndLoadTexture(0, PATH + 'aim.png', AimTexture);    
  FQuad.CreateAndLoadTexture(0, PATH + 'ray.png', RayTexture);

  FQuad.CreateShader(MapGenerationShader);
  MapGenerationShader.LoadPixelShader(PATH + 'Shaders/ps_map_gen.bin');
  MapGenerationShader.BindVariableToPS( 1, @MapShift, SizeOf( MapShift ) );
  FQuad.CreateShader(MapLightningShader);
  MapLightningShader.LoadPixelShader (PATH + 'Shaders/ps_temp.bin'); 
  MapLightningShader.BindVariableToPS( 1, @TopColor, SizeOf( TopColor ) );
  MapLightningShader.BindVariableToPS( 2, @BottomColor, SizeOf( BottomColor ) );
  TopColor[1]:= $25 / $ff;
  TopColor[0]:= $87 / $ff;
  TopColor[2]:= $32 / $ff;
  BottomColor[0]:= $3f / $ff;
  BottomColor[1]:= $fa / $ff;
  BottomColor[2]:= $2f / $ff;

  FQuad.CreateAndLoadFont(PATH + 'Font/Font.png', PATH + 'Font/Font.qef', Font);

  Font.SetIsSmartColoring(True);
end;

destructor TResources.Destroy;
begin
  QuadTexture:= nil;
  LogoTexture:= nil;
  TileTexture:= nil;
  UnitTexture:= nil;
  DummyTexture:= nil;      
  NoiseTexture:= nil;
  CraterTexture:= nil;
  SmokeTexture:= nil;
  TileTexture:= nil;
  ArrowTexture:= nil;
  AimTexture:= nil;
  RayTexture:= nil;
  MapGenerationShader:= nil;
  MapLightningShader:= nil;
  Font:= nil;
  inherited;
end;

end.
