|
- unit uvkuDescriptorSetLayoutFactory;
-
- {$mode objfpc}{$H+}
-
- interface
-
- uses
- Classes, SysUtils,
- Vulkan, uvkuFactoryBase, uvkuDescriptorSetLayout, uvkuAllocationHandler, uvkuTypes;
-
- type
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuDescriptorSetLayoutEx = class(TvkuDescriptorSetLayout)
- private
- fAllocHandler: TvkuAllocationHandler;
- fOwnsHandler: Boolean;
- public
- destructor Destroy; override;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuDescriptorSetLayoutFactory = class(TvkuDeviceObjFactory)
- private
- fFlags: VkDescriptorSetLayoutCreateFlags;
- fBindings: TvkuDescriptorSetLayoutBindingArr;
- function GetBinding(const aIndex: Integer): TVkDescriptorSetLayoutBinding;
- function GetBindingCount: Integer;
- procedure SetBinding(const aIndex: Integer; aValue: TVkDescriptorSetLayoutBinding);
- procedure SetBindingCount(aValue: Integer);
- public
- property Flags: VkDescriptorSetLayoutCreateFlags read fFlags write fFlags;
-
- property Bindings: TvkuDescriptorSetLayoutBindingArr read fBindings write fBindings;
- property BindingCount: Integer read GetBindingCount write SetBindingCount;
- property Binding[const aIndex: Integer]: TVkDescriptorSetLayoutBinding read GetBinding write SetBinding;
-
- function CreateDescriptorSetLayout: TvkuDescriptorSetLayoutEx;
- function CreateDescriptorSetLayout(
- const aAllocHandler: TvkuAllocationHandler;
- const aOwnsHandler: Boolean): TvkuDescriptorSetLayoutEx;
- end;
-
- implementation
-
- uses
- uvkuUtils;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuDescriptorSetLayoutEx//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- destructor TvkuDescriptorSetLayoutEx.Destroy;
- begin
- inherited Destroy;
- if fOwnsHandler then
- FreeAndNil(fAllocHandler);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuDescriptorSetLayoutFactory/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuDescriptorSetLayoutFactory.GetBinding(const aIndex: Integer): TVkDescriptorSetLayoutBinding;
- begin
- if (aIndex < low(fBindings)) or (aIndex > high(fBindings)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fBindings), High(fBindings)]);
- result := fBindings[aIndex];
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuDescriptorSetLayoutFactory.GetBindingCount: Integer;
- begin
- result := Length(fBindings);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuDescriptorSetLayoutFactory.SetBinding(const aIndex: Integer; aValue: TVkDescriptorSetLayoutBinding);
- begin
- if (aIndex < low(fBindings)) or (aIndex > high(fBindings)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fBindings), High(fBindings)]);
- fBindings[aIndex] := aValue;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuDescriptorSetLayoutFactory.SetBindingCount(aValue: Integer);
- begin
- SetLength(fBindings, aValue);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuDescriptorSetLayoutFactory.CreateDescriptorSetLayout: TvkuDescriptorSetLayoutEx;
- begin
- result := CreateDescriptorSetLayout(nil, false);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuDescriptorSetLayoutFactory.CreateDescriptorSetLayout(const aAllocHandler: TvkuAllocationHandler;
- const aOwnsHandler: Boolean): TvkuDescriptorSetLayoutEx;
- var
- CreateInfo: TVkDescriptorSetLayoutCreateInfo;
- begin
- FillByte(CreateInfo, SizeOf(CreateInfo), 0);
- CreateInfo.sType := VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
- CreateInfo.pNext := nil;
- CreateInfo.flags := fFlags;
- CreateInfo.bindingCount := Length(fBindings);
- CreateInfo.pBindings := @fBindings[0];
- if Assigned(aAllocHandler)
- then result := TvkuDescriptorSetLayoutEx.Create(CreateInfo, DeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
- else result := TvkuDescriptorSetLayoutEx.Create(CreateInfo, DeviceCommands);
- try
- TvkuDescriptorSetLayoutEx(result).fAllocHandler := aAllocHandler;
- TvkuDescriptorSetLayoutEx(result).fOwnsHandler := aOwnsHandler;
- except
- FreeAndNil(result);
- raise;
- end;
- end;
-
- end.
|