unit uvkuDescriptorPoolFactory; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Vulkan, uvkuFactoryBase, uvkuDescriptorPool, uvkuTypes; type ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuDescriptorPoolSize = class(TvkuStructure) DescriptorType: TVkDescriptorType; DescriptorCount: VkUint32; function GetStructure: TVkDescriptorPoolSize; procedure SetStructure(const aData: TVkDescriptorPoolSize); end; TvkuDescriptorPoolSizeList = specialize TvkuObjList; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TvkuDescriptorPoolFactory = class(TvkuDeviceObjFactory) private fPoolSizes: TvkuDescriptorPoolSizeList; fvkPoolSizes: TVkDescriptorPoolSizeArr; public Flags: VkDescriptorPoolCreateFlags; MaxSets: VkUint32; property PoolSizes: TvkuDescriptorPoolSizeList read fPoolSizes; function GetStructure: TVkDescriptorPoolCreateInfo; procedure SetStructure(const aData: TVkDescriptorPoolCreateInfo); function CreateDescriptorPool: TvkuDescriptorPool; procedure AfterConstruction; override; procedure BeforeDestruction; override; end; implementation ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuDescriptorPoolSize///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TvkuDescriptorPoolSize.GetStructure: TVkDescriptorPoolSize; begin FillByte(result, SizeOf(result), 0); result.dType := DescriptorType; result.descriptorCount := DescriptorCount; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuDescriptorPoolSize.SetStructure(const aData: TVkDescriptorPoolSize); begin DescriptorType := aData.dType; DescriptorCount := aData.descriptorCount; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TvkuDescriptorPoolFactory////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TvkuDescriptorPoolFactory.GetStructure: TVkDescriptorPoolCreateInfo; var i: Integer; begin SetLength(fvkPoolSizes, fPoolSizes.Length); for i := low(fvkPoolSizes) to high(fvkPoolSizes) do fvkPoolSizes[i] := fPoolSizes[i].GetStructure; FillByte(result, SizeOf(result), 0); result.sType := VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; result.pNext := nil; result.flags := Flags; result.maxSets := MaxSets; result.poolSizeCount := Length(fvkPoolSizes); result.pPoolSizes := @fvkPoolSizes[0]; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuDescriptorPoolFactory.SetStructure(const aData: TVkDescriptorPoolCreateInfo); var i: Integer; begin if Assigned(aData.pPoolSizes) then begin fPoolSizes.Length := aData.poolSizeCount; for i := 0 to fPoolSizes.Length-1 do fPoolSizes[i].SetStructure((aData.pPoolSizes + i)^); end; Flags := aData.flags; MaxSets := aData.maxSets; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TvkuDescriptorPoolFactory.CreateDescriptorPool: TvkuDescriptorPool; begin result := TvkuDescriptorPool.Create(GetStructure, DeviceCommands, AllocCallbacks); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuDescriptorPoolFactory.AfterConstruction; begin inherited AfterConstruction; fPoolSizes := TvkuDescriptorPoolSizeList.Create; end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TvkuDescriptorPoolFactory.BeforeDestruction; begin FreeAndNil(fPoolSizes); inherited BeforeDestruction; end; end.