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.

131 regels
5.3 KiB

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