|
- unit uvkuTypes;
-
- {$mode objfpc}{$H+}
-
- interface
-
- uses
- Classes, SysUtils,
- Vulkan, uvkuUtils;
-
- type
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuStructure = class
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuCommandHelper = class
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- generic TvkuListBase<T> = class(TObject)
- private type
- TPointerType = ^T;
- TArrayType = array of T;
- private
- fItems: TArrayType;
- function GetData: TPointerType;
- function GetItem(const aIndex: Integer): T;
- function GetLength: Integer;
- procedure SetLength(aValue: Integer);
- protected
- procedure InitItem(var aItem: T); virtual;
- procedure FreeItem(var aItem: T); virtual;
- public
- property Length: Integer read GetLength write SetLength;
- property Count: Integer read GetLength write SetLength;
- property Size: Integer read GetLength write SetLength;
- property PData: TPointerType read GetData;
- property Data: TArrayType read fItems;
- property Items[const aIndex: Integer]: T read GetItem; default;
-
- constructor Create;
- destructor Destroy; override;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- generic TvkuList<T> = class(specialize TvkuListBase<T>)
- private
- procedure SetItem(const aIndex: Integer; aValue: T);
- public
- property Items[const aIndex: Integer]: T read GetItem write SetItem; default;
- property Data: TArrayType read fItems write fItems;
-
- procedure SetData(const aData: TPointerType; const aCount: Integer);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- generic TvkuObjList<T> = class(specialize TvkuListBase<T>)
- protected
- procedure InitItem(var aItem: T); override;
- procedure FreeItem(var aItem: T); override;
- end;
-
- PVkCharArr = array of PVkChar;
- TVkPhysicalDeviceArr = array of VkPhysicalDevice;
- TVkQueueFamilyPropertiesArr = array of TVkQueueFamilyProperties;
- TVkSparseImageFormatPropertiesArr = array of TVkSparseImageFormatProperties;
- TVkSurfaceFormatArr = array of TVkSurfaceFormatKHR;
- TVkPresentModeArr = array of TVkPresentModeKHR;
- TVkDisplayPropertiesArr = array of TVkDisplayPropertiesKHR;
- TVkDisplayPlanePropertiesArr = array of TVkDisplayPlanePropertiesKHR;
- TVkDisplayArr = array of VkDisplayKHR;
- TVkDisplayModePropertiesArr = array of TVkDisplayModePropertiesKHR;
- TVkImageArr = array of VkImage;
- TVkCommandBufferArr = array of VkCommandBuffer;
- TVkDescriptorSetLayoutBindingArr = array of TVkDescriptorSetLayoutBinding;
- TVkDescriptorSetLayoutArr = array of VkDescriptorSetLayout;
- TVkPushConstantRangeArr = array of TVkPushConstantRange;
- TVkPipelineShaderStageCreateInfoArr = array of TVkPipelineShaderStageCreateInfo;
- TVkPipelineVertexInputStateCreateInfoArr = array of TVkPipelineVertexInputStateCreateInfo;
- TVkAttachmentDescriptionArr = array of TVkAttachmentDescription;
- TVkSubpassDescriptionArr = array of TVkSubpassDescription;
- TVkSubpassDependencyArr = array of TVkSubpassDependency;
- TVkAttachmentReferenceArr = array of TVkAttachmentReference;
- TVkMemoryBarrierArr = array of TVkMemoryBarrier;
- TVkBufferMemoryBarrierArr = array of TVkBufferMemoryBarrier;
- TVkImageMemoryBarrierArr = array of TVkImageMemoryBarrier;
- TVkViewportArr = array of TVkViewport;
- TVkRect2DArr = array of TVkRect2D;
- TVkSampleMaskArr = array of VkSampleMask;
- TVkVertexInputBindingDescriptionArr = array of TVkVertexInputBindingDescription;
- TVkVertexInputAttributeDescriptionArr = array of TVkVertexInputAttributeDescription;
- TVkPipelineColorBlendAttachmentStateArr = array of TVkPipelineColorBlendAttachmentState;
- TVkDynamicStateArr = array of TVkDynamicState;
- TVkDescriptorPoolSizeArr = array of TVkDescriptorPoolSize;
- TVkDescriptorSetArr = array of VkDescriptorSet;
- TVkDescriptorImageInfoArr = array of TVkDescriptorImageInfo;
- TVkDescriptorBufferInfoArr = array of TVkDescriptorBufferInfo;
- TVkClearValueArr = array of TVkClearValue;
- TVkResultArr = array of TVkResult;
-
- TVkUint32List = specialize TvkuList<VkUint32>;
- TVkFloatList = specialize TvkuList<VkFloat>;
- TVkImageViewList = specialize TvkuList<VkImageView>;
- TVkSamplerList = specialize TvkuList<VkSampler>;
- TVkDescriptorSetLayoutList = specialize TvkuList<VkDescriptorSetLayout>;
- TVkSampleMaskList = specialize TvkuList<VkSampleMask>;
- TVkDynamicStateList = specialize TvkuList<TVkDynamicState>;
- TVkBufferViewList = specialize TvkuList<VkBufferView>;
- TVkClearValueList = specialize TvkuList<TVkClearValue>;
-
- implementation
-
- uses
- typinfo;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuCreateInfoArr//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuListBase.GetItem(const aIndex: Integer): T;
- begin
- if (aIndex < low(fItems)) or (aIndex > high(fItems)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fItems), High(fItems)]);
- result := fItems[aIndex];
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuListBase.GetData: TPointerType;
- begin
- result := @fItems[0];
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuListBase.GetLength: Integer;
- begin
- result := System.Length(fItems);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuListBase.SetLength(aValue: Integer);
- var i: Integer;
- begin
- if (aValue < 0) then
- aValue := 0;
- i := System.Length(fItems);
- while (i > aValue) do begin
- FreeItem(fItems[i-1]);
- dec(i);
- end;
- i := System.Length(fItems) + 1;
- System.SetLength(fItems, aValue);
- while (i <= aValue) do begin
- InitItem(fItems[i-1]);
- inc(i);
- end;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuListBase.InitItem(var aItem: T);
- begin
- FillByte(aItem, SizeOf(aItem), 0);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuListBase.FreeItem(var aItem: T);
- begin
- // DUMMY
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuListBase.Create;
- begin
- inherited Create;
- System.SetLength(fItems, 0);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- destructor TvkuListBase.Destroy;
- begin
- SetLength(0);
- inherited Destroy;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuList///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuList.SetItem(const aIndex: Integer; aValue: T);
- begin
- if (aIndex < low(fItems)) or (aIndex > high(fItems)) then
- raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fItems), High(fItems)]);
- fItems[aIndex] := aValue;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuList.SetData(const aData: TPointerType; const aCount: Integer);
- var i: Integer;
- begin
- if Assigned(aData) then begin
- SetLength(aCount);
- for i := low(fItems) to high(fItems) do
- fItems[i] := (aData + i)^;
- end else
- SetLength(0);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuObjList////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuObjList.InitItem(var aItem: T);
- begin
- inherited InitItem(aItem);
- aItem := T.Create;
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuObjList.FreeItem(var aItem: T);
- begin
- FreeAndNil(aItem);
- inherited FreeItem(aItem);
- end;
-
-
- end.
|