Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

270 Zeilen
6.8 KiB

  1. { ============================================================================
  2. This file is autogenerated from vk.xml
  3. You may retrieve the latest version of this file at the Delphi OpenGL
  4. Community home page, located at http://www.delphigl.com/
  5. The contents of this file are used with permission, subject to
  6. the Mozilla Public License Version 1.1 (the "License"); you may
  7. not use this file except in compliance with the License. You may
  8. obtain a copy of the License at
  9. http://www.mozilla.org/MPL/MPL-1.1.html
  10. Software distributed under the License is distributed on an
  11. "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  12. implied. See the License for the specific language governing
  13. rights and limitations under the License.
  14. Original vk.xml comment:
  15. ==============================================================================
  16. {%COMMENT%}
  17. ============================================================================ }
  18. unit Vulkan;
  19. {$IFDEF FPC}
  20. {$MODE Delphi}
  21. {$IFNDEF WINDOWS}
  22. {$LINKLIB c}
  23. {$ENDIF}
  24. {$MINENUMSIZE 4}
  25. {$ENDIF}
  26. {$I Vulkan.inc}
  27. interface
  28. type
  29. VkUint8 = Byte;
  30. VkUint16 = Word;
  31. VkUint32 = Cardinal;
  32. VkUint64 = QWord;
  33. VkInt16 = SmallInt;
  34. VkInt32 = Integer;
  35. VkInt64 = Int64;
  36. VkFloat = Single;
  37. VkDouble = Double;
  38. VkChar = AnsiChar;
  39. VkSize = SizeUInt;
  40. VkHandle = Pointer;
  41. VkNonDispatchableHandle = {$IFDEF VK_CPU64}Pointer{$ELSE}VkUint64{$ENDIF};
  42. const
  43. VK_INVALID_HANDLE: VkHandle = nil;
  44. VK_INVALID_NDP_HANDLE: VkNonDispatchableHandle = {$IFDEF VK_CPU64}nil{$ELSE}0{$ENDIF};
  45. type
  46. {$IFDEF VK_USE_PLATFORM_WIN32_KHR}
  47. HINSTANCE = VkHandle;
  48. HWND = VkHandle;
  49. {$ENDIF}
  50. PVkVoid = Pointer;
  51. PVkHandle = ^VkHandle;
  52. PVkUint8 = ^VkUint8;
  53. PVkUint16 = ^VkUint16;
  54. PVkUint32 = ^VkUint32;
  55. PVkUint64 = ^VkUint64;
  56. PVkInt16 = ^VkInt16;
  57. PVkInt32 = ^VkInt32;
  58. PVkInt64 = ^VkInt64;
  59. PVkFloat = ^VkFloat;
  60. PVkDouble = ^VkDouble;
  61. PVkChar = ^VkChar;
  62. PVkSize = ^VkSize;
  63. PPVkVoid = ^PVkVoid;
  64. PPVkHandle = ^PVkHandle;
  65. PPVkUint8 = ^PVkUint8;
  66. PPVkUint16 = ^PVkUint16;
  67. PPVkUint32 = ^PVkUint32;
  68. PPVkUint64 = ^PVkUint64;
  69. PPVkInt16 = ^PVkInt16;
  70. PPVkInt32 = ^PVkInt32;
  71. PPVkInt64 = ^PVkInt64;
  72. PPVkFloat = ^PVkFloat;
  73. PPVkDouble = ^PVkDouble;
  74. PPVkChar = ^PVkChar;
  75. PPVkSize = ^PVkSize;
  76. {%INTERFACE%}
  77. type
  78. TVkInstanceCommands = class
  79. Instance: VkInstance;
  80. {%INSTANCE_COMMANDS.INTERFACE%}
  81. end;
  82. TVkDeviceCommands = class
  83. Device: VkDevice;
  84. {%DEVICE_COMMANDS.INTERFACE%}
  85. end;
  86. const
  87. VULKAN_LIBNAME = 'vulkan-1.dll';
  88. type
  89. VkVersion = VkInt32;
  90. function vkMakeVersion(const aMajor, aMinor, aPatch: Integer): VkVersion; inline;
  91. function vkGetVersionMajor(const aVersion: VkVersion): Integer; inline;
  92. function vkGetVersionMinor(const aVersion: VkVersion): Integer; inline;
  93. function vkGetVersionPatch(const aVersion: VkVersion): Integer; inline;
  94. function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
  95. function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;
  96. function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
  97. procedure FinalizeVulkan;
  98. implementation
  99. uses
  100. SysUtils;
  101. type
  102. {$IF DEFINED(VK_WIN)}
  103. TvkLibHandle = TLibHandle;
  104. {$ELSE}
  105. TvkLibHandle = Pointer;
  106. {$ENDIF}
  107. const
  108. {$IF DEFINED(VK_WIN)}
  109. InvalidLibHandle = 0;
  110. {$ELSE}
  111. InvalidLibHandle = nil;
  112. {$ENDIF}
  113. var
  114. vkLibHandle: TvkLibHandle = InvalidLibHandle;
  115. { ===================================== Library Handling ============================================= }
  116. function vkLoadLibrary(const aLibName: String): TvkLibHandle;
  117. begin
  118. {$IF DEFINED(VK_WIN)}
  119. result := LoadLibrary(aLibName);
  120. {$ELSE}
  121. result := InvalidLibHandle;
  122. {$ENDIF}
  123. end;
  124. function vkGetProcAddress(const aProcName: String; aLibHandle: TvkLibHandle = InvalidLibHandle): TvkVoidFunction;
  125. begin
  126. result := nil;
  127. if (aLibHandle = InvalidLibHandle) then
  128. aLibHandle := vkLibHandle;
  129. {$IF DEFINED(VK_WIN)}
  130. result := TvkVoidFunction(GetProcAddress(aLibHandle, AnsiString(aProcName)));
  131. {$ELSE}
  132. result := nil;
  133. {$ENDIF}
  134. end;
  135. procedure vkFreeLibrary(var aLibHandle: TvkLibHandle);
  136. begin
  137. if (aLibHandle <> InvalidLibHandle) then begin
  138. {$IF DEFINED(VK_WIN)}
  139. FreeLibrary(aLibHandle);
  140. {$ENDIF}
  141. aLibHandle := InvalidLibHandle;
  142. end;
  143. end;
  144. { ===================================== Vulkan Version Helpers ======================================= }
  145. function vkMakeVersion(const aMajor, aMinor, aPatch: Integer): VkVersion;
  146. begin
  147. result := (aMajor shl 22) or (aMinor shl 12) or aPatch;
  148. end;
  149. function vkGetVersionMajor(const aVersion: VkVersion): Integer;
  150. begin
  151. result := (aVersion shr 22);
  152. end;
  153. function vkGetVersionMinor(const aVersion: VkVersion): Integer;
  154. begin
  155. result := (aVersion shr 12) and $3FF;
  156. end;
  157. function vkGetVersionPatch(const aVersion: VkVersion): Integer;
  158. begin
  159. result := (aVersion and $FFF);
  160. end;
  161. { ===================================== Initialize Routines ========================================== }
  162. function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
  163. var success: Boolean;
  164. function GetProcAddress(const aName: String): TvkVoidFunction;
  165. begin
  166. result := vkGetProcAddress(aName);
  167. if not Assigned(result) then
  168. success := false;
  169. end;
  170. begin
  171. FinalizeVulkan;
  172. vkLibHandle := vkLoadLibrary(aLibName);
  173. success := (vkLibHandle <> InvalidLibHandle);
  174. if not success then
  175. exit;
  176. {%IMPLEMENTATION%}
  177. result := success;
  178. end;
  179. function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;
  180. function GetProcAddress(const aName: String): TvkVoidFunction;
  181. begin
  182. result := vkGetInstanceProcAddr(aInstance, PVkChar(aName));
  183. end;
  184. begin
  185. result := TVkInstanceCommands.Create;
  186. try
  187. result.Instance := aInstance;
  188. with result do begin
  189. {%INSTANCE_COMMANDS.IMPLEMENTATION%}
  190. end;
  191. except
  192. FreeAndNil(result);
  193. raise;
  194. end;
  195. end;
  196. function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
  197. var
  198. vkGetDeviceProcAddr: TvkGetDeviceProcAddr;
  199. function GetProcAddress(const aName: String): TvkVoidFunction;
  200. begin
  201. result := vkGetDeviceProcAddr(aDevice, PVkChar(aName));
  202. end;
  203. begin
  204. vkGetDeviceProcAddr := TvkGetDeviceProcAddr(vkGetInstanceProcAddr(aInstance, 'vkGetDeviceProcAddr'));
  205. result := TVkDeviceCommands.Create;
  206. try
  207. result.Device := aDevice;
  208. with result do begin
  209. {%DEVICE_COMMANDS.IMPLEMENTATION%}
  210. end;
  211. except
  212. FreeAndNil(result);
  213. raise;
  214. end;
  215. end;
  216. procedure FinalizeVulkan;
  217. begin
  218. vkFreeLibrary(vkLibHandle);
  219. end;
  220. initialization
  221. finalization
  222. FinalizeVulkan;
  223. end.