
(*--------------------------------QuadTree-----------------------------------*)
function QuadtreeCreate(lt, mtd, gg: real): real; stdcall;
 var
   SpacePartition  : TQuadtreeSpacePartition;
 begin
   //SpacePartition := TQuadtreeSpacePartition.Create(SceneNode);
   //TGLScene(SceneNode).Objects.AddChild(SpacePartition);
   SpacePartition.LeafThreshold := Trunc(lt);
   SpacePartition.MaxTreeDepth := Trunc(mtd);
   SpacePartition.GrowGravy := gg;
   Result := Integer(SpacePartition);
 end; 

function QuadtreeAddLeaf(q: real): real; stdcall;
 begin
   //TQuadtreeSpacePartition(Trunc(q)).AddLeaf();
   Result := 1;
 end;


 
(*-----------------------------CollisionManager-------------------------------*)
function CollisionManagerCreate: real; stdcall;
 var
   Manager  : TCollisionManager;
 begin
   Manager := TCollisionManager.Create(SceneNode);
   Result := 1;
 end;

function CollisionManagerCheckCollisions(m, obj1, obj2: real): real; stdcall;
 begin
   //TCollisionManager(Trunc(m)).OnCollision(TGLBaseSceneObject(Trunc(obj1)); TGLBaseSceneObject(Trunc(obj2)));
   //TCollisionManager(Trunc(m)).CheckCollisions;
   Result := 1;
 end;



(*----------------------------------Shader------------------------------------*)
function ShaderCreate(vs, fh: PChar): real; stdcall;
 var
   SH : TGLSLShader;
   Shader: TGLCustomGLSLShader;
 begin
   SH := TGLSLShader.Create(SceneNode);
   SH.VertexProgram.LoadFromFile(vs);
   SH.FragmentProgram.LoadFromFile(fh);
   SH.Enabled := true;

   Shader := TGLCustomGLSLShader.Create(SceneNode);
   Shader.Param['vec_light'].AsVector4f := VectorMake(1, 1, 1, 1);
   Shader.Param['ambient_color'].AsVector4f := VectorMake(0.2, 0.2, 0.2, 1);
   Shader.Param['ambient_intensity'].AsVector1f := 1;

   Result := Integer(SH);
 end;

function ShaderAddMaterial(shader: real; mat: PChar): real; stdcall;
 var
   SH : TGLSLShader;
 begin
   SH := TGLSLShader(Trunc(shader));
   SceneMaterialLibrary.LibMaterialByName(mat).Shader := SH;
   Result := 1;
 end; 

function ShaderSetEnable(shader, mode: real): real; stdcall;
 begin
   TGLSLShader(Trunc(shader)).Enabled := Boolean(Trunc(mode));
   Result := 1;
 end;

function ShaderSetStyle(shader, style: real): real; stdcall;
 begin
   if (style = 1) then TGLSLShader(Trunc(shader)).ShaderStyle := ssHighLevel;
   if (style = 2) then TGLSLShader(Trunc(shader)).ShaderStyle := ssLowLevel;
   if (style = 3) then TGLSLShader(Trunc(shader)).ShaderStyle := ssReplace;
   Result := 1;
 end;



(*--------------------------------FBO Render----------------------------------*)
function FBORenderCreate(parent: real): real; stdcall;
 var
   Fbo : TGLFBORenderer;
 begin
   Fbo := TGLFBORenderer.Create(SceneNode);
    if not (parent = 0) then Fbo.Parent := TGLBaseSceneObject(Trunc(parent));
   TGLScene(SceneNode).Objects.AddChild(Fbo);
   Fbo.SceneScaleFactor := 0;
   Fbo.ForceTextureDimensions := true;
   Fbo.EnabledRenderBuffers := [erbDepth];
   Result := Integer(Fbo);
 end;

function FBORenderSetSize(fbo, w, h: real): real; stdcall;
  var
   F : TGLFBORenderer;
 begin
   F := TGLFBORenderer(Trunc(fbo));
   F.Width := Trunc(w);
   F.Height := Trunc(h);
   Result := 1;
 end;

function FBORenderSetCamera(fbo, cam: real): real; stdcall;
 begin
   TGLFBORenderer(Trunc(fbo)).Camera := TGLCamera(Trunc(cam));
   Result := 1;
 end;

function FBORenderSetColorTexture(fbo: real; mat: PChar): real; stdcall;
 begin
   TGLFBORenderer(Trunc(fbo)).ColorTextureName := mat;
   Result := 1;
 end;

function FBORenderSetDepthTexture(fbo: real; mat: PChar): real; stdcall;
 begin
   TGLFBORenderer(Trunc(fbo)).DepthTextureName := mat;
   Result := 1;
 end;

function FBORenderSetMaterialLibrary(fbo, matlib: real): real; stdcall;
 begin
   TGLFBORenderer(Trunc(fbo)).MaterialLibrary := TGLMaterialLibrary(Trunc(matlib));
   Result := 1;
 end;

function FBORenderSetRootObject(fbo, obj: real): real; stdcall;
 begin
   TGLFBORenderer(Trunc(fbo)).RootObject := TGLBaseSceneObject(Trunc(obj));
   Result := 1;
 end;

function FBORenderSetAspect(fbo, aspect: real): real; stdcall;
 begin
   TGLFBORenderer(Trunc(fbo)).Aspect := aspect;
   Result := 1;
 end;



(*-------------------------------Shadow Volume--------------------------------*)
function ShadowvolumeCreate(parent: real): real; stdcall;
 var
   FShadowVolume: TGLShadowVolume;
 begin
   FShadowVolume := TGLShadowVolume.Create(SceneNode);
   TGLScene(SceneNode).Objects.AddChild(FShadowVolume);
    if not (parent = 0) then FShadowVolume.Parent := TGLBaseSceneObject(Trunc(parent));
   FShadowVolume.Mode := svmDarkening;
   //FShadowVolume.FlushSilhouetteCache;
   Result := Integer(FShadowVolume);
 end;

function ShadowvolumeSetActive(sv, mode: real): real; stdcall;
 begin
   TGLShadowVolume(Trunc(sv)).Active := boolean(Trunc(mode));
   Result := 1;
 end;

function ShadowvolumeAddLight(sv, light: real): real; stdcall;
 begin
   TGLShadowVolume(Trunc(sv)).Lights.AddCaster(TGLLightSource(Trunc(light)));
   Result := 1;
 end;

function ShadowvolumeAddOccluders(sv, obj: real): real; stdcall;
 begin
   TGLShadowVolume(Trunc(sv)).Occluders.AddCaster(TGLBaseSceneObject(Trunc(obj)));
   Result := 1;
 end;

