Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

197 строки
8.4 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. TVkUint32List = specialize TvkuList<VkUint32>;
  69. TVkFloatList = specialize TvkuList<VkFloat>;
  70. TVkImageViewList = specialize TvkuList<VkImageView>;
  71. TVkSamplerList = specialize TvkuList<VkSampler>;
  72. TVkDescriptorSetLayoutList = specialize TvkuList<VkDescriptorSetLayout>;
  73. implementation
  74. uses
  75. typinfo;
  76. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  77. //TvkuCreateInfoArr//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  79. function TvkuListBase.GetItem(const aIndex: Integer): T;
  80. begin
  81. if (aIndex < low(fItems)) or (aIndex > high(fItems)) then
  82. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fItems), High(fItems)]);
  83. result := fItems[aIndex];
  84. end;
  85. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  86. function TvkuListBase.GetData: TPointerType;
  87. begin
  88. result := @fItems[0];
  89. end;
  90. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  91. function TvkuListBase.GetLength: Integer;
  92. begin
  93. result := System.Length(fItems);
  94. end;
  95. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  96. procedure TvkuListBase.SetLength(aValue: Integer);
  97. var i: Integer;
  98. begin
  99. if (aValue < 0) then
  100. aValue := 0;
  101. i := System.Length(fItems);
  102. while (i > aValue) do begin
  103. FreeItem(fItems[i-1]);
  104. dec(i);
  105. end;
  106. i := System.Length(fItems) + 1;
  107. System.SetLength(fItems, aValue);
  108. while (i <= aValue) do begin
  109. InitItem(fItems[i-1]);
  110. inc(i);
  111. end;
  112. end;
  113. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  114. procedure TvkuListBase.InitItem(var aItem: T);
  115. begin
  116. FillByte(aItem, SizeOf(aItem), 0);
  117. end;
  118. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  119. procedure TvkuListBase.FreeItem(var aItem: T);
  120. begin
  121. // DUMMY
  122. end;
  123. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  124. constructor TvkuListBase.Create;
  125. begin
  126. inherited Create;
  127. System.SetLength(fItems, 0);
  128. end;
  129. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  130. destructor TvkuListBase.Destroy;
  131. begin
  132. SetLength(0);
  133. inherited Destroy;
  134. end;
  135. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  136. //TvkuList///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  137. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  138. procedure TvkuList.SetItem(const aIndex: Integer; aValue: T);
  139. begin
  140. if (aIndex < low(fItems)) or (aIndex > high(fItems)) then
  141. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fItems), High(fItems)]);
  142. fItems[aIndex] := aValue;
  143. end;
  144. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  145. procedure TvkuList.SetData(const aData: TPointerType; const aCount: Integer);
  146. var i: Integer;
  147. begin
  148. if Assigned(aData) then begin
  149. SetLength(aCount);
  150. for i := low(fItems) to high(fItems) do
  151. fItems[i] := (aData + i)^;
  152. end else
  153. SetLength(0);
  154. end;
  155. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  156. //TvkuObjList////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  157. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  158. procedure TvkuObjList.InitItem(var aItem: T);
  159. begin
  160. inherited InitItem(aItem);
  161. aItem := T.Create;
  162. end;
  163. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  164. procedure TvkuObjList.FreeItem(var aItem: T);
  165. begin
  166. FreeAndNil(aItem);
  167. inherited FreeItem(aItem);
  168. end;
  169. end.