unit ThoriumHorde3D;

{$mode objfpc} {$H+}

interface

uses
  Classes, SysUtils, Thorium, Thorium_Globals, Horde3D;

{ TLibHorde3D }

  TLibHorde3D = class (TThoriumLibrary)
  protected
    procedure InitializeLibrary; override;
    class function GetName: String; override;
  end;

implementation

function LibHorde3D_GetVersionString: String;
begin
  Result := String(h3dGetVersionString);
end;

function LibHorde3D_CheckExtension(extensionName: String): Boolean;
begin
  Result := h3dCheckExtension(PAnsiChar(extensionName));
end;

function LibHorde3D_GetError: Boolean;
begin
  Result := h3dGetError;
end;

function LibHorde3D_Init: Boolean;
begin
  Result := h3dInit;
end;

procedure LibHorde3D_Release;
begin
  h3dRelease;
end;

procedure LibHorde3D_SetupViewport(x, y, width, height: Integer; resizeBuffers: Boolean);
begin
  h3dSetupViewport(x, y, width, height, resizeBuffers);
end;

(*procedure h3dRender(cameraNode: H3DNode);

procedure h3dFinalizeFrame;

procedure h3dClear;

function h3dGetMessage(level: PInteger; time: PSingle): PAnsiChar;

function h3dGetOption(param: H3DOptions): Single;

function h3dSetOption(param: H3DOptions; value: Single): Boolean;

function h3dGetStat(param: H3DStats; reset: Boolean): Single;

procedure h3dShowOverlay(x_tl, y_tl, u_tl, v_tl, x_bl, y_bl, u_bl, v_bl, x_br,

  y_br, u_br, v_br, x_tr, y_tr, u_tr, v_tr, colR, colG, colB, colA: Single;

  materialRes: H3DRes; layer: Integer);

procedure h3dClearOverlays;

function h3dGetResType(res: H3DRes): H3DResTypes;

function h3dGetResName(res: H3DRes): PAnsiChar;

function h3dGetNextResource(type_: H3DResTypes; start: H3DRes): H3DRes;

function h3dFindResource(type_: H3DResTypes; name: PAnsiChar): H3DRes;

function h3dAddResource(type_: H3DResTypes; name: PAnsiChar;

  flags: Integer): H3DRes;

function h3dCloneResource(sourceRes: H3DRes; name: PAnsiChar): H3DRes;

function h3dRemoveResource(res: H3DRes): Integer;

function h3dIsResLoaded(res: H3DRes): Boolean;

function h3dLoadResource(res: H3DRes; data: PAnsiChar; size: Integer): Boolean;

procedure h3dUnloadResource(res: H3DRes);

function h3dGetResElemCount(res: H3DRes; elem: H3DResourceParams): Integer;

function h3dFindResElem(res: H3DRes; elem, param: H3DResourceParams;

  value: PAnsiChar): Integer;

function h3dGetResParamI(res: H3DRes; elem: H3DResourceParams; elemIdx: Integer;

  param: H3DResourceParams): Integer;

procedure h3dSetResParamI(res: H3DRes; elem: H3DResourceParams;

  elemIdx: Integer; param: H3DResourceParams; value: Integer);

function h3dGetResParamF(res: H3DRes; elem: H3DResourceParams; elemIdx: Integer;

  param: H3DResourceParams; compIdx: Integer): Single;

procedure h3dSetResParamF(res: H3DRes; elem: H3DResourceParams;

  elemIdx: Integer; param: H3DResourceParams; compIdx: Integer; value: Single);


function h3dGetResParamStr(res: H3DRes; elem: H3DResourceParams;

  elemIdx: Integer; param: H3DResourceParams): PAnsiChar;

procedure h3dSetResParamStr(res: H3DRes; elem: H3DResourceParams;

  elemIdx: Integer; param: H3DResourceParams; value: PAnsiChar);

function h3dMapResStream(res: H3DRes; elem: H3DResourceParams; elemIdx: Integer;

  stream: H3DResourceParams; read, write: Boolean): Pointer;

procedure h3dUnmapResStream(res: H3DRes);

function h3dQueryUnloadedResource(index: Integer): H3DRes;

procedure h3dReleaseUnusedResources;

function h3dCreateTexture(name: PAnsiChar; width, height: Integer;

  fmt: H3DFormats; flags: Integer): H3DRes;

procedure h3dSetShaderPreambles(vertPreamble, fragPreamble: PAnsiChar);

function h3dSetMaterialUniform(materialRes: H3DRes; name: PAnsiChar;

  a, b, c, d: Single): Boolean;

function h3dGetPipelineRenderTargetData(pipelineRes: H3DRes;

  targetName: PAnsiChar; bufIndex: Integer; width, height, compCount: PInteger;

  dataBuffer: PSingle; bufferSize: Integer): Boolean;

function h3dGetNodeType(node: H3DNode): H3DNodeTypes;

function h3dGetNodeParent(node: H3DNode): H3DNode;

function h3dSetNodeParent(node, parent: H3DNode): Boolean;

function h3dGetNodeChild(node: H3DNode; index: Integer): H3DNode;

function h3dAddNodes(parent: H3DNode; sceneGraphRes: H3DRes): H3DNode;

procedure h3dRemoveNode(node: H3DNode);

procedure h3dSetNodeActivation(node: H3DNode; active: Boolean);

function h3dCheckNodeTransFlag(node: H3DNode; reset: Boolean): Boolean;

procedure h3dGetNodeTransform(node: H3DNode;

  tx, ty, tz, rx, ry, rz, sx, sy, sz: PSingle);

procedure h3dSetNodeTransform(node: H3DNode;

  tx, ty, tz, rx, ry, rz, sx, sy, sz: Single);

procedure h3dGetNodeTransMats(node: H3DNode; relMat, absMat: PPSingle);

procedure h3dSetNodeTransMat(node: H3DNode; mat4x5: PSingle);

function h3dGetNodeParamI(node: H3DNode; param: H3DNodeParams): Integer;

procedure h3dSetNodeParamI(node: H3DNode; param: H3DNodeParams; value: Integer);

function h3dGetNodeParamF(node: H3DNode; param: H3DNodeParams;

  compIdx: Integer): Single;

procedure h3dSetNodeParamF(node: H3DNode; param: H3DNodeParams;

  compIdx: Integer; value: Single);

function h3dGetNodeParamStr(node: H3DNode; param: H3DNodeParams): PAnsiChar;

procedure h3dSetNodeParamStr(node: H3DNode; param: H3DNodeParams;

  value: PAnsiChar);

procedure h3dGetNodeAABB(node: H3DNode;

  minX, minY, minZ, maxX, maxY, maxZ: PSingle);

function h3dFindNodes(startNode: H3DNode; name: PAnsiChar;

  type_: H3DNodeTypes): Integer;

function h3dGetNodeFindResult(index: Integer): H3DNode;

function h3dCastRay(node: H3DNode; ox, oy, oz, dx, dy, dz: Single;

  numNearest: Integer): Integer;

function h3dGetCastRayResult(index: Integer; node: PH3DNode;

  distance, intersection: PSingle): Boolean;

function h3dCheckNodeVisibility(node, cameraNode: H3DNode;

  checkOcclusion, calcLod: Boolean): Integer;

function h3dAddGroupNode(parent: H3DNode; name: PAnsiChar): H3DNode;

function h3dAddModelNode(parent: H3DNode; name: PAnsiChar;

  geometryRes: H3DRes): H3DNode;

procedure h3dSetupModelAnimStage(modelNode: H3DNode; stage: Integer;

  animationRes: H3DRes; layer: Integer; startNode: PAnsiChar;

  additive: Boolean);

procedure h3dSetModelAnimParams(modelNode: H3DNode; stage: Integer;

  time, weight: Single);

function h3dSetModelMorpher(modelNode: H3DNode; target: PAnsiChar;

  weight: Single): Boolean;

function h3dAddMeshNode(parent: H3DNode; name: PAnsiChar; materialRes: H3DRes;

  batchStart, batchCount, vertRStart, vertREnd: Integer): H3DNode;


function h3dAddJointNode(parent: H3DNode; name: PAnsiChar;

  jointIndex: Integer): H3DNode;

function h3dAddLightNode(parent: H3DNode; name: PAnsiChar; materialRes: H3DRes;

  lightingContext, shadowContext: PAnsiChar): H3DNode;

function h3dAddCameraNode(parent: H3DNode; name: PAnsiChar;

  pipelineRes: H3DRes): H3DNode;

procedure h3dSetupCameraView(cameraNode: H3DNode;

  fov, aspect, nearDist, farDist: Single);

procedure h3dGetCameraProjMat(cameraNode: H3DNode; projMat: PSingle);

function h3dAddEmitterNode(parent: H3DNode; name: PAnsiChar;

  materialRes, particleEffectRes: H3DRes;

  maxParticleCount, respawnCount: Integer): H3DNode;

procedure h3dAdvanceEmitterTime(emitterNode: H3DNode; timeDelta: Single);

function h3dHasEmitterFinished(emitterNode: H3DNode): Boolean; *)


procedure TLibHorde3D.InitializeLibrary;
begin
  RegisterNativeCallFunction(
    'h3dgetversionstring',
    @LibHorde3D_GetVersionString,
    [],
    htString,
    ncRegister
  );

  RegisterNativeCallFunction(
    'h3dcheckextension',
    @LibHorde3D_CheckExtension,
    [htString],
    htNone,
    ncRegister
  );

  RegisterNativeCallFunction(
    'h3dgeterror',
    @LibHorde3D_GetError,
    [],
    htBoolean,
    ncRegister
  );

  RegisterNativeCallFunction(
    'h3dinit',
    @LibHorde3D_Init,
    [],
    htBoolean,
    ncRegister
  );

  RegisterNativeCallFunction(
    'h3drelease',
    @LibHorde3D_Release,
    [],
    htNone,
    ncRegister
  );

  RegisterNativeCallFunction(
    'h3dsetupviewport',
    @LibHorde3D_SetupViewport,
    [htLongInt, htLongInt, htLongInt, htLongInt, htBoolean],
    htNone,
    ncRegister
  );
end;

class function TLibHorde3D.GetName: String;
begin
  Result := 'horde3d';
end;

end.
