nuklear_glfw_vulkan.h 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. /*
  2. * Nuklear - 1.32.0 - public domain
  3. * no warrenty implied; use at your own risk.
  4. * authored from 2015-2016 by Micha Mettke
  5. */
  6. /*
  7. * ==============================================================
  8. *
  9. * API
  10. *
  11. * ===============================================================
  12. */
  13. #ifndef NK_GLFW_VULKAN_H_
  14. #define NK_GLFW_VULKAN_H_
  15. unsigned char nuklearshaders_nuklear_vert_spv[] = {
  16. 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0b, 0x00, 0x0d, 0x00,
  17. 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
  18. 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
  19. 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
  20. 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  21. 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00,
  22. 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00,
  23. 0x0a, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
  24. 0x2a, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00,
  25. 0x03, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0xc2, 0x01, 0x00, 0x00,
  26. 0x04, 0x00, 0x09, 0x00, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, 0x5f, 0x73,
  27. 0x65, 0x70, 0x61, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x64,
  28. 0x65, 0x72, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x00, 0x00,
  29. 0x04, 0x00, 0x0a, 0x00, 0x47, 0x4c, 0x5f, 0x47, 0x4f, 0x4f, 0x47, 0x4c,
  30. 0x45, 0x5f, 0x63, 0x70, 0x70, 0x5f, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x5f,
  31. 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69,
  32. 0x76, 0x65, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x47, 0x4c, 0x5f, 0x47,
  33. 0x4f, 0x4f, 0x47, 0x4c, 0x45, 0x5f, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64,
  34. 0x65, 0x5f, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x00,
  35. 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e,
  36. 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x08, 0x00, 0x00, 0x00,
  37. 0x67, 0x6c, 0x5f, 0x50, 0x65, 0x72, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78,
  38. 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x08, 0x00, 0x00, 0x00,
  39. 0x00, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74,
  40. 0x69, 0x6f, 0x6e, 0x00, 0x05, 0x00, 0x03, 0x00, 0x0a, 0x00, 0x00, 0x00,
  41. 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x00, 0x00,
  42. 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x75, 0x66, 0x66, 0x65,
  43. 0x72, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00, 0x06, 0x00, 0x06, 0x00,
  44. 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x72, 0x6f, 0x6a,
  45. 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00,
  46. 0x10, 0x00, 0x00, 0x00, 0x75, 0x62, 0x6f, 0x00, 0x05, 0x00, 0x05, 0x00,
  47. 0x16, 0x00, 0x00, 0x00, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e,
  48. 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x27, 0x00, 0x00, 0x00,
  49. 0x66, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00,
  50. 0x05, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6c, 0x6f,
  51. 0x72, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x42, 0x00, 0x00, 0x00,
  52. 0x66, 0x72, 0x61, 0x67, 0x55, 0x76, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00,
  53. 0x43, 0x00, 0x00, 0x00, 0x75, 0x76, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00,
  54. 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00,
  56. 0x02, 0x00, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00,
  58. 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00,
  59. 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x0e, 0x00, 0x00, 0x00,
  60. 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
  61. 0x47, 0x00, 0x03, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  62. 0x47, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00,
  63. 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00,
  64. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
  65. 0x16, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. 0x47, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  67. 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00,
  68. 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
  69. 0x42, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  70. 0x47, 0x00, 0x04, 0x00, 0x43, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  71. 0x01, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
  72. 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  73. 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  74. 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
  75. 0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00,
  76. 0x07, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00,
  77. 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00,
  78. 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  79. 0x15, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  80. 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00,
  81. 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x04, 0x00,
  82. 0x0d, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  83. 0x1e, 0x00, 0x03, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
  84. 0x20, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  85. 0x0e, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00,
  86. 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  87. 0x11, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
  88. 0x17, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
  89. 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x15, 0x00, 0x00, 0x00,
  90. 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00,
  91. 0x15, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  92. 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
  93. 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00,
  94. 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x20, 0x00, 0x04, 0x00,
  95. 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
  96. 0x15, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  97. 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00,
  98. 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  99. 0x22, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
  100. 0x3b, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
  101. 0x03, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00,
  102. 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  103. 0x29, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
  104. 0x3b, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00,
  105. 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00,
  106. 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  107. 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  108. 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
  109. 0x00, 0x00, 0x7f, 0x43, 0x2b, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00,
  110. 0x36, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00,
  111. 0x20, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  112. 0x20, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  113. 0x14, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, 0x00,
  114. 0x42, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00,
  115. 0x15, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  116. 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  117. 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00,
  118. 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x11, 0x00, 0x00, 0x00,
  119. 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
  120. 0x3d, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
  121. 0x12, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00,
  122. 0x17, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00,
  123. 0x06, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  124. 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00,
  125. 0x1b, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  126. 0x50, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
  127. 0x1a, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
  128. 0x19, 0x00, 0x00, 0x00, 0x91, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00,
  129. 0x1d, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
  130. 0x41, 0x00, 0x05, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
  131. 0x0a, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00,
  132. 0x1f, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00,
  133. 0x22, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
  134. 0x0c, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00,
  135. 0x06, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00,
  136. 0x7f, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00,
  137. 0x24, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x22, 0x00, 0x00, 0x00,
  138. 0x26, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
  139. 0x21, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x26, 0x00, 0x00, 0x00,
  140. 0x25, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x2c, 0x00, 0x00, 0x00,
  141. 0x2d, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00,
  142. 0x3d, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00,
  143. 0x2d, 0x00, 0x00, 0x00, 0x70, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00,
  144. 0x2f, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x88, 0x00, 0x05, 0x00,
  145. 0x06, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00,
  146. 0x30, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x2c, 0x00, 0x00, 0x00,
  147. 0x32, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
  148. 0x3d, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00,
  149. 0x32, 0x00, 0x00, 0x00, 0x70, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00,
  150. 0x34, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x88, 0x00, 0x05, 0x00,
  151. 0x06, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
  152. 0x30, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x2c, 0x00, 0x00, 0x00,
  153. 0x37, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00,
  154. 0x3d, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
  155. 0x37, 0x00, 0x00, 0x00, 0x70, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00,
  156. 0x39, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x88, 0x00, 0x05, 0x00,
  157. 0x06, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00,
  158. 0x30, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x2c, 0x00, 0x00, 0x00,
  159. 0x3c, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00,
  160. 0x3d, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00,
  161. 0x3c, 0x00, 0x00, 0x00, 0x70, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00,
  162. 0x3e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x88, 0x00, 0x05, 0x00,
  163. 0x06, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00,
  164. 0x30, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00,
  165. 0x40, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00,
  166. 0x3a, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00,
  167. 0x27, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00,
  168. 0x14, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00,
  169. 0x3e, 0x00, 0x03, 0x00, 0x42, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00,
  170. 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00
  171. };
  172. unsigned int nuklearshaders_nuklear_vert_spv_len = 1856;
  173. unsigned char nuklearshaders_nuklear_frag_spv[] = {
  174. 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0b, 0x00, 0x0d, 0x00,
  175. 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
  176. 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
  177. 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
  178. 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  179. 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
  180. 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00,
  181. 0x11, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  182. 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
  183. 0x03, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0xc2, 0x01, 0x00, 0x00,
  184. 0x04, 0x00, 0x09, 0x00, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, 0x5f, 0x73,
  185. 0x65, 0x70, 0x61, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x64,
  186. 0x65, 0x72, 0x5f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x00, 0x00,
  187. 0x04, 0x00, 0x0a, 0x00, 0x47, 0x4c, 0x5f, 0x47, 0x4f, 0x4f, 0x47, 0x4c,
  188. 0x45, 0x5f, 0x63, 0x70, 0x70, 0x5f, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x5f,
  189. 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69,
  190. 0x76, 0x65, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x47, 0x4c, 0x5f, 0x47,
  191. 0x4f, 0x4f, 0x47, 0x4c, 0x45, 0x5f, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64,
  192. 0x65, 0x5f, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x00,
  193. 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e,
  194. 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x09, 0x00, 0x00, 0x00,
  195. 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00,
  196. 0x05, 0x00, 0x06, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x63, 0x75, 0x72, 0x72,
  197. 0x65, 0x6e, 0x74, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00,
  198. 0x05, 0x00, 0x04, 0x00, 0x11, 0x00, 0x00, 0x00, 0x66, 0x72, 0x61, 0x67,
  199. 0x55, 0x76, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x15, 0x00, 0x00, 0x00,
  200. 0x6f, 0x75, 0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00,
  201. 0x05, 0x00, 0x05, 0x00, 0x17, 0x00, 0x00, 0x00, 0x66, 0x72, 0x61, 0x67,
  202. 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
  203. 0x0d, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  204. 0x47, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
  205. 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x11, 0x00, 0x00, 0x00,
  206. 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
  207. 0x15, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  208. 0x47, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  209. 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
  210. 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  211. 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  212. 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
  213. 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00,
  214. 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x19, 0x00, 0x09, 0x00,
  215. 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  216. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  217. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00,
  218. 0x0b, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  219. 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00,
  220. 0x3b, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
  221. 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00,
  222. 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  223. 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
  224. 0x3b, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00,
  225. 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00,
  226. 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00,
  227. 0x14, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  228. 0x20, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  229. 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00,
  230. 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00,
  231. 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  232. 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00,
  233. 0x3b, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
  234. 0x07, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00,
  235. 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00,
  236. 0x0f, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00,
  237. 0x57, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
  238. 0x0e, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00,
  239. 0x09, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00,
  240. 0x07, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  241. 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00,
  242. 0x09, 0x00, 0x00, 0x00, 0x85, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00,
  243. 0x1a, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00,
  244. 0x3e, 0x00, 0x03, 0x00, 0x15, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00,
  245. 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00
  246. };
  247. unsigned int nuklearshaders_nuklear_frag_spv_len = 860;
  248. #include <assert.h>
  249. #include <stddef.h>
  250. #include <string.h>
  251. #define GLFW_INCLUDE_VULKAN
  252. #include <GLFW/glfw3.h>
  253. enum nk_glfw_init_state { NK_GLFW3_DEFAULT = 0, NK_GLFW3_INSTALL_CALLBACKS };
  254. NK_API struct nk_context *
  255. nk_glfw3_init(GLFWwindow *win, VkDevice logical_device,
  256. VkPhysicalDevice physical_device,
  257. uint32_t graphics_queue_family_index, VkImageView *image_views,
  258. uint32_t image_views_len, VkFormat color_format,
  259. enum nk_glfw_init_state init_state,
  260. VkDeviceSize max_vertex_buffer, VkDeviceSize max_element_buffer);
  261. NK_API void nk_glfw3_shutdown(void);
  262. NK_API void nk_glfw3_font_stash_begin(struct nk_font_atlas **atlas);
  263. NK_API void nk_glfw3_font_stash_end(VkQueue graphics_queue);
  264. NK_API void nk_glfw3_new_frame();
  265. NK_API VkSemaphore nk_glfw3_render(VkQueue graphics_queue,
  266. uint32_t buffer_index,
  267. VkSemaphore wait_semaphore,
  268. enum nk_anti_aliasing AA);
  269. NK_API void nk_glfw3_resize(uint32_t framebuffer_width,
  270. uint32_t framebuffer_height);
  271. NK_API void nk_glfw3_device_destroy(void);
  272. NK_API void nk_glfw3_device_create(
  273. VkDevice logical_device, VkPhysicalDevice physical_device,
  274. uint32_t graphics_queue_family_index, VkImageView *image_views,
  275. uint32_t image_views_len, VkFormat color_format,
  276. VkDeviceSize max_vertex_buffer, VkDeviceSize max_element_buffer,
  277. uint32_t framebuffer_width, uint32_t framebuffer_height);
  278. NK_API void nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint);
  279. NK_API void nk_glfw3_key_callback(GLFWwindow *win, int key, int scancode, int action, int mods);
  280. NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff);
  281. NK_API void nk_glfw3_mouse_button_callback(GLFWwindow *win, int button,
  282. int action, int mods);
  283. #endif
  284. /*
  285. * ==============================================================
  286. *
  287. * IMPLEMENTATION
  288. *
  289. * ===============================================================
  290. */
  291. #ifdef NK_GLFW_VULKAN_IMPLEMENTATION
  292. #undef NK_GLFW_VULKAN_IMPLEMENTATION
  293. #include <stdlib.h>
  294. #ifndef NK_GLFW_TEXT_MAX
  295. #define NK_GLFW_TEXT_MAX 256
  296. #endif
  297. #ifndef NK_GLFW_DOUBLE_CLICK_LO
  298. #define NK_GLFW_DOUBLE_CLICK_LO 0.02
  299. #endif
  300. #ifndef NK_GLFW_DOUBLE_CLICK_HI
  301. #define NK_GLFW_DOUBLE_CLICK_HI 0.2
  302. #endif
  303. #ifndef NK_GLFW_MAX_TEXTURES
  304. #define NK_GLFW_MAX_TEXTURES 256
  305. #endif
  306. #define VK_COLOR_COMPONENT_MASK_RGBA \
  307. VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | \
  308. VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
  309. struct nk_glfw_vertex {
  310. float position[2];
  311. float uv[2];
  312. nk_byte col[4];
  313. };
  314. struct nk_vulkan_texture_descriptor_set {
  315. VkImageView image_view;
  316. VkDescriptorSet descriptor_set;
  317. };
  318. struct nk_glfw_device {
  319. struct nk_buffer cmds;
  320. struct nk_draw_null_texture tex_null;
  321. int max_vertex_buffer;
  322. int max_element_buffer;
  323. VkDevice logical_device;
  324. VkPhysicalDevice physical_device;
  325. VkImageView *image_views;
  326. uint32_t image_views_len;
  327. VkFormat color_format;
  328. VkFramebuffer *framebuffers;
  329. uint32_t framebuffers_len;
  330. VkCommandBuffer *command_buffers;
  331. uint32_t command_buffers_len;
  332. VkSampler sampler;
  333. VkCommandPool command_pool;
  334. VkSemaphore render_completed;
  335. VkBuffer vertex_buffer;
  336. VkDeviceMemory vertex_memory;
  337. void *mapped_vertex;
  338. VkBuffer index_buffer;
  339. VkDeviceMemory index_memory;
  340. void *mapped_index;
  341. VkBuffer uniform_buffer;
  342. VkDeviceMemory uniform_memory;
  343. void *mapped_uniform;
  344. VkRenderPass render_pass;
  345. VkDescriptorPool descriptor_pool;
  346. VkDescriptorSetLayout uniform_descriptor_set_layout;
  347. VkDescriptorSet uniform_descriptor_set;
  348. VkDescriptorSetLayout texture_descriptor_set_layout;
  349. struct nk_vulkan_texture_descriptor_set *texture_descriptor_sets;
  350. uint32_t texture_descriptor_sets_len;
  351. VkPipelineLayout pipeline_layout;
  352. VkPipeline pipeline;
  353. VkImage font_image;
  354. VkImageView font_image_view;
  355. VkDeviceMemory font_memory;
  356. };
  357. static struct nk_glfw {
  358. GLFWwindow *win;
  359. int width, height;
  360. int display_width, display_height;
  361. struct nk_glfw_device vulkan;
  362. struct nk_context ctx;
  363. struct nk_font_atlas atlas;
  364. struct nk_vec2 fb_scale;
  365. unsigned int text[NK_GLFW_TEXT_MAX];
  366. nk_char key_events[NK_KEY_MAX];
  367. int text_len;
  368. struct nk_vec2 scroll;
  369. double last_button_click;
  370. int is_double_click_down;
  371. struct nk_vec2 double_click_pos;
  372. float delta_time_seconds_last;
  373. } glfw;
  374. struct Mat4f {
  375. float m[16];
  376. };
  377. NK_INTERN uint32_t nk_glfw3_find_memory_index(
  378. VkPhysicalDevice physical_device, uint32_t type_filter,
  379. VkMemoryPropertyFlags properties) {
  380. VkPhysicalDeviceMemoryProperties mem_properties;
  381. uint32_t i;
  382. vkGetPhysicalDeviceMemoryProperties(physical_device, &mem_properties);
  383. for (i = 0; i < mem_properties.memoryTypeCount; i++) {
  384. if ((type_filter & (1 << i)) &&
  385. (mem_properties.memoryTypes[i].propertyFlags & properties) ==
  386. properties) {
  387. return i;
  388. }
  389. }
  390. assert(0);
  391. return 0;
  392. }
  393. NK_INTERN void nk_glfw3_create_sampler(struct nk_glfw_device *dev) {
  394. VkResult result;
  395. VkSamplerCreateInfo sampler_info;
  396. memset(&sampler_info, 0, sizeof(VkSamplerCreateInfo));
  397. sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
  398. sampler_info.pNext = NULL;
  399. sampler_info.maxAnisotropy = 1.0;
  400. sampler_info.magFilter = VK_FILTER_LINEAR;
  401. sampler_info.minFilter = VK_FILTER_LINEAR;
  402. sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
  403. sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  404. sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  405. sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  406. sampler_info.mipLodBias = 0.0f;
  407. sampler_info.compareEnable = VK_FALSE;
  408. sampler_info.compareOp = VK_COMPARE_OP_ALWAYS;
  409. sampler_info.minLod = 0.0f;
  410. sampler_info.maxLod = 0.0f;
  411. sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
  412. result = vkCreateSampler(dev->logical_device, &sampler_info, NULL,
  413. &dev->sampler);
  414. NK_ASSERT(result == VK_SUCCESS);
  415. }
  416. NK_INTERN void
  417. nk_glfw3_create_command_pool(struct nk_glfw_device *dev,
  418. uint32_t graphics_queue_family_index) {
  419. VkResult result;
  420. VkCommandPoolCreateInfo pool_info;
  421. memset(&pool_info, 0, sizeof(VkCommandPoolCreateInfo));
  422. pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
  423. pool_info.queueFamilyIndex = graphics_queue_family_index;
  424. pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
  425. result = vkCreateCommandPool(dev->logical_device, &pool_info, NULL,
  426. &dev->command_pool);
  427. NK_ASSERT(result == VK_SUCCESS);
  428. }
  429. NK_INTERN void nk_glfw3_create_command_buffers(struct nk_glfw_device *dev) {
  430. VkResult result;
  431. VkCommandBufferAllocateInfo allocate_info;
  432. memset(&allocate_info, 0, sizeof(VkCommandBufferAllocateInfo));
  433. dev->command_buffers = (VkCommandBuffer *)malloc(dev->image_views_len *
  434. sizeof(VkCommandBuffer));
  435. dev->command_buffers_len = dev->image_views_len;
  436. allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
  437. allocate_info.commandPool = dev->command_pool;
  438. allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
  439. allocate_info.commandBufferCount = dev->command_buffers_len;
  440. result = vkAllocateCommandBuffers(dev->logical_device, &allocate_info,
  441. dev->command_buffers);
  442. NK_ASSERT(result == VK_SUCCESS);
  443. }
  444. NK_INTERN void nk_glfw3_create_semaphore(struct nk_glfw_device *dev) {
  445. VkResult result;
  446. VkSemaphoreCreateInfo semaphore_info;
  447. memset(&semaphore_info, 0, sizeof(VkSemaphoreCreateInfo));
  448. semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
  449. result = (vkCreateSemaphore(dev->logical_device, &semaphore_info, NULL,
  450. &dev->render_completed));
  451. NK_ASSERT(result == VK_SUCCESS);
  452. }
  453. NK_INTERN void nk_glfw3_create_buffer_and_memory(struct nk_glfw_device *dev,
  454. VkBuffer *buffer,
  455. VkBufferUsageFlags usage,
  456. VkDeviceMemory *memory,
  457. VkDeviceSize size) {
  458. VkMemoryRequirements mem_reqs;
  459. VkResult result;
  460. VkBufferCreateInfo buffer_info;
  461. VkMemoryAllocateInfo alloc_info;
  462. memset(&buffer_info, 0, sizeof(VkBufferCreateInfo));
  463. buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
  464. buffer_info.size = size;
  465. buffer_info.usage = usage;
  466. buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  467. result = vkCreateBuffer(dev->logical_device, &buffer_info, NULL, buffer);
  468. NK_ASSERT(result == VK_SUCCESS);
  469. vkGetBufferMemoryRequirements(dev->logical_device, *buffer, &mem_reqs);
  470. memset(&alloc_info, 0, sizeof(VkMemoryAllocateInfo));
  471. alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
  472. alloc_info.allocationSize = mem_reqs.size;
  473. alloc_info.memoryTypeIndex = nk_glfw3_find_memory_index(
  474. dev->physical_device, mem_reqs.memoryTypeBits,
  475. VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
  476. VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
  477. result = vkAllocateMemory(dev->logical_device, &alloc_info, NULL, memory);
  478. NK_ASSERT(result == VK_SUCCESS);
  479. result = vkBindBufferMemory(dev->logical_device, *buffer, *memory, 0);
  480. NK_ASSERT(result == VK_SUCCESS);
  481. }
  482. NK_INTERN void nk_glfw3_create_render_pass(struct nk_glfw_device *dev) {
  483. VkAttachmentDescription attachment;
  484. VkAttachmentReference color_reference;
  485. VkSubpassDependency subpass_dependency;
  486. VkSubpassDescription subpass_description;
  487. VkRenderPassCreateInfo render_pass_info;
  488. VkResult result;
  489. memset(&attachment, 0, sizeof(VkAttachmentDescription));
  490. attachment.format = dev->color_format;
  491. attachment.samples = VK_SAMPLE_COUNT_1_BIT;
  492. attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
  493. attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
  494. attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
  495. attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
  496. attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
  497. attachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
  498. memset(&color_reference, 0, sizeof(VkAttachmentReference));
  499. color_reference.attachment = 0;
  500. color_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
  501. memset(&subpass_dependency, 0, sizeof(VkSubpassDependency));
  502. subpass_dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
  503. subpass_dependency.srcAccessMask = 0;
  504. subpass_dependency.srcStageMask =
  505. VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
  506. subpass_dependency.dstSubpass = 0;
  507. subpass_dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
  508. VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
  509. subpass_dependency.dstStageMask =
  510. VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
  511. memset(&subpass_description, 0, sizeof(VkSubpassDescription));
  512. subpass_description.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
  513. subpass_description.colorAttachmentCount = 1;
  514. subpass_description.pColorAttachments = &color_reference;
  515. memset(&render_pass_info, 0, sizeof(VkRenderPassCreateInfo));
  516. render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
  517. render_pass_info.attachmentCount = 1;
  518. render_pass_info.pAttachments = &attachment;
  519. render_pass_info.subpassCount = 1;
  520. render_pass_info.pSubpasses = &subpass_description;
  521. render_pass_info.dependencyCount = 1;
  522. render_pass_info.pDependencies = &subpass_dependency;
  523. result = vkCreateRenderPass(dev->logical_device, &render_pass_info, NULL,
  524. &dev->render_pass);
  525. NK_ASSERT(result == VK_SUCCESS);
  526. }
  527. NK_INTERN void nk_glfw3_create_framebuffers(struct nk_glfw_device *dev,
  528. uint32_t framebuffer_width,
  529. uint32_t framebuffer_height) {
  530. VkFramebufferCreateInfo framebuffer_create_info;
  531. uint32_t i;
  532. VkResult result;
  533. dev->framebuffers =
  534. (VkFramebuffer *)malloc(dev->image_views_len * sizeof(VkFramebuffer));
  535. memset(&framebuffer_create_info, 0, sizeof(VkFramebufferCreateInfo));
  536. framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
  537. framebuffer_create_info.renderPass = dev->render_pass;
  538. framebuffer_create_info.attachmentCount = 1;
  539. framebuffer_create_info.width = framebuffer_width;
  540. framebuffer_create_info.height = framebuffer_height;
  541. framebuffer_create_info.layers = 1;
  542. for (i = 0; i < dev->image_views_len; i++) {
  543. framebuffer_create_info.pAttachments = &dev->image_views[i];
  544. result =
  545. vkCreateFramebuffer(dev->logical_device, &framebuffer_create_info,
  546. NULL, &dev->framebuffers[i]);
  547. NK_ASSERT(result == VK_SUCCESS);
  548. }
  549. dev->framebuffers_len = dev->image_views_len;
  550. }
  551. NK_INTERN void nk_glfw3_create_descriptor_pool(struct nk_glfw_device *dev) {
  552. VkDescriptorPoolSize pool_sizes[2];
  553. VkDescriptorPoolCreateInfo pool_info;
  554. VkResult result;
  555. memset(&pool_sizes, 0, sizeof(VkDescriptorPoolSize) * 2);
  556. pool_sizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
  557. pool_sizes[0].descriptorCount = 1;
  558. pool_sizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
  559. pool_sizes[1].descriptorCount = NK_GLFW_MAX_TEXTURES;
  560. memset(&pool_info, 0, sizeof(VkDescriptorPoolCreateInfo));
  561. pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
  562. pool_info.poolSizeCount = 2;
  563. pool_info.pPoolSizes = pool_sizes;
  564. pool_info.maxSets = 1 + NK_GLFW_MAX_TEXTURES;
  565. result = vkCreateDescriptorPool(dev->logical_device, &pool_info, NULL,
  566. &dev->descriptor_pool);
  567. NK_ASSERT(result == VK_SUCCESS);
  568. }
  569. NK_INTERN void
  570. nk_glfw3_create_uniform_descriptor_set_layout(struct nk_glfw_device *dev) {
  571. VkDescriptorSetLayoutBinding binding;
  572. VkDescriptorSetLayoutCreateInfo descriptor_set_info;
  573. VkResult result;
  574. memset(&binding, 0, sizeof(VkDescriptorSetLayoutBinding));
  575. binding.binding = 0;
  576. binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
  577. binding.descriptorCount = 1;
  578. binding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
  579. memset(&descriptor_set_info, 0, sizeof(VkDescriptorSetLayoutCreateInfo));
  580. descriptor_set_info.sType =
  581. VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
  582. descriptor_set_info.bindingCount = 1;
  583. descriptor_set_info.pBindings = &binding;
  584. result =
  585. vkCreateDescriptorSetLayout(dev->logical_device, &descriptor_set_info,
  586. NULL, &dev->uniform_descriptor_set_layout);
  587. NK_ASSERT(result == VK_SUCCESS);
  588. }
  589. NK_INTERN void
  590. nk_glfw3_create_and_update_uniform_descriptor_set(struct nk_glfw_device *dev) {
  591. VkDescriptorSetAllocateInfo allocate_info;
  592. VkDescriptorBufferInfo buffer_info;
  593. VkWriteDescriptorSet descriptor_write;
  594. VkResult result;
  595. memset(&allocate_info, 0, sizeof(VkDescriptorSetAllocateInfo));
  596. allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
  597. allocate_info.descriptorPool = dev->descriptor_pool;
  598. allocate_info.descriptorSetCount = 1;
  599. allocate_info.pSetLayouts = &dev->uniform_descriptor_set_layout;
  600. result = vkAllocateDescriptorSets(dev->logical_device, &allocate_info,
  601. &dev->uniform_descriptor_set);
  602. NK_ASSERT(result == VK_SUCCESS);
  603. memset(&buffer_info, 0, sizeof(VkDescriptorBufferInfo));
  604. buffer_info.buffer = dev->uniform_buffer;
  605. buffer_info.offset = 0;
  606. buffer_info.range = sizeof(struct Mat4f);
  607. memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
  608. descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
  609. descriptor_write.dstSet = dev->uniform_descriptor_set;
  610. descriptor_write.dstBinding = 0;
  611. descriptor_write.dstArrayElement = 0;
  612. descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
  613. descriptor_write.descriptorCount = 1;
  614. descriptor_write.pBufferInfo = &buffer_info;
  615. vkUpdateDescriptorSets(dev->logical_device, 1, &descriptor_write, 0, NULL);
  616. }
  617. NK_INTERN void
  618. nk_glfw3_create_texture_descriptor_set_layout(struct nk_glfw_device *dev) {
  619. VkDescriptorSetLayoutBinding binding;
  620. VkDescriptorSetLayoutCreateInfo descriptor_set_info;
  621. VkResult result;
  622. memset(&binding, 0, sizeof(VkDescriptorSetLayoutBinding));
  623. binding.binding = 0;
  624. binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
  625. binding.descriptorCount = 1;
  626. binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
  627. memset(&descriptor_set_info, 0, sizeof(VkDescriptorSetLayoutCreateInfo));
  628. descriptor_set_info.sType =
  629. VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
  630. descriptor_set_info.bindingCount = 1;
  631. descriptor_set_info.pBindings = &binding;
  632. result =
  633. vkCreateDescriptorSetLayout(dev->logical_device, &descriptor_set_info,
  634. NULL, &dev->texture_descriptor_set_layout);
  635. NK_ASSERT(result == VK_SUCCESS);
  636. }
  637. NK_INTERN void
  638. nk_glfw3_create_texture_descriptor_sets(struct nk_glfw_device *dev) {
  639. VkDescriptorSetLayout *descriptor_set_layouts;
  640. VkDescriptorSet *descriptor_sets;
  641. VkDescriptorSetAllocateInfo allocate_info;
  642. VkResult result;
  643. int i;
  644. descriptor_set_layouts = (VkDescriptorSetLayout *)malloc(
  645. NK_GLFW_MAX_TEXTURES * sizeof(VkDescriptorSetLayout));
  646. descriptor_sets = (VkDescriptorSet *)malloc(NK_GLFW_MAX_TEXTURES *
  647. sizeof(VkDescriptorSet));
  648. dev->texture_descriptor_sets =
  649. (struct nk_vulkan_texture_descriptor_set *)malloc(
  650. NK_GLFW_MAX_TEXTURES *
  651. sizeof(struct nk_vulkan_texture_descriptor_set));
  652. dev->texture_descriptor_sets_len = 0;
  653. for (i = 0; i < NK_GLFW_MAX_TEXTURES; i++) {
  654. descriptor_set_layouts[i] = dev->texture_descriptor_set_layout;
  655. descriptor_sets[i] = dev->texture_descriptor_sets[i].descriptor_set;
  656. }
  657. memset(&allocate_info, 0, sizeof(VkDescriptorSetAllocateInfo));
  658. allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
  659. allocate_info.descriptorPool = dev->descriptor_pool;
  660. allocate_info.descriptorSetCount = NK_GLFW_MAX_TEXTURES;
  661. allocate_info.pSetLayouts = descriptor_set_layouts;
  662. result = vkAllocateDescriptorSets(dev->logical_device, &allocate_info,
  663. descriptor_sets);
  664. NK_ASSERT(result == VK_SUCCESS);
  665. for (i = 0; i < NK_GLFW_MAX_TEXTURES; i++) {
  666. dev->texture_descriptor_sets[i].descriptor_set = descriptor_sets[i];
  667. }
  668. free(descriptor_set_layouts);
  669. free(descriptor_sets);
  670. }
  671. NK_INTERN void nk_glfw3_create_pipeline_layout(struct nk_glfw_device *dev) {
  672. VkPipelineLayoutCreateInfo pipeline_layout_info;
  673. VkDescriptorSetLayout descriptor_set_layouts[2];
  674. VkResult result;
  675. descriptor_set_layouts[0] = dev->uniform_descriptor_set_layout;
  676. descriptor_set_layouts[1] = dev->texture_descriptor_set_layout;
  677. memset(&pipeline_layout_info, 0, sizeof(VkPipelineLayoutCreateInfo));
  678. pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
  679. pipeline_layout_info.setLayoutCount = 2;
  680. pipeline_layout_info.pSetLayouts = descriptor_set_layouts;
  681. result = (vkCreatePipelineLayout(dev->logical_device, &pipeline_layout_info,
  682. NULL, &dev->pipeline_layout));
  683. NK_ASSERT(result == VK_SUCCESS);
  684. }
  685. NK_INTERN VkPipelineShaderStageCreateInfo
  686. nk_glfw3_create_shader(struct nk_glfw_device *dev, unsigned char *spv_shader,
  687. uint32_t size, VkShaderStageFlagBits stage_bit) {
  688. VkShaderModuleCreateInfo create_info;
  689. VkPipelineShaderStageCreateInfo shader_info;
  690. VkShaderModule module = NULL;
  691. VkResult result;
  692. memset(&create_info, 0, sizeof(VkShaderModuleCreateInfo));
  693. create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
  694. create_info.codeSize = size;
  695. create_info.pCode = (const uint32_t *)spv_shader;
  696. result =
  697. vkCreateShaderModule(dev->logical_device, &create_info, NULL, &module);
  698. NK_ASSERT(result == VK_SUCCESS);
  699. memset(&shader_info, 0, sizeof(VkPipelineShaderStageCreateInfo));
  700. shader_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
  701. shader_info.stage = stage_bit;
  702. shader_info.module = module;
  703. shader_info.pName = "main";
  704. return shader_info;
  705. }
  706. NK_INTERN void nk_glfw3_create_pipeline(struct nk_glfw_device *dev) {
  707. VkPipelineInputAssemblyStateCreateInfo input_assembly_state;
  708. VkPipelineRasterizationStateCreateInfo rasterization_state;
  709. VkPipelineColorBlendAttachmentState attachment_state = {
  710. VK_TRUE,
  711. VK_BLEND_FACTOR_SRC_ALPHA,
  712. VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
  713. VK_BLEND_OP_ADD,
  714. VK_BLEND_FACTOR_SRC_ALPHA,
  715. VK_BLEND_FACTOR_ONE,
  716. VK_BLEND_OP_ADD,
  717. VK_COLOR_COMPONENT_MASK_RGBA,
  718. };
  719. VkPipelineColorBlendStateCreateInfo color_blend_state;
  720. VkPipelineViewportStateCreateInfo viewport_state;
  721. VkPipelineMultisampleStateCreateInfo multisample_state;
  722. VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT,
  723. VK_DYNAMIC_STATE_SCISSOR};
  724. VkPipelineDynamicStateCreateInfo dynamic_state;
  725. VkPipelineShaderStageCreateInfo shader_stages[2];
  726. VkVertexInputBindingDescription vertex_input_info;
  727. VkVertexInputAttributeDescription vertex_attribute_description[3];
  728. VkPipelineVertexInputStateCreateInfo vertex_input;
  729. VkGraphicsPipelineCreateInfo pipeline_info;
  730. VkResult result;
  731. memset(&input_assembly_state, 0,
  732. sizeof(VkPipelineInputAssemblyStateCreateInfo));
  733. input_assembly_state.sType =
  734. VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
  735. input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
  736. input_assembly_state.primitiveRestartEnable = VK_FALSE;
  737. memset(&rasterization_state, 0,
  738. sizeof(VkPipelineRasterizationStateCreateInfo));
  739. rasterization_state.sType =
  740. VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
  741. rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
  742. rasterization_state.cullMode = VK_CULL_MODE_NONE;
  743. rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
  744. rasterization_state.lineWidth = 1.0f;
  745. memset(&color_blend_state, 0, sizeof(VkPipelineColorBlendStateCreateInfo));
  746. color_blend_state.sType =
  747. VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
  748. color_blend_state.attachmentCount = 1;
  749. color_blend_state.pAttachments = &attachment_state;
  750. memset(&viewport_state, 0, sizeof(VkPipelineViewportStateCreateInfo));
  751. viewport_state.sType =
  752. VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
  753. viewport_state.viewportCount = 1;
  754. viewport_state.scissorCount = 1;
  755. memset(&multisample_state, 0, sizeof(VkPipelineMultisampleStateCreateInfo));
  756. multisample_state.sType =
  757. VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
  758. multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
  759. memset(&dynamic_state, 0, sizeof(VkPipelineDynamicStateCreateInfo));
  760. dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
  761. dynamic_state.pDynamicStates = dynamic_states;
  762. dynamic_state.dynamicStateCount = 2;
  763. shader_stages[0] = nk_glfw3_create_shader(
  764. dev, nuklearshaders_nuklear_vert_spv,
  765. nuklearshaders_nuklear_vert_spv_len, VK_SHADER_STAGE_VERTEX_BIT);
  766. shader_stages[1] = nk_glfw3_create_shader(
  767. dev, nuklearshaders_nuklear_frag_spv,
  768. nuklearshaders_nuklear_frag_spv_len, VK_SHADER_STAGE_FRAGMENT_BIT);
  769. memset(&vertex_input_info, 0, sizeof(VkVertexInputBindingDescription));
  770. vertex_input_info.binding = 0;
  771. vertex_input_info.stride = sizeof(struct nk_glfw_vertex);
  772. vertex_input_info.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
  773. memset(&vertex_attribute_description, 0,
  774. sizeof(VkVertexInputAttributeDescription) * 3);
  775. vertex_attribute_description[0].location = 0;
  776. vertex_attribute_description[0].format = VK_FORMAT_R32G32_SFLOAT;
  777. vertex_attribute_description[0].offset =
  778. NK_OFFSETOF(struct nk_glfw_vertex, position);
  779. vertex_attribute_description[1].location = 1;
  780. vertex_attribute_description[1].format = VK_FORMAT_R32G32_SFLOAT;
  781. vertex_attribute_description[1].offset =
  782. NK_OFFSETOF(struct nk_glfw_vertex, uv);
  783. vertex_attribute_description[2].location = 2;
  784. vertex_attribute_description[2].format = VK_FORMAT_R8G8B8A8_UINT;
  785. vertex_attribute_description[2].offset =
  786. NK_OFFSETOF(struct nk_glfw_vertex, col);
  787. memset(&vertex_input, 0, sizeof(VkPipelineVertexInputStateCreateInfo));
  788. vertex_input.sType =
  789. VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
  790. vertex_input.vertexBindingDescriptionCount = 1;
  791. vertex_input.pVertexBindingDescriptions = &vertex_input_info;
  792. vertex_input.vertexAttributeDescriptionCount = 3;
  793. vertex_input.pVertexAttributeDescriptions = vertex_attribute_description;
  794. memset(&pipeline_info, 0, sizeof(VkGraphicsPipelineCreateInfo));
  795. pipeline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
  796. pipeline_info.flags = 0;
  797. pipeline_info.stageCount = 2;
  798. pipeline_info.pStages = shader_stages;
  799. pipeline_info.pVertexInputState = &vertex_input;
  800. pipeline_info.pInputAssemblyState = &input_assembly_state;
  801. pipeline_info.pViewportState = &viewport_state;
  802. pipeline_info.pRasterizationState = &rasterization_state;
  803. pipeline_info.pMultisampleState = &multisample_state;
  804. pipeline_info.pColorBlendState = &color_blend_state;
  805. pipeline_info.pDynamicState = &dynamic_state;
  806. pipeline_info.layout = dev->pipeline_layout;
  807. pipeline_info.renderPass = dev->render_pass;
  808. pipeline_info.basePipelineIndex = -1;
  809. pipeline_info.basePipelineHandle = NULL;
  810. result = vkCreateGraphicsPipelines(dev->logical_device, NULL, 1,
  811. &pipeline_info, NULL, &dev->pipeline);
  812. NK_ASSERT(result == VK_SUCCESS);
  813. vkDestroyShaderModule(dev->logical_device, shader_stages[0].module, NULL);
  814. vkDestroyShaderModule(dev->logical_device, shader_stages[1].module, NULL);
  815. }
  816. NK_INTERN void nk_glfw3_create_render_resources(struct nk_glfw_device *dev,
  817. uint32_t framebuffer_width,
  818. uint32_t framebuffer_height) {
  819. nk_glfw3_create_render_pass(dev);
  820. nk_glfw3_create_framebuffers(dev, framebuffer_width, framebuffer_height);
  821. nk_glfw3_create_descriptor_pool(dev);
  822. nk_glfw3_create_uniform_descriptor_set_layout(dev);
  823. nk_glfw3_create_and_update_uniform_descriptor_set(dev);
  824. nk_glfw3_create_texture_descriptor_set_layout(dev);
  825. nk_glfw3_create_texture_descriptor_sets(dev);
  826. nk_glfw3_create_pipeline_layout(dev);
  827. nk_glfw3_create_pipeline(dev);
  828. }
  829. NK_API void nk_glfw3_device_create(
  830. VkDevice logical_device, VkPhysicalDevice physical_device,
  831. uint32_t graphics_queue_family_index, VkImageView *image_views,
  832. uint32_t image_views_len, VkFormat color_format,
  833. VkDeviceSize max_vertex_buffer, VkDeviceSize max_element_buffer,
  834. uint32_t framebuffer_width, uint32_t framebuffer_height) {
  835. struct nk_glfw_device *dev = &glfw.vulkan;
  836. dev->max_vertex_buffer = max_vertex_buffer;
  837. dev->max_element_buffer = max_element_buffer;
  838. nk_buffer_init_default(&dev->cmds);
  839. dev->logical_device = logical_device;
  840. dev->physical_device = physical_device;
  841. dev->image_views = image_views;
  842. dev->image_views_len = image_views_len;
  843. dev->color_format = color_format;
  844. dev->framebuffers = NULL;
  845. dev->framebuffers_len = 0;
  846. nk_glfw3_create_sampler(dev);
  847. nk_glfw3_create_command_pool(dev, graphics_queue_family_index);
  848. nk_glfw3_create_command_buffers(dev);
  849. nk_glfw3_create_semaphore(dev);
  850. nk_glfw3_create_buffer_and_memory(dev, &dev->vertex_buffer,
  851. VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
  852. &dev->vertex_memory, max_vertex_buffer);
  853. nk_glfw3_create_buffer_and_memory(dev, &dev->index_buffer,
  854. VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
  855. &dev->index_memory, max_element_buffer);
  856. nk_glfw3_create_buffer_and_memory(
  857. dev, &dev->uniform_buffer, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
  858. &dev->uniform_memory, sizeof(struct Mat4f));
  859. vkMapMemory(dev->logical_device, dev->vertex_memory, 0, max_vertex_buffer,
  860. 0, &dev->mapped_vertex);
  861. vkMapMemory(dev->logical_device, dev->index_memory, 0, max_element_buffer,
  862. 0, &dev->mapped_index);
  863. vkMapMemory(dev->logical_device, dev->uniform_memory, 0,
  864. sizeof(struct Mat4f), 0, &dev->mapped_uniform);
  865. nk_glfw3_create_render_resources(dev, framebuffer_width,
  866. framebuffer_height);
  867. }
  868. NK_INTERN void nk_glfw3_device_upload_atlas(VkQueue graphics_queue,
  869. const void *image, int width,
  870. int height) {
  871. struct nk_glfw_device *dev = &glfw.vulkan;
  872. VkImageCreateInfo image_info;
  873. VkResult result;
  874. VkMemoryRequirements mem_reqs;
  875. VkMemoryAllocateInfo alloc_info;
  876. VkBufferCreateInfo buffer_info;
  877. uint8_t *data = 0;
  878. VkCommandBufferBeginInfo begin_info;
  879. VkCommandBuffer command_buffer;
  880. VkImageMemoryBarrier image_memory_barrier;
  881. VkBufferImageCopy buffer_copy_region;
  882. VkImageMemoryBarrier image_shader_memory_barrier;
  883. VkFence fence;
  884. VkFenceCreateInfo fence_create;
  885. VkSubmitInfo submit_info;
  886. VkImageViewCreateInfo image_view_info;
  887. struct {
  888. VkDeviceMemory memory;
  889. VkBuffer buffer;
  890. } staging_buffer;
  891. memset(&image_info, 0, sizeof(VkImageCreateInfo));
  892. image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
  893. image_info.imageType = VK_IMAGE_TYPE_2D;
  894. image_info.format = VK_FORMAT_R8G8B8A8_UNORM;
  895. image_info.extent.width = (uint32_t)width;
  896. image_info.extent.height = (uint32_t)height;
  897. image_info.extent.depth = 1;
  898. image_info.mipLevels = 1;
  899. image_info.arrayLayers = 1;
  900. image_info.samples = VK_SAMPLE_COUNT_1_BIT;
  901. image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
  902. image_info.usage =
  903. VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
  904. image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  905. image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
  906. result =
  907. vkCreateImage(dev->logical_device, &image_info, NULL, &dev->font_image);
  908. NK_ASSERT(result == VK_SUCCESS);
  909. vkGetImageMemoryRequirements(dev->logical_device, dev->font_image,
  910. &mem_reqs);
  911. memset(&alloc_info, 0, sizeof(VkMemoryAllocateInfo));
  912. alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
  913. alloc_info.allocationSize = mem_reqs.size;
  914. alloc_info.memoryTypeIndex = nk_glfw3_find_memory_index(
  915. dev->physical_device, mem_reqs.memoryTypeBits,
  916. VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
  917. result = vkAllocateMemory(dev->logical_device, &alloc_info, NULL,
  918. &dev->font_memory);
  919. NK_ASSERT(result == VK_SUCCESS);
  920. result = vkBindImageMemory(dev->logical_device, dev->font_image,
  921. dev->font_memory, 0);
  922. NK_ASSERT(result == VK_SUCCESS);
  923. memset(&buffer_info, 0, sizeof(VkBufferCreateInfo));
  924. buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
  925. buffer_info.size = alloc_info.allocationSize;
  926. buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
  927. buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  928. result = vkCreateBuffer(dev->logical_device, &buffer_info, NULL,
  929. &staging_buffer.buffer);
  930. NK_ASSERT(result == VK_SUCCESS);
  931. vkGetBufferMemoryRequirements(dev->logical_device, staging_buffer.buffer,
  932. &mem_reqs);
  933. alloc_info.allocationSize = mem_reqs.size;
  934. alloc_info.memoryTypeIndex = nk_glfw3_find_memory_index(
  935. dev->physical_device, mem_reqs.memoryTypeBits,
  936. VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
  937. VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
  938. result = vkAllocateMemory(dev->logical_device, &alloc_info, NULL,
  939. &staging_buffer.memory);
  940. NK_ASSERT(result == VK_SUCCESS);
  941. result = vkBindBufferMemory(dev->logical_device, staging_buffer.buffer,
  942. staging_buffer.memory, 0);
  943. NK_ASSERT(result == VK_SUCCESS);
  944. result = vkMapMemory(dev->logical_device, staging_buffer.memory, 0,
  945. alloc_info.allocationSize, 0, (void **)&data);
  946. NK_ASSERT(result == VK_SUCCESS);
  947. memcpy(data, image, width * height * 4);
  948. vkUnmapMemory(dev->logical_device, staging_buffer.memory);
  949. memset(&begin_info, 0, sizeof(VkCommandBufferBeginInfo));
  950. begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
  951. NK_ASSERT(dev->command_buffers_len > 0);
  952. /*
  953. use the same command buffer as for render as we are regenerating the
  954. buffer during render anyway
  955. */
  956. command_buffer = dev->command_buffers[0];
  957. result = vkBeginCommandBuffer(command_buffer, &begin_info);
  958. NK_ASSERT(result == VK_SUCCESS);
  959. memset(&image_memory_barrier, 0, sizeof(VkImageMemoryBarrier));
  960. image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
  961. image_memory_barrier.image = dev->font_image;
  962. image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
  963. image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
  964. image_memory_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
  965. image_memory_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
  966. image_memory_barrier.subresourceRange.aspectMask =
  967. VK_IMAGE_ASPECT_COLOR_BIT;
  968. image_memory_barrier.subresourceRange.levelCount = 1;
  969. image_memory_barrier.subresourceRange.layerCount = 1;
  970. image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
  971. vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
  972. VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1,
  973. &image_memory_barrier);
  974. memset(&buffer_copy_region, 0, sizeof(VkBufferImageCopy));
  975. buffer_copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
  976. buffer_copy_region.imageSubresource.layerCount = 1;
  977. buffer_copy_region.imageExtent.width = (uint32_t)width;
  978. buffer_copy_region.imageExtent.height = (uint32_t)height;
  979. buffer_copy_region.imageExtent.depth = 1;
  980. vkCmdCopyBufferToImage(
  981. command_buffer, staging_buffer.buffer, dev->font_image,
  982. VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &buffer_copy_region);
  983. memset(&image_shader_memory_barrier, 0, sizeof(VkImageMemoryBarrier));
  984. image_shader_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
  985. image_shader_memory_barrier.image = dev->font_image;
  986. image_shader_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
  987. image_shader_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
  988. image_shader_memory_barrier.oldLayout =
  989. VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
  990. image_shader_memory_barrier.newLayout =
  991. VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
  992. image_shader_memory_barrier.subresourceRange.aspectMask =
  993. VK_IMAGE_ASPECT_COLOR_BIT;
  994. image_shader_memory_barrier.subresourceRange.levelCount = 1;
  995. image_shader_memory_barrier.subresourceRange.layerCount = 1;
  996. image_shader_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
  997. image_shader_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
  998. vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
  999. VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0,
  1000. NULL, 1, &image_shader_memory_barrier);
  1001. result = vkEndCommandBuffer(command_buffer);
  1002. NK_ASSERT(result == VK_SUCCESS);
  1003. memset(&fence_create, 0, sizeof(VkFenceCreateInfo));
  1004. fence_create.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
  1005. result = vkCreateFence(dev->logical_device, &fence_create, NULL, &fence);
  1006. NK_ASSERT(result == VK_SUCCESS);
  1007. memset(&submit_info, 0, sizeof(VkSubmitInfo));
  1008. submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
  1009. submit_info.commandBufferCount = 1;
  1010. submit_info.pCommandBuffers = &command_buffer;
  1011. result = vkQueueSubmit(graphics_queue, 1, &submit_info, fence);
  1012. NK_ASSERT(result == VK_SUCCESS);
  1013. result =
  1014. vkWaitForFences(dev->logical_device, 1, &fence, VK_TRUE, UINT64_MAX);
  1015. NK_ASSERT(result == VK_SUCCESS);
  1016. vkDestroyFence(dev->logical_device, fence, NULL);
  1017. vkFreeMemory(dev->logical_device, staging_buffer.memory, NULL);
  1018. vkDestroyBuffer(dev->logical_device, staging_buffer.buffer, NULL);
  1019. memset(&image_view_info, 0, sizeof(VkImageViewCreateInfo));
  1020. image_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
  1021. image_view_info.image = dev->font_image;
  1022. image_view_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
  1023. image_view_info.format = image_info.format;
  1024. image_view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
  1025. image_view_info.subresourceRange.layerCount = 1;
  1026. image_view_info.subresourceRange.levelCount = 1;
  1027. result = vkCreateImageView(dev->logical_device, &image_view_info, NULL,
  1028. &dev->font_image_view);
  1029. NK_ASSERT(result == VK_SUCCESS);
  1030. }
  1031. NK_INTERN void nk_glfw3_destroy_render_resources(struct nk_glfw_device *dev) {
  1032. uint32_t i;
  1033. vkDestroyPipeline(dev->logical_device, dev->pipeline, NULL);
  1034. vkDestroyPipelineLayout(dev->logical_device, dev->pipeline_layout, NULL);
  1035. vkDestroyDescriptorSetLayout(dev->logical_device,
  1036. dev->texture_descriptor_set_layout, NULL);
  1037. vkDestroyDescriptorSetLayout(dev->logical_device,
  1038. dev->uniform_descriptor_set_layout, NULL);
  1039. vkDestroyDescriptorPool(dev->logical_device, dev->descriptor_pool, NULL);
  1040. for (i = 0; i < dev->framebuffers_len; i++) {
  1041. vkDestroyFramebuffer(dev->logical_device, dev->framebuffers[i], NULL);
  1042. }
  1043. free(dev->framebuffers);
  1044. dev->framebuffers_len = 0;
  1045. free(dev->texture_descriptor_sets);
  1046. dev->texture_descriptor_sets_len = 0;
  1047. vkDestroyRenderPass(dev->logical_device, dev->render_pass, NULL);
  1048. }
  1049. NK_API void nk_glfw3_resize(uint32_t framebuffer_width,
  1050. uint32_t framebuffer_height) {
  1051. struct nk_glfw_device *dev = &glfw.vulkan;
  1052. glfwGetWindowSize(glfw.win, &glfw.width, &glfw.height);
  1053. glfwGetFramebufferSize(glfw.win, &glfw.display_width, &glfw.display_height);
  1054. nk_glfw3_destroy_render_resources(dev);
  1055. nk_glfw3_create_render_resources(dev, framebuffer_width,
  1056. framebuffer_height);
  1057. }
  1058. NK_API void nk_glfw3_device_destroy(void) {
  1059. struct nk_glfw_device *dev = &glfw.vulkan;
  1060. vkDeviceWaitIdle(dev->logical_device);
  1061. nk_glfw3_destroy_render_resources(dev);
  1062. vkFreeCommandBuffers(dev->logical_device, dev->command_pool,
  1063. dev->command_buffers_len, dev->command_buffers);
  1064. vkDestroyCommandPool(dev->logical_device, dev->command_pool, NULL);
  1065. vkDestroySemaphore(dev->logical_device, dev->render_completed, NULL);
  1066. vkUnmapMemory(dev->logical_device, dev->vertex_memory);
  1067. vkUnmapMemory(dev->logical_device, dev->index_memory);
  1068. vkUnmapMemory(dev->logical_device, dev->uniform_memory);
  1069. vkFreeMemory(dev->logical_device, dev->vertex_memory, NULL);
  1070. vkFreeMemory(dev->logical_device, dev->index_memory, NULL);
  1071. vkFreeMemory(dev->logical_device, dev->uniform_memory, NULL);
  1072. vkDestroyBuffer(dev->logical_device, dev->vertex_buffer, NULL);
  1073. vkDestroyBuffer(dev->logical_device, dev->index_buffer, NULL);
  1074. vkDestroyBuffer(dev->logical_device, dev->uniform_buffer, NULL);
  1075. vkDestroySampler(dev->logical_device, dev->sampler, NULL);
  1076. vkFreeMemory(dev->logical_device, dev->font_memory, NULL);
  1077. vkDestroyImage(dev->logical_device, dev->font_image, NULL);
  1078. vkDestroyImageView(dev->logical_device, dev->font_image_view, NULL);
  1079. free(dev->command_buffers);
  1080. nk_buffer_free(&dev->cmds);
  1081. }
  1082. NK_API
  1083. void nk_glfw3_shutdown(void) {
  1084. nk_font_atlas_clear(&glfw.atlas);
  1085. nk_free(&glfw.ctx);
  1086. nk_glfw3_device_destroy();
  1087. memset(&glfw, 0, sizeof(glfw));
  1088. }
  1089. NK_API void nk_glfw3_font_stash_begin(struct nk_font_atlas **atlas) {
  1090. nk_font_atlas_init_default(&glfw.atlas);
  1091. nk_font_atlas_begin(&glfw.atlas);
  1092. *atlas = &glfw.atlas;
  1093. }
  1094. NK_API void nk_glfw3_font_stash_end(VkQueue graphics_queue) {
  1095. struct nk_glfw_device *dev = &glfw.vulkan;
  1096. const void *image;
  1097. int w, h;
  1098. image = nk_font_atlas_bake(&glfw.atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
  1099. nk_glfw3_device_upload_atlas(graphics_queue, image, w, h);
  1100. nk_font_atlas_end(&glfw.atlas, nk_handle_ptr(dev->font_image_view),
  1101. &dev->tex_null);
  1102. if (glfw.atlas.default_font) {
  1103. nk_style_set_font(&glfw.ctx, &glfw.atlas.default_font->handle);
  1104. }
  1105. }
  1106. NK_API void nk_glfw3_new_frame(void) {
  1107. int i;
  1108. double x, y;
  1109. struct nk_context *ctx = &glfw.ctx;
  1110. struct GLFWwindow *win = glfw.win;
  1111. nk_char* k_state = glfw.key_events;
  1112. /* update the timer */
  1113. float delta_time_now = (float)glfwGetTime();
  1114. glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
  1115. glfw.delta_time_seconds_last = delta_time_now;
  1116. glfwGetWindowSize(win, &glfw.width, &glfw.height);
  1117. glfwGetFramebufferSize(win, &glfw.display_width, &glfw.display_height);
  1118. glfw.fb_scale.x = (float)glfw.display_width/(float)glfw.width;
  1119. glfw.fb_scale.y = (float)glfw.display_height/(float)glfw.height;
  1120. nk_input_begin(ctx);
  1121. for (i = 0; i < glfw.text_len; ++i)
  1122. nk_input_unicode(ctx, glfw.text[i]);
  1123. #ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
  1124. /* optional grabbing behavior */
  1125. if (ctx->input.mouse.grab)
  1126. glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
  1127. else if (ctx->input.mouse.ungrab)
  1128. glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
  1129. #endif
  1130. if (k_state[NK_KEY_DEL] >= 0) nk_input_key(ctx, NK_KEY_DEL, k_state[NK_KEY_DEL]);
  1131. if (k_state[NK_KEY_ENTER] >= 0) nk_input_key(ctx, NK_KEY_ENTER, k_state[NK_KEY_ENTER]);
  1132. if (k_state[NK_KEY_TEXT_RESET_MODE] >= 0) nk_input_key(ctx, NK_KEY_TEXT_RESET_MODE, k_state[NK_KEY_TEXT_RESET_MODE]);
  1133. if (k_state[NK_KEY_TAB] >= 0) nk_input_key(ctx, NK_KEY_TAB, k_state[NK_KEY_TAB]);
  1134. if (k_state[NK_KEY_BACKSPACE] >= 0) nk_input_key(ctx, NK_KEY_BACKSPACE, k_state[NK_KEY_BACKSPACE]);
  1135. if (k_state[NK_KEY_UP] >= 0) nk_input_key(ctx, NK_KEY_UP, k_state[NK_KEY_UP]);
  1136. if (k_state[NK_KEY_DOWN] >= 0) nk_input_key(ctx, NK_KEY_DOWN, k_state[NK_KEY_DOWN]);
  1137. if (k_state[NK_KEY_SCROLL_UP] >= 0) nk_input_key(ctx, NK_KEY_SCROLL_UP, k_state[NK_KEY_SCROLL_UP]);
  1138. if (k_state[NK_KEY_SCROLL_DOWN] >= 0) nk_input_key(ctx, NK_KEY_SCROLL_DOWN, k_state[NK_KEY_SCROLL_DOWN]);
  1139. if (k_state[NK_KEY_TEXT_INSERT_MODE] >= 0) nk_input_key(ctx, NK_KEY_TEXT_INSERT_MODE, k_state[NK_KEY_TEXT_INSERT_MODE]);
  1140. if (k_state[NK_KEY_TEXT_REPLACE_MODE] >= 0) nk_input_key(ctx, NK_KEY_TEXT_REPLACE_MODE, k_state[NK_KEY_TEXT_REPLACE_MODE]);
  1141. nk_input_key(ctx, NK_KEY_TEXT_START, glfwGetKey(win, GLFW_KEY_HOME) == GLFW_PRESS);
  1142. nk_input_key(ctx, NK_KEY_TEXT_END, glfwGetKey(win, GLFW_KEY_END) == GLFW_PRESS);
  1143. nk_input_key(ctx, NK_KEY_SCROLL_START, glfwGetKey(win, GLFW_KEY_HOME) == GLFW_PRESS);
  1144. nk_input_key(ctx, NK_KEY_SCROLL_END, glfwGetKey(win, GLFW_KEY_END) == GLFW_PRESS);
  1145. nk_input_key(ctx, NK_KEY_SHIFT, glfwGetKey(win, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS||
  1146. glfwGetKey(win, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS);
  1147. if (glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
  1148. glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS) {
  1149. /* Note these are physical keys and won't respect any layouts/key mapping */
  1150. if (k_state[NK_KEY_COPY] >= 0) nk_input_key(ctx, NK_KEY_COPY, k_state[NK_KEY_COPY]);
  1151. if (k_state[NK_KEY_PASTE] >= 0) nk_input_key(ctx, NK_KEY_PASTE, k_state[NK_KEY_PASTE]);
  1152. if (k_state[NK_KEY_CUT] >= 0) nk_input_key(ctx, NK_KEY_CUT, k_state[NK_KEY_CUT]);
  1153. if (k_state[NK_KEY_TEXT_UNDO] >= 0) nk_input_key(ctx, NK_KEY_TEXT_UNDO, k_state[NK_KEY_TEXT_UNDO]);
  1154. if (k_state[NK_KEY_TEXT_REDO] >= 0) nk_input_key(ctx, NK_KEY_TEXT_REDO, k_state[NK_KEY_TEXT_REDO]);
  1155. if (k_state[NK_KEY_TEXT_LINE_START] >= 0) nk_input_key(ctx, NK_KEY_TEXT_LINE_START, k_state[NK_KEY_TEXT_LINE_START]);
  1156. if (k_state[NK_KEY_TEXT_LINE_END] >= 0) nk_input_key(ctx, NK_KEY_TEXT_LINE_END, k_state[NK_KEY_TEXT_LINE_END]);
  1157. if (k_state[NK_KEY_TEXT_SELECT_ALL] >= 0) nk_input_key(ctx, NK_KEY_TEXT_SELECT_ALL, k_state[NK_KEY_TEXT_SELECT_ALL]);
  1158. if (k_state[NK_KEY_LEFT] >= 0) nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, k_state[NK_KEY_LEFT]);
  1159. if (k_state[NK_KEY_RIGHT] >= 0) nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, k_state[NK_KEY_RIGHT]);
  1160. } else {
  1161. if (k_state[NK_KEY_LEFT] >= 0) nk_input_key(ctx, NK_KEY_LEFT, k_state[NK_KEY_LEFT]);
  1162. if (k_state[NK_KEY_RIGHT] >= 0) nk_input_key(ctx, NK_KEY_RIGHT, k_state[NK_KEY_RIGHT]);
  1163. nk_input_key(ctx, NK_KEY_COPY, 0);
  1164. nk_input_key(ctx, NK_KEY_PASTE, 0);
  1165. nk_input_key(ctx, NK_KEY_CUT, 0);
  1166. }
  1167. glfwGetCursorPos(win, &x, &y);
  1168. nk_input_motion(ctx, (int)x, (int)y);
  1169. #ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
  1170. if (ctx->input.mouse.grabbed) {
  1171. glfwSetCursorPos(glfw.win, ctx->input.mouse.prev.x,
  1172. ctx->input.mouse.prev.y);
  1173. ctx->input.mouse.pos.x = ctx->input.mouse.prev.x;
  1174. ctx->input.mouse.pos.y = ctx->input.mouse.prev.y;
  1175. }
  1176. #endif
  1177. nk_input_button(ctx, NK_BUTTON_LEFT, (int)x, (int)y,
  1178. glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT) ==
  1179. GLFW_PRESS);
  1180. nk_input_button(ctx, NK_BUTTON_MIDDLE, (int)x, (int)y,
  1181. glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_MIDDLE) ==
  1182. GLFW_PRESS);
  1183. nk_input_button(ctx, NK_BUTTON_RIGHT, (int)x, (int)y,
  1184. glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_RIGHT) ==
  1185. GLFW_PRESS);
  1186. nk_input_button(ctx, NK_BUTTON_DOUBLE, (int)glfw.double_click_pos.x,
  1187. (int)glfw.double_click_pos.y, glfw.is_double_click_down);
  1188. nk_input_scroll(ctx, glfw.scroll);
  1189. nk_input_end(&glfw.ctx);
  1190. /* clear after nk_input_end (-1 since we're doing up/down boolean) */
  1191. memset(glfw.key_events, -1, sizeof(glfw.key_events));
  1192. glfw.text_len = 0;
  1193. glfw.scroll = nk_vec2(0, 0);
  1194. }
  1195. NK_INTERN void update_texture_descriptor_set(
  1196. struct nk_glfw_device *dev,
  1197. struct nk_vulkan_texture_descriptor_set *texture_descriptor_set,
  1198. VkImageView image_view) {
  1199. VkDescriptorImageInfo descriptor_image_info;
  1200. VkWriteDescriptorSet descriptor_write;
  1201. texture_descriptor_set->image_view = image_view;
  1202. memset(&descriptor_image_info, 0, sizeof(VkDescriptorImageInfo));
  1203. descriptor_image_info.sampler = dev->sampler;
  1204. descriptor_image_info.imageView = texture_descriptor_set->image_view;
  1205. descriptor_image_info.imageLayout =
  1206. VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
  1207. memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
  1208. descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
  1209. descriptor_write.dstSet = texture_descriptor_set->descriptor_set;
  1210. descriptor_write.dstBinding = 0;
  1211. descriptor_write.dstArrayElement = 0;
  1212. descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
  1213. descriptor_write.descriptorCount = 1;
  1214. descriptor_write.pImageInfo = &descriptor_image_info;
  1215. vkUpdateDescriptorSets(dev->logical_device, 1, &descriptor_write, 0, NULL);
  1216. }
  1217. NK_API
  1218. VkSemaphore nk_glfw3_render(VkQueue graphics_queue, uint32_t buffer_index,
  1219. VkSemaphore wait_semaphore,
  1220. enum nk_anti_aliasing AA) {
  1221. struct nk_glfw_device *dev = &glfw.vulkan;
  1222. struct nk_buffer vbuf, ebuf;
  1223. struct Mat4f projection = {
  1224. {2.0f, 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f,
  1225. 0.0f, -1.0f, 1.0f, 0.0f, 1.0f},
  1226. };
  1227. VkCommandBufferBeginInfo begin_info;
  1228. VkClearValue clear_value = {{{0.0f, 0.0f, 0.0f, 0.0f}}};
  1229. VkRenderPassBeginInfo render_pass_begin_nfo;
  1230. VkCommandBuffer command_buffer;
  1231. VkResult result;
  1232. VkViewport viewport;
  1233. VkDeviceSize doffset = 0;
  1234. VkImageView current_texture = NULL;
  1235. uint32_t index_offset = 0;
  1236. VkRect2D scissor;
  1237. uint32_t wait_semaphore_count;
  1238. VkSemaphore *wait_semaphores;
  1239. VkPipelineStageFlags wait_stage =
  1240. VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
  1241. VkSubmitInfo submit_info;
  1242. projection.m[0] /= glfw.width;
  1243. projection.m[5] /= glfw.height;
  1244. memcpy(dev->mapped_uniform, &projection, sizeof(projection));
  1245. memset(&begin_info, 0, sizeof(VkCommandBufferBeginInfo));
  1246. begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
  1247. memset(&render_pass_begin_nfo, 0, sizeof(VkRenderPassBeginInfo));
  1248. render_pass_begin_nfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
  1249. render_pass_begin_nfo.renderPass = dev->render_pass;
  1250. render_pass_begin_nfo.renderArea.extent.width = (uint32_t)glfw.width;
  1251. render_pass_begin_nfo.renderArea.extent.height = (uint32_t)glfw.height;
  1252. render_pass_begin_nfo.clearValueCount = 1;
  1253. render_pass_begin_nfo.pClearValues = &clear_value;
  1254. render_pass_begin_nfo.framebuffer = dev->framebuffers[buffer_index];
  1255. command_buffer = dev->command_buffers[buffer_index];
  1256. result = vkBeginCommandBuffer(command_buffer, &begin_info);
  1257. NK_ASSERT(result == VK_SUCCESS);
  1258. vkCmdBeginRenderPass(command_buffer, &render_pass_begin_nfo,
  1259. VK_SUBPASS_CONTENTS_INLINE);
  1260. memset(&viewport, 0, sizeof(VkViewport));
  1261. viewport.width = (float)glfw.width;
  1262. viewport.height = (float)glfw.height;
  1263. viewport.maxDepth = 1.0f;
  1264. vkCmdSetViewport(command_buffer, 0, 1, &viewport);
  1265. vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
  1266. dev->pipeline);
  1267. vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
  1268. dev->pipeline_layout, 0, 1,
  1269. &dev->uniform_descriptor_set, 0, NULL);
  1270. {
  1271. /* convert from command queue into draw list and draw to screen */
  1272. const struct nk_draw_command *cmd;
  1273. /* load draw vertices & elements directly into vertex + element buffer
  1274. */
  1275. {
  1276. /* fill convert configuration */
  1277. struct nk_convert_config config;
  1278. static const struct nk_draw_vertex_layout_element vertex_layout[] =
  1279. {{NK_VERTEX_POSITION, NK_FORMAT_FLOAT,
  1280. NK_OFFSETOF(struct nk_glfw_vertex, position)},
  1281. {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT,
  1282. NK_OFFSETOF(struct nk_glfw_vertex, uv)},
  1283. {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8,
  1284. NK_OFFSETOF(struct nk_glfw_vertex, col)},
  1285. {NK_VERTEX_LAYOUT_END}};
  1286. NK_MEMSET(&config, 0, sizeof(config));
  1287. config.vertex_layout = vertex_layout;
  1288. config.vertex_size = sizeof(struct nk_glfw_vertex);
  1289. config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
  1290. config.tex_null = dev->tex_null;
  1291. config.circle_segment_count = 22;
  1292. config.curve_segment_count = 22;
  1293. config.arc_segment_count = 22;
  1294. config.global_alpha = 1.0f;
  1295. config.shape_AA = AA;
  1296. config.line_AA = AA;
  1297. /* setup buffers to load vertices and elements */
  1298. nk_buffer_init_fixed(&vbuf, dev->mapped_vertex,
  1299. (size_t)dev->max_vertex_buffer);
  1300. nk_buffer_init_fixed(&ebuf, dev->mapped_index,
  1301. (size_t)dev->max_element_buffer);
  1302. nk_convert(&glfw.ctx, &dev->cmds, &vbuf, &ebuf, &config);
  1303. }
  1304. /* iterate over and execute each draw command */
  1305. vkCmdBindVertexBuffers(command_buffer, 0, 1, &dev->vertex_buffer,
  1306. &doffset);
  1307. vkCmdBindIndexBuffer(command_buffer, dev->index_buffer, 0,
  1308. VK_INDEX_TYPE_UINT16);
  1309. nk_draw_foreach(cmd, &glfw.ctx, &dev->cmds) {
  1310. if (!cmd->texture.ptr) {
  1311. continue;
  1312. }
  1313. if (cmd->texture.ptr && cmd->texture.ptr != current_texture) {
  1314. int found = 0;
  1315. uint32_t i;
  1316. for (i = 0; i < dev->texture_descriptor_sets_len; i++) {
  1317. if (dev->texture_descriptor_sets[i].image_view ==
  1318. cmd->texture.ptr) {
  1319. found = 1;
  1320. break;
  1321. }
  1322. }
  1323. if (!found) {
  1324. update_texture_descriptor_set(
  1325. dev, &dev->texture_descriptor_sets[i],
  1326. (VkImageView)cmd->texture.ptr);
  1327. dev->texture_descriptor_sets_len++;
  1328. }
  1329. vkCmdBindDescriptorSets(
  1330. command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
  1331. dev->pipeline_layout, 1, 1,
  1332. &dev->texture_descriptor_sets[i].descriptor_set, 0, NULL);
  1333. }
  1334. if (!cmd->elem_count)
  1335. continue;
  1336. scissor.offset.x = (int32_t)(NK_MAX(cmd->clip_rect.x, 0.f) * glfw.fb_scale.x);
  1337. scissor.offset.y = (int32_t)(NK_MAX(cmd->clip_rect.y, 0.f) * glfw.fb_scale.y);
  1338. scissor.extent.width = (uint32_t)(cmd->clip_rect.w * glfw.fb_scale.x);
  1339. scissor.extent.height = (uint32_t)(cmd->clip_rect.h * glfw.fb_scale.y);
  1340. vkCmdSetScissor(command_buffer, 0, 1, &scissor);
  1341. vkCmdDrawIndexed(command_buffer, cmd->elem_count, 1, index_offset,
  1342. 0, 0);
  1343. index_offset += cmd->elem_count;
  1344. }
  1345. nk_clear(&glfw.ctx);
  1346. }
  1347. vkCmdEndRenderPass(command_buffer);
  1348. result = vkEndCommandBuffer(command_buffer);
  1349. NK_ASSERT(result == VK_SUCCESS);
  1350. if (wait_semaphore) {
  1351. wait_semaphore_count = 1;
  1352. wait_semaphores = &wait_semaphore;
  1353. } else {
  1354. wait_semaphore_count = 0;
  1355. wait_semaphores = NULL;
  1356. }
  1357. memset(&submit_info, 0, sizeof(VkSubmitInfo));
  1358. submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
  1359. submit_info.commandBufferCount = 1;
  1360. submit_info.pCommandBuffers = &command_buffer;
  1361. submit_info.pWaitDstStageMask = &wait_stage;
  1362. submit_info.waitSemaphoreCount = wait_semaphore_count;
  1363. submit_info.pWaitSemaphores = wait_semaphores;
  1364. submit_info.signalSemaphoreCount = 1;
  1365. submit_info.pSignalSemaphores = &dev->render_completed;
  1366. result = vkQueueSubmit(graphics_queue, 1, &submit_info, NULL);
  1367. NK_ASSERT(result == VK_SUCCESS);
  1368. return dev->render_completed;
  1369. }
  1370. NK_API void nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint) {
  1371. (void)win;
  1372. if (glfw.text_len < NK_GLFW_TEXT_MAX)
  1373. glfw.text[glfw.text_len++] = codepoint;
  1374. }
  1375. NK_API void
  1376. nk_glfw3_key_callback(GLFWwindow *win, int key, int scancode, int action, int mods)
  1377. {
  1378. static int insert_toggle = 0;
  1379. /*
  1380. * convert GLFW_REPEAT to down (technically GLFW_RELEASE, GLFW_PRESS, GLFW_REPEAT are
  1381. * already 0, 1, 2 but just to be clearer)
  1382. */
  1383. nk_char a = (action == GLFW_RELEASE) ? nk_false : nk_true;
  1384. NK_UNUSED(win);
  1385. NK_UNUSED(scancode);
  1386. NK_UNUSED(mods);
  1387. switch (key) {
  1388. case GLFW_KEY_DELETE: glfw.key_events[NK_KEY_DEL] = a; break;
  1389. case GLFW_KEY_TAB: glfw.key_events[NK_KEY_TAB] = a; break;
  1390. case GLFW_KEY_BACKSPACE: glfw.key_events[NK_KEY_BACKSPACE] = a; break;
  1391. case GLFW_KEY_UP: glfw.key_events[NK_KEY_UP] = a; break;
  1392. case GLFW_KEY_DOWN: glfw.key_events[NK_KEY_DOWN] = a; break;
  1393. case GLFW_KEY_LEFT: glfw.key_events[NK_KEY_LEFT] = a; break;
  1394. case GLFW_KEY_RIGHT: glfw.key_events[NK_KEY_RIGHT] = a; break;
  1395. case GLFW_KEY_ESCAPE: glfw.key_events[NK_KEY_TEXT_RESET_MODE] = a; break;
  1396. case GLFW_KEY_PAGE_UP: glfw.key_events[NK_KEY_SCROLL_UP] = a; break;
  1397. case GLFW_KEY_PAGE_DOWN: glfw.key_events[NK_KEY_SCROLL_DOWN] = a; break;
  1398. /* have to add all keys used for nuklear to get correct repeat behavior
  1399. * NOTE these are scancodes so your custom layout won't matter unfortunately
  1400. * Also while including everything will prevent unnecessary input calls,
  1401. * only the ones with visible effects really matter, ie paste, undo, redo
  1402. * selecting all, copying or cutting 40 times before you release the keys
  1403. * doesn't actually cause any visible problems */
  1404. case GLFW_KEY_C: glfw.key_events[NK_KEY_COPY] = a; break;
  1405. case GLFW_KEY_V: glfw.key_events[NK_KEY_PASTE] = a; break;
  1406. case GLFW_KEY_X: glfw.key_events[NK_KEY_CUT] = a; break;
  1407. case GLFW_KEY_Z: glfw.key_events[NK_KEY_TEXT_UNDO] = a; break;
  1408. case GLFW_KEY_R: glfw.key_events[NK_KEY_TEXT_REDO] = a; break;
  1409. case GLFW_KEY_B: glfw.key_events[NK_KEY_TEXT_LINE_START] = a; break;
  1410. case GLFW_KEY_E: glfw.key_events[NK_KEY_TEXT_LINE_END] = a; break;
  1411. case GLFW_KEY_A: glfw.key_events[NK_KEY_TEXT_SELECT_ALL] = a; break;
  1412. case GLFW_KEY_ENTER:
  1413. case GLFW_KEY_KP_ENTER:
  1414. glfw.key_events[NK_KEY_ENTER] = a;
  1415. break;
  1416. case GLFW_KEY_INSERT:
  1417. /* Only switch on release to avoid repeat issues
  1418. * kind of confusing since we have to negate it but we're already
  1419. * hacking it since Nuklear treats them as two separate keys rather
  1420. * than a single toggle state */
  1421. if (!a) {
  1422. insert_toggle = !insert_toggle;
  1423. if (insert_toggle) {
  1424. glfw.key_events[NK_KEY_TEXT_INSERT_MODE] = !a;
  1425. /* glfw.key_events[NK_KEY_TEXT_REPLACE_MODE] = a; */
  1426. } else {
  1427. /* glfw.key_events[NK_KEY_TEXT_INSERT_MODE] = a; */
  1428. glfw.key_events[NK_KEY_TEXT_REPLACE_MODE] = !a;
  1429. }
  1430. }
  1431. break;
  1432. default:
  1433. ;
  1434. }
  1435. }
  1436. NK_API void nk_gflw3_scroll_callback(GLFWwindow *win, double xoff,
  1437. double yoff) {
  1438. (void)win;
  1439. (void)xoff;
  1440. glfw.scroll.x += (float)xoff;
  1441. glfw.scroll.y += (float)yoff;
  1442. }
  1443. NK_API void nk_glfw3_mouse_button_callback(GLFWwindow *window, int button,
  1444. int action, int mods) {
  1445. double x, y;
  1446. NK_UNUSED(mods);
  1447. if (button != GLFW_MOUSE_BUTTON_LEFT)
  1448. return;
  1449. glfwGetCursorPos(window, &x, &y);
  1450. if (action == GLFW_PRESS) {
  1451. double dt = glfwGetTime() - glfw.last_button_click;
  1452. if (dt > NK_GLFW_DOUBLE_CLICK_LO && dt < NK_GLFW_DOUBLE_CLICK_HI) {
  1453. glfw.is_double_click_down = nk_true;
  1454. glfw.double_click_pos = nk_vec2((float)x, (float)y);
  1455. }
  1456. glfw.last_button_click = glfwGetTime();
  1457. } else
  1458. glfw.is_double_click_down = nk_false;
  1459. }
  1460. NK_INTERN void nk_glfw3_clipboard_paste(nk_handle usr,
  1461. struct nk_text_edit *edit) {
  1462. const char *text = glfwGetClipboardString(glfw.win);
  1463. if (text)
  1464. nk_textedit_paste(edit, text, nk_strlen(text));
  1465. (void)usr;
  1466. }
  1467. NK_INTERN void nk_glfw3_clipboard_copy(nk_handle usr, const char *text,
  1468. int len) {
  1469. char *str = 0;
  1470. (void)usr;
  1471. if (!len)
  1472. return;
  1473. str = (char *)malloc((size_t)len + 1);
  1474. if (!str)
  1475. return;
  1476. memcpy(str, text, (size_t)len);
  1477. str[len] = '\0';
  1478. glfwSetClipboardString(glfw.win, str);
  1479. free(str);
  1480. }
  1481. NK_API struct nk_context *
  1482. nk_glfw3_init(GLFWwindow *win, VkDevice logical_device,
  1483. VkPhysicalDevice physical_device,
  1484. uint32_t graphics_queue_family_index, VkImageView *image_views,
  1485. uint32_t image_views_len, VkFormat color_format,
  1486. enum nk_glfw_init_state init_state,
  1487. VkDeviceSize max_vertex_buffer, VkDeviceSize max_element_buffer) {
  1488. memset(&glfw, 0, sizeof(struct nk_glfw));
  1489. glfw.win = win;
  1490. if (init_state == NK_GLFW3_INSTALL_CALLBACKS) {
  1491. glfwSetScrollCallback(win, nk_gflw3_scroll_callback);
  1492. glfwSetCharCallback(win, nk_glfw3_char_callback);
  1493. glfwSetKeyCallback(win, nk_glfw3_key_callback);
  1494. glfwSetMouseButtonCallback(win, nk_glfw3_mouse_button_callback);
  1495. }
  1496. nk_init_default(&glfw.ctx, 0);
  1497. glfw.ctx.clip.copy = nk_glfw3_clipboard_copy;
  1498. glfw.ctx.clip.paste = nk_glfw3_clipboard_paste;
  1499. glfw.ctx.clip.userdata = nk_handle_ptr(0);
  1500. glfw.last_button_click = 0;
  1501. glfwGetWindowSize(win, &glfw.width, &glfw.height);
  1502. glfwGetFramebufferSize(win, &glfw.display_width, &glfw.display_height);
  1503. nk_glfw3_device_create(logical_device, physical_device,
  1504. graphics_queue_family_index, image_views,
  1505. image_views_len, color_format, max_vertex_buffer,
  1506. max_element_buffer, (uint32_t)glfw.display_width,
  1507. (uint32_t)glfw.display_height);
  1508. glfw.is_double_click_down = nk_false;
  1509. glfw.double_click_pos = nk_vec2(0, 0);
  1510. return &glfw.ctx;
  1511. }
  1512. #endif