|
- { ============================================================================
- This file is autogenerated from vk.xml
- You may retrieve the latest version of this file at the Delphi OpenGL
- Community home page, located at http://www.delphigl.com/
-
- The contents of this file are used with permission, subject to
- the Mozilla Public License Version 1.1 (the "License"); you may
- not use this file except in compliance with the License. You may
- obtain a copy of the License at
- http://www.mozilla.org/MPL/MPL-1.1.html
-
- Software distributed under the License is distributed on an
- "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- implied. See the License for the specific language governing
- rights and limitations under the License.
-
- Original vk.xml comment:
- ==============================================================================
- {%COMMENT%}
- ============================================================================ }
-
- unit Vulkan;
-
- {$IFDEF FPC}
- {$MODE Delphi}
- {$IFNDEF WINDOWS}
- {$LINKLIB c}
- {$ENDIF}
- {$MINENUMSIZE 4}
- {$PACKSET 4}
- {$ENDIF}
-
- {$I Vulkan.inc}
-
- interface
-
- type
- VkUint8 = Byte;
- VkUint16 = Word;
- VkUint32 = Cardinal;
- VkUint64 = QWord;
- VkInt16 = SmallInt;
- VkInt32 = Integer;
- VkInt64 = Int64;
- VkFloat = Single;
- VkDouble = Double;
- VkChar = AnsiChar;
- VkSize = SizeUInt;
- VkHandle = Pointer;
- VkNonDispatchableHandle = {$IFDEF VK_CPU64}Pointer{$ELSE}VkUint64{$ENDIF};
-
- const
- VK_INVALID_HANDLE: VkHandle = nil;
- VK_INVALID_NDP_HANDLE: VkNonDispatchableHandle = {$IFDEF VK_CPU64}nil{$ELSE}0{$ENDIF};
-
- type
- {$IFDEF VK_USE_PLATFORM_WIN32_KHR}
- HINSTANCE = VkHandle;
- HWND = VkHandle;
- {$ENDIF}
-
- PVkVoid = Pointer;
- PVkHandle = ^VkHandle;
- PVkUint8 = ^VkUint8;
- PVkUint16 = ^VkUint16;
- PVkUint32 = ^VkUint32;
- PVkUint64 = ^VkUint64;
- PVkInt16 = ^VkInt16;
- PVkInt32 = ^VkInt32;
- PVkInt64 = ^VkInt64;
- PVkFloat = ^VkFloat;
- PVkDouble = ^VkDouble;
- PVkChar = ^VkChar;
- PVkSize = ^VkSize;
-
- PPVkVoid = ^PVkVoid;
- PPVkHandle = ^PVkHandle;
- PPVkUint8 = ^PVkUint8;
- PPVkUint16 = ^PVkUint16;
- PPVkUint32 = ^PVkUint32;
- PPVkUint64 = ^PVkUint64;
- PPVkInt16 = ^PVkInt16;
- PPVkInt32 = ^PVkInt32;
- PPVkInt64 = ^PVkInt64;
- PPVkFloat = ^PVkFloat;
- PPVkDouble = ^PVkDouble;
- PPVkChar = ^PVkChar;
- PPVkSize = ^PVkSize;
-
- {%INTERFACE%}
-
- type
- TVkInstanceCommands = class
- Instance: VkInstance;
- {%INSTANCE_COMMANDS.INTERFACE%}
- end;
-
- TVkDeviceCommands = class
- Device: VkDevice;
- {%DEVICE_COMMANDS.INTERFACE%}
- end;
-
- const
- VULKAN_LIBNAME = 'vulkan-1.dll';
-
- type
- VkVersion = VkInt32;
-
- function vkMakeVersion(const aMajor, aMinor, aPatch: Integer): VkVersion; inline;
- function vkGetVersionMajor(const aVersion: VkVersion): Integer; inline;
- function vkGetVersionMinor(const aVersion: VkVersion): Integer; inline;
- function vkGetVersionPatch(const aVersion: VkVersion): Integer; inline;
-
- function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
- function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;
- function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
- procedure FinalizeVulkan;
-
- implementation
-
- uses
- SysUtils;
-
- type
- {$IF DEFINED(VK_WIN)}
- TvkLibHandle = TLibHandle;
- {$ELSE}
- TvkLibHandle = Pointer;
- {$ENDIF}
-
- const
- {$IF DEFINED(VK_WIN)}
- InvalidLibHandle = 0;
- {$ELSE}
- InvalidLibHandle = nil;
- {$ENDIF}
-
- var
- vkLibHandle: TvkLibHandle = InvalidLibHandle;
-
- { ===================================== Library Handling ============================================= }
- function vkLoadLibrary(const aLibName: String): TvkLibHandle;
- begin
- {$IF DEFINED(VK_WIN)}
- result := LoadLibrary(aLibName);
- {$ELSE}
- result := InvalidLibHandle;
- {$ENDIF}
- end;
-
- function vkGetProcAddress(const aProcName: String; aLibHandle: TvkLibHandle = InvalidLibHandle): TvkVoidFunction;
- begin
- result := nil;
- if (aLibHandle = InvalidLibHandle) then
- aLibHandle := vkLibHandle;
- {$IF DEFINED(VK_WIN)}
- result := TvkVoidFunction(GetProcAddress(aLibHandle, AnsiString(aProcName)));
- {$ELSE}
- result := nil;
- {$ENDIF}
- end;
-
- procedure vkFreeLibrary(var aLibHandle: TvkLibHandle);
- begin
- if (aLibHandle <> InvalidLibHandle) then begin
- {$IF DEFINED(VK_WIN)}
- FreeLibrary(aLibHandle);
- {$ENDIF}
- aLibHandle := InvalidLibHandle;
- end;
- end;
-
- { ===================================== Vulkan Version Helpers ======================================= }
- function vkMakeVersion(const aMajor, aMinor, aPatch: Integer): VkVersion;
- begin
- result := (aMajor shl 22) or (aMinor shl 12) or aPatch;
- end;
-
- function vkGetVersionMajor(const aVersion: VkVersion): Integer;
- begin
- result := (aVersion shr 22);
- end;
-
- function vkGetVersionMinor(const aVersion: VkVersion): Integer;
- begin
- result := (aVersion shr 12) and $3FF;
- end;
-
- function vkGetVersionPatch(const aVersion: VkVersion): Integer;
- begin
- result := (aVersion and $FFF);
- end;
-
- { ===================================== Initialize Routines ========================================== }
- function InitializeVulkan(const aLibName: String = VULKAN_LIBNAME): Boolean;
- var success: Boolean;
-
- function GetProcAddress(const aName: String): TvkVoidFunction;
- begin
- result := vkGetProcAddress(aName);
- if not Assigned(result) then
- success := false;
- end;
-
- begin
- FinalizeVulkan;
- vkLibHandle := vkLoadLibrary(aLibName);
- success := (vkLibHandle <> InvalidLibHandle);
- if not success then
- exit;
-
- {%IMPLEMENTATION%}
-
- result := success;
- end;
-
- function LoadInstanceCommands(const aInstance: VkInstance): TVkInstanceCommands;
-
- function GetProcAddress(const aName: String): TvkVoidFunction;
- begin
- result := vkGetInstanceProcAddr(aInstance, PVkChar(aName));
- end;
-
- begin
- result := TVkInstanceCommands.Create;
- try
- result.Instance := aInstance;
- with result do begin
- {%INSTANCE_COMMANDS.IMPLEMENTATION%}
- end;
- except
- FreeAndNil(result);
- raise;
- end;
- end;
-
- function LoadDeviceCommands(const aInstance: VkInstance; const aDevice: VkDevice): TVkDeviceCommands;
- var
- vkGetDeviceProcAddr: TvkGetDeviceProcAddr;
-
- function GetProcAddress(const aName: String): TvkVoidFunction;
- begin
- result := vkGetDeviceProcAddr(aDevice, PVkChar(aName));
- end;
-
- begin
- vkGetDeviceProcAddr := TvkGetDeviceProcAddr(vkGetInstanceProcAddr(aInstance, 'vkGetDeviceProcAddr'));
- result := TVkDeviceCommands.Create;
- try
- result.Device := aDevice;
- with result do begin
- {%DEVICE_COMMANDS.IMPLEMENTATION%}
- end;
- except
- FreeAndNil(result);
- raise;
- end;
- end;
-
- procedure FinalizeVulkan;
- begin
- vkFreeLibrary(vkLibHandle);
- end;
-
- initialization
-
- finalization
- FinalizeVulkan;
-
- end.
|