Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TFL3dCobject.Init:Boolean;
- var
- I : Integer;
- J : Integer;
- K : Integer;
- M : Integer;
- N : Integer;
- Num : UINT;
- Mat : UINT;
- Vms : PVms;
- Idx : array of UINT;
- begin
- for I := 0 to High(F3dbs) do
- with F3dbs[I] do
- for J := 0 to High(Levels) do
- with Levels[J] do
- begin
- Vms := Lib.Data;
- if (Ref.MeshCount > 0) and
- (Ref.IndexStart < Vms.Data.IndexCount) and
- (Ref.VertexStart < Vms.Data.VertexCount) and
- (UINT(Ref.MeshStart) + UINT(Ref.MeshCount) <= UINT(Vms.Data.MeshesCount)) then
- begin
- Num := 0;
- if Length(Idx) < Ref.MeshCount then SetLength(Idx, Ref.MeshCount);
- for M := 0 to Ref.MeshCount-1 do
- with Vms.Meshes[Ref.MeshStart + M] do
- begin
- Idx[M] := Ref.IndexStart + Num;
- Inc(Num,VNum);
- end;
- if Num > 0 then
- begin
- N := 0;
- Num := 0;
- SetLength(_3d, Ref.MeshCount);
- for K := 0 to High(Vms.Mats) do
- begin
- Mat := Vms.Mats[K];
- for M := 0 to Ref.MeshCount-1 do
- if Mat = Vms.Meshes[Ref.MeshStart + M].MaterialID then
- begin
- for N := M to Ref.MeshCount-1 do
- with Vms.Meshes[Ref.MeshStart + N] do
- if Mat = MaterialID then
- begin
- _3d[Num].IStart := Idx[N] + Vms.Buffer.IB;
- _3d[Num].ICount := VNum;
- _3d[Num].VStart := Ref.VertexStart + VStart + Vms.Buffer.VB;
- _3d[Num].VCount := VEnd - VStart;
- _3d[Num].Material := MaterialID;
- Inc(Num);
- end;
- Break;
- end;
- end;
- end;
- end;
- end;
- Result := True;
- end;
- //Shader expects that matrices buffer is bound at slot #7.
- //Precalculated matrices of all instances (typical static geometry) gives +25% boost VS updating matrices each frame.
- procedure TFL3dCobject.DrawInstanced(const Context:ID3D11DeviceContext;const Count,Start:UINT;const Level:Byte=0);
- var
- DC : ID3D11DeviceContext;
- P : Integer;
- C : TD3DXColor;
- Cnt : UINT;
- Clr : Single;
- Add : Single;
- M : Integer;
- MatID : UINT;
- Buff : ID3DX11Buffer;
- // Z: Integer;
- begin
- if not Eval or (Count = 0) then Exit;
- if Context = nil then
- FL.Device.GetImmediateContext(DC) else
- DC := Context;
- DC.IASetInputLayout(FL.Layout);
- DC.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- MatID := 0;
- for P := 0 to High(FParts) do
- with FParts[P] do
- if Model >= 0 then
- with F3dbs[Model] do
- if UINT(Level) < UINT(Length(Levels)) then
- with Levels[Level], Lib.Data^, Buffer do
- if Value <> nil then
- begin
- if Buff <> Value then
- begin
- Buff := Value;
- if Failed(Buff.Pipeline(nil,Map)) then
- Exit;
- end;
- FL.Effect.GetVariableByName('Model').AsMatrix.SetMatrix(@Mat);
- for M := 0 to High(_3d) do
- with _3d[M] do
- begin
- if MatID <> Material then
- begin
- MatID := Material;
- Clr := Clr + Add;
- C := D3DXColorToUINT(MIHSV2RGB(DWORD(Round(Clr) shl 16) or $0000FFFF));
- FL.Effect.GetVariableByName('Dc').AsVector.SetFloatVector(@C);
- //This should called as less as possible. It kills performance.
- FL.Effect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply(0,DC);
- end;
- //6000 meshes: fps ~2000-2700
- //for Z := 0 to 100 do //6000 meshes x100 (~600000 calls) fps ~43
- DC.DrawIndexedInstanced(ICount, Count, IStart, VStart, Start);
- end;
- end;
- end;
Add Comment
Please, Sign In to add comment