comparison src/vulkan_api/vulkan_api_generator.nim @ 94:f036546f5ea2

add: device, surface and refactoring
author Sam <sam@basx.dev>
date Tue, 28 Feb 2023 23:51:07 +0700
parents e872cf354110
children 110ed3ee5df8
comparison
equal deleted inserted replaced
93:cb773e81032f 94:f036546f5ea2
248 result = {cApiName}(uint64(result) or uint64(flag))""" 248 result = {cApiName}(uint64(result) or uint64(flag))"""
249 result[0].add &"""func toEnums*(number: {cApiName}): seq[{name}] = 249 result[0].add &"""func toEnums*(number: {cApiName}): seq[{name}] =
250 for value in {name}.items: 250 for value in {name}.items:
251 if (cast[uint64](value) and uint64(number)) > 0: 251 if (cast[uint64](value) and uint64(number)) > 0:
252 result.add value""" 252 result.add value"""
253 result[0].add &"proc `==`*(a, b: {cApiName}): bool = uint64(a) == uint64(b)"
253 else: 254 else:
254 if values.len > 0: 255 if values.len > 0:
255 result[0].add &"""func toBits*(flags: openArray[{name}]): {cApiName} = 256 result[0].add &"""func toBits*(flags: openArray[{name}]): {cApiName} =
256 for flag in flags: 257 for flag in flags:
257 result = {cApiName}(uint(result) or uint(flag))""" 258 result = {cApiName}(uint(result) or uint(flag))"""
258 result[0].add &"""func toEnums*(number: {cApiName}): seq[{name}] = 259 result[0].add &"""func toEnums*(number: {cApiName}): seq[{name}] =
259 for value in {name}.items: 260 for value in {name}.items:
260 if (value.ord and cint(number)) > 0: 261 if (value.ord and cint(number)) > 0:
261 result.add value""" 262 result.add value"""
263 result[0].add &"proc `==`*(a, b: {cApiName}): bool = cint(a) == cint(b)"
262 if predefined_enum_sets.len > 0: 264 if predefined_enum_sets.len > 0:
263 result[0].add "const" 265 result[0].add "const"
264 result[0].add predefined_enum_sets 266 result[0].add predefined_enum_sets
265 result[0].add "type" 267 result[0].add "type"
266 268
419 "import std/strutils", 421 "import std/strutils",
420 "import std/logging", 422 "import std/logging",
421 "import std/typetraits", 423 "import std/typetraits",
422 "import std/macros", 424 "import std/macros",
423 "import std/private/digitsutils", 425 "import std/private/digitsutils",
424 "from typetraits import HoleyEnum",
425 "type", 426 "type",
426 " VkHandle* = distinct uint", 427 " VkHandle* = distinct uint",
427 " VkNonDispatchableHandle* = distinct uint", 428 " VkNonDispatchableHandle* = distinct uint",
428 "when defined(linux):", 429 "when defined(linux):",
429 " let vulkanLib* = loadLib(\"libvulkan.so.1\")", 430 " let vulkanLib* = loadLib(\"libvulkan.so.1\")",
517 if not node.hasAttr("alias"): 518 if not node.hasAttr("alias"):
518 let name = node.child("name")[0].text 519 let name = node.child("name")[0].text
519 outputFiles["basetypes"].add &"proc `$`*(handle: {name}): string = \"{name}(\" & $(uint(handle)) & \")\"" 520 outputFiles["basetypes"].add &"proc `$`*(handle: {name}): string = \"{name}(\" & $(uint(handle)) & \")\""
520 outputFiles["basetypes"].add &"proc valid*(handle: {name}): bool = uint(handle) != 0" 521 outputFiles["basetypes"].add &"proc valid*(handle: {name}): bool = uint(handle) != 0"
521 outputFiles["basetypes"].add &"proc reset*(handle: var {name}) = handle = {name}(0)" 522 outputFiles["basetypes"].add &"proc reset*(handle: var {name}) = handle = {name}(0)"
523 outputFiles["basetypes"].add &"proc `==`*(a, b: {name}): bool = uint(a) == uint(b)"
524
522 525
523 # commands aka functions 526 # commands aka functions
524 var varDecls: Table[string, string] 527 var varDecls: Table[string, string]
525 var procLoads: Table[string, string] # procloads need to be packed into feature/extension loader procs 528 var procLoads: Table[string, string] # procloads need to be packed into feature/extension loader procs
526 for commands in api.findAll("commands"): 529 for commands in api.findAll("commands"):