Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

225 wiersze
10 KiB

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