sokol_spritebatch.h 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306
  1. #if defined(SOKOL_IMPL) && !defined(SOKOL_SPRITEBATCH_IMPL)
  2. #define SOKOL_SPRITEBATCH_IMPL
  3. #endif
  4. #ifndef SOKOL_SPRITEBATCH_INCLUDED
  5. #define SOKOL_SPRITEBATCH_INCLUDED (1)
  6. #if !defined(SOKOL_GFX_INCLUDED)
  7. #error "Please include sokol_gfx.h before sokol_spritebatch.h"
  8. #endif
  9. #if defined(SOKOL_API_DECL) && !defined(SOKOL_SPRITEBATCH_API_DECL)
  10. #define SOKOL_SPRITEBATCH_API_DECL SOKOL_API_DECL
  11. #endif
  12. #ifndef SOKOL_SPRITEBATCH_API_DECL
  13. #if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_SPRITEBATCH_IMPL)
  14. #define SOKOL_SPRITEBATCH_API_DECL __declspec(dllexport)
  15. #elif defined(_WIN32) && defined(SOKOL_DLL)
  16. #define SOKOL_SPRITEBATCH_API_DECL __declspec(dllimport)
  17. #else
  18. #define SOKOL_SPRITEBATCH_API_DECL extern
  19. #endif
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. typedef enum sbatch_sprite_flags {
  25. SBATCH_FLIP_NONE = 0,
  26. SBATCH_FLIP_X = 1 << 0,
  27. SBATCH_FLIP_Y = 1 << 1,
  28. SBATCH_FLIP_BOTH = SBATCH_FLIP_Y | SBATCH_FLIP_X
  29. } sbatch_sprite_flags;
  30. typedef struct sbatch_float2 {
  31. float x;
  32. float y;
  33. } sbatch_float2;
  34. typedef struct sbatch_rect {
  35. float x;
  36. float y;
  37. float width;
  38. float height;
  39. } sbatch_rect;
  40. typedef struct sbatch_sprite {
  41. sg_image image;
  42. sbatch_float2 position;
  43. sbatch_rect source;
  44. const sg_color* color;
  45. float rotation;
  46. sbatch_float2 origin;
  47. sbatch_float2 scale;
  48. uint32_t flags;
  49. float depth;
  50. } sbatch_sprite;
  51. typedef struct sbatch_sprite_rect {
  52. sg_image image;
  53. sbatch_rect destination;
  54. sbatch_rect source;
  55. const sg_color* color;
  56. float rotation;
  57. sbatch_float2 origin;
  58. uint32_t flags;
  59. float depth;
  60. } sbatch_sprite_rect;
  61. typedef struct sbatch_desc {
  62. int context_pool_size;
  63. int pipeline_pool_size;
  64. sg_pixel_format color_format;
  65. sg_pixel_format depth_format;
  66. int sample_count;
  67. } sbatch_desc;
  68. typedef struct sbatch_context {
  69. uint32_t id;
  70. } sbatch_context;
  71. typedef struct sbatch_pipeline {
  72. uint32_t id;
  73. } sbatch_pipeline;
  74. typedef struct sbatch_context_desc {
  75. int canvas_width;
  76. int canvas_height;
  77. int max_sprites;
  78. sbatch_pipeline pipeline;
  79. const char* label;
  80. } sbatch_context_desc;
  81. SOKOL_SPRITEBATCH_API_DECL void sbatch_setup(const sbatch_desc* desc);
  82. SOKOL_SPRITEBATCH_API_DECL void sbatch_shutdown(void);
  83. SOKOL_SPRITEBATCH_API_DECL int sbatch_frame();
  84. SOKOL_SPRITEBATCH_API_DECL sbatch_pipeline sbatch_make_pipeline(const sg_pipeline_desc* desc);
  85. SOKOL_SPRITEBATCH_API_DECL void sbatch_destroy_pipeline(sbatch_pipeline context);
  86. SOKOL_SPRITEBATCH_API_DECL sbatch_context sbatch_make_context(const sbatch_context_desc* desc);
  87. SOKOL_SPRITEBATCH_API_DECL void sbatch_destroy_context(sbatch_context context);
  88. SOKOL_SPRITEBATCH_API_DECL void sbatch_begin(sbatch_context context);
  89. SOKOL_SPRITEBATCH_API_DECL void sbatch_push_sprite(const sbatch_sprite* sprite);
  90. SOKOL_SPRITEBATCH_API_DECL void sbatch_push_sprite_rect(const sbatch_sprite_rect* sprite);
  91. SOKOL_SPRITEBATCH_API_DECL void sbatch_end(void);
  92. SOKOL_SPRITEBATCH_API_DECL void sbatch_apply_fs_uniforms(int ub_index, const sg_range* data);
  93. SOKOL_SPRITEBATCH_API_DECL void sbatch_premultiply_alpha_rgba8(uint8_t* pixels, int pixel_count);
  94. #ifdef __cplusplus
  95. } /* extern "C" */
  96. #endif
  97. #endif /* SOKOL_SPRITEBATCH_INCLUDED */
  98. /*-- IMPLEMENTATION ----------------------------------------------------------*/
  99. #ifdef SOKOL_SPRITEBATCH_IMPL
  100. #define SOKOL_SPRITEBATCH_IMPL_INCLUDED (1)
  101. #include <string.h> /* memset */
  102. #include <math.h> /* sinf, cosf */
  103. #ifndef SOKOL_API_IMPL
  104. #define SOKOL_API_IMPL
  105. #endif
  106. #ifndef SOKOL_ASSERT
  107. #include <assert.h>
  108. #define SOKOL_ASSERT(c) assert(c)
  109. #endif
  110. #ifndef SOKOL_MALLOC
  111. #include <stdlib.h>
  112. #define SOKOL_MALLOC(s) malloc(s)
  113. #define SOKOL_FREE(result) free(result)
  114. #endif
  115. #ifndef SOKOL_DEBUG
  116. #ifndef NDEBUG
  117. #define SOKOL_DEBUG (1)
  118. #endif
  119. #endif
  120. #ifndef SOKOL_LOG
  121. #ifdef SOKOL_DEBUG
  122. #include <stdio.h>
  123. #define SOKOL_LOG(s) { SOKOL_ASSERT(s); puts(s); }
  124. #else
  125. #define SOKOL_LOG(s)
  126. #endif
  127. #endif
  128. #define _SBATCH_IMAGE_SLOT_MASK (0xFFFF)
  129. #define _SBATCH_DEFAULT(val, def) (((val) == 0) ? (def) : (val))
  130. #define _SBATCH_MAX_VERTICES (1 << 16)
  131. #define _SBATCH_MAX_QUADS (_SBATCH_MAX_VERTICES / 4)
  132. #define _SBATCH_MAX_INDICES (_SBATCH_MAX_QUADS * 6)
  133. #define _SBATCH_INITIAL_BATCH_CAPACITY (32)
  134. #define _SBATCH_INVALID_SLOT_INDEX (0)
  135. #define _SBATCH_SLOT_SHIFT (16)
  136. #define _SBATCH_MAX_POOL_SIZE (1<<_SBATCH_SLOT_SHIFT)
  137. #define _SBATCH_SLOT_MASK (_SBATCH_MAX_POOL_SIZE-1)
  138. #define _SBATCH_STRBUF_LEN (96)
  139. typedef struct {
  140. float x;
  141. float y;
  142. float z;
  143. float u;
  144. float v;
  145. uint32_t rgba;
  146. } _sbatch_vertex;
  147. typedef struct {
  148. uint32_t id;
  149. sg_resource_state state;
  150. } _sbatch_slot;
  151. typedef struct {
  152. char buf[_SBATCH_STRBUF_LEN];
  153. } _sbatch_str;
  154. typedef struct _sbatch_fs_uniform_state {
  155. int ub_index;
  156. const sg_range* data;
  157. } _sbatch_fs_uniform_state;
  158. typedef struct {
  159. _sbatch_str label;
  160. _sbatch_slot slot;
  161. sbatch_context_desc desc;
  162. int sprite_count;
  163. _sbatch_vertex* vertices;
  164. sg_image* images;
  165. sg_buffer vertex_buffer;
  166. sbatch_pipeline pipeline;
  167. int update_frame_index;
  168. _sbatch_fs_uniform_state fs_uniform_state;
  169. } _sbatch_context;
  170. typedef struct {
  171. int size;
  172. int queue_top;
  173. uint32_t* gen_ctrs;
  174. int* free_queue;
  175. } _sbatch_pool;
  176. typedef struct {
  177. _sbatch_pool pool;
  178. _sbatch_context* contexts;
  179. } _sbatch_context_pool;
  180. typedef struct {
  181. _sbatch_str label;
  182. _sbatch_slot slot;
  183. sg_pipeline_desc desc;
  184. sg_pipeline pipeline;
  185. } _sbatch_pipeline;
  186. typedef struct {
  187. _sbatch_pool pool;
  188. _sbatch_pipeline* pipelines;
  189. } _sbatch_pipeline_pool;
  190. typedef struct {
  191. sg_image image;
  192. int width;
  193. int height;
  194. float texel_width;
  195. float texel_height;
  196. } _sbatch_sprite_data;
  197. typedef struct {
  198. _sbatch_sprite_data* data;
  199. size_t size;
  200. } _sbatch_sprite_pool;
  201. typedef struct {
  202. bool begin_called;
  203. _sbatch_slot slot;
  204. sg_bindings bindings;
  205. sg_shader shader;
  206. sbatch_pipeline pipeline;
  207. sbatch_context ctx_id;
  208. _sbatch_context_pool context_pool;
  209. _sbatch_pipeline_pool pipeline_pool;
  210. _sbatch_sprite_pool sprite_pool;
  211. sg_buffer index_buffer;
  212. int frame_index;
  213. } _sbatch_t;
  214. typedef struct {
  215. float m[4][4];
  216. } _sbatch_mat4x4;
  217. static _sbatch_t _sbatch;
  218. /*
  219. Embedded source code compiled with:
  220. sokol-shdc -i sgl.glsl -o sgl.h -l glsl330:glsl100:hlsl4:metal_macos:metal_ios:metal_sim:wgpu -b
  221. @vs vs
  222. uniform vs_params {
  223. mat4 mvp;
  224. };
  225. in vec3 pos;
  226. in vec2 texcoord0;
  227. in vec4 color0;
  228. out vec2 uv;
  229. out vec4 color;
  230. void main() {
  231. gl_Position = mvp * vec4(pos, 1.0f);
  232. uv = texcoord0;
  233. color = color0;
  234. }
  235. @end
  236. @fs fs
  237. uniform sampler2D tex;
  238. in vec2 uv;
  239. in vec4 color;
  240. out vec4 frag_color;
  241. void main() {
  242. frag_color = color * texture(tex, uv);
  243. }
  244. @end
  245. @program spritebatch vs fs
  246. */
  247. #include <stdint.h>
  248. #include <stdbool.h>
  249. #if !defined(SOKOL_SHDC_ALIGN)
  250. #if defined(_MSC_VER)
  251. #define SOKOL_SHDC_ALIGN(a) __declspec(align(a))
  252. #else
  253. #define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a)))
  254. #endif
  255. #endif
  256. #define ATTR_vs_pos (0)
  257. #define ATTR_vs_texcoord0 (1)
  258. #define ATTR_vs_color0 (2)
  259. #define SLOT_tex (0)
  260. #define SLOT_vs_params (0)
  261. #pragma pack(push,1)
  262. SOKOL_SHDC_ALIGN(16) typedef struct vs_params_t {
  263. float mvp[16];
  264. } vs_params_t;
  265. #pragma pack(pop)
  266. /*
  267. #version 330
  268. uniform vec4 vs_params[4];
  269. layout(location = 0) in vec3 pos;
  270. out vec2 uv;
  271. layout(location = 1) in vec2 texcoord0;
  272. out vec4 color;
  273. layout(location = 2) in vec4 color0;
  274. void main()
  275. {
  276. gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * vec4(pos, 1.0);
  277. uv = texcoord0;
  278. color = color0;
  279. }
  280. */
  281. static const char vs_source_glsl330[337] = {
  282. 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e,
  283. 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61,
  284. 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,
  285. 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,
  286. 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,
  287. 0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,
  288. 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,
  289. 0x76,0x65,0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,
  290. 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,
  291. 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,
  292. 0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,
  293. 0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,
  294. 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,
  295. 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61,
  296. 0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,
  297. 0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,
  298. 0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,
  299. 0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x70,0x6f,0x73,0x2c,0x20,0x31,
  300. 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74,0x65,
  301. 0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,
  302. 0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,
  303. 0x00,
  304. };
  305. /*
  306. #version 330
  307. uniform sampler2D tex;
  308. layout(location = 0) out vec4 frag_color;
  309. in vec4 color;
  310. in vec2 uv;
  311. void main()
  312. {
  313. frag_color = color * texture(tex, uv);
  314. }
  315. */
  316. static const char fs_source_glsl330[169] = {
  317. 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e,
  318. 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,
  319. 0x74,0x65,0x78,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,
  320. 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,
  321. 0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,
  322. 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,
  323. 0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,
  324. 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,
  325. 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,
  326. 0x20,0x2a,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x2c,0x20,
  327. 0x75,0x76,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
  328. };
  329. /*
  330. #version 100
  331. uniform vec4 vs_params[4];
  332. attribute vec3 pos;
  333. varying vec2 uv;
  334. attribute vec2 texcoord0;
  335. varying vec4 color;
  336. attribute vec4 color0;
  337. void main()
  338. {
  339. gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * vec4(pos, 1.0);
  340. uv = texcoord0;
  341. color = color0;
  342. }
  343. */
  344. static const char vs_source_glsl100[303] = {
  345. 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x31,0x30,0x30,0x0a,0x0a,0x75,0x6e,
  346. 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61,
  347. 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x61,0x74,0x74,0x72,0x69,0x62,0x75,
  348. 0x74,0x65,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x6f,0x73,0x3b,0x0a,0x76,0x61,0x72,
  349. 0x79,0x69,0x6e,0x67,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x61,0x74,
  350. 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x20,0x76,0x65,0x63,0x32,0x20,0x74,0x65,0x78,
  351. 0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x76,0x61,0x72,0x79,0x69,0x6e,0x67,0x20,
  352. 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x61,0x74,0x74,0x72,
  353. 0x69,0x62,0x75,0x74,0x65,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,
  354. 0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,
  355. 0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,
  356. 0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,
  357. 0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,
  358. 0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,
  359. 0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,
  360. 0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,
  361. 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63,
  362. 0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,
  363. 0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
  364. };
  365. /*
  366. #version 100
  367. precision mediump float;
  368. precision highp int;
  369. uniform highp sampler2D tex;
  370. varying highp vec4 color;
  371. varying highp vec2 uv;
  372. void main()
  373. {
  374. gl_FragData[0] = color * texture2D(tex, uv);
  375. }
  376. */
  377. static const char fs_source_glsl100[207] = {
  378. 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x31,0x30,0x30,0x0a,0x70,0x72,0x65,
  379. 0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d,0x70,0x20,0x66,
  380. 0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,
  381. 0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,
  382. 0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,
  383. 0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x3b,0x0a,0x0a,0x76,0x61,0x72,0x79,0x69,0x6e,
  384. 0x67,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,
  385. 0x6f,0x72,0x3b,0x0a,0x76,0x61,0x72,0x79,0x69,0x6e,0x67,0x20,0x68,0x69,0x67,0x68,
  386. 0x70,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,
  387. 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,
  388. 0x5f,0x46,0x72,0x61,0x67,0x44,0x61,0x74,0x61,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x63,
  389. 0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,
  390. 0x28,0x74,0x65,0x78,0x2c,0x20,0x75,0x76,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
  391. };
  392. /*
  393. cbuffer vs_params : register(b0)
  394. {
  395. row_major float4x4 _21_mvp : packoffset(c0);
  396. };
  397. static float4 gl_Position;
  398. static float3 pos;
  399. static float2 uv;
  400. static float2 texcoord0;
  401. static float4 color;
  402. static float4 color0;
  403. struct SPIRV_Cross_Input
  404. {
  405. float3 pos : TEXCOORD0;
  406. float2 texcoord0 : TEXCOORD1;
  407. float4 color0 : TEXCOORD2;
  408. };
  409. struct SPIRV_Cross_Output
  410. {
  411. float2 uv : TEXCOORD0;
  412. float4 color : TEXCOORD1;
  413. float4 gl_Position : SV_Position;
  414. };
  415. #line 18 "gfx.glsl"
  416. void vert_main()
  417. {
  418. #line 18 "gfx.glsl"
  419. gl_Position = mul(float4(pos, 1.0f), _21_mvp);
  420. #line 19 "gfx.glsl"
  421. uv = texcoord0;
  422. #line 20 "gfx.glsl"
  423. color = color0;
  424. }
  425. SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
  426. {
  427. pos = stage_input.pos;
  428. texcoord0 = stage_input.texcoord0;
  429. color0 = stage_input.color0;
  430. vert_main();
  431. SPIRV_Cross_Output stage_output;
  432. stage_output.gl_Position = gl_Position;
  433. stage_output.uv = uv;
  434. stage_output.color = color;
  435. return stage_output;
  436. }
  437. */
  438. static const uint8_t vs_bytecode_hlsl4[884] = {
  439. 0x44,0x58,0x42,0x43,0x5f,0x8c,0xaf,0xe1,0x5e,0x2d,0xba,0x0e,0x85,0xba,0xeb,0xc5,
  440. 0x0c,0x64,0x6d,0x0c,0x01,0x00,0x00,0x00,0x74,0x03,0x00,0x00,0x05,0x00,0x00,0x00,
  441. 0x34,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x58,0x01,0x00,0x00,0xc8,0x01,0x00,0x00,
  442. 0xf8,0x02,0x00,0x00,0x52,0x44,0x45,0x46,0xb8,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  443. 0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0x04,0xfe,0xff,
  444. 0x10,0x81,0x00,0x00,0x90,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  445. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  446. 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,
  447. 0x73,0x00,0xab,0xab,0x3c,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x60,0x00,0x00,0x00,
  448. 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,
  449. 0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x80,0x00,0x00,0x00,
  450. 0x00,0x00,0x00,0x00,0x5f,0x32,0x31,0x5f,0x6d,0x76,0x70,0x00,0x02,0x00,0x03,0x00,
  451. 0x04,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4d,0x69,0x63,0x72,
  452. 0x6f,0x73,0x6f,0x66,0x74,0x20,0x28,0x52,0x29,0x20,0x48,0x4c,0x53,0x4c,0x20,0x53,
  453. 0x68,0x61,0x64,0x65,0x72,0x20,0x43,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x72,0x20,0x31,
  454. 0x30,0x2e,0x31,0x00,0x49,0x53,0x47,0x4e,0x5c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
  455. 0x08,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  456. 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x00,0x00,0x50,0x00,0x00,0x00,
  457. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  458. 0x03,0x03,0x00,0x00,0x50,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  459. 0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x0f,0x0f,0x00,0x00,0x54,0x45,0x58,0x43,
  460. 0x4f,0x4f,0x52,0x44,0x00,0xab,0xab,0xab,0x4f,0x53,0x47,0x4e,0x68,0x00,0x00,0x00,
  461. 0x03,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  462. 0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0c,0x00,0x00,
  463. 0x50,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
  464. 0x01,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  465. 0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,
  466. 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x00,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,
  467. 0x74,0x69,0x6f,0x6e,0x00,0xab,0xab,0xab,0x53,0x48,0x44,0x52,0x28,0x01,0x00,0x00,
  468. 0x40,0x00,0x01,0x00,0x4a,0x00,0x00,0x00,0x59,0x00,0x00,0x04,0x46,0x8e,0x20,0x00,
  469. 0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x5f,0x00,0x00,0x03,0x72,0x10,0x10,0x00,
  470. 0x00,0x00,0x00,0x00,0x5f,0x00,0x00,0x03,0x32,0x10,0x10,0x00,0x01,0x00,0x00,0x00,
  471. 0x5f,0x00,0x00,0x03,0xf2,0x10,0x10,0x00,0x02,0x00,0x00,0x00,0x65,0x00,0x00,0x03,
  472. 0x32,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x65,0x00,0x00,0x03,0xf2,0x20,0x10,0x00,
  473. 0x01,0x00,0x00,0x00,0x67,0x00,0x00,0x04,0xf2,0x20,0x10,0x00,0x02,0x00,0x00,0x00,
  474. 0x01,0x00,0x00,0x00,0x68,0x00,0x00,0x02,0x01,0x00,0x00,0x00,0x36,0x00,0x00,0x05,
  475. 0x32,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x10,0x10,0x00,0x01,0x00,0x00,0x00,
  476. 0x36,0x00,0x00,0x05,0xf2,0x20,0x10,0x00,0x01,0x00,0x00,0x00,0x46,0x1e,0x10,0x00,
  477. 0x02,0x00,0x00,0x00,0x38,0x00,0x00,0x08,0xf2,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
  478. 0x56,0x15,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x8e,0x20,0x00,0x00,0x00,0x00,0x00,
  479. 0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x0a,0xf2,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
  480. 0x06,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x8e,0x20,0x00,0x00,0x00,0x00,0x00,
  481. 0x00,0x00,0x00,0x00,0x46,0x0e,0x10,0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,0x0a,
  482. 0xf2,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0xa6,0x1a,0x10,0x00,0x00,0x00,0x00,0x00,
  483. 0x46,0x8e,0x20,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x46,0x0e,0x10,0x00,
  484. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xf2,0x20,0x10,0x00,0x02,0x00,0x00,0x00,
  485. 0x46,0x0e,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x8e,0x20,0x00,0x00,0x00,0x00,0x00,
  486. 0x03,0x00,0x00,0x00,0x3e,0x00,0x00,0x01,0x53,0x54,0x41,0x54,0x74,0x00,0x00,0x00,
  487. 0x07,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,
  488. 0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  489. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  490. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  491. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
  492. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  493. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  494. 0x00,0x00,0x00,0x00,
  495. };
  496. /*
  497. Texture2D<float4> tex : register(t0);
  498. SamplerState _tex_sampler : register(s0);
  499. static float4 frag_color;
  500. static float4 color;
  501. static float2 uv;
  502. struct SPIRV_Cross_Input
  503. {
  504. float2 uv : TEXCOORD0;
  505. float4 color : TEXCOORD1;
  506. };
  507. struct SPIRV_Cross_Output
  508. {
  509. float4 frag_color : SV_Target0;
  510. };
  511. #line 14 "gfx.glsl"
  512. void frag_main()
  513. {
  514. #line 14 "gfx.glsl"
  515. frag_color = color * tex.Sample(_tex_sampler, uv);
  516. }
  517. SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
  518. {
  519. color = stage_input.color;
  520. uv = stage_input.uv;
  521. frag_main();
  522. SPIRV_Cross_Output stage_output;
  523. stage_output.frag_color = frag_color;
  524. return stage_output;
  525. }
  526. */
  527. static const uint8_t fs_bytecode_hlsl4[620] = {
  528. 0x44,0x58,0x42,0x43,0xd1,0x93,0x1f,0x1b,0x9d,0x70,0x90,0xeb,0xc2,0x7c,0x26,0x07,
  529. 0xdf,0x52,0xda,0x49,0x01,0x00,0x00,0x00,0x6c,0x02,0x00,0x00,0x05,0x00,0x00,0x00,
  530. 0x34,0x00,0x00,0x00,0xd4,0x00,0x00,0x00,0x20,0x01,0x00,0x00,0x54,0x01,0x00,0x00,
  531. 0xf0,0x01,0x00,0x00,0x52,0x44,0x45,0x46,0x98,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  532. 0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0x04,0xff,0xff,
  533. 0x10,0x81,0x00,0x00,0x6d,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
  534. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  535. 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x69,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
  536. 0x05,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
  537. 0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x5f,0x74,0x65,0x78,0x5f,0x73,0x61,0x6d,
  538. 0x70,0x6c,0x65,0x72,0x00,0x74,0x65,0x78,0x00,0x4d,0x69,0x63,0x72,0x6f,0x73,0x6f,
  539. 0x66,0x74,0x20,0x28,0x52,0x29,0x20,0x48,0x4c,0x53,0x4c,0x20,0x53,0x68,0x61,0x64,
  540. 0x65,0x72,0x20,0x43,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x72,0x20,0x31,0x30,0x2e,0x31,
  541. 0x00,0xab,0xab,0xab,0x49,0x53,0x47,0x4e,0x44,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
  542. 0x08,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  543. 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x38,0x00,0x00,0x00,
  544. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  545. 0x0f,0x0f,0x00,0x00,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x00,0xab,0xab,0xab,
  546. 0x4f,0x53,0x47,0x4e,0x2c,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
  547. 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
  548. 0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,
  549. 0x74,0x00,0xab,0xab,0x53,0x48,0x44,0x52,0x94,0x00,0x00,0x00,0x40,0x00,0x00,0x00,
  550. 0x25,0x00,0x00,0x00,0x5a,0x00,0x00,0x03,0x00,0x60,0x10,0x00,0x00,0x00,0x00,0x00,
  551. 0x58,0x18,0x00,0x04,0x00,0x70,0x10,0x00,0x00,0x00,0x00,0x00,0x55,0x55,0x00,0x00,
  552. 0x62,0x10,0x00,0x03,0x32,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x62,0x10,0x00,0x03,
  553. 0xf2,0x10,0x10,0x00,0x01,0x00,0x00,0x00,0x65,0x00,0x00,0x03,0xf2,0x20,0x10,0x00,
  554. 0x00,0x00,0x00,0x00,0x68,0x00,0x00,0x02,0x01,0x00,0x00,0x00,0x45,0x00,0x00,0x09,
  555. 0xf2,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
  556. 0x46,0x7e,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x10,0x00,0x00,0x00,0x00,0x00,
  557. 0x38,0x00,0x00,0x07,0xf2,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x0e,0x10,0x00,
  558. 0x00,0x00,0x00,0x00,0x46,0x1e,0x10,0x00,0x01,0x00,0x00,0x00,0x3e,0x00,0x00,0x01,
  559. 0x53,0x54,0x41,0x54,0x74,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  560. 0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  561. 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  562. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  563. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  564. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  565. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  566. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  567. };
  568. /*
  569. #include <metal_stdlib>
  570. #include <simd/simd.h>
  571. using namespace metal;
  572. struct vs_params
  573. {
  574. float4x4 mvp;
  575. };
  576. struct main0_out
  577. {
  578. float2 uv [[user(locn0)]];
  579. float4 color [[user(locn1)]];
  580. float4 gl_Position [[position]];
  581. };
  582. struct main0_in
  583. {
  584. float3 pos [[attribute(0)]];
  585. float2 texcoord0 [[attribute(1)]];
  586. float4 color0 [[attribute(2)]];
  587. };
  588. #line 18 "gfx.glsl"
  589. vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _21 [[buffer(0)]])
  590. {
  591. main0_out out = {};
  592. #line 18 "gfx.glsl"
  593. out.gl_Position = _21.mvp * float4(in.pos, 1.0);
  594. #line 19 "gfx.glsl"
  595. out.uv = in.texcoord0;
  596. #line 20 "gfx.glsl"
  597. out.color = in.color0;
  598. return out;
  599. }
  600. */
  601. static const char vs_source_metal_macos[689] = {
  602. 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
  603. 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
  604. 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
  605. 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
  606. 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x76,
  607. 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
  608. 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6d,0x76,0x70,0x3b,0x0a,0x7d,0x3b,0x0a,
  609. 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,
  610. 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,
  611. 0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,
  612. 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,
  613. 0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,
  614. 0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,
  615. 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,
  616. 0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,
  617. 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,
  618. 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x6f,0x73,0x20,0x5b,
  619. 0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,
  620. 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x74,0x65,0x78,0x63,
  621. 0x6f,0x6f,0x72,0x64,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,
  622. 0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
  623. 0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,
  624. 0x69,0x62,0x75,0x74,0x65,0x28,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
  625. 0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x38,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,
  626. 0x73,0x6c,0x22,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,
  627. 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,
  628. 0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
  629. 0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x76,0x73,
  630. 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,
  631. 0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,
  632. 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,
  633. 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x38,0x20,0x22,
  634. 0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,
  635. 0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
  636. 0x5f,0x32,0x31,0x2e,0x6d,0x76,0x70,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
  637. 0x28,0x69,0x6e,0x2e,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x23,
  638. 0x6c,0x69,0x6e,0x65,0x20,0x31,0x39,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,
  639. 0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x75,0x76,0x20,0x3d,0x20,
  640. 0x69,0x6e,0x2e,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x23,0x6c,
  641. 0x69,0x6e,0x65,0x20,0x32,0x30,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,
  642. 0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,
  643. 0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,
  644. 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,
  645. 0x00,
  646. };
  647. /*
  648. #include <metal_stdlib>
  649. #include <simd/simd.h>
  650. using namespace metal;
  651. struct main0_out
  652. {
  653. float4 frag_color [[color(0)]];
  654. };
  655. struct main0_in
  656. {
  657. float2 uv [[user(locn0)]];
  658. float4 color [[user(locn1)]];
  659. };
  660. #line 14 "gfx.glsl"
  661. fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler texSmplr [[sampler(0)]])
  662. {
  663. main0_out out = {};
  664. #line 14 "gfx.glsl"
  665. out.frag_color = in.color * tex.sample(texSmplr, in.uv);
  666. return out;
  667. }
  668. */
  669. static const char fs_source_metal_macos[486] = {
  670. 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
  671. 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
  672. 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
  673. 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
  674. 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,
  675. 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
  676. 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,
  677. 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,
  678. 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,
  679. 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,
  680. 0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,
  681. 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,
  682. 0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,
  683. 0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,
  684. 0x31,0x34,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,0x22,0x0a,0x66,0x72,
  685. 0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,
  686. 0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,
  687. 0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,
  688. 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,
  689. 0x3e,0x20,0x74,0x65,0x78,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,
  690. 0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x74,0x65,
  691. 0x78,0x53,0x6d,0x70,0x6c,0x72,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,
  692. 0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,
  693. 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,
  694. 0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x34,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,
  695. 0x6c,0x73,0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x66,0x72,0x61,
  696. 0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,
  697. 0x6f,0x72,0x20,0x2a,0x20,0x74,0x65,0x78,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,
  698. 0x74,0x65,0x78,0x53,0x6d,0x70,0x6c,0x72,0x2c,0x20,0x69,0x6e,0x2e,0x75,0x76,0x29,
  699. 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,
  700. 0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
  701. };
  702. /*
  703. #include <metal_stdlib>
  704. #include <simd/simd.h>
  705. using namespace metal;
  706. struct vs_params
  707. {
  708. float4x4 mvp;
  709. };
  710. struct main0_out
  711. {
  712. float2 uv [[user(locn0)]];
  713. float4 color [[user(locn1)]];
  714. float4 gl_Position [[position]];
  715. };
  716. struct main0_in
  717. {
  718. float3 pos [[attribute(0)]];
  719. float2 texcoord0 [[attribute(1)]];
  720. float4 color0 [[attribute(2)]];
  721. };
  722. #line 18 "gfx.glsl"
  723. vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _21 [[buffer(0)]])
  724. {
  725. main0_out out = {};
  726. #line 18 "gfx.glsl"
  727. out.gl_Position = _21.mvp * float4(in.pos, 1.0);
  728. #line 19 "gfx.glsl"
  729. out.uv = in.texcoord0;
  730. #line 20 "gfx.glsl"
  731. out.color = in.color0;
  732. return out;
  733. }
  734. */
  735. static const char vs_source_metal_ios[689] = {
  736. 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
  737. 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
  738. 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
  739. 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
  740. 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x76,
  741. 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
  742. 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6d,0x76,0x70,0x3b,0x0a,0x7d,0x3b,0x0a,
  743. 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,
  744. 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,
  745. 0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,
  746. 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,
  747. 0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,
  748. 0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,
  749. 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,
  750. 0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,
  751. 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,
  752. 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x6f,0x73,0x20,0x5b,
  753. 0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,
  754. 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x74,0x65,0x78,0x63,
  755. 0x6f,0x6f,0x72,0x64,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,
  756. 0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
  757. 0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,
  758. 0x69,0x62,0x75,0x74,0x65,0x28,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
  759. 0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x38,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,
  760. 0x73,0x6c,0x22,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,
  761. 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,
  762. 0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
  763. 0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x76,0x73,
  764. 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,
  765. 0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,
  766. 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,
  767. 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x38,0x20,0x22,
  768. 0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,
  769. 0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
  770. 0x5f,0x32,0x31,0x2e,0x6d,0x76,0x70,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
  771. 0x28,0x69,0x6e,0x2e,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x23,
  772. 0x6c,0x69,0x6e,0x65,0x20,0x31,0x39,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,
  773. 0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x75,0x76,0x20,0x3d,0x20,
  774. 0x69,0x6e,0x2e,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x23,0x6c,
  775. 0x69,0x6e,0x65,0x20,0x32,0x30,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,
  776. 0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,
  777. 0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,
  778. 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,
  779. 0x00,
  780. };
  781. /*
  782. #include <metal_stdlib>
  783. #include <simd/simd.h>
  784. using namespace metal;
  785. struct main0_out
  786. {
  787. float4 frag_color [[color(0)]];
  788. };
  789. struct main0_in
  790. {
  791. float2 uv [[user(locn0)]];
  792. float4 color [[user(locn1)]];
  793. };
  794. #line 14 "gfx.glsl"
  795. fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler texSmplr [[sampler(0)]])
  796. {
  797. main0_out out = {};
  798. #line 14 "gfx.glsl"
  799. out.frag_color = in.color * tex.sample(texSmplr, in.uv);
  800. return out;
  801. }
  802. */
  803. static const char fs_source_metal_ios[486] = {
  804. 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
  805. 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
  806. 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
  807. 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
  808. 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,
  809. 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
  810. 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,
  811. 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,
  812. 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,
  813. 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,
  814. 0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,
  815. 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,
  816. 0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,
  817. 0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,
  818. 0x31,0x34,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,0x22,0x0a,0x66,0x72,
  819. 0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,
  820. 0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,
  821. 0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,
  822. 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,
  823. 0x3e,0x20,0x74,0x65,0x78,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,
  824. 0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x74,0x65,
  825. 0x78,0x53,0x6d,0x70,0x6c,0x72,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,
  826. 0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,
  827. 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,
  828. 0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x34,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,
  829. 0x6c,0x73,0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x66,0x72,0x61,
  830. 0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,
  831. 0x6f,0x72,0x20,0x2a,0x20,0x74,0x65,0x78,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,
  832. 0x74,0x65,0x78,0x53,0x6d,0x70,0x6c,0x72,0x2c,0x20,0x69,0x6e,0x2e,0x75,0x76,0x29,
  833. 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,
  834. 0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
  835. };
  836. /*
  837. #include <metal_stdlib>
  838. #include <simd/simd.h>
  839. using namespace metal;
  840. struct vs_params
  841. {
  842. float4x4 mvp;
  843. };
  844. struct main0_out
  845. {
  846. float2 uv [[user(locn0)]];
  847. float4 color [[user(locn1)]];
  848. float4 gl_Position [[position]];
  849. };
  850. struct main0_in
  851. {
  852. float3 pos [[attribute(0)]];
  853. float2 texcoord0 [[attribute(1)]];
  854. float4 color0 [[attribute(2)]];
  855. };
  856. #line 18 "gfx.glsl"
  857. vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _21 [[buffer(0)]])
  858. {
  859. main0_out out = {};
  860. #line 18 "gfx.glsl"
  861. out.gl_Position = _21.mvp * float4(in.pos, 1.0);
  862. #line 19 "gfx.glsl"
  863. out.uv = in.texcoord0;
  864. #line 20 "gfx.glsl"
  865. out.color = in.color0;
  866. return out;
  867. }
  868. */
  869. static const char vs_source_metal_sim[689] = {
  870. 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
  871. 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
  872. 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
  873. 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
  874. 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x76,
  875. 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
  876. 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6d,0x76,0x70,0x3b,0x0a,0x7d,0x3b,0x0a,
  877. 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,
  878. 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,
  879. 0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,
  880. 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,
  881. 0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,
  882. 0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,
  883. 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,
  884. 0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,
  885. 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,
  886. 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x6f,0x73,0x20,0x5b,
  887. 0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,
  888. 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x74,0x65,0x78,0x63,
  889. 0x6f,0x6f,0x72,0x64,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,
  890. 0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
  891. 0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,
  892. 0x69,0x62,0x75,0x74,0x65,0x28,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
  893. 0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x38,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,
  894. 0x73,0x6c,0x22,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,
  895. 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,
  896. 0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
  897. 0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x76,0x73,
  898. 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,
  899. 0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,
  900. 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,
  901. 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x38,0x20,0x22,
  902. 0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,
  903. 0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
  904. 0x5f,0x32,0x31,0x2e,0x6d,0x76,0x70,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
  905. 0x28,0x69,0x6e,0x2e,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x23,
  906. 0x6c,0x69,0x6e,0x65,0x20,0x31,0x39,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,
  907. 0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x75,0x76,0x20,0x3d,0x20,
  908. 0x69,0x6e,0x2e,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x23,0x6c,
  909. 0x69,0x6e,0x65,0x20,0x32,0x30,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,
  910. 0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,
  911. 0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,
  912. 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,
  913. 0x00,
  914. };
  915. /*
  916. #include <metal_stdlib>
  917. #include <simd/simd.h>
  918. using namespace metal;
  919. struct main0_out
  920. {
  921. float4 frag_color [[color(0)]];
  922. };
  923. struct main0_in
  924. {
  925. float2 uv [[user(locn0)]];
  926. float4 color [[user(locn1)]];
  927. };
  928. #line 14 "gfx.glsl"
  929. fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler texSmplr [[sampler(0)]])
  930. {
  931. main0_out out = {};
  932. #line 14 "gfx.glsl"
  933. out.frag_color = in.color * tex.sample(texSmplr, in.uv);
  934. return out;
  935. }
  936. */
  937. static const char fs_source_metal_sim[486] = {
  938. 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
  939. 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
  940. 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
  941. 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
  942. 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,
  943. 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
  944. 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,
  945. 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,
  946. 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,
  947. 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,
  948. 0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,
  949. 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,
  950. 0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,
  951. 0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,
  952. 0x31,0x34,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,0x22,0x0a,0x66,0x72,
  953. 0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,
  954. 0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,
  955. 0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,
  956. 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,
  957. 0x3e,0x20,0x74,0x65,0x78,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,
  958. 0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x74,0x65,
  959. 0x78,0x53,0x6d,0x70,0x6c,0x72,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,
  960. 0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,
  961. 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,
  962. 0x0a,0x23,0x6c,0x69,0x6e,0x65,0x20,0x31,0x34,0x20,0x22,0x67,0x66,0x78,0x2e,0x67,
  963. 0x6c,0x73,0x6c,0x22,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x66,0x72,0x61,
  964. 0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,
  965. 0x6f,0x72,0x20,0x2a,0x20,0x74,0x65,0x78,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,
  966. 0x74,0x65,0x78,0x53,0x6d,0x70,0x6c,0x72,0x2c,0x20,0x69,0x6e,0x2e,0x75,0x76,0x29,
  967. 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,
  968. 0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
  969. };
  970. /*
  971. #version 450
  972. layout(set = 0, binding = 0, std140) uniform vs_params
  973. {
  974. mat4 mvp;
  975. } _21;
  976. layout(location = 0) in vec3 pos;
  977. layout(location = 0) out vec2 uv;
  978. layout(location = 1) in vec2 texcoord0;
  979. layout(location = 1) out vec4 color;
  980. layout(location = 2) in vec4 color0;
  981. void main()
  982. {
  983. gl_Position = _21.mvp * vec4(pos, 1.0);
  984. uv = texcoord0;
  985. color = color0;
  986. }
  987. */
  988. static const uint8_t vs_bytecode_wgpu[1716] = {
  989. 0x03,0x02,0x23,0x07,0x00,0x00,0x01,0x00,0x08,0x00,0x08,0x00,0x2f,0x00,0x00,0x00,
  990. 0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,
  991. 0x02,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,
  992. 0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  993. 0x0f,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,
  994. 0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x27,0x00,0x00,0x00,
  995. 0x29,0x00,0x00,0x00,0x2b,0x00,0x00,0x00,0x2d,0x00,0x00,0x00,0x07,0x00,0x03,0x00,
  996. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x05,0x00,0x07,0x00,0x00,0x00,
  997. 0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,0x00,0x00,0x00,0x00,0x03,0x00,0x37,0x00,
  998. 0x02,0x00,0x00,0x00,0xc2,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x2f,0x2f,0x20,0x4f,
  999. 0x70,0x4d,0x6f,0x64,0x75,0x6c,0x65,0x50,0x72,0x6f,0x63,0x65,0x73,0x73,0x65,0x64,
  1000. 0x20,0x63,0x6c,0x69,0x65,0x6e,0x74,0x20,0x76,0x75,0x6c,0x6b,0x61,0x6e,0x31,0x30,
  1001. 0x30,0x0a,0x2f,0x2f,0x20,0x4f,0x70,0x4d,0x6f,0x64,0x75,0x6c,0x65,0x50,0x72,0x6f,
  1002. 0x63,0x65,0x73,0x73,0x65,0x64,0x20,0x63,0x6c,0x69,0x65,0x6e,0x74,0x20,0x6f,0x70,
  1003. 0x65,0x6e,0x67,0x6c,0x31,0x30,0x30,0x0a,0x2f,0x2f,0x20,0x4f,0x70,0x4d,0x6f,0x64,
  1004. 0x75,0x6c,0x65,0x50,0x72,0x6f,0x63,0x65,0x73,0x73,0x65,0x64,0x20,0x74,0x61,0x72,
  1005. 0x67,0x65,0x74,0x2d,0x65,0x6e,0x76,0x20,0x76,0x75,0x6c,0x6b,0x61,0x6e,0x31,0x2e,
  1006. 0x30,0x0a,0x2f,0x2f,0x20,0x4f,0x70,0x4d,0x6f,0x64,0x75,0x6c,0x65,0x50,0x72,0x6f,
  1007. 0x63,0x65,0x73,0x73,0x65,0x64,0x20,0x74,0x61,0x72,0x67,0x65,0x74,0x2d,0x65,0x6e,
  1008. 0x76,0x20,0x6f,0x70,0x65,0x6e,0x67,0x6c,0x0a,0x2f,0x2f,0x20,0x4f,0x70,0x4d,0x6f,
  1009. 0x64,0x75,0x6c,0x65,0x50,0x72,0x6f,0x63,0x65,0x73,0x73,0x65,0x64,0x20,0x65,0x6e,
  1010. 0x74,0x72,0x79,0x2d,0x70,0x6f,0x69,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x0a,0x23,
  1011. 0x6c,0x69,0x6e,0x65,0x20,0x31,0x0a,0x00,0x05,0x00,0x04,0x00,0x05,0x00,0x00,0x00,
  1012. 0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,0x05,0x00,0x06,0x00,0x0d,0x00,0x00,0x00,
  1013. 0x67,0x6c,0x5f,0x50,0x65,0x72,0x56,0x65,0x72,0x74,0x65,0x78,0x00,0x00,0x00,0x00,
  1014. 0x06,0x00,0x06,0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,
  1015. 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x06,0x00,0x07,0x00,0x0d,0x00,0x00,0x00,
  1016. 0x01,0x00,0x00,0x00,0x67,0x6c,0x5f,0x50,0x6f,0x69,0x6e,0x74,0x53,0x69,0x7a,0x65,
  1017. 0x00,0x00,0x00,0x00,0x06,0x00,0x07,0x00,0x0d,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
  1018. 0x67,0x6c,0x5f,0x43,0x6c,0x69,0x70,0x44,0x69,0x73,0x74,0x61,0x6e,0x63,0x65,0x00,
  1019. 0x06,0x00,0x07,0x00,0x0d,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x67,0x6c,0x5f,0x43,
  1020. 0x75,0x6c,0x6c,0x44,0x69,0x73,0x74,0x61,0x6e,0x63,0x65,0x00,0x05,0x00,0x03,0x00,
  1021. 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x05,0x00,0x13,0x00,0x00,0x00,
  1022. 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x00,0x00,0x00,0x06,0x00,0x04,0x00,
  1023. 0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6d,0x76,0x70,0x00,0x05,0x00,0x03,0x00,
  1024. 0x15,0x00,0x00,0x00,0x5f,0x32,0x31,0x00,0x05,0x00,0x03,0x00,0x1b,0x00,0x00,0x00,
  1025. 0x70,0x6f,0x73,0x00,0x05,0x00,0x03,0x00,0x27,0x00,0x00,0x00,0x75,0x76,0x00,0x00,
  1026. 0x05,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,
  1027. 0x30,0x00,0x00,0x00,0x05,0x00,0x04,0x00,0x2b,0x00,0x00,0x00,0x63,0x6f,0x6c,0x6f,
  1028. 0x72,0x00,0x00,0x00,0x05,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x63,0x6f,0x6c,0x6f,
  1029. 0x72,0x30,0x00,0x00,0x48,0x00,0x05,0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1030. 0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x0d,0x00,0x00,0x00,
  1031. 0x01,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,0x00,0x05,0x00,
  1032. 0x0d,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
  1033. 0x48,0x00,0x05,0x00,0x0d,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,
  1034. 0x04,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x0d,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
  1035. 0x48,0x00,0x04,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,
  1036. 0x48,0x00,0x05,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,
  1037. 0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1038. 0x07,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x13,0x00,0x00,0x00,
  1039. 0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x22,0x00,0x00,0x00,
  1040. 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x21,0x00,0x00,0x00,
  1041. 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x1b,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1042. 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x27,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1043. 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x29,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1044. 0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x2b,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1045. 0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1046. 0x02,0x00,0x00,0x00,0x13,0x00,0x02,0x00,0x03,0x00,0x00,0x00,0x21,0x00,0x03,0x00,
  1047. 0x04,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x00,0x03,0x00,0x08,0x00,0x00,0x00,
  1048. 0x20,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x09,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
  1049. 0x04,0x00,0x00,0x00,0x15,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
  1050. 0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,
  1051. 0x01,0x00,0x00,0x00,0x1c,0x00,0x04,0x00,0x0c,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
  1052. 0x0b,0x00,0x00,0x00,0x1e,0x00,0x06,0x00,0x0d,0x00,0x00,0x00,0x09,0x00,0x00,0x00,
  1053. 0x08,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00,
  1054. 0x0e,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,
  1055. 0x0e,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x15,0x00,0x04,0x00,
  1056. 0x10,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,
  1057. 0x10,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x04,0x00,
  1058. 0x12,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,
  1059. 0x13,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x14,0x00,0x00,0x00,
  1060. 0x02,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x14,0x00,0x00,0x00,
  1061. 0x15,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x16,0x00,0x00,0x00,
  1062. 0x02,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x19,0x00,0x00,0x00,
  1063. 0x08,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x1a,0x00,0x00,0x00,
  1064. 0x01,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x1a,0x00,0x00,0x00,
  1065. 0x1b,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x08,0x00,0x00,0x00,
  1066. 0x1d,0x00,0x00,0x00,0x00,0x00,0x80,0x3f,0x20,0x00,0x04,0x00,0x23,0x00,0x00,0x00,
  1067. 0x03,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x25,0x00,0x00,0x00,
  1068. 0x08,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x26,0x00,0x00,0x00,
  1069. 0x03,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x26,0x00,0x00,0x00,
  1070. 0x27,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x28,0x00,0x00,0x00,
  1071. 0x01,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x28,0x00,0x00,0x00,
  1072. 0x29,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x23,0x00,0x00,0x00,
  1073. 0x2b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,
  1074. 0x01,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,
  1075. 0x2d,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x36,0x00,0x05,0x00,0x03,0x00,0x00,0x00,
  1076. 0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,
  1077. 0x06,0x00,0x00,0x00,0x08,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
  1078. 0x00,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x16,0x00,0x00,0x00,0x17,0x00,0x00,0x00,
  1079. 0x15,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x12,0x00,0x00,0x00,
  1080. 0x18,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x19,0x00,0x00,0x00,
  1081. 0x1c,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x51,0x00,0x05,0x00,0x08,0x00,0x00,0x00,
  1082. 0x1e,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x51,0x00,0x05,0x00,
  1083. 0x08,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  1084. 0x51,0x00,0x05,0x00,0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,
  1085. 0x02,0x00,0x00,0x00,0x50,0x00,0x07,0x00,0x09,0x00,0x00,0x00,0x21,0x00,0x00,0x00,
  1086. 0x1e,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x1d,0x00,0x00,0x00,
  1087. 0x91,0x00,0x05,0x00,0x09,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x18,0x00,0x00,0x00,
  1088. 0x21,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x23,0x00,0x00,0x00,0x24,0x00,0x00,0x00,
  1089. 0x0f,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x24,0x00,0x00,0x00,
  1090. 0x22,0x00,0x00,0x00,0x08,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x11,0x00,0x00,0x00,
  1091. 0x00,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x25,0x00,0x00,0x00,0x2a,0x00,0x00,0x00,
  1092. 0x29,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x27,0x00,0x00,0x00,0x2a,0x00,0x00,0x00,
  1093. 0x08,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1094. 0x3d,0x00,0x04,0x00,0x09,0x00,0x00,0x00,0x2e,0x00,0x00,0x00,0x2d,0x00,0x00,0x00,
  1095. 0x3e,0x00,0x03,0x00,0x2b,0x00,0x00,0x00,0x2e,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,
  1096. 0x38,0x00,0x01,0x00,
  1097. };
  1098. /*
  1099. #version 450
  1100. layout(location = 0, set = 2, binding = 0) uniform sampler2D tex;
  1101. layout(location = 0) out vec4 frag_color;
  1102. layout(location = 1) in vec4 color;
  1103. layout(location = 0) in vec2 uv;
  1104. void main()
  1105. {
  1106. frag_color = color * texture(tex, uv);
  1107. }
  1108. */
  1109. static const uint8_t fs_bytecode_wgpu[924] = {
  1110. 0x03,0x02,0x23,0x07,0x00,0x00,0x01,0x00,0x08,0x00,0x08,0x00,0x1a,0x00,0x00,0x00,
  1111. 0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,
  1112. 0x02,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,
  1113. 0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  1114. 0x0f,0x00,0x08,0x00,0x04,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,
  1115. 0x00,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x16,0x00,0x00,0x00,
  1116. 0x10,0x00,0x03,0x00,0x05,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x07,0x00,0x03,0x00,
  1117. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x05,0x00,0x07,0x00,0x00,0x00,
  1118. 0x67,0x66,0x78,0x2e,0x67,0x6c,0x73,0x6c,0x00,0x00,0x00,0x00,0x03,0x00,0x37,0x00,
  1119. 0x02,0x00,0x00,0x00,0xc2,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x2f,0x2f,0x20,0x4f,
  1120. 0x70,0x4d,0x6f,0x64,0x75,0x6c,0x65,0x50,0x72,0x6f,0x63,0x65,0x73,0x73,0x65,0x64,
  1121. 0x20,0x63,0x6c,0x69,0x65,0x6e,0x74,0x20,0x76,0x75,0x6c,0x6b,0x61,0x6e,0x31,0x30,
  1122. 0x30,0x0a,0x2f,0x2f,0x20,0x4f,0x70,0x4d,0x6f,0x64,0x75,0x6c,0x65,0x50,0x72,0x6f,
  1123. 0x63,0x65,0x73,0x73,0x65,0x64,0x20,0x63,0x6c,0x69,0x65,0x6e,0x74,0x20,0x6f,0x70,
  1124. 0x65,0x6e,0x67,0x6c,0x31,0x30,0x30,0x0a,0x2f,0x2f,0x20,0x4f,0x70,0x4d,0x6f,0x64,
  1125. 0x75,0x6c,0x65,0x50,0x72,0x6f,0x63,0x65,0x73,0x73,0x65,0x64,0x20,0x74,0x61,0x72,
  1126. 0x67,0x65,0x74,0x2d,0x65,0x6e,0x76,0x20,0x76,0x75,0x6c,0x6b,0x61,0x6e,0x31,0x2e,
  1127. 0x30,0x0a,0x2f,0x2f,0x20,0x4f,0x70,0x4d,0x6f,0x64,0x75,0x6c,0x65,0x50,0x72,0x6f,
  1128. 0x63,0x65,0x73,0x73,0x65,0x64,0x20,0x74,0x61,0x72,0x67,0x65,0x74,0x2d,0x65,0x6e,
  1129. 0x76,0x20,0x6f,0x70,0x65,0x6e,0x67,0x6c,0x0a,0x2f,0x2f,0x20,0x4f,0x70,0x4d,0x6f,
  1130. 0x64,0x75,0x6c,0x65,0x50,0x72,0x6f,0x63,0x65,0x73,0x73,0x65,0x64,0x20,0x65,0x6e,
  1131. 0x74,0x72,0x79,0x2d,0x70,0x6f,0x69,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x0a,0x23,
  1132. 0x6c,0x69,0x6e,0x65,0x20,0x31,0x0a,0x00,0x05,0x00,0x04,0x00,0x05,0x00,0x00,0x00,
  1133. 0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,0x05,0x00,0x05,0x00,0x0b,0x00,0x00,0x00,
  1134. 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x00,0x00,0x05,0x00,0x04,0x00,
  1135. 0x0d,0x00,0x00,0x00,0x63,0x6f,0x6c,0x6f,0x72,0x00,0x00,0x00,0x05,0x00,0x03,0x00,
  1136. 0x12,0x00,0x00,0x00,0x74,0x65,0x78,0x00,0x05,0x00,0x03,0x00,0x16,0x00,0x00,0x00,
  1137. 0x75,0x76,0x00,0x00,0x47,0x00,0x04,0x00,0x0b,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1138. 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x0d,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1139. 0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x12,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1140. 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x12,0x00,0x00,0x00,0x22,0x00,0x00,0x00,
  1141. 0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x12,0x00,0x00,0x00,0x21,0x00,0x00,0x00,
  1142. 0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x16,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
  1143. 0x00,0x00,0x00,0x00,0x13,0x00,0x02,0x00,0x03,0x00,0x00,0x00,0x21,0x00,0x03,0x00,
  1144. 0x04,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x00,0x03,0x00,0x08,0x00,0x00,0x00,
  1145. 0x20,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x09,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
  1146. 0x04,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
  1147. 0x09,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x0a,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,
  1148. 0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x0c,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  1149. 0x09,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x0c,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,
  1150. 0x01,0x00,0x00,0x00,0x19,0x00,0x09,0x00,0x0f,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
  1151. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1152. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1b,0x00,0x03,0x00,0x10,0x00,0x00,0x00,
  1153. 0x0f,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1154. 0x10,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x11,0x00,0x00,0x00,0x12,0x00,0x00,0x00,
  1155. 0x00,0x00,0x00,0x00,0x17,0x00,0x04,0x00,0x14,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
  1156. 0x02,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  1157. 0x14,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x15,0x00,0x00,0x00,0x16,0x00,0x00,0x00,
  1158. 0x01,0x00,0x00,0x00,0x36,0x00,0x05,0x00,0x03,0x00,0x00,0x00,0x05,0x00,0x00,0x00,
  1159. 0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0x06,0x00,0x00,0x00,
  1160. 0x08,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1161. 0x3d,0x00,0x04,0x00,0x09,0x00,0x00,0x00,0x0e,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,
  1162. 0x3d,0x00,0x04,0x00,0x10,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x12,0x00,0x00,0x00,
  1163. 0x3d,0x00,0x04,0x00,0x14,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x16,0x00,0x00,0x00,
  1164. 0x57,0x00,0x05,0x00,0x09,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x13,0x00,0x00,0x00,
  1165. 0x17,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x09,0x00,0x00,0x00,0x19,0x00,0x00,0x00,
  1166. 0x0e,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x0b,0x00,0x00,0x00,
  1167. 0x19,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00,
  1168. };
  1169. #if !defined(SOKOL_GFX_INCLUDED)
  1170. #error "Please include sokol_gfx.h before sgl.h"
  1171. #endif
  1172. static inline const sg_shader_desc* spritebatch_shader_desc(sg_backend backend) {
  1173. if (backend == SG_BACKEND_GLCORE33) {
  1174. static sg_shader_desc desc;
  1175. static bool valid;
  1176. if (!valid) {
  1177. valid = true;
  1178. desc.attrs[0].name = "pos";
  1179. desc.attrs[1].name = "texcoord0";
  1180. desc.attrs[2].name = "color0";
  1181. desc.vs.source = vs_source_glsl330;
  1182. desc.vs.entry = "main";
  1183. desc.vs.uniform_blocks[0].size = 64;
  1184. desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params";
  1185. desc.vs.uniform_blocks[0].uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
  1186. desc.vs.uniform_blocks[0].uniforms[0].array_count = 4;
  1187. desc.fs.source = fs_source_glsl330;
  1188. desc.fs.entry = "main";
  1189. desc.fs.images[0].name = "tex";
  1190. desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
  1191. desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
  1192. desc.label = "spritebatch_shader";
  1193. };
  1194. return &desc;
  1195. }
  1196. if (backend == SG_BACKEND_GLES2) {
  1197. static sg_shader_desc desc;
  1198. static bool valid;
  1199. if (!valid) {
  1200. valid = true;
  1201. desc.attrs[0].name = "pos";
  1202. desc.attrs[1].name = "texcoord0";
  1203. desc.attrs[2].name = "color0";
  1204. desc.vs.source = vs_source_glsl100;
  1205. desc.vs.entry = "main";
  1206. desc.vs.uniform_blocks[0].size = 64;
  1207. desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params";
  1208. desc.vs.uniform_blocks[0].uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
  1209. desc.vs.uniform_blocks[0].uniforms[0].array_count = 4;
  1210. desc.fs.source = fs_source_glsl100;
  1211. desc.fs.entry = "main";
  1212. desc.fs.images[0].name = "tex";
  1213. desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
  1214. desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
  1215. desc.label = "spritebatch_shader";
  1216. };
  1217. return &desc;
  1218. }
  1219. if (backend == SG_BACKEND_D3D11) {
  1220. static sg_shader_desc desc;
  1221. static bool valid;
  1222. if (!valid) {
  1223. valid = true;
  1224. desc.attrs[0].sem_name = "TEXCOORD";
  1225. desc.attrs[0].sem_index = 0;
  1226. desc.attrs[1].sem_name = "TEXCOORD";
  1227. desc.attrs[1].sem_index = 1;
  1228. desc.attrs[2].sem_name = "TEXCOORD";
  1229. desc.attrs[2].sem_index = 2;
  1230. desc.vs.bytecode.ptr = vs_bytecode_hlsl4;
  1231. desc.vs.bytecode.size = 884;
  1232. desc.vs.entry = "main";
  1233. desc.vs.uniform_blocks[0].size = 64;
  1234. desc.fs.bytecode.ptr = fs_bytecode_hlsl4;
  1235. desc.fs.bytecode.size = 620;
  1236. desc.fs.entry = "main";
  1237. desc.fs.images[0].name = "tex";
  1238. desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
  1239. desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
  1240. desc.label = "spritebatch_shader";
  1241. };
  1242. return &desc;
  1243. }
  1244. if (backend == SG_BACKEND_METAL_MACOS) {
  1245. static sg_shader_desc desc;
  1246. static bool valid;
  1247. if (!valid) {
  1248. valid = true;
  1249. desc.vs.source = vs_source_metal_macos;
  1250. desc.vs.entry = "main0";
  1251. desc.vs.uniform_blocks[0].size = 64;
  1252. desc.fs.source = fs_source_metal_macos;
  1253. desc.fs.entry = "main0";
  1254. desc.fs.images[0].name = "tex";
  1255. desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
  1256. desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
  1257. desc.label = "spritebatch_shader";
  1258. };
  1259. return &desc;
  1260. }
  1261. if (backend == SG_BACKEND_METAL_IOS) {
  1262. static sg_shader_desc desc;
  1263. static bool valid;
  1264. if (!valid) {
  1265. valid = true;
  1266. desc.vs.source = vs_source_metal_ios;
  1267. desc.vs.entry = "main0";
  1268. desc.vs.uniform_blocks[0].size = 64;
  1269. desc.fs.source = fs_source_metal_ios;
  1270. desc.fs.entry = "main0";
  1271. desc.fs.images[0].name = "tex";
  1272. desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
  1273. desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
  1274. desc.label = "spritebatch_shader";
  1275. };
  1276. return &desc;
  1277. }
  1278. if (backend == SG_BACKEND_METAL_SIMULATOR) {
  1279. static sg_shader_desc desc;
  1280. static bool valid;
  1281. if (!valid) {
  1282. valid = true;
  1283. desc.vs.source = vs_source_metal_sim;
  1284. desc.vs.entry = "main0";
  1285. desc.vs.uniform_blocks[0].size = 64;
  1286. desc.fs.source = fs_source_metal_sim;
  1287. desc.fs.entry = "main0";
  1288. desc.fs.images[0].name = "tex";
  1289. desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
  1290. desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
  1291. desc.label = "spritebatch_shader";
  1292. };
  1293. return &desc;
  1294. }
  1295. if (backend == SG_BACKEND_WGPU) {
  1296. static sg_shader_desc desc;
  1297. static bool valid;
  1298. if (!valid) {
  1299. valid = true;
  1300. desc.vs.bytecode.ptr = vs_bytecode_wgpu;
  1301. desc.vs.bytecode.size = 1716;
  1302. desc.vs.entry = "main";
  1303. desc.vs.uniform_blocks[0].size = 64;
  1304. desc.fs.bytecode.ptr = fs_bytecode_wgpu;
  1305. desc.fs.bytecode.size = 924;
  1306. desc.fs.entry = "main";
  1307. desc.fs.images[0].name = "tex";
  1308. desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
  1309. desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
  1310. desc.label = "spritebatch_shader";
  1311. };
  1312. return &desc;
  1313. }
  1314. return 0;
  1315. }
  1316. static void _sbatch_strcpy(_sbatch_str* dst, const char* src) {
  1317. SOKOL_ASSERT(dst);
  1318. if (src) {
  1319. #if defined(_MSC_VER)
  1320. strncpy_s(dst->buf, _SBATCH_STRBUF_LEN, src, (_SBATCH_STRBUF_LEN - 1));
  1321. #else
  1322. strncpy(dst->buf, src, _SBATCH_STRBUF_LEN);
  1323. #endif
  1324. dst->buf[_SBATCH_STRBUF_LEN - 1] = 0;
  1325. }
  1326. else {
  1327. memset(dst->buf, 0, _SBATCH_STRBUF_LEN);
  1328. }
  1329. }
  1330. static _sbatch_str _sbatch_make_str(const char* str) {
  1331. _sbatch_str res;
  1332. _sbatch_strcpy(&res, str);
  1333. return res;
  1334. }
  1335. static void _sbatch_init_pool(_sbatch_pool* pool, int num) {
  1336. SOKOL_ASSERT(pool && (num >= 1));
  1337. /* slot 0 is reserved for the 'invalid id', so bump the pool size by 1 */
  1338. pool->size = num + 1;
  1339. pool->queue_top = 0;
  1340. /* generation counters indexable by pool slot index, slot 0 is reserved */
  1341. const size_t gen_ctrs_size = sizeof(uint32_t) * (size_t)pool->size;
  1342. pool->gen_ctrs = (uint32_t*)SOKOL_MALLOC(gen_ctrs_size);
  1343. SOKOL_ASSERT(pool->gen_ctrs);
  1344. memset(pool->gen_ctrs, 0, gen_ctrs_size);
  1345. /* it's not a bug to only reserve 'num' here */
  1346. pool->free_queue = (int*)SOKOL_MALLOC(sizeof(int) * (size_t)num);
  1347. SOKOL_ASSERT(pool->free_queue);
  1348. /* never allocate the zero-th pool item since the invalid id is 0 */
  1349. for (int i = pool->size - 1; i >= 1; i--) {
  1350. pool->free_queue[pool->queue_top++] = i;
  1351. }
  1352. }
  1353. static void _sbatch_discard_pool(_sbatch_pool* pool) {
  1354. SOKOL_ASSERT(pool);
  1355. SOKOL_ASSERT(pool->free_queue);
  1356. SOKOL_FREE(pool->free_queue);
  1357. pool->free_queue = 0;
  1358. SOKOL_ASSERT(pool->gen_ctrs);
  1359. SOKOL_FREE(pool->gen_ctrs);
  1360. pool->gen_ctrs = 0;
  1361. pool->size = 0;
  1362. pool->queue_top = 0;
  1363. }
  1364. static int _sbatch_pool_alloc_index(_sbatch_pool* pool) {
  1365. SOKOL_ASSERT(pool);
  1366. SOKOL_ASSERT(pool->free_queue);
  1367. if (pool->queue_top > 0) {
  1368. const int slot_index = pool->free_queue[--pool->queue_top];
  1369. SOKOL_ASSERT((slot_index > 0) && (slot_index < pool->size));
  1370. return slot_index;
  1371. }
  1372. /* pool exhausted */
  1373. return _SBATCH_INVALID_SLOT_INDEX;
  1374. }
  1375. static void _sbatch_pool_free_index(_sbatch_pool* pool, int slot_index) {
  1376. SOKOL_ASSERT((slot_index > _SBATCH_INVALID_SLOT_INDEX) && (slot_index < pool->size));
  1377. SOKOL_ASSERT(pool);
  1378. SOKOL_ASSERT(pool->free_queue);
  1379. SOKOL_ASSERT(pool->queue_top < pool->size);
  1380. #ifdef SOKOL_DEBUG
  1381. /* debug check against double-free */
  1382. for (int i = 0; i < pool->queue_top; i++) {
  1383. SOKOL_ASSERT(pool->free_queue[i] != slot_index);
  1384. }
  1385. #endif
  1386. pool->free_queue[pool->queue_top++] = slot_index;
  1387. SOKOL_ASSERT(pool->queue_top <= (pool->size - 1));
  1388. }
  1389. /* allocate the slot at slot_index:
  1390. - bump the slot's generation counter
  1391. - create a resource id from the generation counter and slot index
  1392. - set the slot's id to this id
  1393. - set the slot's state to ALLOC
  1394. - return the resource id
  1395. */
  1396. static uint32_t _sbatch_slot_alloc(_sbatch_pool* pool, _sbatch_slot* slot, int slot_index) {
  1397. /* FIXME: add handling for an overflowing generation counter,
  1398. for now, just overflow (another option is to disable
  1399. the slot)
  1400. */
  1401. SOKOL_ASSERT(pool && pool->gen_ctrs);
  1402. SOKOL_ASSERT((slot_index > _SBATCH_INVALID_SLOT_INDEX) && (slot_index < pool->size));
  1403. SOKOL_ASSERT((slot->state == SG_RESOURCESTATE_INITIAL) && (slot->id == SG_INVALID_ID));
  1404. const uint32_t ctr = ++pool->gen_ctrs[slot_index];
  1405. slot->id = (ctr << _SBATCH_SLOT_SHIFT) | (slot_index & _SBATCH_SLOT_MASK);
  1406. slot->state = SG_RESOURCESTATE_ALLOC;
  1407. return slot->id;
  1408. }
  1409. /* extract slot index from id */
  1410. static int _sbatch_slot_index(uint32_t id) {
  1411. const int slot_index = (int)(id & _SBATCH_SLOT_MASK);
  1412. SOKOL_ASSERT(_SBATCH_INVALID_SLOT_INDEX != slot_index);
  1413. return slot_index;
  1414. }
  1415. static void _sbatch_setup_context_pool(const sbatch_desc* desc) {
  1416. SOKOL_ASSERT(desc);
  1417. /* note: the pool will have an additional item, since slot 0 is reserved */
  1418. SOKOL_ASSERT((desc->context_pool_size > 0) && (desc->context_pool_size < _SBATCH_MAX_POOL_SIZE));
  1419. _sbatch_init_pool(&_sbatch.context_pool.pool, desc->context_pool_size);
  1420. const size_t pool_byte_size = sizeof(_sbatch_context) * (size_t)_sbatch.context_pool.pool.size;
  1421. _sbatch.context_pool.contexts = (_sbatch_context*)SOKOL_MALLOC(pool_byte_size);
  1422. SOKOL_ASSERT(_sbatch.context_pool.contexts);
  1423. memset(_sbatch.context_pool.contexts, 0, pool_byte_size);
  1424. }
  1425. static void _sbatch_discard_context_pool(void) {
  1426. SOKOL_ASSERT(_sbatch.context_pool.contexts);
  1427. SOKOL_FREE(_sbatch.context_pool.contexts);
  1428. _sbatch.context_pool.contexts = 0;
  1429. _sbatch_discard_pool(&_sbatch.context_pool.pool);
  1430. }
  1431. /* get context pointer without id-check */
  1432. static _sbatch_context* _sbatch_context_at(uint32_t ctx_id) {
  1433. SOKOL_ASSERT(SG_INVALID_ID != ctx_id);
  1434. const int slot_index = _sbatch_slot_index(ctx_id);
  1435. SOKOL_ASSERT((slot_index > _SBATCH_INVALID_SLOT_INDEX) && (slot_index < _sbatch.context_pool.pool.size));
  1436. return &_sbatch.context_pool.contexts[slot_index];
  1437. }
  1438. /* get context pointer with id-check, returns 0 if no match */
  1439. static _sbatch_context* _sbatch_lookup_context(uint32_t ctx_id) {
  1440. if (SG_INVALID_ID != ctx_id) {
  1441. _sbatch_context* ctx = _sbatch_context_at(ctx_id);
  1442. if (ctx->slot.id == ctx_id) {
  1443. return ctx;
  1444. }
  1445. }
  1446. return NULL;
  1447. }
  1448. /* make context handle from raw uint32_t id */
  1449. static sbatch_context _sbatch_make_ctx_id(uint32_t ctx_id) {
  1450. sbatch_context ctx;
  1451. ctx.id = ctx_id;
  1452. return ctx;
  1453. }
  1454. static sbatch_context _sbatch_alloc_context(void) {
  1455. sbatch_context ctx_id;
  1456. const int slot_index = _sbatch_pool_alloc_index(&_sbatch.context_pool.pool);
  1457. if (_SBATCH_INVALID_SLOT_INDEX != slot_index) {
  1458. ctx_id = _sbatch_make_ctx_id(_sbatch_slot_alloc(&_sbatch.context_pool.pool, &_sbatch.context_pool.contexts[slot_index].slot, slot_index));
  1459. }
  1460. else {
  1461. /* pool is exhausted */
  1462. ctx_id = _sbatch_make_ctx_id(SG_INVALID_ID);
  1463. }
  1464. return ctx_id;
  1465. }
  1466. static void _sbatch_setup_pipeline_pool(const sbatch_desc* desc) {
  1467. SOKOL_ASSERT(desc);
  1468. /* note: the pool will have an additional item, since slot 0 is reserved */
  1469. SOKOL_ASSERT((desc->pipeline_pool_size > 0) && (desc->pipeline_pool_size < _SBATCH_MAX_POOL_SIZE));
  1470. _sbatch_init_pool(&_sbatch.pipeline_pool.pool, desc->pipeline_pool_size);
  1471. const size_t pool_byte_size = sizeof(_sbatch_pipeline) * (size_t)_sbatch.pipeline_pool.pool.size;
  1472. _sbatch.pipeline_pool.pipelines = (_sbatch_pipeline*)SOKOL_MALLOC(pool_byte_size);
  1473. SOKOL_ASSERT(_sbatch.pipeline_pool.pipelines);
  1474. memset(_sbatch.pipeline_pool.pipelines, 0, pool_byte_size);
  1475. }
  1476. static void _sbatch_discard_pipeline_pool(void) {
  1477. SOKOL_ASSERT(_sbatch.pipeline_pool.pipelines);
  1478. SOKOL_FREE(_sbatch.pipeline_pool.pipelines);
  1479. _sbatch.pipeline_pool.pipelines = 0;
  1480. _sbatch_discard_pool(&_sbatch.pipeline_pool.pool);
  1481. }
  1482. /* get pipeline pointer without id-check */
  1483. static _sbatch_pipeline* _sbatch_pipeline_at(uint32_t pip_id) {
  1484. SOKOL_ASSERT(SG_INVALID_ID != pip_id);
  1485. const int slot_index = _sbatch_slot_index(pip_id);
  1486. SOKOL_ASSERT((slot_index > _SBATCH_INVALID_SLOT_INDEX) && (slot_index < _sbatch.pipeline_pool.pool.size));
  1487. return &_sbatch.pipeline_pool.pipelines[slot_index];
  1488. }
  1489. /* get pipeline pointer with id-check, returns 0 if no match */
  1490. static _sbatch_pipeline* _sbatch_lookup_pipeline(uint32_t pip_id) {
  1491. if (SG_INVALID_ID != pip_id) {
  1492. _sbatch_pipeline* pip = _sbatch_pipeline_at(pip_id);
  1493. if (pip->slot.id == pip_id) {
  1494. return pip;
  1495. }
  1496. }
  1497. return NULL;
  1498. }
  1499. /* make pipeline handle from raw uint32_t id */
  1500. static sbatch_pipeline _sbatch_make_pip_id(uint32_t pip_id) {
  1501. sbatch_pipeline pip;
  1502. pip.id = pip_id;
  1503. return pip;
  1504. }
  1505. static sbatch_pipeline _sbatch_alloc_pipeline(void) {
  1506. sbatch_pipeline pip_id;
  1507. const int slot_index = _sbatch_pool_alloc_index(&_sbatch.pipeline_pool.pool);
  1508. if (_SBATCH_INVALID_SLOT_INDEX != slot_index) {
  1509. pip_id = _sbatch_make_pip_id(_sbatch_slot_alloc(&_sbatch.pipeline_pool.pool, &_sbatch.pipeline_pool.pipelines[slot_index].slot, slot_index));
  1510. }
  1511. else {
  1512. /* pool is exhausted */
  1513. pip_id = _sbatch_make_pip_id(SG_INVALID_ID);
  1514. }
  1515. return pip_id;
  1516. }
  1517. static sbatch_context_desc _sbatch_context_desc_defaults(const sbatch_context_desc* desc) {
  1518. sbatch_context_desc res = *desc;
  1519. res.max_sprites = _SBATCH_DEFAULT(res.max_sprites, 4096);
  1520. res.canvas_height = _SBATCH_DEFAULT(res.canvas_height, 480);
  1521. res.canvas_width = _SBATCH_DEFAULT(res.canvas_width, 640);
  1522. return res;
  1523. }
  1524. static void _sbatch_init_context(sbatch_context ctx_id, const sbatch_context_desc* in_desc) {
  1525. sg_push_debug_group("sokol-spritebatch");
  1526. SOKOL_ASSERT((ctx_id.id != SG_INVALID_ID) && in_desc);
  1527. _sbatch_context* ctx = _sbatch_lookup_context(ctx_id.id);
  1528. SOKOL_ASSERT(ctx);
  1529. ctx->update_frame_index = -1;
  1530. ctx->desc = _sbatch_context_desc_defaults(in_desc);
  1531. ctx->label = _sbatch_make_str(ctx->desc.label);
  1532. ctx->desc.label = NULL;
  1533. const int max_vertices = 4 * ctx->desc.max_sprites;
  1534. const size_t vbuf_size = (size_t)max_vertices * sizeof(_sbatch_vertex);
  1535. ctx->vertices = (_sbatch_vertex*)SOKOL_MALLOC(vbuf_size);
  1536. SOKOL_ASSERT(ctx->vertices);
  1537. ctx->images = (sg_image*)SOKOL_MALLOC((size_t)ctx->desc.max_sprites * sizeof(sg_image));
  1538. SOKOL_ASSERT(ctx->images);
  1539. ctx->pipeline.id = _SBATCH_DEFAULT(in_desc->pipeline.id, _sbatch.pipeline.id);
  1540. ctx->sprite_count = 0;
  1541. sg_buffer_desc vbuf_desc;
  1542. memset(&vbuf_desc, 0, sizeof(vbuf_desc));
  1543. vbuf_desc.size = vbuf_size;
  1544. vbuf_desc.type = SG_BUFFERTYPE_VERTEXBUFFER;
  1545. vbuf_desc.usage = SG_USAGE_STREAM;
  1546. vbuf_desc.label = "sokol-spritebatch-vertices";
  1547. ctx->vertex_buffer = sg_make_buffer(&vbuf_desc);
  1548. SOKOL_ASSERT(SG_INVALID_ID != ctx->vertex_buffer.id);
  1549. sg_pop_debug_group();
  1550. }
  1551. static void _sbatch_destroy_context(sbatch_context ctx_id) {
  1552. _sbatch_context* ctx = _sbatch_lookup_context(ctx_id.id);
  1553. if (ctx) {
  1554. if (ctx->vertices) {
  1555. SOKOL_FREE(ctx->vertices);
  1556. }
  1557. if (ctx->images) {
  1558. SOKOL_FREE(ctx->images);
  1559. }
  1560. sg_push_debug_group("sokol-spritebatch");
  1561. sg_destroy_buffer(ctx->vertex_buffer);
  1562. sg_pop_debug_group();
  1563. memset(ctx, 0, sizeof(*ctx));
  1564. _sbatch_pool_free_index(&_sbatch.context_pool.pool, _sbatch_slot_index(ctx_id.id));
  1565. }
  1566. }
  1567. static sg_pipeline_desc _sbatch_pipeline_desc_defaults(const sg_pipeline_desc* desc) {
  1568. sg_pipeline_desc pipeline_desc = *desc;
  1569. pipeline_desc.color_count = _SBATCH_DEFAULT(pipeline_desc.color_count, 1);
  1570. if (pipeline_desc.color_count == 1) {
  1571. pipeline_desc.colors[0].blend.enabled = _SBATCH_DEFAULT(desc->colors[0].blend.enabled, true);
  1572. pipeline_desc.colors[0].blend.src_factor_rgb = _SBATCH_DEFAULT(desc->colors[0].blend.src_factor_rgb, SG_BLENDFACTOR_ONE);
  1573. pipeline_desc.colors[0].blend.src_factor_alpha = _SBATCH_DEFAULT(desc->colors[0].blend.src_factor_rgb, SG_BLENDFACTOR_ONE);
  1574. pipeline_desc.colors[0].blend.dst_factor_rgb = _SBATCH_DEFAULT(desc->colors[0].blend.src_factor_rgb, SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA);
  1575. pipeline_desc.colors[0].blend.dst_factor_alpha = _SBATCH_DEFAULT(desc->colors[0].blend.src_factor_rgb, SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA);
  1576. }
  1577. pipeline_desc.shader.id = _SBATCH_DEFAULT(desc->shader.id, _sbatch.shader.id);
  1578. pipeline_desc.index_type = SG_INDEXTYPE_UINT16;
  1579. pipeline_desc.layout.attrs[0].format = SG_VERTEXFORMAT_FLOAT3;
  1580. pipeline_desc.layout.attrs[1].format = SG_VERTEXFORMAT_FLOAT2;
  1581. pipeline_desc.layout.attrs[2].format = SG_VERTEXFORMAT_UBYTE4N;
  1582. pipeline_desc.label = _SBATCH_DEFAULT(desc->label, "sokol-spritebatch-pipline");
  1583. return pipeline_desc;
  1584. }
  1585. static void _sbatch_init_pipeline(sbatch_pipeline pip_id, const sg_pipeline_desc* in_desc) {
  1586. sg_push_debug_group("sokol-spritebatch");
  1587. SOKOL_ASSERT((pip_id.id != SG_INVALID_ID) && in_desc);
  1588. _sbatch_pipeline* pip = _sbatch_lookup_pipeline(pip_id.id);
  1589. SOKOL_ASSERT(pip);
  1590. pip->desc = _sbatch_pipeline_desc_defaults(in_desc);
  1591. pip->label = _sbatch_make_str(pip->desc.label);
  1592. pip->desc.label = NULL;
  1593. pip->pipeline = sg_make_pipeline(&pip->desc);
  1594. SOKOL_ASSERT(pip->pipeline.id != SG_INVALID_ID);
  1595. sg_pop_debug_group();
  1596. }
  1597. static void _sbatch_destroy_pipeline(sbatch_pipeline pip_id) {
  1598. _sbatch_pipeline* pip = _sbatch_lookup_pipeline(pip_id.id);
  1599. if (pip) {
  1600. sg_push_debug_group("sokol-spritebatch");
  1601. sg_destroy_pipeline(pip->pipeline);
  1602. sg_pop_debug_group();
  1603. memset(pip, 0, sizeof(*pip));
  1604. _sbatch_pool_free_index(&_sbatch.pipeline_pool.pool, _sbatch_slot_index(pip_id.id));
  1605. }
  1606. }
  1607. static uint32_t _sbatch_pack_color_bytes(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
  1608. return (uint32_t)a << 24 | (uint32_t)b << 16 | (uint32_t)g << 8 | (uint32_t)r;
  1609. }
  1610. static float _sbatch_clampf(float v, float low, float high) {
  1611. if (v < low) {
  1612. return low;
  1613. }
  1614. if (v > high) {
  1615. return high;
  1616. }
  1617. return v;
  1618. }
  1619. static uint32_t _sbatch_pack_color(const sg_color* color) {
  1620. const uint8_t r = (uint8_t)(_sbatch_clampf(color->r, 0.0f, 1.0f) * 255.0f);
  1621. const uint8_t g = (uint8_t)(_sbatch_clampf(color->g, 0.0f, 1.0f) * 255.0f);
  1622. const uint8_t b = (uint8_t)(_sbatch_clampf(color->b, 0.0f, 1.0f) * 255.0f);
  1623. const uint8_t a = (uint8_t)(_sbatch_clampf(color->a, 0.0f, 1.0f) * 255.0f);
  1624. return _sbatch_pack_color_bytes(r, g, b, a);
  1625. }
  1626. static int _sg_image_slot_index(uint32_t id) {
  1627. int slot_index = (int)(id & _SBATCH_IMAGE_SLOT_MASK);
  1628. SOKOL_ASSERT(0 != slot_index);
  1629. return slot_index;
  1630. }
  1631. static void _sbatch_setup_sprite_pool(void) {
  1632. sg_desc sg_desc = sg_query_desc();
  1633. const int num_slots = sg_desc.image_pool_size;
  1634. _sbatch.sprite_pool.size = (size_t)num_slots * sizeof(_sbatch_sprite_data);
  1635. _sbatch.sprite_pool.data = (_sbatch_sprite_data*)SOKOL_MALLOC(_sbatch.sprite_pool.size);
  1636. SOKOL_ASSERT(_sbatch.sprite_pool.data);
  1637. memset(_sbatch.sprite_pool.data, 0, _sbatch.sprite_pool.size);
  1638. }
  1639. static void _sbatch_init_quad_rotated(
  1640. _sbatch_vertex* vertices, float x, float y, float dx, float dy,
  1641. float w, float h, float sin, float cos, uint32_t rgba,
  1642. sbatch_float2 top_left, sbatch_float2 bottom_right, float depth) {
  1643. _sbatch_vertex* top_left_vertex = vertices;
  1644. top_left_vertex->x = x + dx * cos - dy * sin;
  1645. top_left_vertex->y = y + dx * sin + dy * cos;
  1646. top_left_vertex->z = depth;
  1647. top_left_vertex->rgba = rgba;
  1648. top_left_vertex->u = top_left.x;
  1649. top_left_vertex->v = top_left.y;
  1650. _sbatch_vertex* top_right_vertex = vertices + 1;
  1651. top_right_vertex->x = x + (dx + w) * cos - dy * sin;
  1652. top_right_vertex->y = y + (dx + w) * sin + dy * cos;
  1653. top_right_vertex->z = depth;
  1654. top_right_vertex->rgba = rgba;
  1655. top_right_vertex->u = bottom_right.x;
  1656. top_right_vertex->v = top_left.y;
  1657. _sbatch_vertex* bottom_left_vertex = vertices + 2;
  1658. bottom_left_vertex->x = x + dx * cos - (dy + h) * sin;
  1659. bottom_left_vertex->y = y + dx * sin + (dy + h) * cos;
  1660. bottom_left_vertex->z = depth;
  1661. bottom_left_vertex->rgba = rgba;
  1662. bottom_left_vertex->u = top_left.x;
  1663. bottom_left_vertex->v = bottom_right.y;
  1664. _sbatch_vertex* bottom_right_vertex = vertices + 3;
  1665. bottom_right_vertex->x = x + (dx + w) * cos - (dy + h) * sin;
  1666. bottom_right_vertex->y = y + (dx + w) * sin + (dy + h) * cos;
  1667. bottom_right_vertex->z = depth;
  1668. bottom_right_vertex->rgba = rgba;
  1669. bottom_right_vertex->u = bottom_right.x;
  1670. bottom_right_vertex->v = bottom_right.y;
  1671. }
  1672. static void _sbatch_init_quad(
  1673. _sbatch_vertex* vertices, float x, float y, float w, float h, uint32_t rgba,
  1674. sbatch_float2 top_left, sbatch_float2 bottom_right, float depth) {
  1675. _sbatch_vertex* top_left_vertex = vertices;
  1676. top_left_vertex->x = x;
  1677. top_left_vertex->y = y;
  1678. top_left_vertex->z = depth;
  1679. top_left_vertex->rgba = rgba;
  1680. top_left_vertex->u = top_left.x;
  1681. top_left_vertex->v = top_left.y;
  1682. _sbatch_vertex* top_right_vertex = vertices + 1;
  1683. top_right_vertex->x = x + w;
  1684. top_right_vertex->y = y;
  1685. top_right_vertex->z = depth;
  1686. top_right_vertex->rgba = rgba;
  1687. top_right_vertex->u = bottom_right.x;
  1688. top_right_vertex->v = top_left.y;
  1689. _sbatch_vertex* bottom_left_vertex = vertices + 2;
  1690. bottom_left_vertex->x = x;
  1691. bottom_left_vertex->y = y + h;
  1692. bottom_left_vertex->z = depth;
  1693. bottom_left_vertex->rgba = rgba;
  1694. bottom_left_vertex->u = top_left.x;
  1695. bottom_left_vertex->v = bottom_right.y;
  1696. _sbatch_vertex* bottom_right_vertex = vertices + 3;
  1697. bottom_right_vertex->x = x + w;
  1698. bottom_right_vertex->y = y + h;
  1699. bottom_right_vertex->z = depth;
  1700. bottom_right_vertex->rgba = rgba;
  1701. bottom_right_vertex->u = bottom_right.x;
  1702. bottom_right_vertex->v = bottom_right.y;
  1703. }
  1704. static void _sbatch_init_index_buffer(void) {
  1705. uint16_t* index_buffer = (uint16_t*)SOKOL_MALLOC(_SBATCH_MAX_INDICES * sizeof(uint16_t));
  1706. SOKOL_ASSERT(index_buffer);
  1707. uint16_t* index_ptr = index_buffer;
  1708. for (uint32_t i = 0; i < _SBATCH_MAX_QUADS; i++, index_ptr += 6) {
  1709. // Triangle 1
  1710. *(index_ptr + 0) = (uint16_t)(i * 4);
  1711. *(index_ptr + 1) = (uint16_t)(i * 4 + 1);
  1712. *(index_ptr + 2) = (uint16_t)(i * 4 + 2);
  1713. // Triangle 2
  1714. *(index_ptr + 3) = (uint16_t)(i * 4 + 1);
  1715. *(index_ptr + 4) = (uint16_t)(i * 4 + 3);
  1716. *(index_ptr + 5) = (uint16_t)(i * 4 + 2);
  1717. }
  1718. sg_buffer_desc index_buffer_desc;
  1719. memset(&index_buffer_desc, 0, sizeof(index_buffer_desc));
  1720. index_buffer_desc.size = _SBATCH_MAX_INDICES * sizeof(uint16_t);
  1721. index_buffer_desc.type = SG_BUFFERTYPE_INDEXBUFFER;
  1722. index_buffer_desc.usage = SG_USAGE_IMMUTABLE;
  1723. index_buffer_desc.label = "sokol-spritebatch-indices";
  1724. index_buffer_desc.data.size = _SBATCH_MAX_INDICES * sizeof(uint16_t);
  1725. index_buffer_desc.data.ptr = index_buffer;
  1726. _sbatch.index_buffer = sg_make_buffer(&index_buffer_desc);
  1727. SOKOL_ASSERT(SG_INVALID_ID != _sbatch.index_buffer.id);
  1728. SOKOL_FREE(index_buffer);
  1729. _sbatch.bindings.index_buffer = _sbatch.index_buffer;
  1730. }
  1731. static bool _sbatch_rect_is_valid(const sbatch_rect* rect) {
  1732. if (rect->width != 0.0f && rect->height != 0.0f) {
  1733. return true;
  1734. }
  1735. return false;
  1736. }
  1737. SOKOL_SPRITEBATCH_API_DECL int sbatch_frame() {
  1738. return ++_sbatch.frame_index;
  1739. }
  1740. SOKOL_API_IMPL void sbatch_setup(const sbatch_desc* desc) {
  1741. memset(&_sbatch, 0, sizeof _sbatch);
  1742. sbatch_desc batch_desc = *desc;
  1743. batch_desc.context_pool_size = _SBATCH_DEFAULT(batch_desc.context_pool_size, 32);
  1744. batch_desc.pipeline_pool_size = _SBATCH_DEFAULT(batch_desc.pipeline_pool_size, 32);
  1745. _sbatch_setup_context_pool(&batch_desc);
  1746. _sbatch_setup_pipeline_pool(&batch_desc);
  1747. _sbatch_setup_sprite_pool();
  1748. _sbatch.shader = sg_make_shader(spritebatch_shader_desc(sg_query_backend()));
  1749. sg_pipeline_desc pipeline_desc;
  1750. memset(&pipeline_desc, 0, sizeof(sg_pipeline_desc));
  1751. pipeline_desc.shader = _sbatch.shader;
  1752. pipeline_desc.label = "spritebatch-default-pipeline";
  1753. pipeline_desc.color_count = 1;
  1754. pipeline_desc.colors[0].pixel_format = desc->color_format;
  1755. pipeline_desc.depth.pixel_format = desc->depth_format;
  1756. pipeline_desc.sample_count = desc->sample_count;
  1757. _sbatch.pipeline = sbatch_make_pipeline(&pipeline_desc);
  1758. _sbatch_init_index_buffer();
  1759. }
  1760. SOKOL_API_IMPL void sbatch_shutdown(void) {
  1761. sg_destroy_buffer(_sbatch.index_buffer);
  1762. sbatch_destroy_pipeline(_sbatch.pipeline);
  1763. sg_destroy_shader(_sbatch.shader);
  1764. SOKOL_FREE(_sbatch.sprite_pool.data);
  1765. _sbatch_discard_pipeline_pool();
  1766. _sbatch_discard_context_pool();
  1767. }
  1768. SOKOL_SPRITEBATCH_API_DECL sbatch_pipeline sbatch_make_pipeline(const sg_pipeline_desc* desc) {
  1769. SOKOL_ASSERT(desc);
  1770. const sbatch_pipeline result = _sbatch_alloc_pipeline();
  1771. _sbatch_init_pipeline(result, desc);
  1772. return result;
  1773. }
  1774. SOKOL_SPRITEBATCH_API_DECL void sbatch_destroy_pipeline(sbatch_pipeline pipeline) {
  1775. SOKOL_ASSERT(pipeline.id != SG_INVALID_ID);
  1776. _sbatch_destroy_pipeline(pipeline);
  1777. }
  1778. SOKOL_API_IMPL sbatch_context sbatch_make_context(const sbatch_context_desc* desc) {
  1779. SOKOL_ASSERT(desc);
  1780. const sbatch_context result = _sbatch_alloc_context();
  1781. _sbatch_init_context(result, desc);
  1782. return result;
  1783. }
  1784. SOKOL_API_IMPL void sbatch_destroy_context(sbatch_context context) {
  1785. SOKOL_ASSERT(context.id != SG_INVALID_ID);
  1786. _sbatch_destroy_context(context);
  1787. }
  1788. SOKOL_API_IMPL void sbatch_begin(sbatch_context context) {
  1789. SOKOL_ASSERT(context.id != SG_INVALID_ID);
  1790. _sbatch.ctx_id = context;
  1791. SOKOL_ASSERT(!_sbatch.begin_called);
  1792. _sbatch.begin_called = true;
  1793. _sbatch_context* ctx = _sbatch_context_at(_sbatch.ctx_id.id);
  1794. // a sbatch_context object can only be used in one sbatch_begin call per frame.
  1795. SOKOL_ASSERT(_sbatch.frame_index != ctx->update_frame_index);
  1796. ctx->update_frame_index = _sbatch.frame_index;
  1797. SOKOL_ASSERT(ctx);
  1798. _sbatch.bindings.vertex_buffers[0] = ctx->vertex_buffer;
  1799. }
  1800. SOKOL_API_IMPL void sbatch_push_sprite(const sbatch_sprite* sprite) {
  1801. SOKOL_ASSERT(sprite);
  1802. SOKOL_ASSERT(sprite->image.id != SG_INVALID_ID);
  1803. _sbatch_context* ctx = _sbatch_context_at(_sbatch.ctx_id.id);
  1804. SOKOL_ASSERT(ctx);
  1805. if (ctx->sprite_count < ctx->desc.max_sprites) {
  1806. const int sprite_index = ctx->sprite_count++;
  1807. _sbatch_sprite_data* cached_sprite_data = &_sbatch.sprite_pool.data[_sg_image_slot_index(sprite->image.id)];
  1808. if (cached_sprite_data->image.id != sprite->image.id) {
  1809. const sg_image_info info = sg_query_image_info(sprite->image);
  1810. cached_sprite_data->height = info.height;
  1811. cached_sprite_data->width = info.width;
  1812. cached_sprite_data->texel_height = 1.0f / (float)info.height;
  1813. cached_sprite_data->texel_width = 1.0f / (float)info.width;
  1814. cached_sprite_data->image = sprite->image;
  1815. }
  1816. const sbatch_float2 scale = { _SBATCH_DEFAULT(sprite->scale.x, 1.0f), _SBATCH_DEFAULT(sprite->scale.y, 1.0f) };
  1817. const sbatch_float2 scaled_origin = { scale.x * sprite->origin.x, scale.y * sprite->origin.y };
  1818. float width, height;
  1819. sbatch_float2 tex_coord_top_left;
  1820. sbatch_float2 tex_coord_bottom_right;
  1821. if (_sbatch_rect_is_valid(&sprite->source)) {
  1822. width = sprite->source.width * scale.x;
  1823. height = sprite->source.height * scale.y;
  1824. tex_coord_top_left.x = sprite->source.x * cached_sprite_data->texel_width;
  1825. tex_coord_top_left.y = sprite->source.y * cached_sprite_data->texel_height;
  1826. tex_coord_bottom_right.x = (sprite->source.x + sprite->source.width) * cached_sprite_data->texel_width;
  1827. tex_coord_bottom_right.y = (sprite->source.y + sprite->source.height) * cached_sprite_data->texel_height;
  1828. } else {
  1829. width = (float)cached_sprite_data->width * scale.x;
  1830. height = (float)cached_sprite_data->height * scale.y;
  1831. tex_coord_top_left.x = 0.0f;
  1832. tex_coord_top_left.y = 0.0f;
  1833. tex_coord_bottom_right.x = 1.0f;
  1834. tex_coord_bottom_right.y = 1.0f;
  1835. }
  1836. if ((sprite->flags & SBATCH_FLIP_Y) != SBATCH_FLIP_NONE) {
  1837. const float temp = tex_coord_bottom_right.y;
  1838. tex_coord_bottom_right.y = tex_coord_top_left.y;
  1839. tex_coord_top_left.y = temp;
  1840. }
  1841. if ((sprite->flags & SBATCH_FLIP_X) != SBATCH_FLIP_NONE) {
  1842. const float temp = tex_coord_bottom_right.x;
  1843. tex_coord_bottom_right.x = tex_coord_top_left.x;
  1844. tex_coord_top_left.x = temp;
  1845. }
  1846. uint32_t packed_color = sprite->color ? _sbatch_pack_color(sprite->color) : 0xFFFFFFFF;
  1847. ctx->images[sprite_index] = sprite->image;
  1848. const int base_vertex_index = sprite_index * 4;
  1849. _sbatch_vertex* vertices = ctx->vertices + base_vertex_index;
  1850. if (sprite->rotation == 0.0f) {
  1851. _sbatch_init_quad(vertices,
  1852. sprite->position.x - scaled_origin.x,
  1853. sprite->position.y - scaled_origin.y,
  1854. width,
  1855. height,
  1856. packed_color,
  1857. tex_coord_top_left,
  1858. tex_coord_bottom_right,
  1859. sprite->depth);
  1860. } else {
  1861. _sbatch_init_quad_rotated(vertices,
  1862. sprite->position.x,
  1863. sprite->position.y,
  1864. -scaled_origin.x,
  1865. -scaled_origin.y,
  1866. width,
  1867. height,
  1868. sinf(sprite->rotation),
  1869. cosf(sprite->rotation),
  1870. packed_color,
  1871. tex_coord_top_left,
  1872. tex_coord_bottom_right,
  1873. sprite->depth);
  1874. }
  1875. } else {
  1876. if (ctx->label.buf[0] != '\0') {
  1877. SOKOL_LOG("sokol_spritebatch.h: dropped sprites, increase max_sprites of sbatch_context:");
  1878. SOKOL_LOG(ctx->label.buf);
  1879. } else {
  1880. SOKOL_LOG("sokol_spritebatch.h: dropped sprites, increase max_sprites");
  1881. }
  1882. }
  1883. }
  1884. SOKOL_API_IMPL void sbatch_push_sprite_rect(const sbatch_sprite_rect* sprite) {
  1885. SOKOL_ASSERT(sprite);
  1886. SOKOL_ASSERT(sprite->image.id != SG_INVALID_ID);
  1887. _sbatch_context* ctx = _sbatch_context_at(_sbatch.ctx_id.id);
  1888. SOKOL_ASSERT(ctx);
  1889. if (ctx->sprite_count < ctx->desc.max_sprites) {
  1890. const int sprite_index = ctx->sprite_count++;
  1891. _sbatch_sprite_data* cached_sprite_data = &_sbatch.sprite_pool.data[_sg_image_slot_index(sprite->image.id)];
  1892. if (cached_sprite_data->image.id != sprite->image.id) {
  1893. const sg_image_info info = sg_query_image_info(sprite->image);
  1894. cached_sprite_data->height = info.height;
  1895. cached_sprite_data->width = info.width;
  1896. cached_sprite_data->texel_height = 1.0f / (float)info.height;
  1897. cached_sprite_data->texel_width = 1.0f / (float)info.width;
  1898. cached_sprite_data->image = sprite->image;
  1899. }
  1900. sbatch_float2 scaled_origin;
  1901. sbatch_float2 tex_coord_top_left;
  1902. sbatch_float2 tex_coord_bottom_right;
  1903. if (_sbatch_rect_is_valid(&sprite->source)) {
  1904. tex_coord_top_left.x = sprite->source.x * cached_sprite_data->texel_width;
  1905. tex_coord_top_left.y = sprite->source.y * cached_sprite_data->texel_height;
  1906. tex_coord_bottom_right.x = (sprite->source.x + sprite->source.width) * cached_sprite_data->texel_width;
  1907. tex_coord_bottom_right.y = (sprite->source.y + sprite->source.height) * cached_sprite_data->texel_height;
  1908. scaled_origin.x = sprite->origin.x * sprite->destination.width / sprite->source.width;
  1909. scaled_origin.y = sprite->origin.y * sprite->destination.height / sprite->source.height;
  1910. } else {
  1911. tex_coord_top_left.x = 0.0f;
  1912. tex_coord_top_left.y = 0.0f;
  1913. tex_coord_bottom_right.x = 1.0f;
  1914. tex_coord_bottom_right.y = 1.0f;
  1915. scaled_origin.x = sprite->origin.x * sprite->destination.width * cached_sprite_data->texel_width;
  1916. scaled_origin.y = sprite->origin.y * sprite->destination.height * cached_sprite_data->texel_height;
  1917. }
  1918. if ((sprite->flags & SBATCH_FLIP_Y) != SBATCH_FLIP_NONE) {
  1919. const float temp = tex_coord_bottom_right.y;
  1920. tex_coord_bottom_right.y = tex_coord_top_left.y;
  1921. tex_coord_top_left.y = temp;
  1922. }
  1923. if ((sprite->flags & SBATCH_FLIP_X) != SBATCH_FLIP_NONE) {
  1924. const float temp = tex_coord_bottom_right.x;
  1925. tex_coord_bottom_right.x = tex_coord_top_left.x;
  1926. tex_coord_top_left.x = temp;
  1927. }
  1928. uint32_t packed_color = sprite->color ? _sbatch_pack_color(sprite->color) : 0xFFFFFFFF;
  1929. ctx->images[sprite_index] = sprite->image;
  1930. const int base_vertex_index = sprite_index * 4;
  1931. _sbatch_vertex* vertices = ctx->vertices + base_vertex_index;
  1932. if (sprite->rotation == 0.0f) {
  1933. _sbatch_init_quad(vertices,
  1934. sprite->destination.x - scaled_origin.x,
  1935. sprite->destination.y - scaled_origin.y,
  1936. sprite->destination.width,
  1937. sprite->destination.height,
  1938. packed_color,
  1939. tex_coord_top_left,
  1940. tex_coord_bottom_right,
  1941. sprite->depth);
  1942. } else {
  1943. _sbatch_init_quad_rotated(vertices,
  1944. sprite->destination.x,
  1945. sprite->destination.y,
  1946. -scaled_origin.x,
  1947. -scaled_origin.y,
  1948. sprite->destination.width,
  1949. sprite->destination.height,
  1950. sinf(sprite->rotation),
  1951. cosf(sprite->rotation),
  1952. packed_color,
  1953. tex_coord_top_left,
  1954. tex_coord_bottom_right,
  1955. sprite->depth);
  1956. }
  1957. } else {
  1958. if (ctx->label.buf[0] != '\0') {
  1959. SOKOL_LOG("sokol_spritebatch.h: dropped sprites, increase max_sprites of sbatch_context:");
  1960. SOKOL_LOG(ctx->label.buf);
  1961. } else {
  1962. SOKOL_LOG("sokol_spritebatch.h: dropped sprites, increase max_sprites");
  1963. }
  1964. }
  1965. }
  1966. static void _sbatch_draw(int base_element, sg_image current_image, int num_elements) {
  1967. _sbatch.bindings.fs_images[0] = current_image;
  1968. sg_apply_bindings(&_sbatch.bindings);
  1969. sg_draw(base_element, num_elements, 1);
  1970. }
  1971. static _sbatch_mat4x4 _sbatch_orthographic_off_center(float left, float right, float bottom, float top, float z_near, float z_far) {
  1972. _sbatch_mat4x4 result;
  1973. result.m[0][0] = 2.0f / (right - left);
  1974. result.m[0][1] = 0.0f;
  1975. result.m[0][2] = 0.0f;
  1976. result.m[0][3] = 0.0f;
  1977. result.m[1][0] = 0.0f;
  1978. result.m[1][1] = 2.0f / (top - bottom);
  1979. result.m[1][2] = 0.0f;
  1980. result.m[1][3] = 0.0f;
  1981. result.m[2][0] = 0.0f;
  1982. result.m[2][1] = 0.0f;
  1983. result.m[2][2] = 1.0f / (z_near - z_far);
  1984. result.m[2][3] = 0.0f;
  1985. result.m[3][0] = (left + right) / (left - right);
  1986. result.m[3][1] = (bottom + top) / (bottom - top);
  1987. result.m[3][2] = z_near / (z_near - z_far);
  1988. result.m[3][3] = 1.0f;
  1989. return result;
  1990. }
  1991. void sbatch_end(void) {
  1992. SOKOL_ASSERT(_sbatch.begin_called);
  1993. _sbatch.begin_called = false;
  1994. _sbatch_context* ctx = _sbatch_context_at(_sbatch.ctx_id.id);
  1995. SOKOL_ASSERT(ctx);
  1996. if (ctx->sprite_count == 0) {
  1997. return;
  1998. }
  1999. const int max_vertices = 4 * ctx->sprite_count;
  2000. const size_t vbuf_size = (size_t)max_vertices * sizeof(_sbatch_vertex);
  2001. const sg_range range = { ctx->vertices, vbuf_size };
  2002. sg_update_buffer(ctx->vertex_buffer, &range);
  2003. int batch_size = 0;
  2004. int base_element = 0;
  2005. sg_image current_image = ctx->images[0];
  2006. const _sbatch_pipeline* pipeline = _sbatch_pipeline_at(ctx->pipeline.id);
  2007. sg_apply_pipeline(pipeline->pipeline);
  2008. sg_apply_viewportf(0.0f, 0.0f, (float)ctx->desc.canvas_width, (float)ctx->desc.canvas_height, true);
  2009. _sbatch_mat4x4 matrix =
  2010. _sbatch_orthographic_off_center(0.0f, (float)ctx->desc.canvas_width, (float)ctx->desc.canvas_height, 0.0f, 0.0f, 1000.0f);
  2011. const sg_range matrix_range = { &matrix, sizeof matrix };
  2012. sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &matrix_range);
  2013. if(ctx->fs_uniform_state.data) {
  2014. sg_apply_uniforms(SG_SHADERSTAGE_FS, ctx->fs_uniform_state.ub_index, ctx->fs_uniform_state.data);
  2015. }
  2016. for (int i = 0; i < ctx->sprite_count; ++i, ++batch_size) {
  2017. if (ctx->images[i].id != current_image.id) {
  2018. const int num_elements = batch_size * 6;
  2019. _sbatch_draw(base_element, current_image, num_elements);
  2020. batch_size = 0;
  2021. base_element += num_elements;
  2022. current_image = ctx->images[i];
  2023. }
  2024. }
  2025. const int num_elements = batch_size * 6;
  2026. _sbatch_draw(base_element, current_image, num_elements);
  2027. ctx->sprite_count = 0;
  2028. }
  2029. SOKOL_API_IMPL void sbatch_apply_fs_uniforms(int ub_index, const sg_range* data) {
  2030. SOKOL_ASSERT(data);
  2031. SOKOL_ASSERT(data->ptr);
  2032. _sbatch_context* ctx = _sbatch_context_at(_sbatch.ctx_id.id);
  2033. ctx->fs_uniform_state.ub_index = ub_index;
  2034. ctx->fs_uniform_state.data = data;
  2035. }
  2036. SOKOL_API_IMPL void sbatch_premultiply_alpha_rgba8(uint8_t* pixels, int pixel_count) {
  2037. SOKOL_ASSERT(pixels);
  2038. for (int i = 0; i < pixel_count; ++i) {
  2039. pixels[0] = pixels[0] * pixels[3] / 255;
  2040. pixels[1] = pixels[1] * pixels[3] / 255;
  2041. pixels[2] = pixels[2] * pixels[3] / 255;
  2042. pixels += 4;
  2043. }
  2044. }
  2045. #endif /* SOKOL_SPRITEBATCH_IMPL */