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.

200 lines
8.7 KiB

  1. unit uvkuTypes;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuUtils;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. generic TvkuListBase<T> = class(TObject)
  10. private type
  11. TPointerType = ^T;
  12. TArrayType = array of T;
  13. private
  14. fItems: TArrayType;
  15. function GetData: TPointerType;
  16. function GetItem(const aIndex: Integer): T;
  17. function GetLength: Integer;
  18. procedure SetLength(aValue: Integer);
  19. protected
  20. procedure InitItem(var aItem: T); virtual;
  21. procedure FreeItem(var aItem: T); virtual;
  22. public
  23. property Length: Integer read GetLength write SetLength;
  24. property Count: Integer read GetLength write SetLength;
  25. property Size: Integer read GetLength write SetLength;
  26. property PData: TPointerType read GetData;
  27. property Data: TArrayType read fItems;
  28. property Items[const aIndex: Integer]: T read GetItem; default;
  29. constructor Create;
  30. destructor Destroy; override;
  31. end;
  32. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. generic TvkuList<T> = class(specialize TvkuListBase<T>)
  34. private
  35. procedure SetItem(const aIndex: Integer; aValue: T);
  36. public
  37. property Items[const aIndex: Integer]: T read GetItem write SetItem; default;
  38. property Data: TArrayType read fItems write fItems;
  39. procedure SetData(const aData: TPointerType; const aCount: Integer);
  40. end;
  41. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. generic TvkuObjList<T> = class(specialize TvkuListBase<T>)
  43. protected
  44. procedure InitItem(var aItem: T); override;
  45. procedure FreeItem(var aItem: T); override;
  46. end;
  47. PVkCharArr = array of PVkChar;
  48. TVkPhysicalDeviceArr = array of VkPhysicalDevice;
  49. TVkQueueFamilyPropertiesArr = array of TVkQueueFamilyProperties;
  50. TVkSparseImageFormatPropertiesArr = array of TVkSparseImageFormatProperties;
  51. TVkSurfaceFormatArr = array of TVkSurfaceFormatKHR;
  52. TVkPresentModeArr = array of TVkPresentModeKHR;
  53. TVkDisplayPropertiesArr = array of TVkDisplayPropertiesKHR;
  54. TVkDisplayPlanePropertiesArr = array of TVkDisplayPlanePropertiesKHR;
  55. TVkDisplayArr = array of VkDisplayKHR;
  56. TVkDisplayModePropertiesArr = array of TVkDisplayModePropertiesKHR;
  57. TVkImageArr = array of VkImage;
  58. TVkCommandBufferArr = array of VkCommandBuffer;
  59. TVkDescriptorSetLayoutBindingArr = array of TVkDescriptorSetLayoutBinding;
  60. TVkDescriptorSetLayoutArr = array of VkDescriptorSetLayout;
  61. TVkPushConstantRangeArr = array of TVkPushConstantRange;
  62. TVkPipelineShaderStageCreateInfoArr = array of TVkPipelineShaderStageCreateInfo;
  63. TVkPipelineVertexInputStateCreateInfoArr = array of TVkPipelineVertexInputStateCreateInfo;
  64. TVkAttachmentDescriptionArr = array of TVkAttachmentDescription;
  65. TVkSubpassDescriptionArr = array of TVkSubpassDescription;
  66. TVkSubpassDependencyArr = array of TVkSubpassDependency;
  67. TVkAttachmentReferenceArr = array of TVkAttachmentReference;
  68. TVkMemoryBarrierArr = array of TVkMemoryBarrier;
  69. TVkBufferMemoryBarrierArr = array of TVkBufferMemoryBarrier;
  70. TVkImageMemoryBarrierArr = array of TVkImageMemoryBarrier;
  71. TVkUint32List = specialize TvkuList<VkUint32>;
  72. TVkFloatList = specialize TvkuList<VkFloat>;
  73. TVkImageViewList = specialize TvkuList<VkImageView>;
  74. TVkSamplerList = specialize TvkuList<VkSampler>;
  75. TVkDescriptorSetLayoutList = specialize TvkuList<VkDescriptorSetLayout>;
  76. implementation
  77. uses
  78. typinfo;
  79. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80. //TvkuCreateInfoArr//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  82. function TvkuListBase.GetItem(const aIndex: Integer): T;
  83. begin
  84. if (aIndex < low(fItems)) or (aIndex > high(fItems)) then
  85. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fItems), High(fItems)]);
  86. result := fItems[aIndex];
  87. end;
  88. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  89. function TvkuListBase.GetData: TPointerType;
  90. begin
  91. result := @fItems[0];
  92. end;
  93. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  94. function TvkuListBase.GetLength: Integer;
  95. begin
  96. result := System.Length(fItems);
  97. end;
  98. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  99. procedure TvkuListBase.SetLength(aValue: Integer);
  100. var i: Integer;
  101. begin
  102. if (aValue < 0) then
  103. aValue := 0;
  104. i := System.Length(fItems);
  105. while (i > aValue) do begin
  106. FreeItem(fItems[i-1]);
  107. dec(i);
  108. end;
  109. i := System.Length(fItems) + 1;
  110. System.SetLength(fItems, aValue);
  111. while (i <= aValue) do begin
  112. InitItem(fItems[i-1]);
  113. inc(i);
  114. end;
  115. end;
  116. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  117. procedure TvkuListBase.InitItem(var aItem: T);
  118. begin
  119. FillByte(aItem, SizeOf(aItem), 0);
  120. end;
  121. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  122. procedure TvkuListBase.FreeItem(var aItem: T);
  123. begin
  124. // DUMMY
  125. end;
  126. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  127. constructor TvkuListBase.Create;
  128. begin
  129. inherited Create;
  130. System.SetLength(fItems, 0);
  131. end;
  132. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  133. destructor TvkuListBase.Destroy;
  134. begin
  135. SetLength(0);
  136. inherited Destroy;
  137. end;
  138. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  139. //TvkuList///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  140. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  141. procedure TvkuList.SetItem(const aIndex: Integer; aValue: T);
  142. begin
  143. if (aIndex < low(fItems)) or (aIndex > high(fItems)) then
  144. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fItems), High(fItems)]);
  145. fItems[aIndex] := aValue;
  146. end;
  147. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  148. procedure TvkuList.SetData(const aData: TPointerType; const aCount: Integer);
  149. var i: Integer;
  150. begin
  151. if Assigned(aData) then begin
  152. SetLength(aCount);
  153. for i := low(fItems) to high(fItems) do
  154. fItems[i] := (aData + i)^;
  155. end else
  156. SetLength(0);
  157. end;
  158. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  159. //TvkuObjList////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  160. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  161. procedure TvkuObjList.InitItem(var aItem: T);
  162. begin
  163. inherited InitItem(aItem);
  164. aItem := T.Create;
  165. end;
  166. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  167. procedure TvkuObjList.FreeItem(var aItem: T);
  168. begin
  169. FreeAndNil(aItem);
  170. inherited FreeItem(aItem);
  171. end;
  172. end.