No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

83 líneas
3.1 KiB

  1. unit uvkuBuffer;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuBase;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuBuffer = class(TvkuAllocHandle)
  10. private
  11. fHandle: VkBuffer;
  12. fDeviceCommands: TVkDeviceCommands;
  13. procedure CreateHandle(const aCreateInfo: TVkBufferCreateInfo);
  14. public
  15. property Handle: VkBuffer read fHandle;
  16. property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
  17. constructor Create(
  18. const aCreateInfo: TVkBufferCreateInfo;
  19. const aDeviceCommands: TVkDeviceCommands;
  20. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  21. constructor Create(
  22. const aHandle: VkBuffer;
  23. const aOwnsHandle: Boolean;
  24. const aDeviceCommands: TVkDeviceCommands;
  25. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  26. destructor Destroy; override;
  27. end;
  28. implementation
  29. uses
  30. uvkuUtils;
  31. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  32. //TvkuBuffer/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. procedure TvkuBuffer.CreateHandle(const aCreateInfo: TVkBufferCreateInfo);
  35. var err: TVkResult;
  36. begin
  37. err := fDeviceCommands.vkCreateBuffer(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
  38. if (err < VK_SUCCESS) then
  39. raise TvkuErrorException.Create('unable to create buffer', err);
  40. end;
  41. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. constructor TvkuBuffer.Create(const aCreateInfo: TVkBufferCreateInfo; const aDeviceCommands: TVkDeviceCommands;
  43. const aAllocCallbacks: PVkAllocationCallbacks);
  44. begin
  45. inherited Create;
  46. fDeviceCommands := aDeviceCommands;
  47. SetAllocCallbacks(aAllocCallbacks);
  48. CreateHandle(aCreateInfo);
  49. end;
  50. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. constructor TvkuBuffer.Create(const aHandle: VkBuffer; const aOwnsHandle: Boolean;
  52. const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
  53. begin
  54. inherited Create;
  55. fHandle := aHandle;
  56. fDeviceCommands := aDeviceCommands;
  57. OwnsHandle := aOwnsHandle;
  58. SetAllocCallbacks(aAllocCallbacks);
  59. end;
  60. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  61. destructor TvkuBuffer.Destroy;
  62. begin
  63. if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
  64. fDeviceCommands.vkDestroyBuffer(fDeviceCommands.Device, fHandle, AllocCallbacks);
  65. fHandle := VK_INVALID_NDP_HANDLE;
  66. inherited Destroy;
  67. end;
  68. end.