|
- unit uvkuFactoryBase;
-
- {$mode objfpc}{$H+}
-
- interface
-
- uses
- Classes, SysUtils,
- Vulkan, uvkuInstance, uvkuDevice, uvkuAllocationHandler, uvkuTypes;
-
- type
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuFactory = class(TvkuStructure)
- private
- fAllocHandler: TvkuAllocationHandler;
- fOwnsAllocCallbacks: Boolean;
- fAllocCallbacks: PVkAllocationCallbacks;
-
- procedure FreeAllocCallbacks;
-
- procedure SetAllocCallbacks(aValue: PVkAllocationCallbacks);
- procedure SetAllocHandler(aValue: TvkuAllocationHandler);
- public
- property AllocHandler: TvkuAllocationHandler read fAllocHandler write SetAllocHandler;
- property AllocCallbacks: PVkAllocationCallbacks read fAllocCallbacks write SetAllocCallbacks;
-
- destructor Destroy; override;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuInstanceObjFactory = class(TvkuFactory)
- private
- fInstanceCommands: TVkInstanceCommands;
- public
- property InstanceCommands: TVkInstanceCommands read fInstanceCommands;
-
- constructor Create(const aInstance: TvkuInstance);
- constructor Create(const aInstanceCommands: TVkInstanceCommands);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuDeviceObjFactory = class(TvkuFactory)
- private
- fDeviceCommands: TVkDeviceCommands;
- public
- property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
-
- constructor Create(const aDevice: TvkuDevice);
- constructor Create(const aDeviceCommands: TVkDeviceCommands);
- end;
-
- implementation
-
- uses
- uvkuUtils;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuFactory////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuFactory.FreeAllocCallbacks;
- begin
- if Assigned(fAllocCallbacks) and fOwnsAllocCallbacks then
- Dispose(fAllocCallbacks);
- fAllocCallbacks := nil;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuFactory.SetAllocCallbacks(aValue: PVkAllocationCallbacks);
- begin
- fAllocHandler := nil;
- FreeAllocCallbacks;
- fAllocCallbacks := aValue;
- fOwnsAllocCallbacks := false;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuFactory.SetAllocHandler(aValue: TvkuAllocationHandler);
- begin
- FreeAllocCallbacks;
- fAllocHandler := aValue;
- if Assigned(fAllocHandler) then begin
- new(fAllocCallbacks);
- fOwnsAllocCallbacks := true;
- fAllocCallbacks^ := fAllocHandler.GetStructure;
- end;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- destructor TvkuFactory.Destroy;
- begin
- FreeAllocCallbacks;
- inherited Destroy;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuInstanceObjFactory/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuInstanceObjFactory.Create(const aInstance: TvkuInstance);
- begin
- Create(aInstance.InstanceCommands);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuInstanceObjFactory.Create(const aInstanceCommands: TVkInstanceCommands);
- begin
- inherited Create;
- fInstanceCommands := aInstanceCommands;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuDeviceObjFactory///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuDeviceObjFactory.Create(const aDevice: TvkuDevice);
- begin
- Create(aDevice.DeviceCommands);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuDeviceObjFactory.Create(const aDeviceCommands: TVkDeviceCommands);
- begin
- inherited Create;
- fDeviceCommands := aDeviceCommands;
- end;
-
- end.
|