You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
5.1 KiB

  1. unit uvkuFactoryBase;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuInstance, uvkuDevice, uvkuAllocationHandler, uvkuTypes;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuFactory = class(TvkuStructure)
  10. private
  11. fAllocHandler: TvkuAllocationHandler;
  12. fOwnsAllocCallbacks: Boolean;
  13. fAllocCallbacks: PVkAllocationCallbacks;
  14. procedure FreeAllocCallbacks;
  15. procedure SetAllocCallbacks(aValue: PVkAllocationCallbacks);
  16. procedure SetAllocHandler(aValue: TvkuAllocationHandler);
  17. public
  18. property AllocHandler: TvkuAllocationHandler read fAllocHandler write SetAllocHandler;
  19. property AllocCallbacks: PVkAllocationCallbacks read fAllocCallbacks write SetAllocCallbacks;
  20. destructor Destroy; override;
  21. end;
  22. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  23. TvkuInstanceObjFactory = class(TvkuFactory)
  24. private
  25. fInstanceCommands: TVkInstanceCommands;
  26. public
  27. property InstanceCommands: TVkInstanceCommands read fInstanceCommands;
  28. constructor Create(const aInstance: TvkuInstance);
  29. constructor Create(const aInstanceCommands: TVkInstanceCommands);
  30. end;
  31. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  32. TvkuDeviceObjFactory = class(TvkuFactory)
  33. private
  34. fDeviceCommands: TVkDeviceCommands;
  35. public
  36. property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
  37. constructor Create(const aDevice: TvkuDevice);
  38. constructor Create(const aDeviceCommands: TVkDeviceCommands);
  39. end;
  40. implementation
  41. uses
  42. uvkuUtils;
  43. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  44. //TvkuFactory////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  45. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  46. procedure TvkuFactory.FreeAllocCallbacks;
  47. begin
  48. if Assigned(fAllocCallbacks) and fOwnsAllocCallbacks then
  49. Dispose(fAllocCallbacks);
  50. fAllocCallbacks := nil;
  51. end;
  52. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  53. procedure TvkuFactory.SetAllocCallbacks(aValue: PVkAllocationCallbacks);
  54. begin
  55. fAllocHandler := nil;
  56. FreeAllocCallbacks;
  57. fAllocCallbacks := aValue;
  58. fOwnsAllocCallbacks := false;
  59. end;
  60. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  61. procedure TvkuFactory.SetAllocHandler(aValue: TvkuAllocationHandler);
  62. begin
  63. FreeAllocCallbacks;
  64. fAllocHandler := aValue;
  65. if Assigned(fAllocHandler) then begin
  66. new(fAllocCallbacks);
  67. fOwnsAllocCallbacks := true;
  68. fAllocCallbacks^ := fAllocHandler.GetStructure;
  69. end;
  70. end;
  71. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  72. destructor TvkuFactory.Destroy;
  73. begin
  74. FreeAllocCallbacks;
  75. inherited Destroy;
  76. end;
  77. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. //TvkuInstanceObjFactory/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  79. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80. constructor TvkuInstanceObjFactory.Create(const aInstance: TvkuInstance);
  81. begin
  82. Create(aInstance.InstanceCommands);
  83. end;
  84. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  85. constructor TvkuInstanceObjFactory.Create(const aInstanceCommands: TVkInstanceCommands);
  86. begin
  87. inherited Create;
  88. fInstanceCommands := aInstanceCommands;
  89. end;
  90. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  91. //TvkuDeviceObjFactory///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  93. constructor TvkuDeviceObjFactory.Create(const aDevice: TvkuDevice);
  94. begin
  95. Create(aDevice.DeviceCommands);
  96. end;
  97. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  98. constructor TvkuDeviceObjFactory.Create(const aDeviceCommands: TVkDeviceCommands);
  99. begin
  100. inherited Create;
  101. fDeviceCommands := aDeviceCommands;
  102. end;
  103. end.