|
- unit uvkuRenderPassFactory;
-
- {$mode objfpc}{$H+}
-
- interface
-
- uses
- Classes, SysUtils,
- Vulkan, uvkuFactoryBase, uvkuRenderPass, uvkuAllocationHandler, uvkuTypes;
-
- type
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuRenderPassEx = class(TvkuRenderPass)
- private
- fAllocHandler: TvkuAllocationHandler;
- fOwnsHandler: Boolean;
- public
- destructor Destroy; override;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuRenderPassFactory = class(TvkuDeviceObjFactory)
- private
- fFlags: VkRenderPassCreateFlags;
- fAttachments: TvkuAttachmentDescriptionArr;
- fSubpasses: TvkuSubpassDescriptionArr;
- fDependencies: TvkuSubpassDependencyArr;
-
- function GetAttachment(const aIndex: Integer): TVkAttachmentDescription;
- function GetAttachmentCount: Integer;
- function GetDependency(const aIndex: Integer): TVkSubpassDependency;
- function GetDependencyCount: Integer;
- function GetSubpass(const aIndex: Integer): TVkSubpassDescription;
- function GetSubpassCount: Integer;
-
- procedure SetAttachment(const aIndex: Integer; aValue: TVkAttachmentDescription);
- procedure SetAttachmentCount(aValue: Integer);
- procedure SetDependency(const aIndex: Integer; aValue: TVkSubpassDependency);
- procedure SetDependencyCount(aValue: Integer);
- procedure SetSubpass(const aIndex: Integer; aValue: TVkSubpassDescription);
- procedure SetSubpassCount(aValue: Integer);
- public
- property Flags: VkRenderPassCreateFlags read fFlags write fFlags;
-
- property Attachments: TvkuAttachmentDescriptionArr read fAttachments write fAttachments;
- property AttachmentCount: Integer read GetAttachmentCount write SetAttachmentCount;
- property Attachment[const aIndex: Integer]: TVkAttachmentDescription read GetAttachment write SetAttachment;
-
- property Subpasses: TvkuSubpassDescriptionArr read fSubpasses write fSubpasses;
- property SubpassCount: Integer read GetSubpassCount write SetSubpassCount;
- property Subpass[const aIndex: Integer]: TVkSubpassDescription read GetSubpass write SetSubpass;
-
- property Dependencies: TvkuSubpassDependencyArr read fDependencies write fDependencies;
- property DependencyCount: Integer read GetDependencyCount write SetDependencyCount;
- property Dependency[const aIndex: Integer]: TVkSubpassDependency read GetDependency write SetDependency;
-
- function CreateRenderPass: TvkuRenderPassEx;
- function CreateRenderPass(
- const aAllocHandler: TvkuAllocationHandler;
- const aOwnsHandler: Boolean): TvkuRenderPassEx;
- end;
-
- implementation
-
- uses
- uvkuUtils;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuRenderPassEx///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- destructor TvkuRenderPassEx.Destroy;
- begin
- inherited Destroy;
- if fOwnsHandler then
- FreeAndNil(fAllocHandler);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuRenderPassFactory//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuRenderPassFactory.GetAttachment(const aIndex: Integer): TVkAttachmentDescription;
- begin
- if (aIndex < low(fAttachments)) or (aIndex > high(fAttachments)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fAttachments), High(fAttachments)]);
- result := fAttachments[aIndex];
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuRenderPassFactory.GetAttachmentCount: Integer;
- begin
- result := Length(fAttachments);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuRenderPassFactory.GetDependency(const aIndex: Integer): TVkSubpassDependency;
- begin
- if (aIndex < low(fDependencies)) or (aIndex > high(fDependencies)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fDependencies), High(fDependencies)]);
- result := fDependencies[aIndex];
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuRenderPassFactory.GetDependencyCount: Integer;
- begin
- result := Length(fDependencies);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuRenderPassFactory.GetSubpass(const aIndex: Integer): TVkSubpassDescription;
- begin
- if (aIndex < low(fSubpasses)) or (aIndex > high(fSubpasses)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fSubpasses), High(fSubpasses)]);
- result := fSubpasses[aIndex];
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuRenderPassFactory.GetSubpassCount: Integer;
- begin
- result := Length(fSubpasses);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuRenderPassFactory.SetAttachment(const aIndex: Integer; aValue: TVkAttachmentDescription);
- begin
- if (aIndex < low(fAttachments)) or (aIndex > high(fAttachments)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fAttachments), High(fAttachments)]);
- fAttachments[aIndex] := aValue;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuRenderPassFactory.SetAttachmentCount(aValue: Integer);
- begin
- SetLength(fAttachments, aValue);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuRenderPassFactory.SetDependency(const aIndex: Integer; aValue: TVkSubpassDependency);
- begin
- if (aIndex < low(fDependencies)) or (aIndex > high(fDependencies)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fDependencies), High(fDependencies)]);
- fDependencies[aIndex] := aValue;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuRenderPassFactory.SetDependencyCount(aValue: Integer);
- begin
- SetLength(fDependencies, aValue);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuRenderPassFactory.SetSubpass(const aIndex: Integer; aValue: TVkSubpassDescription);
- begin
- if (aIndex < low(fSubpasses)) or (aIndex > high(fSubpasses)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fSubpasses), High(fSubpasses)]);
- fSubpasses[aIndex] := aValue;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuRenderPassFactory.SetSubpassCount(aValue: Integer);
- begin
- SetLength(fSubpasses, aValue);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuRenderPassFactory.CreateRenderPass: TvkuRenderPassEx;
- begin
- result := CreateRenderPass(nil, false);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuRenderPassFactory.CreateRenderPass(const aAllocHandler: TvkuAllocationHandler;
- const aOwnsHandler: Boolean): TvkuRenderPassEx;
- var
- CreateInfo: TVkRenderPassCreateInfo;
- begin
- FillByte(CreateInfo, SizeOf(CreateInfo), 0);
- CreateInfo.sType := VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
- CreateInfo.pNext := nil;
- CreateInfo.flags := fFlags;
- CreateInfo.attachmentCount := Length(fAttachments);
- CreateInfo.pAttachments := @fAttachments[0];
- CreateInfo.subpassCount := Length(fSubpasses);
- CreateInfo.pSubpasses := @fSubpasses[0];
- CreateInfo.dependencyCount := Length(fDependencies);
- CreateInfo.pDependencies := @fDependencies[0];
- if Assigned(aAllocHandler)
- then result := TvkuRenderPassEx.Create(CreateInfo, DeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
- else result := TvkuRenderPassEx.Create(CreateInfo, DeviceCommands);
- try
- TvkuRenderPassEx(result).fAllocHandler := aAllocHandler;
- TvkuRenderPassEx(result).fOwnsHandler := aOwnsHandler;
- except
- FreeAndNil(result);
- raise;
- end;
- end;
-
-
- end.
|